CharlotteS.
CharlotteS.

Reputation: 447

R cran: sf Sew two MULTILINESTRING/LINESTRING

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

Upvotes: 0

Views: 519

Answers (1)

BEVAN
BEVAN

Reputation: 635

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)

Upvotes: 1

Related Questions