[Gdal-dev] Using OGR Python to analyse stream layers

Frank Warmerdam warmerdam at pobox.com
Mon Feb 9 09:44:04 EST 2004


Christopher Fonnesbeck wrote:
> I have a nice vegetation dynamics simulation model written in python 
> that needs to access spatial data for the modelling of disturbances, 
> such as floods. I have been trying unsuccessfully to interface with 
> GRASS, and so am turning to other options. I was hoping OGR python would 
> work, as all that I need to do is locate the nearest stream segment to 
> the disturbance, then route the disturbance down the network. I'm hoping 
> that someone who is experienced with OGR python can provide some advice 
> as to whether this is worth pursuing.

Chris,

The OGR Python interface would be fine for accessing stream vectors in any
OGR supported format (which does not include GRASS at this time).  However,
OGR has no mechanism for finding the nearest feature to a point, or for
computing the distance betweena feature and a point.  So you would end up
having to do this yourself in python which could be kind of computationally
expensive.

One slightly exotic solution to your problem might be to keep your network
data in PostGIS and then use the PostGIS primitives (based on GEOS) to find
the nearest geometry.  You could use access postgis via OGR's PostGIS driver
or do the operations directly from Python using ODBC and then use a python
package to parse the results from PostGIS.  You can request results in WKT
for instance.  You could use OGR to parse the WKT geometry but there is also
another "pure python" module available now that understands OGC geometry
formats that might be even simpler.

   http://postgis.refractions.net/

If you go with a straight OGR solution and some simple format like shapefiles,
you will be stuck doing all the distance computations yourself.

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    | Geospatial Programmer for Rent




More information about the Gdal-dev mailing list