[Gdal-dev] Cookie cutting shapefiles in OGR

Frank Warmerdam warmerdam at pobox.com
Sun Jul 2 16:18:36 EDT 2006


Alexandre Leroux wrote:
> 
> Hi list,
> 
> I haven't got any news from my cookie cutting challenge below. Anyone 
> has a clue to help me get started?
> 
> Thanks and cheers! :-)
> 
> Alex
> 
> 
>> Can someone tell me if I can do the following with OGR: I have two 
>> shapefiles and need to cookie cut one with the other while keeping the 
>> attributes of the first shapefile in the newly generated third shapefile.
>>
>> I saw there is OGRGeometry::Intersection which would allow me to do 
>> this, but I'd need to verify the intersection of all features from 
>> shapefile #1 with all features of shapefile #2, which would take days 
>> and days to compute with OGR (that's what my collegue which knows OGR 
>> way better told me). Is there a way to cookie cut shapefiles directly 
>> at the layer level?

Alex,

There is no built in support to do this conveniently.  You could do an
intersection of all features in layer one against each feature in layer
two, with a pretest to avoid intersection operations on features whose
BBOXes don't even intersect.  Even better would be to keep some sort of
spatial index in memory so you would only do bbox comparisons with
features that are relatively nearby.  But I will also warn that the
Intersection() operator is pretty expensive, partly because each OGR
geometry must be turned into a GEOS geometry internally.  So another
optimization would be to translate all your geometries into GEOS geometries
once, and do the intersection directly with geos.  That would avoid a lot
of re-conversion compared to a more ogr based approach.

But basically, any approach with OGR and GEOS is going to involve quite
a bit of scripting or programming work on your part.

You might want to look at options for doing this in GRASS.  I believe it
has some sort of layer overlay operation (perhaps done in the raster
domain?).

Best regards,
-- 
---------------------------------------+--------------------------------------
I set the clouds in motion - turn up   | Frank Warmerdam, warmerdam at pobox.com
light and sound - activate the windows | http://pobox.com/~warmerdam
and watch the world go round - Rush    | President OSGF, http://osgeo.org




More information about the Gdal-dev mailing list