Question

Fill polygon with raster

  • 24 February 2015
  • 15 replies
  • 18 views

Hi,

 

 

I have a polygon (shp), and i would like to produce a raster, that is to say, I want to fill the polygon with a seamless texture. The output raster will thus have transparent value outside the polygon, and should make a padding of the image texture inside the polygon.

 

 

Best regards,

 

 

Asher

15 replies

Userlevel 4
Hi,

 

 

Create a raster that is at least as big as the bounding box of your polygon, then use the Clipper to set all values outside the polygon to NODATA.

 

 

David
Thanks David for your answer. Seems good to fill outside values, but, how o handle inside values (by repeating a texture) ?

 

 

Regards
Userlevel 2
Badge +17
Hi,

 

 

This may work as expected if the raster interpretation is RGBA32 or RGBA64.

 

- Clip the raster by the polygons (Clipper).

 

- Set 0 to Nodata value for the clipped rasters (RasterBandNodataSetter).

 

- Mosaic them (RasterMosaicker).

 

- Remove the Nodata setting (RasterBandNodateRemover).

 

 

Value of the 4th band (A: Alpha) controls the transparency of cells.

 

If the interpretation was not RGBA*, consider changing the interpretation to RGBA* before setting Nodata, with the RasterInterpretationCoercer.

 

 

Takashi
Userlevel 2
Badge +17
Correction. If you need to change the interpretation of the raster, it should be performed before clipping.
Takashi, thanks for your answer. However, I am not sure I understand the way to process.

 

As input, I only have a polygon (created from the coast line). I want to create a raster with its extent defined by the bounding box of the polygon and the same coordinate system. Then, I would like for the raster all of its values outside the polygon transparent, and apply a texture inside the polygon. I may have forgive to mention that my texture is only a few pixels widht and height (lets say 512x512) and that the raster I would like to create is by far bigger. Thus, the texture has to be repeated (it is a seamless texture, so it should not be a problem).

 

Test data can be downloaded from this link: https://www.dropbox.com/sh/89vypj28i8bhu3r/AACWPCzyHu9Iv1EoXz7xWHH6a?dl=0

 

 

Hope you could help
Badge +3
Hi i checked your data.

 

 

If u use such a small texture on such a large area you need to seamlessly flip and order a very large number of these.

 

I think that is not very usefull as the  resolution of the texture is way to fine for such size, or the scale for taht matter.

 

 

I build a bit, but had no patience to wait for the mapping of the grid i created on the boundingobx of the seashape.

 

 

A maybe faster way would be to turn it into a surface.

 

Turn the sea polygon into a surface by elevating it like a small amount.

 

Then simply use the Surface Draper. You have control over the texturemapping with that tool.

 

Then create a boundingbox and clip outside bit.

 

 

combine into a raster.

 

 

 
Thanks Takashi. How can I go from SurfaceDrapper to raster ?

 

another point : the size of the output raster depends on its resolution. Isn't It possible to control this in order to have a reasonnable computation time ? Can you please share your workbench si I van try to play with?

 

 

Regards
Userlevel 2
Badge +17
I got your requirement. The points are:

 

1. Create a texture raster covering extent of the shape.

 

2. Add Alpha band to the raster so that Nodata area will be transparent.

 

3. Clip the raster by the shape.

 

See this demo. (https://drive.google.com/file/d/0B0ufVP2t0eApLUdqUzhtNjV3NUU/view?usp=sharing)

 

 

Including two workspaces; one for FME 2014 SP5, another for FME 2015.0.

 

Not including source data. Set your sample data to readers before running. 
Userlevel 2
Badge +17
Probably the data flow is equivalent to the first David's suggestion.
Userlevel 2
Badge +17
I thought the polygon is land, but perhaps I was wrong?

 

If the polygon represents water area, use the Inside featue output from the last Clipper.
Badge +3
Hi here is a workspace.

 

 (forget about the surface drapething...too much hassle..)

 

 

i scaled yopur texture by 10 to speed up proces, this takes 39 sec for 2 rasters (you can make parameter of this)

 

zoom in ..

 

 

 

output raster:

 

 

 

Badge +3

 

 

btw to make it seemless you can refer to this site (one of many)http://design.tutsplus.com/articles/how-to-turn-a-texture-into-a-seamlessly-tiled-background--psd-1565

 

 

This is somewhat hard to do in fme, but with some effort i guess it can e done.
Badge +3
..ok forgot alpha

 

 

here is with alpha

 

 

 

much more efficient as it now does 8.7 secs for 2 rasters as i removed the mosaickers...
Badge +3
...last 2 intepretationcoercers are not needed, just set the one prior to clipper to "createalphafromnodata"
Userlevel 2
Badge +17
Upgraded my demo workspace inspired by Gio's solution.

 

Thanks for the Affiner suggestion.

 

download: (https://drive.google.com/file/d/0B0ufVP2t0eApQk15T1h4NFNDdlE/view?usp=sharing)

Reply