[gdal-dev] Intersection of two Layers
Kai Muehlbauer
kai.muehlbauer at uni-bonn.de
Tue Jan 19 22:35:52 PST 2016
Am 19.01.2016 um 13:09 schrieb Even Rouault:
> 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).
Thank you Ari and Even for the comments and suggestions. I'll try to
test the "prepared" stuff first, hoping that those functions are also
available within the python bindings (which I use).
I'll give an update here, when I have results on this.
Cheers,
Kai
More information about the gdal-dev
mailing list