MitchStares / MonitoringPlotter

0 stars 0 forks source link

Randomly generate plots within selected site polygon #1

Open MitchStares opened 2 years ago

MitchStares commented 2 years ago
  1. Loop st_make_grid through individual polygons inside layer ✅
  2. Grab centroids and display as points
  3. Create polygons on random points in that list within polygon that meet size specifications
  4. Select n number of grids from list of grids within individual polygon ✅
  5. Add functionality for complex polygons (not just Squares) ✅
  6. Test leaflets ability to work on individual selected polygons ✅
  7. Apply on selected polygon ✅
  8. Apply on selected polygons with button and gui options ✅
  9. Extend to non-rectangular shapes (e.g. Circles)
  10. Extend to imported layers ✅
MitchStares commented 2 years ago

Added functionality inside leaflet.extras to allow for click events to register on drawn items in shiny. Switched Shiny app to using MitchStares/leaflet.extras.updated. https://github.com/MitchStares/leaflet.extras.updated/commit/16ba84f6dac8bcc9b0eba41f01228095b09058f0

MitchStares commented 2 years ago

App now stores drawn and uploaded polygons in data.frame (polygonTracker) for intelligent filtering on makeGrid. makeGrid() and selectPlots() function work within an observeEvent() triggered by button press.

Primary issue for the implementation was determining what layer of leaflet the click belonged to. Uploaded shapefiles, even if stored on the same layer in leafletProxy() %>% addPolygon(group = "draw") had a different data structure. Uploaded files did not have an ID by default, and added IDs were stored under a separate layer within clickData$clickedPolygon$id$id[[1]] (in my case, id$iter[[1]]).

Drawn shapefiles always stored id directly under clickData$clickedPolygon$id.

Original implementation was using which() to subset rows of polygonTracker using a long form OR statement ||. This caused a weird error where multiple clicks on the map would trigger an atomic vector error on the which statement. Not entirely sure why.

Work around was to use an if() statement to determine if the names() of a clickData$clickedPolygon$id contained "iter", instead of the logical OR statement on polygonTracker.

Solved in commit eac22e69be64531f1275e926f0b5ff9297b02202

MitchStares commented 2 years ago

Checkboxes to toggle the rendering of grids or plots implemented. UI done via checkboxGroupInput() and server done with if() statements for each of the two options using %in% for the text values for each checkbox.