inbo / fish-tracking

🐟 Collection of scripts for processing and analysing fish tracking data
3 stars 0 forks source link

Solve issues by merging lines with polygons with gUnion(): refactor to sf package? #72

Closed damianooldoni closed 2 years ago

damianooldoni commented 3 years ago

Merging lines and polygons is possible with gUnion() but it will return an object of class spatialCollections which is not very useful as it is a kind of list, a collection. See problems described in #71 .

Moving to sf package I think it becomes unavoidable. However, attention to be paid in the refactoring as we have to be sure that everything can be written using sf.

damianooldoni commented 3 years ago

ALthough refactoring to sf is something that sooner or later should be done, it seems not solving the problem caused by putting together polygons and lines

study.area_sf <- st_union(ws_bpns_sf, pbarn_freshwater_sf)
class(study.area_sf$geometry)
[1] "sfc_GEOMETRYCOLLECTION" "sfc"

and if I try to run a sf-ized version of find.projections.receivers() I get very soon an error where I try to get some coordinates from the study area:

Error in st_coordinates.sfc(st_geometry(x)) : 
  not implemented for objects of class sfc_GEOMETRYCOLLECTION 

I will try to find a way to make polygons from lines. In this way the union will be still a polygon instead of a collection.

damianooldoni commented 3 years ago

Yes, use mapview code for either lines or polygons only. Use leaflet for a combination of the two.

I am running that chunk, still waiting the crash :smile:

damianooldoni commented 3 years ago

I will reply further on the PR #73.