mirror of
https://github.com/marceloprates/prettymaps.git
synced 2025-08-18 20:31:43 +02:00
Added support for Point and Line geometries
This commit is contained in:
@@ -125,7 +125,12 @@ def transform(layers, x, y, scale_x, scale_y, rotation):
|
|||||||
|
|
||||||
|
|
||||||
def draw_text(ax, text, x, y, **kwargs):
|
def draw_text(ax, text, x, y, **kwargs):
|
||||||
ax.text(x, y, text, **kwargs)
|
if 'bbox' in kwargs:
|
||||||
|
bbox_kwargs = kwargs.pop('bbox')
|
||||||
|
text = ax.text(x, y, text, **kwargs)
|
||||||
|
text.set_bbox(**bbox_kwargs)
|
||||||
|
else:
|
||||||
|
text = ax.text(x, y, text, **kwargs)
|
||||||
|
|
||||||
|
|
||||||
# Plot
|
# Plot
|
||||||
@@ -263,7 +268,7 @@ def plot(
|
|||||||
|
|
||||||
# Plot background
|
# Plot background
|
||||||
if "background" in drawing_kwargs:
|
if "background" in drawing_kwargs:
|
||||||
geom = scale(box(*layers["perimeter"].bounds), 2, 2)
|
geom = scale(box(*layers["perimeter"].bounds), 1.2, 1.2)
|
||||||
|
|
||||||
if vsketch is None:
|
if vsketch is None:
|
||||||
ax.add_patch(PolygonPatch(geom, **drawing_kwargs["background"]))
|
ax.add_patch(PolygonPatch(geom, **drawing_kwargs["background"]))
|
||||||
|
@@ -146,6 +146,8 @@ def get_geometries(
|
|||||||
buffer: float = 0,
|
buffer: float = 0,
|
||||||
circle: Boolean = True,
|
circle: Boolean = True,
|
||||||
dilate: float = 0,
|
dilate: float = 0,
|
||||||
|
point_size: float = 1,
|
||||||
|
line_width: float = 1
|
||||||
) -> Union[Polygon, MultiPolygon]:
|
) -> Union[Polygon, MultiPolygon]:
|
||||||
"""Get geometries
|
"""Get geometries
|
||||||
|
|
||||||
@@ -163,8 +165,8 @@ def get_geometries(
|
|||||||
[type]: [description]
|
[type]: [description]
|
||||||
"""
|
"""
|
||||||
|
|
||||||
if perimeter is not None:
|
|
||||||
# Boundary defined by polygon (perimeter)
|
# Boundary defined by polygon (perimeter)
|
||||||
|
if perimeter is not None:
|
||||||
geometries = ox.geometries_from_polygon(
|
geometries = ox.geometries_from_polygon(
|
||||||
unary_union(perimeter.to_crs(3174).buffer(buffer+perimeter_tolerance).to_crs(4326).geometry)
|
unary_union(perimeter.to_crs(3174).buffer(buffer+perimeter_tolerance).to_crs(4326).geometry)
|
||||||
if buffer >0 or perimeter_tolerance > 0
|
if buffer >0 or perimeter_tolerance > 0
|
||||||
@@ -172,9 +174,8 @@ def get_geometries(
|
|||||||
tags={tags: True} if type(tags) == str else tags,
|
tags={tags: True} if type(tags) == str else tags,
|
||||||
)
|
)
|
||||||
perimeter = unary_union(ox.project_gdf(perimeter).geometry)
|
perimeter = unary_union(ox.project_gdf(perimeter).geometry)
|
||||||
|
|
||||||
elif (point is not None) and (radius is not None):
|
|
||||||
# Boundary defined by circle with radius 'radius' around point
|
# Boundary defined by circle with radius 'radius' around point
|
||||||
|
elif (point is not None) and (radius is not None):
|
||||||
geometries = ox.geometries_from_point(
|
geometries = ox.geometries_from_point(
|
||||||
point,
|
point,
|
||||||
dist=radius + dilate + buffer,
|
dist=radius + dilate + buffer,
|
||||||
@@ -189,50 +190,27 @@ def get_geometries(
|
|||||||
geometries = ox.project_gdf(geometries)
|
geometries = ox.project_gdf(geometries)
|
||||||
|
|
||||||
# Intersect with perimeter
|
# Intersect with perimeter
|
||||||
geometries = geometries.intersection(perimeter).buffer(0)
|
geometries = geometries.intersection(perimeter)
|
||||||
|
|
||||||
if union:
|
# Get points, lines, polys & multipolys
|
||||||
polys = unary_union(
|
points, lines, polys, multipolys = map(
|
||||||
reduce(
|
lambda t: [x for x in geometries if isinstance(x, t)],
|
||||||
lambda x, y: x + y,
|
[Point, LineString, Polygon, MultiPolygon]
|
||||||
[
|
|
||||||
[x] if type(x) == Polygon else list(x)
|
|
||||||
for x in geometries
|
|
||||||
if type(x) in [Polygon, MultiPolygon]
|
|
||||||
],
|
|
||||||
[],
|
|
||||||
)
|
|
||||||
)
|
|
||||||
points = unary_union([
|
|
||||||
x for x in geometries
|
|
||||||
if isinstance(x, Point)
|
|
||||||
]).buffer(2)
|
|
||||||
|
|
||||||
lines = unary_union([
|
|
||||||
x for x in geometries
|
|
||||||
if isinstance(x, LineString)
|
|
||||||
]).buffer(3)
|
|
||||||
|
|
||||||
geometries = unary_union([polys, points, lines])
|
|
||||||
|
|
||||||
else:
|
|
||||||
geometries = MultiPolygon(
|
|
||||||
reduce(
|
|
||||||
lambda x, y: x + y,
|
|
||||||
[
|
|
||||||
[x] if type(x) == Polygon else list(x)
|
|
||||||
for x in geometries
|
|
||||||
if type(x) in [Polygon, MultiPolygon]
|
|
||||||
],
|
|
||||||
[],
|
|
||||||
)
|
|
||||||
)
|
)
|
||||||
|
# Convert points, lines & polygons into multipolygons
|
||||||
|
points = [x.buffer(point_size) for x in points]
|
||||||
|
lines = [x.buffer(line_width) for x in lines]
|
||||||
|
# Concatenate multipolys
|
||||||
|
multipolys = reduce(lambda x,y: x+y, [list(x) for x in multipolys]) if len(multipolys) > 0 else []
|
||||||
|
# Group everything
|
||||||
|
geometries = MultiPolygon(points + lines + polys + multipolys)
|
||||||
|
# Compute union if specified
|
||||||
|
if union: geometries = unary_union(geometries);
|
||||||
|
|
||||||
return geometries
|
return geometries
|
||||||
|
|
||||||
|
|
||||||
def get_streets(
|
def get_streets(
|
||||||
|
|
||||||
perimeter: Optional[GeoDataFrame] = None,
|
perimeter: Optional[GeoDataFrame] = None,
|
||||||
point: Optional[Tuple] = None,
|
point: Optional[Tuple] = None,
|
||||||
radius: Optional[float] = None,
|
radius: Optional[float] = None,
|
||||||
@@ -244,7 +222,6 @@ def get_streets(
|
|||||||
circle: Boolean = True,
|
circle: Boolean = True,
|
||||||
dilate: float = 0,
|
dilate: float = 0,
|
||||||
truncate_by_edge: Boolean = True
|
truncate_by_edge: Boolean = True
|
||||||
|
|
||||||
) -> MultiPolygon:
|
) -> MultiPolygon:
|
||||||
"""
|
"""
|
||||||
Get streets
|
Get streets
|
||||||
|
Reference in New Issue
Block a user