I am trying to make a tool to analyse GPX files using OpenStreetMap data for identification of locations. I have successfully extracted all the waypoints from the GPX files and created as a MultiPoint object, and extracted OpenStreetMap border relation (border data) with overpass wrapper. The problem is taking relations with 500+ objects and turn them into Polygon or MultiPolygons. I have successfully created all the parts of the border as LineString objects, and all parts that are circular (LinearRings) are successfully made into Polygon objects. The problem is to join all the non-circular objects.
newLines = []
for line in lines:
if isinstance(line, MultiLineString):
newLines.extend(line)
else:
newLines.append(line)
try:
polygons.append(Polygon(linemerge(newLines)))
logger.debug("Created Polygon from sum of lines")
except:
try:
polygons.append(MultiPolygon(linemerge(newLines)))
logger.debug("Created MultiPolygon from sum of lines")
except:
logger.debug("Failed to create Polygon from sum of lines")
raise
... from log file, no exception thrown
2016/03/17 21:43:59: gpxupload.py DEBUG - Failed to create Polygon from sum of lines
What goes wrong?