0

I'm trying to create a geojson file data based on data from my local postgis database using ogr2ogr. I'm trying to clip to a specific area and when I start to run the command, everything starts fine, but I then get an ERROR 6: GeoJSON driver doesn't support creating more than one layer and I'm not quite sure how to solve it.

Do I need to select only one column in the SELECT statement?

Command:

ogr2ogr -f GeoJSON ./test-buildings.geojson PG:"host=localhost dbname=gis user=*USERNAME* port=5432" -clipdst -84.419932, 33.992761, -84.371342, 34.018029 -clipdstsql 'SELECT way, "building" as type FROM planet_osm_polygon ORDER BY ST_YMin(ST_Envelope(way)) DESC' -progress
17
  • What do you get with ogrinfo -al -so when using the same SQL?
    – user30184
    Apr 8, 2016 at 18:12
  • When I run ogrinfo -al -so 'SELECT way, "building" as type FROM planet_osm_polygon ORDER BY ST_YMin(ST_Envelope(way)) DESC', I get a failure to open datasource. Is that syntax right?
    – BDD
    Apr 8, 2016 at 18:14
  • You must include also the data source part PG:...
    – user30184
    Apr 8, 2016 at 19:00
  • Whoops. Totally spaced on that. After running it again with a datasource, I got this.
    – BDD
    Apr 8, 2016 at 19:37
  • Looks Ok. Does test-buildings.geojson already exist? It shouldn't.
    – user30184
    Apr 8, 2016 at 19:49

1 Answer 1

1

I'm not completely sure, but when reading the ogr2ogr documentation, the -clipdst and -clipdstsql seems to relate to destination data object and therefore might not be relevant to this operation.

Is there a reason why you chose those variables?

I would suggest using the following syntax (untested):

ogr2ogr -f GeoJSON ./test-buildings.geojson PG:"host=localhost dbname=gis 
user=*USERNAME* port=5432" -spat -84.419932 33.992761 -84.371342 34.018029 -clipsrc 
-sql 'SELECT way, "building" as type FROM planet_osm_polygon ORDER BY ST_YMin(ST_Envelope(way)) 
DESC' -progress

In this case I define the extent of the target area with the -spat variable and use the -clipsrc variable to clip the geometries to the -spat variable. I define the sql statement with the -sql variable

1
  • -clipsrc requires a reference, so I don't think -spat is required? I used -clipdst because it worked.
    – BDD
    Apr 8, 2016 at 14:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.