mirror of
https://github.com/marceloprates/prettymaps.git
synced 2025-08-17 03:54:10 +02:00
Implement Plotting coastline with just perimeter and change CRS for loaded polygons
Now using WGS84 shape file https://osmdata.openstreetmap.de/download/water-polygons-split-4326.zip
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
from functools import reduce
|
from functools import reduce
|
||||||
|
|
||||||
import osmnx as ox
|
import osmnx as ox
|
||||||
|
from osmnx import utils_geo
|
||||||
import numpy as np
|
import numpy as np
|
||||||
from shapely.geometry import Point, Polygon, MultiPolygon, MultiLineString
|
from shapely.geometry import Point, Polygon, MultiPolygon, MultiLineString
|
||||||
from shapely.ops import unary_union
|
from shapely.ops import unary_union
|
||||||
@@ -30,21 +31,19 @@ def get_perimeter(query, by_osmid = False, **kwargs):
|
|||||||
def get_coast(perimeter = None, point = None, radius = None, tags = {}, perimeter_tolerance = 0, union = True, circle = True, dilate = 0, file_location = None):
|
def get_coast(perimeter = None, point = None, radius = None, tags = {}, perimeter_tolerance = 0, union = True, circle = True, dilate = 0, file_location = None):
|
||||||
if perimeter is not None:
|
if perimeter is not None:
|
||||||
# Boundary defined by polygon (perimeter)
|
# Boundary defined by polygon (perimeter)
|
||||||
geometries = ox.geometries_from_polygon(
|
bbox=perimeter.to_crs(3174)
|
||||||
unary_union(perimeter.geometry).buffer(perimeter_tolerance) if perimeter_tolerance > 0 else unary_union(perimeter.geometry),
|
bbox=bbox.buffer(perimeter_tolerance+dilate)
|
||||||
tags = {tags: True} if type(tags) == str else tags
|
bbox=bbox.to_crs(4326)
|
||||||
)
|
bbox=bbox.envelope
|
||||||
|
geometries = read_file(file_location, bbox=bbox)
|
||||||
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):
|
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
|
||||||
bbox=GeoDataFrame(geometry = [Point(point[::-1])], crs = 4326)
|
north,south,west,east=utils_geo.bbox_from_point(point, dist=radius+dilate)
|
||||||
bbox=bbox.to_crs(3174)
|
bbox=(west,south,east,north)
|
||||||
bbox=bbox.buffer(radius+dilate)
|
|
||||||
bbox=bbox.envelope
|
|
||||||
# Load the polygons for the coastline from a file
|
# Load the polygons for the coastline from a file
|
||||||
geometries=read_file(file_location, bbox=bbox)
|
geometries=read_file(file_location, bbox=bbox)
|
||||||
geometries=geometries.to_crs("epsg:4326")
|
|
||||||
perimeter = get_boundary(point, radius, geometries.crs, circle = circle, dilate = dilate)
|
perimeter = get_boundary(point, radius, geometries.crs, circle = circle, dilate = dilate)
|
||||||
|
|
||||||
# Project GDF
|
# Project GDF
|
||||||
|
Reference in New Issue
Block a user