-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
KML File with 'MultiGeometry' #1
Comments
So, despite I don't have any skills in Programming or whatnot, I've managed to implement support for the MultiGeometry. It's probably super rudimentary fix, but at least it works, but probably only in cases, when the MultiGeometry consists only of one type of object. Still I'm happy with it. def parse_recursively(self, root, result):
if "Folder" in root:
for folder in ensure_list(root["Folder"]):
name = folder["name"]
result[name] = {}
self.parse_recursively(folder, result[name])
if "Placemark" in root:
for placemark in ensure_list(root["Placemark"]):
if "MultiGeometry" in placemark:
name = placemark["name"]
result[name] = {}
self.parse_recursively(placemark["MultiGeometry"], result[name])
elif "LineString" in placemark:
geom = LineString(self.parse_pos_list(placemark["LineString"]["coordinates"]))
name = placemark["name"]
if name not in result:
result[name] = [geom]
else:
result[name].append(geom)
elif "Polygon" in placemark:
geom = LinearRing(
self.parse_pos_list(
placemark["Polygon"]["outerBoundaryIs"]["LinearRing"]["coordinates"],
),
)
name = placemark["name"]
if name not in result:
result[name] = [geom]
else:
result[name].append(geom)
elif "Point" in placemark:
geom = Point(self.parse_pos_list(placemark["Point"]["coordinates"]))
name = placemark["name"]
if name not in result:
result[name] = [geom]
else:
result[name].append(geom)
else:
msg = f"Placemark {placemark} unknown"
raise ValueError(msg)
if "LineString" in root:
for linestring in ensure_list(root["LineString"]):
geom = LineString(self.parse_pos_list(linestring["coordinates"]))
name = ""
if name not in result:
result[name] = [geom]
else:
result[name].append(geom)
if "Polygon" in root:
for polygon in ensure_list(root["Polygon"]):
geom = LinearRing(
self.parse_pos_list(
polygon["outerBoundaryIs"]["LinearRing"]["coordinates"],
),
)
name = ""
if name not in result:
result[name] = [geom]
else:
result[name].append(geom)
if "Point" in root:
for point in ensure_list(root["Point"]):
geom = Point(self.parse_pos_list(point["coordinates"]))
name = ""
if name not in result:
result[name] = [geom]
else:
result[name].append(geom) |
This is an issue indeed. Can you provide an example KML that shows this behavior? |
I'm not sure if this issue actually needed to be solved. If MultiGeometry would consist for example out of LineStrings and Points, then it wouldn't make any sense, because we can use functions like |
As I tried to feed my KML file into the script, I've got this error:
I created my KML file with QGIS. It seems like QGIS exports KML with tag 'MultiGeometry'. After removing this tag manually from the file, script worked flawlessly. Probably it would be nice, if the script could read files with these tags as well.
The text was updated successfully, but these errors were encountered: