-
Notifications
You must be signed in to change notification settings - Fork 15
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
Quadtree read/write, no build #226
base: main
Are you sure you want to change the base?
Conversation
…reased readability)
Done
Not working/testes:
|
def map_overlay(self, file_name, xlim=None, ylim=None, color="black", width=800): | ||
if self.data is None: | ||
# No grid (yet) | ||
return False | ||
try: | ||
if not hasattr(self, "df"): | ||
self.df = None | ||
if self.df is None: | ||
self._get_datashader_dataframe() | ||
|
||
transformer = Transformer.from_crs(4326, 3857, always_xy=True) | ||
xl0, yl0 = transformer.transform(xlim[0], ylim[0]) | ||
xl1, yl1 = transformer.transform(xlim[1], ylim[1]) | ||
xlim = [xl0, xl1] | ||
ylim = [yl0, yl1] | ||
ratio = (ylim[1] - ylim[0]) / (xlim[1] - xlim[0]) | ||
height = int(width * ratio) | ||
cvs = ds.Canvas( | ||
x_range=xlim, y_range=ylim, plot_height=height, plot_width=width | ||
) | ||
agg = cvs.line(self.df, x=["x1", "x2"], y=["y1", "y2"], axis=1) | ||
img = tf.shade(agg) | ||
path = os.path.dirname(file_name) | ||
if not path: | ||
path = os.getcwd() | ||
name = os.path.basename(file_name) | ||
name = os.path.splitext(name)[0] | ||
export_image(img, name, export_path=path) | ||
return True | ||
except Exception: | ||
return False | ||
|
||
def snap_to_grid(self, polyline, max_snap_distance=1.0): | ||
if len(polyline) == 0: | ||
return gpd.GeoDataFrame() | ||
geom_list = [] | ||
for iline, line in polyline.iterrows(): | ||
geom = line["geometry"] | ||
if geom.geom_type == "LineString": | ||
geom_list.append(geom) | ||
gdf = gpd.GeoDataFrame({"geometry": geom_list}) | ||
snapped_uds, snapped_gdf = xu.snap_to_grid( | ||
gdf, self.data.grid, max_snap_distance=max_snap_distance | ||
) | ||
snapped_gdf = snapped_gdf.set_crs(self.crs) | ||
return snapped_gdf | ||
|
||
# Internal functions | ||
def _get_datashader_dataframe(self): | ||
# Create a dataframe with line elements | ||
x1 = self.data.grid.edge_node_coordinates[:, 0, 0] | ||
x2 = self.data.grid.edge_node_coordinates[:, 1, 0] | ||
y1 = self.data.grid.edge_node_coordinates[:, 0, 1] | ||
y2 = self.data.grid.edge_node_coordinates[:, 1, 1] | ||
transformer = Transformer.from_crs(self.crs, 3857, always_xy=True) | ||
x1, y1 = transformer.transform(x1, y1) | ||
x2, y2 = transformer.transform(x2, y2) | ||
self.df = pd.DataFrame(dict(x1=x1, y1=y1, x2=x2, y2=y2)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure if this belongs in this repo? Especially the datashader stuff is really meant for GUI stuff and could be easily rewritten to two simple functions (1) that converts a quadtree grid into a dataframe and (2) that creates a map overlay image based on xlim ylim and the dataframe
Issue addressed
Fixes #
Explanation
Explain how you addressed the bug/feature request, what choices you made and why.
Checklist
main
Additional Notes (optional)
Add any additional notes or information that may be helpful.