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 npimport pandas as pdimport rasterio as riofrom affine import Affinefrom rasterio.warp import calculate_default_transform, reproject, Resamplingimport datashader as dsfrom datashader.transfer_functions import shadefrom datashader.transfer_functions import stackfrom datashader.transfer_functions import dynspreadfrom datashader.transfer_functions import set_backgroundfrom datashader.colors import Elevationimport xrspatial# Convert the geometries of the input to x,y coordinates and create a new dataframedf = gdf_clipped.reset_index()[["index", "geometry"]]df["x"] = df.geometry.xdf["y"] = df.geometry.y# Calculate the canvas size based on the bounding box dimensions and pixel sizebbox_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 valuepoints_agg = cvs.points(df, x="x", y="y", agg=ds.min("index"))# Set non-finite data to zeropoints_agg.data[~np.isfinite(points_agg.data)] = 0# Create a shaded version of the pointspoints_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 metricproximity_agg = xrspatial.proximity(points_agg, distance_metric="GREAT_CIRCLE")# Stack the shaded points and proximity map togetherstack(shade(proximity_agg, cmap=["#bbeb9e", "black"], how="eq_hist"), points_shaded)
|