Question

Clip images based on polygon and export new images include point label


Badge +5
Hi everybody,

 

 

I have a point file and an image file. I made buffer square for point file.

 

 

My target is clipping image file based on buffer square and display points lable into images extracted. And when raster exported include point and name attribute's point.

 

 

Could you tell me the solution to make it?

 

 

 

20 replies

Userlevel 2
Badge +17
Hi Hoa,

 

 

The Clipper can be used to clip the raster by the sqaure polygons. But you will have to create copies of the raster for each square since there are overlaps of some squares.

 

One possible way is:

 

(1) Set unique ID attribute to the sqaures. If they have unique attribute already, you can use that. Otherwise, use the Counter to add sequential number to them as temporary ID.

 

(2) Add a FeatureMerger; send the original raster to the Requestor port; send the squares to the Supplier port.

 

- Join On: Requestor 1, Supplier 1 (unconditional merging)

 

- Feature Merge Type: Attributes Only

 

- Process Duplicate Suppliers: Yes

 

- List Name: _list

 

(3) Connect a ListExploder to the Merged port of the FeatureMerger; set "_list{}" to the List Attribute parameter. The raster will be copied for each square, and the copied rasters have all attributes including the ID of square for each.

 

(4) Add a Clipper; send the original squares to the Clipper port; send the copied rasters to the Clippee port; set the ID attribute to the "Group By" parameter.

 

- Merge Attributes: Yes (Accumulation Mode: Merge Clipper)

 

 

Required clipped rasters will be output from the Inside port of the Clipper, each raster  will have attributes of associated square (i.e. the clipper).

 

I think you can then draw a point and a text onto each raster.

 

 

Takashi
Badge +3
I fyour raster is big, you might consider to not copy it.

 

 

If you use the clippers on a single raster, you can create a list of the clipper id's on each clipped raster part.

 

Then create a comma separated string out of it.

 

By testing each id against the id-string you can construct the rasters for each box
Badge +5
Thank you Takashi and Gio. I export to .jpg file with name images.

 

 

No way to print label attributes images on each image like my target, right?

 

 

Because I have too many images, if I make to draw and label for each image, it lost many times.

 

 

 

 
Userlevel 2
Badge +17
You can use the VectorOnRasterOverlayer (basic) or the MapnikRasterizer (advanced) to draw text and point onto a raster.

 

See the help docs on the transformers to learn more about the usage.

 

VecrotOnRasteerOverlayer (http://docs.safe.com/fme/html/FME_Desktop_Documentation/FME_Desktop_Help.htm#../Subsystems/FME_Transformers/Content/Transformers/vectoronrasteroverlayer.htm)

 

MapnikRasterizer (http://docs.safe.com/fme/html/FME_Desktop_Documentation/FME_Desktop_Help.htm#../Subsystems/FME_Transformers/Content/Transformers/mapnikrasterizer.htm)
Badge +5
Hi Takashi,

 

 

Thank you so much. I saw the VectorOnRasterOverlayer or the MapnikRasterizer to get only a raster image, right?

 

 

I cliped all part images . Then, I use MapnikRasterizer to make overlay image and point ?

 

 

 

 

 
Badge +3
Yes, you can use either of them to put the labels on your rasters.
Userlevel 2
Badge +17
I share a workspace (FME 2015.0) which illustrates basic usage of the MapnikRasterizer to draw a label text and a point marker onto a raster.

 

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

 

 

The transformer has many options/parameters, cannot explain all of them.

 

This article would be a good start point to learn more about the transformer.

 

FMEpedia - Introduction to MapnikRasterizer (http://fmepedia.safe.com/articles/Samples_and_Demos/Introduction-to-MapnikRasterizer)
Userlevel 2
Badge +17
This example is better. I removed the previous link.

 

https://drive.google.com/file/d/0B0ufVP2t0eApb0JxQkxxcllhRWc/view?usp=sharing
Badge +5
Thank you, Takashi and Gio.

 

 

I tried it with a raster image, It's ok. But I have many raster images and a point file (many point).

 

 

I see MapnikRasterizer get only point and only raster.

 

Could you tell me how to batch for many raster images?

 

 

Thank you

 

 
Userlevel 2
Badge +17
If you give a common attribute to the raster and associated point, you can set it to the "Group By" parameter of the MapnikRasterizer, so that the input features will be processed for each individual pair of raster and point.

 

 

The ID attribute which I mentioned in my first post can also be used as the common attribute for the grouping, if you have clipped the original raster by the procedure that I suggested.
Badge +5
Dear Takashi,

 

 

I made it as the image below but I still get error.

 

I don't know why :(. Could you tell me why?

 

 

Thank you

 

Userlevel 2
Badge +17
How did you set "Group By" parameter of the Clipper?
Badge +5
I set "Group BY" parameter based on img_name :(. Maybe, it does not run because that parameter?
Userlevel 2
Badge +17
The number of input polygons is 1076, but the number of clipped features is 1605.

 

It's strange.

 

Is "img_name" an attribute of the polygons?

 

Is "img_name" value unique for each polygon?
Userlevel 2
Badge +17
Anyway, first of all, check if the clipped features are created as expected.
Badge +5
I checked the model. I see mapnikRassterizer didn't get img_name attribute.

 

So It can't run :(.

 

 

Badge +5
Hi Takashi,

 

 

Img_name is like ID name for each polygon. It's value unique for each polygon
Userlevel 2
Badge +17
Looks like you forgot to set "img_name" to the "Group By" for the MapnikRasterizer.

 

 

And, why do you send polygons to the MapnikRasterizer? You will have to set Symbolizer appropriately for polygons, if you send the buffer polygons instead of the original points.

 

Usage of the MapnikRasterizer is not so simple. I would recommend you to learn the usage with simple exmaples. See the help of the transformer and this link. (http://fmepedia.safe.com/articles/Samples_and_Demos/Introduction-to-MapnikRasterizer)

 

 

In addition, I can see a warning message (blue text) in the Log window.

 

Have you checked whether the clipped rasters have been created properly?
Userlevel 2
Badge +17
If every point is located at the center of the buffer polygon, you can transform each polygon into the original point using the CenterPointReplacer.
Badge +5
Oh, I mistake model. I put point file to send mapnikRasterizer and edit "Group by" for Mapnik. 

 

 

I done it :). It's successful . Thank you so much, Takashi and Gio .

 

 

So great !

 

Reply