0

I am looking for a way to convert KML to three Shapefiles (point, line, polygon) with a Windows script (exe or bat). The script should open a window to choose the input KML and save the three Shapefiles to a defined path with a defined coordinate reference system.

  • 1
    welcome to GIS SE! please take the tour to get familiar with how the focussed Q/A works; for a question to fullfill the standards, you should at least add a minimum of research, and in the particular case of coding requests, your own code to work on. as you got an answer to the spatial part of the script, you might want to migrate this question to SO, since the rest is mainly straight forward programming. – ThingumaBob Apr 24 '18 at 9:28
4

You can execute ogr2ogr 3 times with -where statement:

ogr2ogr -where "OGR_GEOMETRY='Point'" ...
ogr2ogr -where "OGR_GEOMETRY='LineString'" ...
ogr2ogr -where "OGR_GEOMETRY='Polygon'" ...

See OGR SQL page

The bat file (i.e. export.bat) may looks like:

@echo off
ogr2ogr -where "OGR_GEOMETRY='Point'" -f "ESRI Shapefile" points.shp %1
ogr2ogr -where "OGR_GEOMETRY='LineString'" -f "ESRI Shapefile" lines.shp %1
ogr2ogr -where "OGR_GEOMETRY='Polygon'" -f "ESRI Shapefile" polygons.shp %1

And execute string will be: export.bat c:\tmp\test.kml

Optional syntax for working with input parameters can be found here: https://stackoverflow.com/a/3433012/2901140

The ogr2ogr command line may be more complicated to suits your needs.

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