inbo / fish-tracking

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

Error in calculating distances between receivers #79

Closed PieterjanVerhelst closed 8 months ago

PieterjanVerhelst commented 10 months ago

I run the code in receiver-distance_analysis (code prepare_dataset.R) to calculate the distance between stations of the michimit project. To do so, this code is ran to load and process the shapefiles of the study area (code lines 380 - 408):

# Michimit
michimit <- load.shapefile("./data/Belgium_Netherlands/michimit_rivers.shp",
                            "michimit_rivers",
                           coordinate_epsg)
plot(michimit)

ws_bpns <- load.shapefile("./data/Belgium_Netherlands/ws_bpns.shp",
                          "ws_bpns",
                          coordinate_epsg)
plot(ws_bpns$geometry)

# Validate waterbodies
michimit <- validate_waterbody(michimit)
ws_bpns <- validate_waterbody(ws_bpns)

# Combine shapefiles
michimit$origin_shapefile = "michimit"
ws_bpns$origin_shapefile = "ws_bpns_sf"

ws_bpns <- 
  ws_bpns %>%
  dplyr::select(Id, origin_shapefile, geometry)
michimit <- 
  michimit %>% 
  dplyr::select(Id = OIDN, origin_shapefile, geometry)

study.area <- rbind(michimit, ws_bpns)

plot(study.area)

Next, the stations are loaded (code line: 604 - 608):

# Michimit network
locations.receivers <- load.receivers(
  "./data/receivernetworks/receivernetwork_michimit.csv",
  coordinate_epsg
)

When I run the code to project the receivers on the shapefiles, I get an error (code line 659 - 666):

# for study area combined by two study areas made of polygons and lines 
projections.locations.receivers <- find.projections.receivers(
  shape.study.area = michimit,
  receivers = locations.receivers,
  projection = coordinate_epsg,
  shape.study.area2 = ws_bpns, 
  shape.study.area_merged = study.area
)

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

@damianooldoni any thoughts on this? Package inconsistency?