Closed PieterjanVerhelst closed 3 years ago
@damianooldoni just a kind reminder if you have an idea to solve this issue. If this is tackled, I can proceed with the analysis of the data 😄 .
I will fast check whether the solutions discussed in this post work and if yes, which one is the best one.
I find working with sf
so chill :smile:
> # transform to sf data.frame
> ws_bpns_sf <- st_as_sf(ws_bpns)
> ws_bpns <- load.shapefile("./data/Belgium_Netherlands/ws_bpns.shp",
+ "ws_bpns",
+ coordinate.string)
OGR data source with driver: ESRI Shapefile
Source: "C:\Users\damiano_oldoni\Documents\INBO\repositories\fish-tracking\scripts\receiver_distance_analysis\data\Belgium_Netherlands\ws_bpns.shp", layer: "ws_bpns"
with 1 features
It has 1 fields
Integer64 fields read as strings: Id
> # transform to sf data.frame
> ws_bpns_sf <- st_as_sf(ws_bpns)
> if (isFALSE(st_is_valid(ws_bpns_sf))) {
+ message(glue("Shapefile is invalid. Make it valid first."))
+ ws_bpns_sf <- st_make_valid(ws_bpns_sf)
+ valid_shape <- st_is_valid(ws_bpns_sf)
+ message(glue("Validation succeded: {valid_shape}"))
+ }
Shapefile is invalid. Make it valid first.
Validation succeded: TRUE
> # transform back to SpatialPolygonsDataFrame (sp)
> ws_bpns <- as_Spatial(ws_bpns_sf)
> remove(ws_bpns_sf)
It takes ages to import vhag
, I don't know why. But I would apply the same strategy as done above for ws_bpns
. If it works, I will put this validation step in a function so that you don't have to write so many lines of code in prepare_dataset.R
.
Let me know if it works. Thanks.
vhag
seems to have a valid geometry. And so, the commando study.area <- gUnion(vhag, ws_bpns)
doesn't throw any error anymore. :+1
@PieterjanVerhelst, please, check this and if you find it working as I found, I will make a branch where I will add the validation as a standard part of the preparation and I will put it in a function. A PR will then follow fast.
@damianooldoni thanks for the quick reply! Indeed vhag
takes a very long time to upload, therefore I created a shapefile with the selection of rivers I need. The file name is pbarn_freshwater.shp
and is in the folder \data\Belgium_Netherlands
. So if I am correct, you did not made changes to the code (I don't see any commits coming in), but you want me to try the chunk code from above, right?
update: that code works perfectly 😄 !! Here the result:
Bring on the PR!
Cool! I hope to find a little of time for it tomorrow.
For the project
2015 PHD VERHELST EEL
I tried to combine two shapefiles, one are lines (Vhag.shp
) and the other is a polygon (ws_bpns.shp
). Note that this is to calculate distances between stations from the Belgian Lifewatch network. I now use other shape files than before, because the 'new' ones have a better fit to the actual rivers and contain more tributaries (= more useful in the future when tracking network potential changes or expands). However, when runninggUnion()
this gives an error (line 33 - 45):For other projects I would also like to apply
gUnion()
on the following shapefile sets:Note that I use combinations per project, as I think creating a big shapefile covering Belgium and The Netherlands may in some cases be requiring too much calculation time for what I need. Unless you disagree, than we can make a big Belgium-Netherlands map (= Vhag.shp + ws_bpns.shp + LowCountries_Water_2004.shp + WATERDEEL_VLAK.shp)
All shapefiles are uploaded in the folder
\data\Belgium_Netherlands
under the branch #69 . Hence, I would only address this issue after that branch has been merged with the master branch.