Skip to content
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

Refactor with type annotations (Sourcery refactored) #21

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 18 additions & 16 deletions pygeoif/factories.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ def from_wkt(geo_str: str):
"""

wkt = geo_str.strip()
wkt = " ".join([l.strip() for l in wkt.splitlines()])
wkt = " ".join(l.strip() for l in wkt.splitlines())
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function from_wkt refactored with the following changes:

wkt = wkt_regex.match(wkt).group("wkt")
ftype = wkt_regex.match(wkt).group("type")
outerstr = outer.search(wkt)
Expand All @@ -142,14 +142,14 @@ def from_wkt(geo_str: str):
coords = coordinates.split(",")
return LinearRing([c.split() for c in coords])
elif ftype == "POLYGON":
coords = []
for interior in inner.findall(coordinates):
coords.append((interior[1:-1]).split(","))
coords = [
(interior[1:-1]).split(",")
for interior in inner.findall(coordinates)
]

if len(coords) > 1:
# we have a polygon with holes
exteriors = []
for ext in coords[1:]:
exteriors.append([c.split() for c in ext])
exteriors = [[c.split() for c in ext] for ext in coords[1:]]
else:
exteriors = None
return Polygon([c.split() for c in coords[0]], exteriors)
Expand All @@ -163,24 +163,26 @@ def from_wkt(geo_str: str):
coords.append(coord.strip())
return MultiPoint([c.split() for c in coords])
elif ftype == "MULTILINESTRING":
coords = []
for lines in inner.findall(coordinates):
coords.append([c.split() for c in lines[1:-1].split(",")])
coords = [
[c.split() for c in lines[1:-1].split(",")]
for lines in inner.findall(coordinates)
]

return MultiLineString(coords)
elif ftype == "MULTIPOLYGON":
polygons = []
m = mpre.split(coordinates)
for polygon in m:
if len(polygon) < 3:
continue
coords = []
for interior in inner.findall("(" + polygon + ")"):
coords.append((interior[1:-1]).split(","))
coords = [
(interior[1:-1]).split(",")
for interior in inner.findall("(" + polygon + ")")
]

if len(coords) > 1:
# we have a polygon with holes
exteriors = []
for ext in coords[1:]:
exteriors.append([c.split() for c in ext])
exteriors = [[c.split() for c in ext] for ext in coords[1:]]
else:
exteriors = None
polygons.append(Polygon([c.split() for c in coords[0]], exteriors))
Expand Down