[Gdal-dev] Re: OGR C API question

Frank Warmerdam warmerdam at pobox.com
Mon Mar 29 17:03:17 EST 2004


Etienne Dube wrote:
> Hi Stephan,
> 
> You have to make sure the SRID reference from the layer table is present in 
> the spatial_ref_sys table. Otherwise it seems that OGR is unable to apply the 
> spatial filter. First, if you haven't actually installed the PostGIS 
> functions in your database, do it:
> 
> createlang -U postgres plpgsql <dbname>
> psql postgres -d <dbname> -f postgis.sql
> 
> Then, you can use ogr2ogr to fill in the rows from a shapefile:
> 
> ogr2ogr -f "PostgreSQL" -s_srs 
> 'GEOGCS["GCS_North_American_1983",DATUM["D_North_American_1983",SPHEROID["GRS_1980",6378137,298.257222101]],PRIMEM["Greenwich",0],UNIT["Degree",0.0174532925199433]]'  
> "PG:dbname=<dbname> user=<username>" SHAPEFILE.SHP
> 
> (Of course, you have to replace <dbname> and <username> by the correct 
> values.)
> 
> I've found that if you don't specify the -s_srs (source spatial ref. sys.) 
> when importing an ESRI shapefile with ogr2ogr, the SRID row in 
> spatial_ref_sys won't be created. Make sure you use the same datum as the 
> data in your shapefile.
> 
> Now, spatial filtering should work with OGR on this dataset. However, (correct 
> me if I'm wrong) the current implementation seems to be broken, it won't use 
> spatial queries to fetch the features from the table. Instead, it SELECTs all 
> the data in the layer, and uses a brute force approach (intersection on all 
> geometries). See the "OGRFeature *OGRPGLayer::GetNextFeature()" function in 
> ogrpglayer.cpp. So, if you're working on large datasets, methods like 
> OGRLayer::GetExtent() or OGRLayer::GetFeatureCount() will take a looooooong 
> time to execute. Same thing if, say, you want to display all the geometries 
> in a small rectangle; OGR will have to intersect this rectangle with all the 
> geometries in the layer, which takes some time to do.

Etienne (or Stephan),

If you can isolate this issue I would encourage you to submit it in the OGR
bugzilla and I will try to correct it in the next few weeks.  I have a few
other improvements I would like to make to the PostGIS driver in OGR anyways.

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