Validate KML geometries in python

02-17-2022 05:38 AM
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:


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 MVP Regular Contributor
MVP Regular Contributor

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