Skip to content
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

feat: generate h3 polygons and create webmap #46

Merged
merged 41 commits into from
Nov 21, 2024

Conversation

ioalexei
Copy link
Contributor

@ioalexei ioalexei commented May 17, 2024

Addresses issue #25

Adds files:

  • points_to_h3.py
  • create_webmap.py
  • templates/maplibre_template.html

Points to H3

Input:

  • Input file: point layer with GVI scores
  • Output file
  • (Optional) H3 cell resolution (see here)

Output:

  • File containing h3 polygons at the specified resolution with mean GVI score as an attribute

Example usage:

  • python3 -m src.points_to_h3 data/processed/gvi_score_layer.gpkg data/processed/h3_polygons.gpkg 11

Create webmap

Input:

  • Input file: H3 polygon file
  • Output: HTML file to display MapLibre webmap
  • (Optional) filename for HTML file
  • (Optional) default zoom level for webmap

Output:

  • HTML file that contains javascript to generate a webmap showing the H3 polygons, styled by mean GVI score

Example usage:

  • python3 -m src.create_webmap ./data/processed/h3_polygons.gpkg ./outputs gvi_webmap.html 10

ioalexei and others added 21 commits May 16, 2024 13:37
- add h3pandas to dependencies
- add app launch to end of file
- use single aggregation (mean) instead of multiple
- change order of arguments based on defaults
- adding Typer help and defaults
- adding code to generate colours and breakpoints for map
- formatting
- fix interpolation breaks
- fix hard coded template path
Hard code colours into dataframe/json rather than using MapLibre interpolation
remove temp file
- add pop to show gvi score when polygon is clicked
- Round GVI scores to 2 decimal places for neater pop-ups
- Reduce bounding box buffer from 0.5 degrees to 0.25
- Set default zoom to 12
Update sample .env file to include placeholder for Maptiler api key
Fix line lengths
@danbjoseph
Copy link
Member

  • When I generate the web map and then open the file in a browser the map is blank and there is an error is in the console. is it possible to have it generate the overlay but just not show the basemap if there's no API key? can you add details to the Readme about the API key (where to get it, where to put it)?
    Screenshot 2024-06-17 at 5 23 54 PM

  • hex grids look good, although trying to generate with resolution 9 results in an error

Screenshot 2024-06-17 at 5 17 43 PM Screenshot 2024-06-17 at 5 18 03 PM Screenshot 2024-06-17 at 5 20 01 PM

@ioalexei
Copy link
Contributor Author

Added a note to the ReadMe re. MapTiler API key - will look into the other comments and come back to you

Add a leading `0` to cell resolution if it is  a single digit
The Jinja template will use an empty basemap if there is no Maptiler API key in the .env file
@danbjoseph
Copy link
Member

also, i added a MapTiler API key to the .env file but it doesn't seem to be reading it in.

@ioalexei
Copy link
Contributor Author

2e3586c fixes the Maptiler API issue by adding load_dotenv() to the create_webmap script and correcting an error in the HTML template

the error above is because the function expects zoom level to be the 4th of 4 arguments (input data, output folder, output filename, zoom level) - because only 3 were passed, it interpreted zoom level as the file name. I've made a mistake in the example in the documentation.

Is it better to not ask for a separate folder and filename and just take a path to a file for the output? Or should I just update the readme to give a code sampe that will work with this pattern

@danbjoseph
Copy link
Member

danbjoseph commented Aug 13, 2024

yeah, i think a path to the file (instead of separate path and filename) matches the other steps?

@ioalexei
Copy link
Contributor Author

Updated with ioalexei@b42316d

@danbjoseph danbjoseph changed the title Generate h3 polygons and create webmap feat: generate h3 polygons and create webmap Aug 26, 2024
@danbjoseph
Copy link
Member

this is looking good, except for it to render the hex layer when there isn't a MapTiler API key, it seems that the .env file has to have...

MAPTILER_API_KEY = "None"

if the user copies the template and doesn't touch the line then it will be MAPTILER_API_KEY = "MY_MAPTILER_API_KEY" and it doesn't work? or if they delete the line and the MAPTILER_API_KEY key isn't present, it doesn't work?

@danbjoseph
Copy link
Member

if there is no MAPTILER_API_KEY line it works (shows the hex grid without a base map)

MAPTILER_API_KEY = "MAPTILER_API_KEY"  # doesn't work 
MAPTILER_API_KEY = ""  # doesn't work 

i guess we could just put a commented note in the .env.example file to remove the line if not used?

@ioalexei
Copy link
Contributor Author

Added a new commit to account for a blank variable - but think it makes sense to put a note in the example .env file too as it might be hard to account of all the ways it could be invalid

@danbjoseph
Copy link
Member

  • functionality seems good to me for a merge
  • as @ioalexei notes, ruff flags h3pandas as unused but it's used in line 79 of the hex creation file ( gdf.h3.geo_to_h3()) - is there an edit that will let the check pass?

@danbjoseph
Copy link
Member

i don't thinkviridis is ideal for this because of the green for the mid values and then yellow and purple on the extremes. i added a commit to change it Greens.

Screenshot 2024-10-25 at 5 38 09 PM Screenshot 2024-10-25 at 5 37 17 PM

@ioalexei
Copy link
Contributor Author

Added fix for #88 :

  • changed int to float for legend generation, so that it handles smaller ranges
  • changed rounding in the legend labels to 2 decimal places rather than 0

src/points_to_h3.py Outdated Show resolved Hide resolved
@danbjoseph danbjoseph self-requested a review November 21, 2024 01:00
@danbjoseph danbjoseph merged commit 3a4a8e3 into AmericanRedCross:main Nov 21, 2024
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants