4

I have a KML file containing 5,000,000 places all around the world.

The big quantity of places makes it a pain to use in Google Earth, so I want to split it, one small file per country.

Bonus if tiny countries are grouped together, and huge countries like USA split into states.

Requirements:

  • Takes a KML file
  • Splits it into areas, I don't have to set up countries definitions myself
  • Produces KML files with a prefix+area filename, for instance mydata_Algeria.kml
  • Free
  • Webapps OK, visitors could choose the area they want, and download only that data

If splitting by countries is too difficult, splitting by latitudes/longitudes is OK too.

1

The easiest way to achieve this is to use a geographic information system (GIS). A free solution is QGIS in its current Version 2.18 (Version 3.0 will come out mid-October/November)

However, you would still need to use some programming when you want to meet your goal. In addition you would need a basic understanding of GIS.

A possible workflow without programming would be:

  • Load your KML file and a shapefile of the world countries
  • (optional): On the world countries file, Create a field which holds a grouping value
  • Select A country with the Select tool or with a expression like "my_field" = 'grouping value' be aware of the single and double quotation (double indicating a field name, while single is a string/text)
  • Use a tool "Select by location" under Vector -> Research tools
  • Right click on your *.kml file and choose "save as.."
  • In the new window, you can choose the file format and can tick the option "only Save selected features"
  • Name the file according to with your standards.

Another way would be to use the graphic modeler of QGIS or the python integration with pygis

  • Would I have to perform the last 5 steps for each country in the world? A solution that does all countries at once would be the best, especially if it can be called from command line. Thanks! – Nicolas Raoul Sep 5 '17 at 9:09
  • @NicolasRaoul There is certainly a way to automate this process but I would need some time to test it. When QGIS is installed, you have also the osgeo shell installed which comes with ogr2ogr. – LaughU Sep 5 '17 at 9:23

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.