[gdal-dev] Intersection of two Layers

Even Rouault even.rouault at spatialys.com
Tue Jan 19 04:09:43 PST 2016


Le mardi 19 janvier 2016 08:40:30, Ari Jolma a écrit :
> 18.01.2016, 11:56, Kai Muehlbauer kirjoitti:
> > Hi,
> > 
> > at the moment I calculate the intersection of two OGR Layers (A, B) by
> > iterating over features/geometries (GA) of layer A and then calling
> > GA.Intersection(GB) for every Feature/Geometry (GB) of B. I set a
> > spatial filter for layer B with every GA. The intersections
> > features/geometries are written to a result layer (C).
> > 
> > In my use case the features/geometries of layer B are much smaller
> > than the features of layer A. Means that quite a big number of B's
> > geometries are fully contained in A's geometries.
> > 
> > To speed things up, I check for containment GA.contains(GB). If GB is
> > contained in GA, I just copy GB to C, otherwise I calculate
> > GA.Intersection(GB) and write this to C.
> > 
> > I found that I also could use the layer intersection function
> > (OGRLayer::Intersection). Unfortunately the intersection is calculated
> > for every feature/geometry.
> > 
> > Would it be possible to extend the layer intersection function to
> > allow for containment check (eg. as an option) and just copy the
> > contained geometries without calculation of expensive intersection?
> > Suggestions, opinions?
> 
> There's the Options argument, which could be used. Something like
> "PRETEST=CONTAINMENT" could indicate a wish to test containment before
> intersection.

The use of GEOS prepared geometry operations could also potentially help. OGR 
has already mapped GEOSPreparedIntersects as OGRPreparedGeometryIntersects and 
that could probably be unconditionnaly used, with the geometry of the outer 
loop being the prepared geometry with OGRCreatePreparedGeometry()
And perhaps GEOSPreparedContains could be used for containement (if the above 
suggestion desn't speed up things enough).

> 
> A test dataset and a patch would be useful.
> 
> Ari
> 
> > In my use case I get improvements of around 20% of processing time.
> > 
> > Cheers,
> > Kai
> > _______________________________________________
> > gdal-dev mailing list
> > gdal-dev at lists.osgeo.org
> > http://lists.osgeo.org/mailman/listinfo/gdal-dev
> 
> _______________________________________________
> gdal-dev mailing list
> gdal-dev at lists.osgeo.org
> http://lists.osgeo.org/mailman/listinfo/gdal-dev

-- 
Spatialys - Geospatial professional services
http://www.spatialys.com


More information about the gdal-dev mailing list