9

I have downloaded a GML file from Statistics Canada and would like to convert it into GeoJSON to use parts of it in a D3 visualization on the web. However, I did not find a converter that would do that for me (I tried http://converter.mygeodata.eu/ , but the GeoJSON it returned did not contain any actual geometry).

What is the best approach to convert GML into GeoJSON?

17

You Can use ogr2ogr. Simplest to install it would be to download fwTools.

the following command will do

ogr2ogr -f "GeoJSON" E:\lakes.geojson e:\lakes.gml

Else if you have QuantumGIS, you can add your GML layer to map and by Right-Clicking the Layer, Select Save As to GeoJSON format.

  • Thanks! I just tried it & I got "ERROR 1: Unrecognized geometry type <Surface>." - does this mean that there a features in GML that cannot easily be converted to GeoJSON? – Lars Grammel Jul 1 '12 at 17:26
  • 2
    as per gis.stackexchange.com/a/11482/5850, you need GDAL 1.8.0 or above..what is your version? – vinayan Jul 2 '12 at 1:08
  • 1
    @LarsGrammel try the latest version, gisinternals.com/sdk/… – vinayan Jul 2 '12 at 1:25
  • I used the latest fwTools for Windows (2.4.7). Will try the latest version of GDAL as you suggested. – Lars Grammel Jul 2 '12 at 2:06
  • GDAL 1.9.1 (included in the latest SDK) worked for me. Thanks! – Lars Grammel Jul 2 '12 at 2:17
0

As vinayan said, ogr2ogr would be a good solution, but a handy way I've used in the past to quickly convert vector formats it to use this existing OpenLayers example:

http://openlayers.org/dev/examples/vector-formats.html

Just draw your features or paste the data and hit add feature.

0

If you have R Studio (it's a free software), you can use the converter located here to easily convert large GML files to GeoJSON:

https://gist.github.com/geotheory/7103991

  • That example has nothing to do with GML to GeoJSON – g07kore Apr 27 '17 at 8:11

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.