- start working on QRCode Tool - serching for alternatives

This commit is contained in:
Marius Stanciu
2019-10-23 17:58:06 +03:00
parent bf670d7967
commit 70fbb7f852
3 changed files with 22 additions and 9 deletions

View File

@@ -22,7 +22,7 @@
# import xml.etree.ElementTree as ET
from svg.path import Line, Arc, CubicBezier, QuadraticBezier, parse_path
from svg.path.path import Move
from shapely.geometry import LineString
from shapely.geometry import LineString, LinearRing, MultiLineString
from shapely.affinity import skew, affine_transform, rotate
import numpy as np
@@ -71,7 +71,6 @@ def path2shapely(path, object_type, res=1.0):
rings = []
for component in path:
# Line
if isinstance(component, Line):
start = component.start
@@ -123,6 +122,8 @@ def path2shapely(path, object_type, res=1.0):
if points:
rings.append(points)
rings = MultiLineString(rings)
if len(rings) > 0:
if len(rings) == 1:
# Polygons are closed and require more than 2 points
@@ -131,7 +132,14 @@ def path2shapely(path, object_type, res=1.0):
else:
geo_element = LineString(rings[0])
else:
geo_element = Polygon(rings[0], rings[1:])
try:
geo_element = Polygon(rings[0], rings[1:])
except Exception as e:
coords = list()
for line in rings:
coords.append(line.coords[0])
coords.append(line.coords[1])
geo_element = Polygon(coords)
geometry.append(geo_element)
return geometry