Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

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?

share|improve this question
add comment

2 Answers 2

up vote 10 down vote accepted

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.

share|improve this answer
    
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
add comment

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.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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