Fixes SVG parser to produce polygons. Fixes #212.

This commit is contained in:
Juan Pablo Caram
2016-09-21 13:01:51 -04:00
parent 03c49f3afd
commit dbe0105f9b
3 changed files with 28 additions and 15 deletions

View File

@@ -223,10 +223,16 @@ class Geometry(object):
def find_polygon(self, point, geoset=None):
"""
Find an object that object.contains(Point(point)) in
poly, which can can be iterable, contain iterable of, or
geoset, which can can be iterable, contain iterables of, or
be itself an implementer of .contains().
:param poly: See description
Note:
* Shapely Polygons will work as expected here. Linearrings
will only yield true if the point is in the perimeter.
:param point: See description
:param geoset: Set to search. If none, the defaults to
self.solid_geometry.
:return: Polygon containing point or None.
"""
@@ -416,6 +422,8 @@ class Geometry(object):
:param filename: Path to the SVG file.
:type filename: str
:param flip: Flip the vertically.
:type flip: bool
:return: None
"""
@@ -424,8 +432,6 @@ class Geometry(object):
svg_root = svg_tree.getroot()
# Change origin to bottom left
# h = float(svg_root.get('height'))
# w = float(svg_root.get('width'))
h = svgparselength(svg_root.get('height'))[0] # TODO: No units support yet
geos = getsvggeo(svg_root)
@@ -437,12 +443,15 @@ class Geometry(object):
self.solid_geometry = []
if type(self.solid_geometry) is list:
self.solid_geometry.append(cascaded_union(geos))
# self.solid_geometry.append(cascaded_union(geos))
if type(geos) is list:
self.solid_geometry += geos
else:
self.solid_geometry.append(geos)
else: # It's shapely geometry
self.solid_geometry = cascaded_union([self.solid_geometry,
cascaded_union(geos)])
return
# self.solid_geometry = cascaded_union([self.solid_geometry,
# cascaded_union(geos)])
self.solid_geometry = [self.solid_geometry, geos]
def size(self):
"""