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.

closed as off-topic by ahmadhanb, tinlyx, user30184, Ian Turton Apr 24 '18 at 9:55

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "Questions seeking help to debug/write/improve code must include the desired behavior, a specific problem or error and the shortest code necessary to reproduce it in the question itself. Providing a clear problem statement and evidence of a code attempt will help others to help you. See: How to create a Minimal, Complete, and Verifiable example." – ahmadhanb, tinlyx, user30184, Ian Turton
If this question can be reworded to fit the rules in the help center, please edit the question.

  • 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

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.