I am trying to match a large set (43M) of small circular polygons to a smaller set of very large polygons.

To make this process as fast as possible I've created points from the centers of the small polygons and have successfully matched them to the the larger polygons substantially faster than before using the following code:

Large_poly_layer > The very large polygons pts > points data source

for large_poly in Large_poly_layer:
    polygeom = large_poly.GetGeometryRef()
    for pt in pts:
        fid = pt.GetFID()
        // this then writes the FID to a numpy array

Now what I am trying to do is obtain any points that didn't match, so that I can buffer them into polygons and see if they'll match at that points.

I think the fastest way to do this would be to do the inverse of the spatial filter but I cannot find a decent way to do it.

I have also attempted the following:

-copying the whole large point dataset to a memory layer in ogr then deleting points that have matched, but the lack of spatial indexing in the memory format makes this process incredibly slow.

-I also cannot write back to the original source data as it is contained in a .gdb file

  • Are the small circular polygons the same size? – Marc Pfister Dec 12 '18 at 14:54
  • No, they vary in size between 25m and 75m – Francis Dec 12 '18 at 15:02

Inverting your current filter means you would have the rest of the 43m points to search through, so that doesn't sound good.

Since you know the radius of your circles, you can buffer the big polygons by the largest radius and then search for points that intersect the polygon's boundary, which should get any of the circles that have centers outside the polygon but still overlap.

My recommendation would be use a spatial index like rtree to check for bounding box intersections, then shapely to make sure the circle is actually fully inside the polygon.

  • Buffering the larger polygons seems like a good idea to try next, I'll give it a go and report back. – Francis Dec 12 '18 at 15:15
  • +1 but some of 25-m radius circles could be in the 75 m buffer without overlapping the non buffered large polygon. One more step is still necessary (the approach would be perfect with buffers of the same size) and in any case this will reduce the number of candidates. If there are only a few possible buffer sizes, select by attribute could help. – radouxju Dec 12 '18 at 15:16
  • Good point - you may have to select all the points inside the 75m buffer and outside the polygon instead. – Marc Pfister Dec 12 '18 at 15:28
  • I am currently trying to play with the SetAttributeFilter so that I can exclude matched polygons, any polygons that previously matched are having a field altered from 0 to 1 then I can filter out the 1's – Francis Dec 12 '18 at 15:30
  • You could also select with a polygon and store the FIDs in a list, then select again with a buffered polygon and skip any FIDs you already have. Or use a Python set to store FIDs. – Marc Pfister Dec 12 '18 at 15:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.