Calculate the length of shared boundaries between multiple polygonsLength of the boundary intersection...

Can you say "leftside right"?

Why does this quiz question say that protons and electrons do not combine to form neutrons?

Did ancient Germans take pride in leaving the land untouched?

Taking an academic pseudonym?

What could cause an entire planet of humans to become aphasic?

typeof generic and casted type

Minimum Viable Product for RTS game?

How can I give a Ranger advantage on a check due to Favored Enemy without spoiling the story for the player?

Is the tritone (A4 / d5) still banned in Roman Catholic music?

How do I narratively explain how in-game circumstances do not mechanically allow a PC to instantly kill an NPC?

Multiple null checks in Java 8

Is it possible to narrate a novel in a faux-historical style without alienating the reader?

What is the Buddhist view in Socratic questioning?

Determinant of 3x3 matrix by cofactor expansion

Short story about a man betting a group he could tell a story, and one of them would disappear and the others would not notice

Have the UK Conservatives lost the working majority and if so, what does this mean?

Is there any way to play D&D without a DM?

Disk space full during insert, what happens?

What happens if both players misunderstand the game state until it's too late?

Are one-line email responses considered disrespectful?

Sed-Grep-Awk operations

How can guns be countered by melee combat without raw-ability or exceptional explanations?

Is there a name for this series?

Do the speed limit reductions due to pollution also apply to electric cars in France?



Calculate the length of shared boundaries between multiple polygons


Length of the boundary intersection between two polygons in RHow to intersect lines and polygons in R?Using R to calculate the area of multiple polygons on a map that intersect with another overlaid polygonDifference between intersect {raster} and gIntersection {rgeos} in polygons - R?Identify adjacent and no-adjacent polygons between multiple shapefiles using R?PostGIS: Extracting borders between contiguous (but not perfectly aligned) polygonsFiguring out coordinates of a line in a shapefileAdjacency Matrix Not Including VerticesIntersect two shapefiles and out the result as shapefileLength of the boundary intersection between two polygons in Rget intersects of indexed grouped polygons between 2 SpatialPolygonDataframes in R













0















I am trying to calculate the length of shared boundaries between multiple polygons in R. Specifically, I would like to calculate the shared boundary length of all the polygons in Census Place GIS data downloaded from NHGIS from the year 2000. (If you want to obtain the exact data, go to NHGIS.org; Select Data; Under Geographic Levels, select Place; Under years, select 2000; In the table below, select the "GIS Files" tab and download the first file.)



I've looked at this thread, but unfortunately this code throws multiple errors:
https://stackoverflow.com/questions/45338384/calculate-the-length-of-shared-boundaries-between-multiple-polygons. I've tried working with the code to modify it but I haven't been able to get it to work. I believe the problem has to do with the complexity of the intersections. One gIntersection often has multiple classes (Points, Lines, Polygons) with different lengths, as seen in the previous link, but the proposed solution does not work.



My question is identical to this unanswered question:
Length of the boundary intersection between two polygons in R



    require(rgdal)  
require(rgeos)
library(sp)
library(raster)
library(spatialEco)
library(spdep)

Shapefile <- readOGR(".","US_place_2000")
Shapefile <- sp.na.omit(Shapefile, margin=1) # NAs are present for some reason?
Touching_List <- gTouches(Shapefile, byid = TRUE, returnDense=FALSE)
# also tried Touching_List <- poly2nb(Shapefile, queen = FALSE)

all.length.list <- lapply(1:length(Touching_List), function(from) {
if(is.null(Touching_List[[from]]==FALSE){
lines <- rgeos::gIntersection(Shapefile[from,], Shapefile[Touching_List[[from]],], byid = TRUE)
if (class(lines) == "SpatialCollections") {
list.Lines <- lapply(1:length(Touching_List[[from]]), function(to) {
line.single <- rgeos::gIntersection(Shapefile[from,], Shapefile[Touching_List[[from]][to],])
if (class(line.single) == "SpatialPoints") {
# Double the point to create a line
L1 <- rbind(line.single@coords, line.single@coords)
rownames(L1) <- letters[1:2]
Sl1 <- Line(L1)
Lines.single <- Lines(list(Sl1), ID = as.character(to))
} else if (class(line.single) == "SpatialLines") {
Lines.single <- line.single@lines[[1]]
Lines.single@ID <- as.character(to)
}
Lines.single
})
lines <- SpatialLines(list.Lines)
}
l_lines <- sp::SpatialLinesLengths(lines)
res <- data.frame(origin = from,
perimeter = perimeters[from],
touching = Touching_List[[from]],
t.length = l_lines,
t.pc = 100*l_lines/perimeters[from])
res
}
})

all.length.df <- do.call("rbind", all.length.list)









share|improve this question







New contributor




user2689604 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

























    0















    I am trying to calculate the length of shared boundaries between multiple polygons in R. Specifically, I would like to calculate the shared boundary length of all the polygons in Census Place GIS data downloaded from NHGIS from the year 2000. (If you want to obtain the exact data, go to NHGIS.org; Select Data; Under Geographic Levels, select Place; Under years, select 2000; In the table below, select the "GIS Files" tab and download the first file.)



    I've looked at this thread, but unfortunately this code throws multiple errors:
    https://stackoverflow.com/questions/45338384/calculate-the-length-of-shared-boundaries-between-multiple-polygons. I've tried working with the code to modify it but I haven't been able to get it to work. I believe the problem has to do with the complexity of the intersections. One gIntersection often has multiple classes (Points, Lines, Polygons) with different lengths, as seen in the previous link, but the proposed solution does not work.



    My question is identical to this unanswered question:
    Length of the boundary intersection between two polygons in R



        require(rgdal)  
    require(rgeos)
    library(sp)
    library(raster)
    library(spatialEco)
    library(spdep)

    Shapefile <- readOGR(".","US_place_2000")
    Shapefile <- sp.na.omit(Shapefile, margin=1) # NAs are present for some reason?
    Touching_List <- gTouches(Shapefile, byid = TRUE, returnDense=FALSE)
    # also tried Touching_List <- poly2nb(Shapefile, queen = FALSE)

    all.length.list <- lapply(1:length(Touching_List), function(from) {
    if(is.null(Touching_List[[from]]==FALSE){
    lines <- rgeos::gIntersection(Shapefile[from,], Shapefile[Touching_List[[from]],], byid = TRUE)
    if (class(lines) == "SpatialCollections") {
    list.Lines <- lapply(1:length(Touching_List[[from]]), function(to) {
    line.single <- rgeos::gIntersection(Shapefile[from,], Shapefile[Touching_List[[from]][to],])
    if (class(line.single) == "SpatialPoints") {
    # Double the point to create a line
    L1 <- rbind(line.single@coords, line.single@coords)
    rownames(L1) <- letters[1:2]
    Sl1 <- Line(L1)
    Lines.single <- Lines(list(Sl1), ID = as.character(to))
    } else if (class(line.single) == "SpatialLines") {
    Lines.single <- line.single@lines[[1]]
    Lines.single@ID <- as.character(to)
    }
    Lines.single
    })
    lines <- SpatialLines(list.Lines)
    }
    l_lines <- sp::SpatialLinesLengths(lines)
    res <- data.frame(origin = from,
    perimeter = perimeters[from],
    touching = Touching_List[[from]],
    t.length = l_lines,
    t.pc = 100*l_lines/perimeters[from])
    res
    }
    })

    all.length.df <- do.call("rbind", all.length.list)









    share|improve this question







    New contributor




    user2689604 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
    Check out our Code of Conduct.























      0












      0








      0








      I am trying to calculate the length of shared boundaries between multiple polygons in R. Specifically, I would like to calculate the shared boundary length of all the polygons in Census Place GIS data downloaded from NHGIS from the year 2000. (If you want to obtain the exact data, go to NHGIS.org; Select Data; Under Geographic Levels, select Place; Under years, select 2000; In the table below, select the "GIS Files" tab and download the first file.)



      I've looked at this thread, but unfortunately this code throws multiple errors:
      https://stackoverflow.com/questions/45338384/calculate-the-length-of-shared-boundaries-between-multiple-polygons. I've tried working with the code to modify it but I haven't been able to get it to work. I believe the problem has to do with the complexity of the intersections. One gIntersection often has multiple classes (Points, Lines, Polygons) with different lengths, as seen in the previous link, but the proposed solution does not work.



      My question is identical to this unanswered question:
      Length of the boundary intersection between two polygons in R



          require(rgdal)  
      require(rgeos)
      library(sp)
      library(raster)
      library(spatialEco)
      library(spdep)

      Shapefile <- readOGR(".","US_place_2000")
      Shapefile <- sp.na.omit(Shapefile, margin=1) # NAs are present for some reason?
      Touching_List <- gTouches(Shapefile, byid = TRUE, returnDense=FALSE)
      # also tried Touching_List <- poly2nb(Shapefile, queen = FALSE)

      all.length.list <- lapply(1:length(Touching_List), function(from) {
      if(is.null(Touching_List[[from]]==FALSE){
      lines <- rgeos::gIntersection(Shapefile[from,], Shapefile[Touching_List[[from]],], byid = TRUE)
      if (class(lines) == "SpatialCollections") {
      list.Lines <- lapply(1:length(Touching_List[[from]]), function(to) {
      line.single <- rgeos::gIntersection(Shapefile[from,], Shapefile[Touching_List[[from]][to],])
      if (class(line.single) == "SpatialPoints") {
      # Double the point to create a line
      L1 <- rbind(line.single@coords, line.single@coords)
      rownames(L1) <- letters[1:2]
      Sl1 <- Line(L1)
      Lines.single <- Lines(list(Sl1), ID = as.character(to))
      } else if (class(line.single) == "SpatialLines") {
      Lines.single <- line.single@lines[[1]]
      Lines.single@ID <- as.character(to)
      }
      Lines.single
      })
      lines <- SpatialLines(list.Lines)
      }
      l_lines <- sp::SpatialLinesLengths(lines)
      res <- data.frame(origin = from,
      perimeter = perimeters[from],
      touching = Touching_List[[from]],
      t.length = l_lines,
      t.pc = 100*l_lines/perimeters[from])
      res
      }
      })

      all.length.df <- do.call("rbind", all.length.list)









      share|improve this question







      New contributor




      user2689604 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.












      I am trying to calculate the length of shared boundaries between multiple polygons in R. Specifically, I would like to calculate the shared boundary length of all the polygons in Census Place GIS data downloaded from NHGIS from the year 2000. (If you want to obtain the exact data, go to NHGIS.org; Select Data; Under Geographic Levels, select Place; Under years, select 2000; In the table below, select the "GIS Files" tab and download the first file.)



      I've looked at this thread, but unfortunately this code throws multiple errors:
      https://stackoverflow.com/questions/45338384/calculate-the-length-of-shared-boundaries-between-multiple-polygons. I've tried working with the code to modify it but I haven't been able to get it to work. I believe the problem has to do with the complexity of the intersections. One gIntersection often has multiple classes (Points, Lines, Polygons) with different lengths, as seen in the previous link, but the proposed solution does not work.



      My question is identical to this unanswered question:
      Length of the boundary intersection between two polygons in R



          require(rgdal)  
      require(rgeos)
      library(sp)
      library(raster)
      library(spatialEco)
      library(spdep)

      Shapefile <- readOGR(".","US_place_2000")
      Shapefile <- sp.na.omit(Shapefile, margin=1) # NAs are present for some reason?
      Touching_List <- gTouches(Shapefile, byid = TRUE, returnDense=FALSE)
      # also tried Touching_List <- poly2nb(Shapefile, queen = FALSE)

      all.length.list <- lapply(1:length(Touching_List), function(from) {
      if(is.null(Touching_List[[from]]==FALSE){
      lines <- rgeos::gIntersection(Shapefile[from,], Shapefile[Touching_List[[from]],], byid = TRUE)
      if (class(lines) == "SpatialCollections") {
      list.Lines <- lapply(1:length(Touching_List[[from]]), function(to) {
      line.single <- rgeos::gIntersection(Shapefile[from,], Shapefile[Touching_List[[from]][to],])
      if (class(line.single) == "SpatialPoints") {
      # Double the point to create a line
      L1 <- rbind(line.single@coords, line.single@coords)
      rownames(L1) <- letters[1:2]
      Sl1 <- Line(L1)
      Lines.single <- Lines(list(Sl1), ID = as.character(to))
      } else if (class(line.single) == "SpatialLines") {
      Lines.single <- line.single@lines[[1]]
      Lines.single@ID <- as.character(to)
      }
      Lines.single
      })
      lines <- SpatialLines(list.Lines)
      }
      l_lines <- sp::SpatialLinesLengths(lines)
      res <- data.frame(origin = from,
      perimeter = perimeters[from],
      touching = Touching_List[[from]],
      t.length = l_lines,
      t.pc = 100*l_lines/perimeters[from])
      res
      }
      })

      all.length.df <- do.call("rbind", all.length.list)






      r






      share|improve this question







      New contributor




      user2689604 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.











      share|improve this question







      New contributor




      user2689604 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.









      share|improve this question




      share|improve this question






      New contributor




      user2689604 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.









      asked 17 mins ago









      user2689604user2689604

      1




      1




      New contributor




      user2689604 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.





      New contributor





      user2689604 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.






      user2689604 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.






















          0






          active

          oldest

          votes











          Your Answer








          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "79"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: false,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: null,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });






          user2689604 is a new contributor. Be nice, and check out our Code of Conduct.










          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fgis.stackexchange.com%2fquestions%2f313248%2fcalculate-the-length-of-shared-boundaries-between-multiple-polygons%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          0






          active

          oldest

          votes








          0






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes








          user2689604 is a new contributor. Be nice, and check out our Code of Conduct.










          draft saved

          draft discarded


















          user2689604 is a new contributor. Be nice, and check out our Code of Conduct.













          user2689604 is a new contributor. Be nice, and check out our Code of Conduct.












          user2689604 is a new contributor. Be nice, and check out our Code of Conduct.
















          Thanks for contributing an answer to Geographic Information Systems Stack Exchange!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fgis.stackexchange.com%2fquestions%2f313248%2fcalculate-the-length-of-shared-boundaries-between-multiple-polygons%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Щит и меч (фильм) Содержание Названия серий | Сюжет |...

          Венесуэла на летних Олимпийских играх 2000 Содержание Состав...

          Meter-Bus Содержание Параметры шины | Стандартизация |...