mocnik-science / osm-python-tools

A library to access OpenStreetMap related services
GNU General Public License v3.0
441 stars 48 forks source link

Cannot build geometry for relation that is not polygon #75

Open SlytherinGe opened 10 months ago

SlytherinGe commented 10 months ago

I just found that we can't get the geometry of some relations, say relation(116278).

As in element.py, the code for getting the geometry of a relation is as follows:

            elif self.type() == 'relation':
                membersOuter = self.__geometry_extract(self.members(onlyOuter=True))
                if len(membersOuter) == 0:
                    self._raiseException('Cannot build geometry: no outer rings found.')
                membersInner = self.__geometry_extract(self.members(onlyInner=True))
                ringsOuter = self.__geometry_buildRings(membersOuter)
                ringsInner = self.__geometry_buildRings(membersInner)
                ringsOuter = self.__geometry_orientRings(ringsOuter, positive=True)
                ringsInner = self.__geometry_orientRings(ringsInner, positive=False)
                polygons = self.__geometry_buildPolygons(ringsOuter, ringsInner)
                if len(polygons) > 1:
                    return geojson.MultiPolygon(polygons)
                else:
                    return geojson.Polygon(polygons[0])

But some geometries of relations, like routes, are also very important. How can I get the geometry for these none-polygon relations?

vectro commented 7 months ago

As a workaround, you can get the geometries of a route's members and then combine them.