0

I try to sew/merge/bind two LINESTRINGs together (spanish coast + french coast) to have the full map of the whole coast. I found all the shpaefiles here:

https://www.marineregions.org/gazetteer.php?p=details&id=3417

https://www.marineregions.org/gazetteer.php?p=details&id=19888

Import and plot the data

frenchCoast_CoteBanyuls <- st_read("coasts_subnational/coasts_subnational.shp") %>% 
  st_geometry() # 
plot(frenchCoast_CoteBanyuls)

spainCoast_CoteBanyuls <- st_read("coasts_subnational SPAIN/coasts_subnational.shp")%>% 
  st_geometry() # 
spainCoast_CoteBanyuls <- st_cast(x = spainCoast_CoteBanyuls, to = "LINESTRING")

plot(spainCoast_CoteBanyuls, add = T)

enter image description here

enter image description here

This map and features seem ok.

According to all the posts I found, I tried to merge the two shapefiles together:

CoteBanyuls_c <- c(frenchCoast_CoteBanyuls, spainCoast_CoteBanyuls)
# CoteBanyuls_rbind <- rbind(frenchCoast_CoteBanyuls, spainCoast_CoteBanyuls)
# CoteBanyuls <- st_union(CoteBanyuls)
# CoteBanyuls <- union(CoteBanyuls)
# CoteBanyuls <- bind(CoteBanyuls)
plot(CoteBanyuls)

the c() function gives a shapefile that does not have the good dimensions (see below) and none of these solutions does plot the good shape of the two coast merged (seems to plot only the spanish coast).

enter image description here

enter image description here

What did I do wrong ? I do not understand why these solutions are not working... Do you have some ideas ?

Thanks in advance ! Charlotte

CharlotteS.
  • 355
  • 1
  • 12

1 Answers1

1

I think the issue comes from extracting only the geometry attributes before you combine them. Try this:

frenchCoast_CoteBanyuls <- st_read("coasts_subnational/coasts_subnational.shp")
spainCoast_CoteBanyuls <- st_read("coasts_subnational SPAIN/coasts_subnational.shp")

combined_coast <- rbind(spainCoast_CoteBanyuls, frenchCoast_CoteBanyuls) 

mapview::mapview(combined_coast)
BEVAN
  • 426
  • 2
  • 12
  • Hey Bevan! Thank you very much for your answer and for the delay of mine. It seems that I have a problem with the script: > mapview::mapview(combined_coast) Error in gsub("", "\\u003c/", payload, fixed = TRUE) : input string 1 is invalid UTF-8 I cannot understand this answer? An idea ? Thanks again !! – CharlotteS. Jun 09 '22 at 21:43
  • I am pretty sure it due to the accent in the text fields in the French dataset, though I don't get that error unless I try to assign one of those variables to color or something. The mapview part was not part of your original workflow and just how I quickly check spatial stuff in R on top of a basemap. You can proably ignore it and just proceed with your merged coastline – BEVAN Jun 10 '22 at 02:16