You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi, I am trying to create proximity maps using multi-point and multiline features, for multipoint it works fine, but I am not finding the right way to make it work for line geometries, what would be the appropriate way to convert the gpd to make it suitable for xrspatial?
Here is the working code for multipoint gpd as input:
import numpy as np
import pandas as pd
import rasterio as rio
from affine import Affine
from rasterio.warp import calculate_default_transform, reproject, Resampling
import datashader as ds
from datashader.transfer_functions import shade
from datashader.transfer_functions import stack
from datashader.transfer_functions import dynspread
from datashader.transfer_functions import set_background
from datashader.colors import Elevation
import xrspatial
# Convert the geometries of the input to x,y coordinates and create a new dataframe
df = gdf_clipped.reset_index()[["index", "geometry"]]
df["x"] = df.geometry.x
df["y"] = df.geometry.y
# Calculate the canvas size based on the bounding box dimensions and pixel size
bbox_width = mask.total_bounds[2] - gdf_clipped.total_bounds[0]
bbox_height = mask.total_bounds[3] - gdf_clipped.total_bounds[1]
if resolution == "1":
pixel_size = 0.009 # decimal degrees (1km)
elif resolution == "2":
pixel_size = 0.002245788210298804 # decimal degrees (250m)
W = int(np.ceil(bbox_width / pixel_size))
H = int(np.ceil(bbox_height / pixel_size))
cvs = ds.Canvas(plot_width=W, plot_height=H,
x_range=(gdf_clipped.total_bounds[0], gdf_clipped.total_bounds[2]),
y_range=(gdf_clipped.total_bounds[1], gdf_clipped.total_bounds[3]))
# Aggregate the points in the canvas using the minimum of their index value
points_agg = cvs.points(df, x="x", y="y", agg=ds.min("index"))
# Set non-finite data to zero
points_agg.data[~np.isfinite(points_agg.data)] = 0
# Create a shaded version of the points
points_shaded = dynspread(shade(points_agg, cmap="salmon", min_alpha=0, span=(0,1), how="linear"),
threshold=1,
max_px=5)
# Calculate the proximity of each point to its nearest neighbor using the Great Circle distance metric
proximity_agg = xrspatial.proximity(points_agg, distance_metric="GREAT_CIRCLE")
# Stack the shaded points and proximity map together
stack(shade(proximity_agg, cmap=["#bbeb9e", "black"], how="eq_hist"),
points_shaded)
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Hi, I am trying to create proximity maps using multi-point and multiline features, for multipoint it works fine, but I am not finding the right way to make it work for line geometries, what would be the appropriate way to convert the gpd to make it suitable for xrspatial?
Here is the working code for multipoint gpd as input:
Beta Was this translation helpful? Give feedback.
All reactions