-
-
Notifications
You must be signed in to change notification settings - Fork 311
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
grass.jupyter: Use InteractiveMap with custom projections #4204
Draft
29riyasaxena
wants to merge
8
commits into
OSGeo:main
Choose a base branch
from
29riyasaxena:customproj
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from 4 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
ad8383c
grass.jupyter: Use InteractiveMap with custom projections
29riyasaxena da3d28f
Modify CustomRenderer
29riyasaxena b190c8d
Update Code
29riyasaxena 66a6c9b
Display Map in custom_proj
29riyasaxena 3c2412e
Add g flag
29riyasaxena ac26da7
Add custom_CRS
29riyasaxena 0017b9d
Merge branch 'main' into customproj
petrasovaa a5388b4
Merge branch 'main' into customproj
echoix File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
# | ||
# AUTHOR(S): Caitlin Haedrich <caitlin DOT haedrich AT gmail> | ||
# Anna Petrasova <kratochanna AT gmail> | ||
# Riya <29riyasaxena AT gmail> | ||
# | ||
# PURPOSE: This module contains functions for interactive visualizations | ||
# in Jupyter Notebooks. | ||
|
@@ -16,7 +17,8 @@ | |
import base64 | ||
import json | ||
from pathlib import Path | ||
from .reprojection_renderer import ReprojectionRenderer | ||
import grass.script as gs | ||
from .reprojection_renderer import ReprojectionRenderer, DirectRenderer | ||
|
||
from .utils import ( | ||
get_region_bounds_latlon, | ||
|
@@ -213,6 +215,7 @@ def __init__( | |
use_region=False, | ||
saved_region=None, | ||
map_backend=None, | ||
crs=None, | ||
): | ||
"""Creates a blank folium/ipyleaflet map centered on g.region. | ||
|
||
|
@@ -305,14 +308,44 @@ def _import_ipyleaflet(error): | |
# Store Region | ||
self.region = None | ||
|
||
if crs: | ||
proj = gs.read_command("g.proj", flags="jf", srid=crs) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I meant
You can use parse_command |
||
crs_dict = {"name": "crs", "proj4def": proj} | ||
self._renderer = DirectRenderer( | ||
crs=crs_dict, use_region=use_region, saved_region=saved_region | ||
) | ||
self.bounds = self._renderer.get_bbox() | ||
self.resolution = self._renderer.get_resolution() | ||
self.origin = self._renderer.get_origin() | ||
custom_crs = { | ||
"name": "custom", | ||
"proj4def": crs_dict, | ||
"bounds": self.bounds, | ||
"origin": self.origin, | ||
"resolutions": self.origin, | ||
} | ||
|
||
else: | ||
self._renderer = ReprojectionRenderer( | ||
use_region=use_region, saved_region=saved_region | ||
) | ||
|
||
if self._ipyleaflet: | ||
basemap = xyzservices.providers.query_name(tiles) | ||
if API_key and basemap.get("accessToken"): | ||
basemap["accessToken"] = API_key | ||
layout = self._ipywidgets.Layout(width=f"{width}px", height=f"{height}px") | ||
self.map = self._ipyleaflet.Map( | ||
basemap=basemap, layout=layout, scroll_wheel_zoom=True | ||
) | ||
if crs: | ||
self.map = self._ipyleaflet.Map( | ||
basemap=basemap, | ||
layout=layout, | ||
scroll_wheel_zoom=True, | ||
crs=custom_crs, | ||
) | ||
else: | ||
self.map = self._ipyleaflet.Map( | ||
basemap=basemap, layout=layout, scroll_wheel_zoom=True | ||
) | ||
|
||
else: | ||
self.map = self._folium.Map( | ||
|
@@ -321,14 +354,11 @@ def _import_ipyleaflet(error): | |
tiles=tiles, | ||
API_key=API_key, # pylint: disable=invalid-name | ||
) | ||
|
||
# Set LayerControl default | ||
self.layer_control_object = None | ||
self.region_rectangle = None | ||
|
||
self._renderer = ReprojectionRenderer( | ||
use_region=use_region, saved_region=saved_region | ||
) | ||
|
||
def add_vector(self, name, title=None, **kwargs): | ||
"""Imports vector into temporary WGS84 location, re-formats to a GeoJSON and | ||
adds to map. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
You need to get the CRS of the current project with g.proj, use the 'srid' key to get EPSG