Converting between KML and shapefile (SHP) format?

  • My users are sending me point data that were digitized using Google Earth.

    How can I convert their KML to a shapefile?

  • fmark

    fmark Correct answer

    10 years ago

    Using the open source ogr2ogr from GDAL/OGR:

    ogr2ogr -f 'ESRI Shapefile' output.shp input.kml
    

    As noted in grego's comment below, you may need to use double quotes instead of single quotes for the output format option (e.g. "ESRI Shapefile" for the Windows command line). See also the gdal wiki.

    ...and just to preempt next natural question, it works the other way too: ogr2ogr -f KML output.kml input.shp

    If you prefer to use GUI based tools, QGIS can act as a front end for ogr2ogr.

    Wow, GDAL can do everything when it comes to transformations...

    @dkroy - except for double stereo formats

    wish there was an online GDAL/OGR site *hint hint peeps*

    @Pure.Krome, there is a wiki at http://trac.osgeo.org/gdal/ and the mailing list is very active (Those that prefer forum-like interface can use the gmane gateway .)

    @mattwilkie I think he meant something like Zamzar.com. An online conversion service.

    I had to use double quotes for the "ESRI Shapefile" arg.

    In my OSGEO Shell, simple quotes around 'ESRI Shapefile' don't seem to work, I had to replaced them by using double quotes: "ESRI Shapefile"

    A couple of syntax points worth noting when using ogr2ogr (save yourselves hours of frustration): **1. For any of the option "tags" in your ogr2ogr string, make sure there's no spaces between the - and the word i.e. -progress NOT - progress)**

    **2. Typing ogr2ogr -help (hit enter) shows you all the possible options.** It's important to use these option "tags" in the correct sequence i.e. -progress -f NOT -f -progress) (Here's what ogr2ogr -help prints out): Usage: ogr2ogr [--help-general] [-skipfailures] [-append] [-update] [-select field_list] [-where restricted_where|@filename] [-progress] [-sql |@filename] [-dialect dialect] [-preserve_fid] [-fid FID] etc. etc.

    **3. The format is the only part of the string that should have quotes around it.** (Either single quotes or double quotes, depending what environment you're running ogr2ogr in: for me, in the QGIS > OSGeo4W shell, I use double quotes i.e. "KML" not 'KML' **4. You can get the full format list (90 different formats) by typing in:** ogr2ogr --formats

License under CC-BY-SA with attribution


Content dated before 6/26/2020 9:53 AM