-4

I have recieved a file from my company with over 7.000 coordinates. They are sorted in a bad way that I cannot easly access what i need. For example:

  1. We have track lines: L75
  2. We have a crossing point: OW 34
  3. We have a Kilometer points: 45

They sorted the coordinates by crossing point. Meaning that for every line in the country the crossing points are stacked behind each other in the file. With no other indications (as the name of the point is the crossing).

What I want to achieve is a way to reorganize them by track line and then crossing point. I am curently manualy doing it but it is a repetative boring job.

I tried dragging and dropping but one at a time seems a bit ludicrous.

E_net4
  • 27,810
  • 13
  • 101
  • 139

1 Answers1

1

If you're comfortable to try some coding you could write a simple script to parse your KML/KMZ file, sort the placemarks any which way you want then output a new KML or KMZ file exactly as you want it.

The python pykml module is one of the easiest ways to get started and here is a tutorial.

There are a handlful of examples posted in stackoverflow for using pykml. You can post pykml questions into stackoverflow when you get started. Just add "pykml" tag to the question.

Here is an example to parse a KMZ file with doc.kml entry structured with a <Document> with a collection of child <Placemark> elements. Code opens the KMZ file and iterates over the placemarks printing the name field of each placemark and its point coordinates.

from os import path
from pykml import parser
from zipfile import ZipFile

kml_file = "test.kmz"
kmz = ZipFile(kml_file, 'r')
with kmz.open('doc.kml', 'r') as f:
  doc = parser.parse(f)
for pm in doc.getroot().Document.Placemark:
  print(pm.name, pm.Point.coordinates)

You could do likewise adding each placemark to a collection (list or dictionary object) then sort it.

CodeMonkey
  • 22,825
  • 4
  • 35
  • 75
  • Well my progamming skills are not as good. And learning a completly new language just for this seems a bit overkill. I am curently using vscode to manualy edit the file into diffrent files. – Pieter-Jan Casteels Aug 17 '20 at 00:34