EOmaps
EOmaps copied to clipboard
✏️ Add basic drawing capabilities
❗ This is a work-in-progress pull request to add basic drawing capabilities to EOmaps.
-
<shape>
is the shape to draw... currently there are-
circle
,rectangle
,polygon
-
-
kwargs
passed to the shape can be used to set the style- e.g.
fc="r", ec="k", lw=2
etc.
- e.g.
UI currently works as follows:
- first, execute the command to start the drawer
- for
circle
andrectangle
:- first LEFT click sets the center (drag mouse to set the radius)
- RIGHT click aborts the draw
- MIDDLE click fixes the radius and draws the shape
- for
polygon
- LEFT click to add points to the polygon (drag while hold to continuously add points)
- RIGHT click aborts the draw
- MIDDLE click to close the polygon and draw the shape
To start drawing, use:
m = Maps()
m.add_feature.preset.coastline()
m.util.draw.<shape>(... kwargs ...)
To draw shapes that are saved to a geo-coded shapefile, use: (shapes are automatically saved after draw (e.g. middle-click))
# path to a folder with write-access to store the shapes
save_path = ...
m = Maps()
m.add_feature.preset.coastline()
# initialize a new drawer that saves shapefiles to save_path
p1 = m.util.draw.new_poly(savepath=save_path)
# on next click, start drawing a rectangle
p1.<shape>(... kwargs ...)
these shapes can then be re-loaded to a map with:
m = Maps(Maps.CRS.Mollweide())
m.add_feature.preset.coastline()
gdf = gpd.read_file(save_path)
m.add_gdf(gdf, fc="g", alpha=0.5, lw=1, picker_name="asdf")
# make the shapes clickable
m.cb.pick["asdf"].attach.highlight_geometry(fc="r", alpha=.5)
m.cb.pick["asdf"].attach.annotate(text=lambda ID, **kwargs: f"This is shape {ID}")
![](https://user-images.githubusercontent.com/22773387/173678067-1c4b49ca-f049-43d3-8c89-7e6be88f27fa.gif)
Codecov Report
Merging #90 (6c81297) into dev (30d03c6) will increase coverage by
0.05%
. The diff coverage is78.78%
.
@@ Coverage Diff @@
## dev #90 +/- ##
==========================================
+ Coverage 71.35% 71.40% +0.05%
==========================================
Files 12 12
Lines 6518 6540 +22
==========================================
+ Hits 4651 4670 +19
- Misses 1867 1870 +3
Impacted Files | Coverage Δ | |
---|---|---|
eomaps/eomaps.py | 67.48% <50.00%> (ø) |
|
eomaps/utilities.py | 60.00% <72.22%> (+0.75%) |
:arrow_up: |
eomaps/helpers.py | 73.06% <88.88%> (+0.42%) |
:arrow_up: |
eomaps/callbacks.py | 87.57% <100.00%> (-0.04%) |
:arrow_down: |
Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.