grass.jupyter: Created attracting and elegant legend feature for rasters in InteractiveMap.#7077
grass.jupyter: Created attracting and elegant legend feature for rasters in InteractiveMap.#7077shahid-rahaman wants to merge 4 commits intoOSGeo:mainfrom
Conversation
f0b4776 to
e568a16
Compare
|
Reproducible code examples and screenshots? |
@wenzeslaus Sorry for late reply, I have updated the description. I have been facing some dev system crash. Is there any standard way to setup dev environment? I somehow did but it was quirky, I installed grass from local repo by ./configure>make -j10> sudo make install, but it throws few errors sometimes due to which I cannot run local test/checks as it is not installed properly. Am I missing something or is there any documentation to setup dev enviroment? |
wenzeslaus
left a comment
There was a problem hiding this comment.
Well, the legend in screenshots does look attractive and elegant.
Anyway, you should still make the title shorter and more technical.
More work is needed here and I did not test myself yet, but I like the direction here.
| all_colours = subprocess.check_output(f"r.colors.out map={raster}", shell=True).decode("utf-8").strip() | ||
| colors = {} | ||
| last_ht = None | ||
| for colour in all_colours.split("\n"): |
There was a problem hiding this comment.
There is an API for calling tools. Preferably, use the new grass.tools API and JSON output.
| if "nv" in colour or "default" in colour: | ||
| continue | ||
| elev_col_info = colour.split() | ||
| ht = float(elev_col_info[0]) | ||
| rgb = elev_col_info[1] | ||
| label = f"{last_ht:.1f} - {ht:.1f} m" if last_ht else f"≤ {ht:.1f} m" | ||
| colors[label] = f"rgb({rgb.replace(':', ',')})" | ||
| last_ht = ht |
There was a problem hiding this comment.
While the result of this looks good for elevation and slope color tables in your screenshots, try with a viridis and magma color tables. Maybe you can sometimes use the r.colors.out output directly, while sometimes you need to take additional steps.
| border-bottom: 1px solid rgba(255, 255, 255, 0.1); | ||
| color: black; | ||
| "> | ||
| {raster.capitalize()} Map |
There was a problem hiding this comment.
A detail at this point, but since I noticed that: rasters have a title which would be the nice name for a legend. Use that instead of capitalize and name generation.
https://grass.osgeo.org/grass-devel/manuals/r.support.html
https://grass.osgeo.org/grass-devel/manuals/r.info.html
| from branca.element import MacroElement | ||
| from jinja2 import Template |
There was a problem hiding this comment.
This will need to be handled more carefully. Neither of those is our current direct dependency. jinja2 is used here and there for special things (like tests and addon tools) and we likely bring that in with folium (I did not check). However, branca is not the most active project and it is still <1.0.
| for item in reversed(list(self.map.layers)): | ||
| if isinstance(item, self._ipyleaflet.Popup): | ||
| self.map.remove(item) | ||
| self.map.remove(item) No newline at end of file |
| border: 1px solid rgba(0, 0, 0, 0.2); | ||
| border-radius: 12px; | ||
| color: black; | ||
| font-family: 'Segoe UI', Arial, sans-serif; |
There was a problem hiding this comment.
There is no user-specified font anywhere here? There is a font used for the 2D rendering (for the non-interactive Map). There is always GRASS_FONT env var which is meant for display/rendering so this would not be too far from the current use.
|
@wenzeslaus Thanks for your time, I understand there are some preferred approach for GRASS, I used python core logics and module to make it work, like "subprocess", I had used it several times personally. However, I will try align the code with the existing dependencies and preferred approach. |
|
Please, sync up to the main branch. Then, the following link will allow reviewers to test without the need to have the changes locally: |
I have synced it but getting libpdal error on this link but locally make worked fine without pdal. Am I doing something wrong? |
Created legend feature for rasters with easy to use commands. Gave it a transparent glass frost look for better UX.
@petrasovaa If looks good to you, I will write the tests for the corresponding entities.
Let me know if requires any adjustments.
For instance, use it like below.
Elevation Map

Slope Map

Aspect Map

regards