Question

Loop through features of a shapefile to use them sequentially as clippers


Badge

I would like to use each polygon of a shapefile sequentially to clip a big raster then coerce that raster clippee to points and do a PointOnAreaOverlayer to get _overlaps for each polygon (in a new field in the polygons shapefile). How would I go about doing that ?


4 replies

Userlevel 4

Sounds like you've pretty much described the solution to your question :-)

What have you tried so far and why didn't you get the desired result?

Userlevel 5
Badge +25

I wouldn't use the Clipper to be honest. SpatialFilter does the trick too. I'd also turn the raster into points before doing that spatial filter:

If your polygons don't overlap they'll pass on their attributes to the points.

Userlevel 2
Badge +17

If the polygons do not overlap each other, you can just apply the Clipper or the SpatialFilter.

Otherwise, you may have to create copies of the raster for every polygon, then clip each raster by corresponding polygon, one by one.

Tips. If the goal is to count the number of raster cells within each polygon, it would also be possible to transform the raster into a point cloud, clip it by the polygons, then count the number of points with the PointCloudPropertyExtractor. The PointCloudPropertyExtractor adds only an attribute called "_num_points" that stores the number of points, if you unchecked all components in the parameters. I expect using point cloud could be faster than coercing the raster into points.

Badge

My raster would contain over 1 billion points if I coerced it all at once. My shapefile contains over 3000 polygons. Here is my workbench as it is now. It clips the raster only once to the extent of all the polygons together. I would like to loop somehow so the raster gets clipped 3000 times sequentially with one polygon at a time. I looked at a Loop Custom Transformer but I don't yet get how to use it.

Reply