1

How should I convert GML to geojson data using ogr2ogr. I used :

ogr2ogr -f "GeoJSON" bd.geojson bd.gml

But in this case I have only part of my data , not all. I tried add -append , but it didn't work properly.

  • 1
    Please expand your question with an example feature from the gml and the geojson – Ian Turton Feb 26 '16 at 19:46
  • I have many poligons , linestring and point in one file *.gml . When I converted to geojson I saw only poligons. I am thinking that there are possible the same "name" of records. And when I exported data to Postgis I used loop "for" and -append , because I had the same problem. But in this case I don't know how I should write script . – Agnieszka Feb 26 '16 at 20:02
1

It's hard to say for sure what the issue is based on your question, but you could try to use the -nlt flag (from documentation http://www.gdal.org/ogr2ogr.html). This will (explicitly) specify the output geometry type. Since you have mixed geometry you might try the command ogr2ogr -f "GeoJSON" -nlt "GEOMETRYCOLLECTION" bd.geojson bd.gml

  • I have to errors: ERROR 6: GeoJSON driver doesn't support creating more than one layer ERROR 1: Terminating translation prematurely after failed after changing ogr2ogr -f "GeoJSON" -nlt "GEOMETRYCOLLECTION" bd.geojson bd.gml – Agnieszka Feb 26 '16 at 20:28
  • 1
    What does "ogrinfo -al -so bd.gml" report? – user30184 Feb 26 '16 at 20:36
  • How I can create simillar loop for gml->geojson? for %%I in (*.gml) do ( psql -c "drop table if exists -d %base% -h "%host%" -p %port% -U %user% ogr2ogr -append -f "PostgreSQL" "PG:dbname=%base% user=%user% password=%pass% host=%host% port=%port%" %%I -nlt GEOMETRY -lco PRECISION=NO) It is working for POSTGIS for my complex data, – Agnieszka Feb 26 '16 at 21:29
  • @Agnieszka It is working or it isn't working? You need a loop to convert all your gml to geojson or fix the loop you have? If the former, try for %%I in (*.gml) DO ( SET oldName=%%I SET newName=%oldName:.gml=.geojson% ogr2ogr -f "GeoJSON" -nlt "GEOMETRYCOLLECTION" %newName% %%I ) – Dave-Evans Feb 27 '16 at 14:58
  • I would rather try with -nlt geometry but we should really see the ogrinfo report. If source gml has several layers they must be converted one by one into several GeoJSON files. – user30184 Feb 27 '16 at 15:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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