Validate KML geometries in python

336
1
02-17-2022 05:38 AM
AamirMurtaza43
New Contributor

I have CSV file where in a column there are some KML geometries. These geometries can be points, lines, polygons etc. I would like to validate them and check if they are correctly written.

I'm reading the CSV with Pandas

import pandas as pd
csv = read_csv('file.csv')

#Let's take into account just the first location
coordinates = csv.['location'].loc[0] 

coordinates would be:

<Point><coordinates>2.34880,48.85341</coordinates></Point>

I tried to proceed with fastKML, but it searches for a complete KML file to check and not just the string I got.

So I'm wondering, is there any possibility to validate directly the sting?

0 Kudos
1 Reply
by Anonymous User
Not applicable

Regex would probably be the way to go.  If you have a standard valid example of how each type should be, you can set up a regex match to validate, similar to how email addresses are validated.

0 Kudos