Second-level neighbors of large polygon (neighbors' neighbors)Large point to Polygon by...

How to play songs that contain one guitar when we have two or more guitarists?

Why are "square law" devices important?

How do I write a maintainable, fast, compile-time bit-mask in C++?

Is it ethical to apply for a job on someone's behalf?

Do error bars on probabilities have any meaning?

Why is quixotic not Quixotic (a proper adjective)?

What does "don't have a baby" imply or mean in this sentence?

How can I differentiate duration vs starting time

How bad is a Computer Science course that doesn't teach Design Patterns?

Why would you use 2 alternate layout buttons instead of 1, when only one can be selected at once

Is it common to refer to someone as "Prof. Dr. [LastName]"?

What does @ mean in a hostname in DNS configuration?

Why don't you get burned by the wood benches in a sauna?

Aliased pipeline using head and cut

Why is Bernie Sanders maximum accepted donation on actblue $5600?

If I have Haste cast on me, does it reduce the casting time for my spells that normally take more than a turn to cast?

How does the spell Slow affect freefall?

Integral problem. Unsure of the approach.

Can a Hydra make multiple opportunity attacks at once?

How do I add a strong "onion flavor" to the biryani (in restaurant style)?

Is there a way to pause a running process on Linux systems and resume later?

What is the reason behind this musical reference to Pinocchio in the Close Encounters main theme?

Found a major flaw in paper from home university – to which I would like to return

SQL Server 2017 crashes when backing up because filepath is wrong



Second-level neighbors of large polygon (neighbors' neighbors)


Large point to Polygon by buffer-join-buffer-dissolve issuesMosaic large dataset with RAny tool to view large tiff images?Doing spatial regression using big data when Spatial weight matrix is too large for R?Fill the gaps using nearest neighborsR memory issue with large polygon grid fileConverting coordinate and raster values of each pixel to csv of large raster using Python?Exporting Multiple Rasters to a Table: working with large datasetcreate neighborhood list in R with large datasetWhy does myRaster[1] <- 5 takes a very long time for a large raster?













0















I have a large-ish set of polygons and am after identifying second-level neighbors of each, that is, the neighbors of the neighbors of each polygon (distinctly, i.e. the 2nd-level neighbors cannot contain self or 1st-level neighbors).



With a smaller number of polygons this is very easy -- owing to the "traversal" property of an adjacency matrix, we can simply square the neighbors matrix and we'll have the second-level matrix (with some minor touch-ups for the "distinctness" condition), but this doesn't extend easily to a large set of polygons:



library(sp)
library(rgeos)

dim = c(150, 150)
poly = as(GridTopology(c(0, 0), c(1, 1), dim), 'SpatialPolygons')

plot(poly[sample(prod(dim), 100), ])

neighbors = gTouches(poly, byid = TRUE)
neighbors2 = neighbors %*% neighbors



Error: cannot allocate vector of size xxx Gb




(Actually it may well compute if you've got a big-RAM machine, but anyway it will be very slow)



The problem of course is that neighbors is a huge matrix, and it's quite sparse:



format(object.size(neighbors), 'Gb')
# [1] "1.9 Gb"
mean(neighbors)
# [1] 0.0003520079


This of course is what the returnDense argument of gTouches is for, but I'm struggling to use the following output to get second-level neighbors:



neighbors = gTouches(poly, byid = TRUE)








share



























    0















    I have a large-ish set of polygons and am after identifying second-level neighbors of each, that is, the neighbors of the neighbors of each polygon (distinctly, i.e. the 2nd-level neighbors cannot contain self or 1st-level neighbors).



    With a smaller number of polygons this is very easy -- owing to the "traversal" property of an adjacency matrix, we can simply square the neighbors matrix and we'll have the second-level matrix (with some minor touch-ups for the "distinctness" condition), but this doesn't extend easily to a large set of polygons:



    library(sp)
    library(rgeos)

    dim = c(150, 150)
    poly = as(GridTopology(c(0, 0), c(1, 1), dim), 'SpatialPolygons')

    plot(poly[sample(prod(dim), 100), ])

    neighbors = gTouches(poly, byid = TRUE)
    neighbors2 = neighbors %*% neighbors



    Error: cannot allocate vector of size xxx Gb




    (Actually it may well compute if you've got a big-RAM machine, but anyway it will be very slow)



    The problem of course is that neighbors is a huge matrix, and it's quite sparse:



    format(object.size(neighbors), 'Gb')
    # [1] "1.9 Gb"
    mean(neighbors)
    # [1] 0.0003520079


    This of course is what the returnDense argument of gTouches is for, but I'm struggling to use the following output to get second-level neighbors:



    neighbors = gTouches(poly, byid = TRUE)








    share

























      0












      0








      0








      I have a large-ish set of polygons and am after identifying second-level neighbors of each, that is, the neighbors of the neighbors of each polygon (distinctly, i.e. the 2nd-level neighbors cannot contain self or 1st-level neighbors).



      With a smaller number of polygons this is very easy -- owing to the "traversal" property of an adjacency matrix, we can simply square the neighbors matrix and we'll have the second-level matrix (with some minor touch-ups for the "distinctness" condition), but this doesn't extend easily to a large set of polygons:



      library(sp)
      library(rgeos)

      dim = c(150, 150)
      poly = as(GridTopology(c(0, 0), c(1, 1), dim), 'SpatialPolygons')

      plot(poly[sample(prod(dim), 100), ])

      neighbors = gTouches(poly, byid = TRUE)
      neighbors2 = neighbors %*% neighbors



      Error: cannot allocate vector of size xxx Gb




      (Actually it may well compute if you've got a big-RAM machine, but anyway it will be very slow)



      The problem of course is that neighbors is a huge matrix, and it's quite sparse:



      format(object.size(neighbors), 'Gb')
      # [1] "1.9 Gb"
      mean(neighbors)
      # [1] 0.0003520079


      This of course is what the returnDense argument of gTouches is for, but I'm struggling to use the following output to get second-level neighbors:



      neighbors = gTouches(poly, byid = TRUE)








      share














      I have a large-ish set of polygons and am after identifying second-level neighbors of each, that is, the neighbors of the neighbors of each polygon (distinctly, i.e. the 2nd-level neighbors cannot contain self or 1st-level neighbors).



      With a smaller number of polygons this is very easy -- owing to the "traversal" property of an adjacency matrix, we can simply square the neighbors matrix and we'll have the second-level matrix (with some minor touch-ups for the "distinctness" condition), but this doesn't extend easily to a large set of polygons:



      library(sp)
      library(rgeos)

      dim = c(150, 150)
      poly = as(GridTopology(c(0, 0), c(1, 1), dim), 'SpatialPolygons')

      plot(poly[sample(prod(dim), 100), ])

      neighbors = gTouches(poly, byid = TRUE)
      neighbors2 = neighbors %*% neighbors



      Error: cannot allocate vector of size xxx Gb




      (Actually it may well compute if you've got a big-RAM machine, but anyway it will be very slow)



      The problem of course is that neighbors is a huge matrix, and it's quite sparse:



      format(object.size(neighbors), 'Gb')
      # [1] "1.9 Gb"
      mean(neighbors)
      # [1] 0.0003520079


      This of course is what the returnDense argument of gTouches is for, but I'm struggling to use the following output to get second-level neighbors:



      neighbors = gTouches(poly, byid = TRUE)






      r big-data adjacency





      share












      share










      share



      share










      asked 8 mins ago









      MichaelChiricoMichaelChirico

      4151415




      4151415






















          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
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fgis.stackexchange.com%2fquestions%2f313164%2fsecond-level-neighbors-of-large-polygon-neighbors-neighbors%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
















          draft saved

          draft discarded




















































          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%2f313164%2fsecond-level-neighbors-of-large-polygon-neighbors-neighbors%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

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

          is 'sed' thread safeWhat should someone know about using Python scripts in the shell?Nexenta bash script uses...

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