The slot for “plotOrder” comes up as 1 instead of a vector with length specific to my data The 2019 Stack Overflow Developer Survey Results Are InSubset a SpatialPolygonsDataFrame by ID in R?Convert a spatial polygon object to data frame using RSpatial weight matrix with boundary effects in R?Dissolving/Unifying Ill Behaved/Irregular Polygons in RData frame to SpatialPolygonsDataFrame with multiple polygons“Hole” argument ignored in call to Polygon functionUnique SpatialPolygons object with multiple polygons slots in RBuilding multiple extents as polygons from lat/long list values in RGroup and aggregate SpatialPolygonsDataFrame by column in RGroup and union polygons that share a border in R

Why doesn't shell automatically fix "useless use of cat"?

Falsification in Math vs Science

Flight paths in orbit around Ceres?

Why does the nucleus not repel itself?

Match Roman Numerals

Using xargs with pdftk

What is the motivation for a law requiring 2 parties to consent for recording a conversation

Cooking pasta in a water boiler

Can we generate random numbers using irrational numbers like π and e?

What is the most efficient way to store a numeric range?

Is it correct to say the Neural Networks are an alternative way of performing Maximum Likelihood Estimation? if not, why?

Geography at the pixel level

Worn-tile Scrabble

I am an eight letter word. What am I?

Relationship between Gromov-Witten and Taubes' Gromov invariant

How can I add encounters in the Lost Mine of Phandelver campaign without giving PCs too much XP?

Did any laptop computers have a built-in 5 1/4 inch floppy drive?

Why was M87 targeted for the Event Horizon Telescope instead of Sagittarius A*?

Why don't hard Brexiteers insist on a hard border to prevent illegal immigration after Brexit?

A word that means fill it to the required quantity

Why doesn't UInt have a toDouble()?

Is an up-to-date browser secure on an out-of-date OS?

How do you keep chess fun when your opponent constantly defeats?

Is it ethical to upload a automatically generated paper to a non peer-reviewed site as part of a larger research?



The slot for “plotOrder” comes up as 1 instead of a vector with length specific to my data



The 2019 Stack Overflow Developer Survey Results Are InSubset a SpatialPolygonsDataFrame by ID in R?Convert a spatial polygon object to data frame using RSpatial weight matrix with boundary effects in R?Dissolving/Unifying Ill Behaved/Irregular Polygons in RData frame to SpatialPolygonsDataFrame with multiple polygons“Hole” argument ignored in call to Polygon functionUnique SpatialPolygons object with multiple polygons slots in RBuilding multiple extents as polygons from lat/long list values in RGroup and aggregate SpatialPolygonsDataFrame by column in RGroup and union polygons that share a border in R



.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








-1















My goal is to find neighbors from my SpatialPolygons object using the poly2nb() command from the sp package in R.



This is my code thus far:



 p <- s_gis %>%
select(long, lat) %>%
Polygon()
ps <- Polygons(list(p), 1000)
sps <- SpatialPolygons(list(ps))


where s_gis is my dataset. I'm otherwise able to make a successful SpatialPolygons object except for the fact that the slot for plotOrder reads 1, instead of 636353 like it is in my dataset.



Running the poly2nb() commands returns an error Error in sp$mbxv[i]:(n * 2) : argument of length 0 which I'm assuming is coming from the fact that it's finding 0 neighbors given that I only have a plotOrder of 1.



How do I modify the plotOrder?



In addition, regarding my error message from the poly2nb() command, if the problem runs deeper, can someone shed some insight as to why?



I have also tried ps@plotOrder <- s_gis$order to no avail.



EDIT:



#get lat, long, and groupid
s_gis_latlon <- s_gis %>%
select(long,lat, group)

#group lists by group id
p_groups <- split(s_gis_latlon, s_gis_latlon$group)

#delete group id so that we can have 2-column matrix for Polygon
p_groups1 <- lapply(p_groups, function(x) x[,3] <- NULL; x )

# turn each element of list into a polygon
p_groups1 <- lapply(names(p_groups1),
function(x) b <- Polygon(p_groups1[[x]])
b
)

#turn list of polygons into Polygons
ps <- Polygons(p_groups1,1)

data <- s_gis %>%
group_by(group) %>%
summarize(district_wealthrange = mean(wealthrange))

#create SpatialPolygons object
sps <- SpatialPolygons(ps@Polygons)


I'm getting the error Error in SpatialPolygons(ps@Polygons) :
no slot of name "Polygons" for this object of class "Polygon"










share|improve this question









New contributor




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




















  • What's s_gis? Can you show us its summary() and maybe its head()? What does sps end up as? Is it one polygon or many? How are you running poly2nb to get that error? What are you running it on? On sps? Do you care about the plot order or working out the neighbourhood?

    – Spacedman
    Apr 5 at 23:37












  • s_gis is one of the datasets I'm using. The summary is quite large; however, I did select out long and lat which results in a tibble with dimensions 661228 x 2. sps ends up Slot "plotOrder": [1] 1 Slot "labpt": [1] 76.83899 29.49845 Slot "ID": [1] "1000" Slot "area": [1] 196.6975 Slot "coords": # I removed these to save char. space Slot "plotOrder": [1] 1 Slot "bbox": min max x 68.186249 97.41529 y 6.755953 37.07827 Slot "proj4string": CRS arguments: +proj=longlat +datum=WGS84

    – Lathan
    Apr 5 at 23:46












  • I'm runnning poly2nb(sps, queen = FALSE) and I care more about working out the neighborhood. Thanks so much for your quick response!

    – Lathan
    Apr 5 at 23:49

















-1















My goal is to find neighbors from my SpatialPolygons object using the poly2nb() command from the sp package in R.



This is my code thus far:



 p <- s_gis %>%
select(long, lat) %>%
Polygon()
ps <- Polygons(list(p), 1000)
sps <- SpatialPolygons(list(ps))


where s_gis is my dataset. I'm otherwise able to make a successful SpatialPolygons object except for the fact that the slot for plotOrder reads 1, instead of 636353 like it is in my dataset.



Running the poly2nb() commands returns an error Error in sp$mbxv[i]:(n * 2) : argument of length 0 which I'm assuming is coming from the fact that it's finding 0 neighbors given that I only have a plotOrder of 1.



How do I modify the plotOrder?



In addition, regarding my error message from the poly2nb() command, if the problem runs deeper, can someone shed some insight as to why?



I have also tried ps@plotOrder <- s_gis$order to no avail.



EDIT:



#get lat, long, and groupid
s_gis_latlon <- s_gis %>%
select(long,lat, group)

#group lists by group id
p_groups <- split(s_gis_latlon, s_gis_latlon$group)

#delete group id so that we can have 2-column matrix for Polygon
p_groups1 <- lapply(p_groups, function(x) x[,3] <- NULL; x )

# turn each element of list into a polygon
p_groups1 <- lapply(names(p_groups1),
function(x) b <- Polygon(p_groups1[[x]])
b
)

#turn list of polygons into Polygons
ps <- Polygons(p_groups1,1)

data <- s_gis %>%
group_by(group) %>%
summarize(district_wealthrange = mean(wealthrange))

#create SpatialPolygons object
sps <- SpatialPolygons(ps@Polygons)


I'm getting the error Error in SpatialPolygons(ps@Polygons) :
no slot of name "Polygons" for this object of class "Polygon"










share|improve this question









New contributor




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




















  • What's s_gis? Can you show us its summary() and maybe its head()? What does sps end up as? Is it one polygon or many? How are you running poly2nb to get that error? What are you running it on? On sps? Do you care about the plot order or working out the neighbourhood?

    – Spacedman
    Apr 5 at 23:37












  • s_gis is one of the datasets I'm using. The summary is quite large; however, I did select out long and lat which results in a tibble with dimensions 661228 x 2. sps ends up Slot "plotOrder": [1] 1 Slot "labpt": [1] 76.83899 29.49845 Slot "ID": [1] "1000" Slot "area": [1] 196.6975 Slot "coords": # I removed these to save char. space Slot "plotOrder": [1] 1 Slot "bbox": min max x 68.186249 97.41529 y 6.755953 37.07827 Slot "proj4string": CRS arguments: +proj=longlat +datum=WGS84

    – Lathan
    Apr 5 at 23:46












  • I'm runnning poly2nb(sps, queen = FALSE) and I care more about working out the neighborhood. Thanks so much for your quick response!

    – Lathan
    Apr 5 at 23:49













-1












-1








-1








My goal is to find neighbors from my SpatialPolygons object using the poly2nb() command from the sp package in R.



This is my code thus far:



 p <- s_gis %>%
select(long, lat) %>%
Polygon()
ps <- Polygons(list(p), 1000)
sps <- SpatialPolygons(list(ps))


where s_gis is my dataset. I'm otherwise able to make a successful SpatialPolygons object except for the fact that the slot for plotOrder reads 1, instead of 636353 like it is in my dataset.



Running the poly2nb() commands returns an error Error in sp$mbxv[i]:(n * 2) : argument of length 0 which I'm assuming is coming from the fact that it's finding 0 neighbors given that I only have a plotOrder of 1.



How do I modify the plotOrder?



In addition, regarding my error message from the poly2nb() command, if the problem runs deeper, can someone shed some insight as to why?



I have also tried ps@plotOrder <- s_gis$order to no avail.



EDIT:



#get lat, long, and groupid
s_gis_latlon <- s_gis %>%
select(long,lat, group)

#group lists by group id
p_groups <- split(s_gis_latlon, s_gis_latlon$group)

#delete group id so that we can have 2-column matrix for Polygon
p_groups1 <- lapply(p_groups, function(x) x[,3] <- NULL; x )

# turn each element of list into a polygon
p_groups1 <- lapply(names(p_groups1),
function(x) b <- Polygon(p_groups1[[x]])
b
)

#turn list of polygons into Polygons
ps <- Polygons(p_groups1,1)

data <- s_gis %>%
group_by(group) %>%
summarize(district_wealthrange = mean(wealthrange))

#create SpatialPolygons object
sps <- SpatialPolygons(ps@Polygons)


I'm getting the error Error in SpatialPolygons(ps@Polygons) :
no slot of name "Polygons" for this object of class "Polygon"










share|improve this question









New contributor




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












My goal is to find neighbors from my SpatialPolygons object using the poly2nb() command from the sp package in R.



This is my code thus far:



 p <- s_gis %>%
select(long, lat) %>%
Polygon()
ps <- Polygons(list(p), 1000)
sps <- SpatialPolygons(list(ps))


where s_gis is my dataset. I'm otherwise able to make a successful SpatialPolygons object except for the fact that the slot for plotOrder reads 1, instead of 636353 like it is in my dataset.



Running the poly2nb() commands returns an error Error in sp$mbxv[i]:(n * 2) : argument of length 0 which I'm assuming is coming from the fact that it's finding 0 neighbors given that I only have a plotOrder of 1.



How do I modify the plotOrder?



In addition, regarding my error message from the poly2nb() command, if the problem runs deeper, can someone shed some insight as to why?



I have also tried ps@plotOrder <- s_gis$order to no avail.



EDIT:



#get lat, long, and groupid
s_gis_latlon <- s_gis %>%
select(long,lat, group)

#group lists by group id
p_groups <- split(s_gis_latlon, s_gis_latlon$group)

#delete group id so that we can have 2-column matrix for Polygon
p_groups1 <- lapply(p_groups, function(x) x[,3] <- NULL; x )

# turn each element of list into a polygon
p_groups1 <- lapply(names(p_groups1),
function(x) b <- Polygon(p_groups1[[x]])
b
)

#turn list of polygons into Polygons
ps <- Polygons(p_groups1,1)

data <- s_gis %>%
group_by(group) %>%
summarize(district_wealthrange = mean(wealthrange))

#create SpatialPolygons object
sps <- SpatialPolygons(ps@Polygons)


I'm getting the error Error in SpatialPolygons(ps@Polygons) :
no slot of name "Polygons" for this object of class "Polygon"







r sp spdep






share|improve this question









New contributor




Lathan 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




Lathan 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








edited Apr 6 at 18:20







Lathan













New contributor




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









asked Apr 5 at 23:25









LathanLathan

32




32




New contributor




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





New contributor





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






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












  • What's s_gis? Can you show us its summary() and maybe its head()? What does sps end up as? Is it one polygon or many? How are you running poly2nb to get that error? What are you running it on? On sps? Do you care about the plot order or working out the neighbourhood?

    – Spacedman
    Apr 5 at 23:37












  • s_gis is one of the datasets I'm using. The summary is quite large; however, I did select out long and lat which results in a tibble with dimensions 661228 x 2. sps ends up Slot "plotOrder": [1] 1 Slot "labpt": [1] 76.83899 29.49845 Slot "ID": [1] "1000" Slot "area": [1] 196.6975 Slot "coords": # I removed these to save char. space Slot "plotOrder": [1] 1 Slot "bbox": min max x 68.186249 97.41529 y 6.755953 37.07827 Slot "proj4string": CRS arguments: +proj=longlat +datum=WGS84

    – Lathan
    Apr 5 at 23:46












  • I'm runnning poly2nb(sps, queen = FALSE) and I care more about working out the neighborhood. Thanks so much for your quick response!

    – Lathan
    Apr 5 at 23:49

















  • What's s_gis? Can you show us its summary() and maybe its head()? What does sps end up as? Is it one polygon or many? How are you running poly2nb to get that error? What are you running it on? On sps? Do you care about the plot order or working out the neighbourhood?

    – Spacedman
    Apr 5 at 23:37












  • s_gis is one of the datasets I'm using. The summary is quite large; however, I did select out long and lat which results in a tibble with dimensions 661228 x 2. sps ends up Slot "plotOrder": [1] 1 Slot "labpt": [1] 76.83899 29.49845 Slot "ID": [1] "1000" Slot "area": [1] 196.6975 Slot "coords": # I removed these to save char. space Slot "plotOrder": [1] 1 Slot "bbox": min max x 68.186249 97.41529 y 6.755953 37.07827 Slot "proj4string": CRS arguments: +proj=longlat +datum=WGS84

    – Lathan
    Apr 5 at 23:46












  • I'm runnning poly2nb(sps, queen = FALSE) and I care more about working out the neighborhood. Thanks so much for your quick response!

    – Lathan
    Apr 5 at 23:49
















What's s_gis? Can you show us its summary() and maybe its head()? What does sps end up as? Is it one polygon or many? How are you running poly2nb to get that error? What are you running it on? On sps? Do you care about the plot order or working out the neighbourhood?

– Spacedman
Apr 5 at 23:37






What's s_gis? Can you show us its summary() and maybe its head()? What does sps end up as? Is it one polygon or many? How are you running poly2nb to get that error? What are you running it on? On sps? Do you care about the plot order or working out the neighbourhood?

– Spacedman
Apr 5 at 23:37














s_gis is one of the datasets I'm using. The summary is quite large; however, I did select out long and lat which results in a tibble with dimensions 661228 x 2. sps ends up Slot "plotOrder": [1] 1 Slot "labpt": [1] 76.83899 29.49845 Slot "ID": [1] "1000" Slot "area": [1] 196.6975 Slot "coords": # I removed these to save char. space Slot "plotOrder": [1] 1 Slot "bbox": min max x 68.186249 97.41529 y 6.755953 37.07827 Slot "proj4string": CRS arguments: +proj=longlat +datum=WGS84

– Lathan
Apr 5 at 23:46






s_gis is one of the datasets I'm using. The summary is quite large; however, I did select out long and lat which results in a tibble with dimensions 661228 x 2. sps ends up Slot "plotOrder": [1] 1 Slot "labpt": [1] 76.83899 29.49845 Slot "ID": [1] "1000" Slot "area": [1] 196.6975 Slot "coords": # I removed these to save char. space Slot "plotOrder": [1] 1 Slot "bbox": min max x 68.186249 97.41529 y 6.755953 37.07827 Slot "proj4string": CRS arguments: +proj=longlat +datum=WGS84

– Lathan
Apr 5 at 23:46














I'm runnning poly2nb(sps, queen = FALSE) and I care more about working out the neighborhood. Thanks so much for your quick response!

– Lathan
Apr 5 at 23:49





I'm runnning poly2nb(sps, queen = FALSE) and I care more about working out the neighborhood. Thanks so much for your quick response!

– Lathan
Apr 5 at 23:49










1 Answer
1






active

oldest

votes


















0














Now we know enough to reproduce your error message, I'll do that with a data frame of lat-long numbers:



> library(sp)
> s_gis = data.frame(long=runif(5), lat=runif(5))


that should be equivalent to your s_gis with lat-long selected. Continue with your code to make sps:



> p = Polygon(s_gis)
> ps = Polygons(list(p), 1000)
> sps = SpatialPolygons(list(ps))


and now use the spdep package:



> library(spdep)
Loading required package: Matrix
> poly2nb(sps, queen=FALSE)
Error in sp$mbxv[i]:(n * 2) : argument of length 0
>


and there's your error.



poly2nb computes the adjacency matrix between polygons. How many polygons have you got?



> length(sps)
[1] 1
> plot(sps)


enter image description here



One! (although it looks a bit like two but that's because the random lines cross over. This is one ring). No wonder it failed! This data is simply a set of point coordinates in each row - how do you think this data frame could define more than one polygon?






share|improve this answer























  • I've edited my original question. I've tried grouping my coordinates by a group id (which corresponds to each polygon). However, I'm getting a strange lists within a list issue when I make my SpatialPolygon object. The correct plot order is in my sps object; however, it's nested within a list which I can't seem to index. Thus, poly2nb() is still returning the same error message since it's not seeing the plot order and consequently not seeing the correct list of multiple polygon objects that I have.

    – Lathan
    Apr 6 at 18:24











  • You've completely changed the question now. I answered your question about the error you were getting from poly2nb (which didn't even relate to the title about the plot order, but never mind) and now you've added a load of stuff that gives a different error, you've still not shown us some sample data to make a reproducible answer, and I suspect you've left out some important packages necessary to make your code run. I would revert your edits, mark my answer as an answer, and create a new question with your new code, some sample data, and your new error message.

    – Spacedman
    Apr 7 at 11:03











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



);






Lathan 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%2f317953%2fthe-slot-for-plotorder-comes-up-as-1-instead-of-a-vector-with-length-specific%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









0














Now we know enough to reproduce your error message, I'll do that with a data frame of lat-long numbers:



> library(sp)
> s_gis = data.frame(long=runif(5), lat=runif(5))


that should be equivalent to your s_gis with lat-long selected. Continue with your code to make sps:



> p = Polygon(s_gis)
> ps = Polygons(list(p), 1000)
> sps = SpatialPolygons(list(ps))


and now use the spdep package:



> library(spdep)
Loading required package: Matrix
> poly2nb(sps, queen=FALSE)
Error in sp$mbxv[i]:(n * 2) : argument of length 0
>


and there's your error.



poly2nb computes the adjacency matrix between polygons. How many polygons have you got?



> length(sps)
[1] 1
> plot(sps)


enter image description here



One! (although it looks a bit like two but that's because the random lines cross over. This is one ring). No wonder it failed! This data is simply a set of point coordinates in each row - how do you think this data frame could define more than one polygon?






share|improve this answer























  • I've edited my original question. I've tried grouping my coordinates by a group id (which corresponds to each polygon). However, I'm getting a strange lists within a list issue when I make my SpatialPolygon object. The correct plot order is in my sps object; however, it's nested within a list which I can't seem to index. Thus, poly2nb() is still returning the same error message since it's not seeing the plot order and consequently not seeing the correct list of multiple polygon objects that I have.

    – Lathan
    Apr 6 at 18:24











  • You've completely changed the question now. I answered your question about the error you were getting from poly2nb (which didn't even relate to the title about the plot order, but never mind) and now you've added a load of stuff that gives a different error, you've still not shown us some sample data to make a reproducible answer, and I suspect you've left out some important packages necessary to make your code run. I would revert your edits, mark my answer as an answer, and create a new question with your new code, some sample data, and your new error message.

    – Spacedman
    Apr 7 at 11:03















0














Now we know enough to reproduce your error message, I'll do that with a data frame of lat-long numbers:



> library(sp)
> s_gis = data.frame(long=runif(5), lat=runif(5))


that should be equivalent to your s_gis with lat-long selected. Continue with your code to make sps:



> p = Polygon(s_gis)
> ps = Polygons(list(p), 1000)
> sps = SpatialPolygons(list(ps))


and now use the spdep package:



> library(spdep)
Loading required package: Matrix
> poly2nb(sps, queen=FALSE)
Error in sp$mbxv[i]:(n * 2) : argument of length 0
>


and there's your error.



poly2nb computes the adjacency matrix between polygons. How many polygons have you got?



> length(sps)
[1] 1
> plot(sps)


enter image description here



One! (although it looks a bit like two but that's because the random lines cross over. This is one ring). No wonder it failed! This data is simply a set of point coordinates in each row - how do you think this data frame could define more than one polygon?






share|improve this answer























  • I've edited my original question. I've tried grouping my coordinates by a group id (which corresponds to each polygon). However, I'm getting a strange lists within a list issue when I make my SpatialPolygon object. The correct plot order is in my sps object; however, it's nested within a list which I can't seem to index. Thus, poly2nb() is still returning the same error message since it's not seeing the plot order and consequently not seeing the correct list of multiple polygon objects that I have.

    – Lathan
    Apr 6 at 18:24











  • You've completely changed the question now. I answered your question about the error you were getting from poly2nb (which didn't even relate to the title about the plot order, but never mind) and now you've added a load of stuff that gives a different error, you've still not shown us some sample data to make a reproducible answer, and I suspect you've left out some important packages necessary to make your code run. I would revert your edits, mark my answer as an answer, and create a new question with your new code, some sample data, and your new error message.

    – Spacedman
    Apr 7 at 11:03













0












0








0







Now we know enough to reproduce your error message, I'll do that with a data frame of lat-long numbers:



> library(sp)
> s_gis = data.frame(long=runif(5), lat=runif(5))


that should be equivalent to your s_gis with lat-long selected. Continue with your code to make sps:



> p = Polygon(s_gis)
> ps = Polygons(list(p), 1000)
> sps = SpatialPolygons(list(ps))


and now use the spdep package:



> library(spdep)
Loading required package: Matrix
> poly2nb(sps, queen=FALSE)
Error in sp$mbxv[i]:(n * 2) : argument of length 0
>


and there's your error.



poly2nb computes the adjacency matrix between polygons. How many polygons have you got?



> length(sps)
[1] 1
> plot(sps)


enter image description here



One! (although it looks a bit like two but that's because the random lines cross over. This is one ring). No wonder it failed! This data is simply a set of point coordinates in each row - how do you think this data frame could define more than one polygon?






share|improve this answer













Now we know enough to reproduce your error message, I'll do that with a data frame of lat-long numbers:



> library(sp)
> s_gis = data.frame(long=runif(5), lat=runif(5))


that should be equivalent to your s_gis with lat-long selected. Continue with your code to make sps:



> p = Polygon(s_gis)
> ps = Polygons(list(p), 1000)
> sps = SpatialPolygons(list(ps))


and now use the spdep package:



> library(spdep)
Loading required package: Matrix
> poly2nb(sps, queen=FALSE)
Error in sp$mbxv[i]:(n * 2) : argument of length 0
>


and there's your error.



poly2nb computes the adjacency matrix between polygons. How many polygons have you got?



> length(sps)
[1] 1
> plot(sps)


enter image description here



One! (although it looks a bit like two but that's because the random lines cross over. This is one ring). No wonder it failed! This data is simply a set of point coordinates in each row - how do you think this data frame could define more than one polygon?







share|improve this answer












share|improve this answer



share|improve this answer










answered Apr 6 at 8:18









SpacedmanSpacedman

24.9k23551




24.9k23551












  • I've edited my original question. I've tried grouping my coordinates by a group id (which corresponds to each polygon). However, I'm getting a strange lists within a list issue when I make my SpatialPolygon object. The correct plot order is in my sps object; however, it's nested within a list which I can't seem to index. Thus, poly2nb() is still returning the same error message since it's not seeing the plot order and consequently not seeing the correct list of multiple polygon objects that I have.

    – Lathan
    Apr 6 at 18:24











  • You've completely changed the question now. I answered your question about the error you were getting from poly2nb (which didn't even relate to the title about the plot order, but never mind) and now you've added a load of stuff that gives a different error, you've still not shown us some sample data to make a reproducible answer, and I suspect you've left out some important packages necessary to make your code run. I would revert your edits, mark my answer as an answer, and create a new question with your new code, some sample data, and your new error message.

    – Spacedman
    Apr 7 at 11:03

















  • I've edited my original question. I've tried grouping my coordinates by a group id (which corresponds to each polygon). However, I'm getting a strange lists within a list issue when I make my SpatialPolygon object. The correct plot order is in my sps object; however, it's nested within a list which I can't seem to index. Thus, poly2nb() is still returning the same error message since it's not seeing the plot order and consequently not seeing the correct list of multiple polygon objects that I have.

    – Lathan
    Apr 6 at 18:24











  • You've completely changed the question now. I answered your question about the error you were getting from poly2nb (which didn't even relate to the title about the plot order, but never mind) and now you've added a load of stuff that gives a different error, you've still not shown us some sample data to make a reproducible answer, and I suspect you've left out some important packages necessary to make your code run. I would revert your edits, mark my answer as an answer, and create a new question with your new code, some sample data, and your new error message.

    – Spacedman
    Apr 7 at 11:03
















I've edited my original question. I've tried grouping my coordinates by a group id (which corresponds to each polygon). However, I'm getting a strange lists within a list issue when I make my SpatialPolygon object. The correct plot order is in my sps object; however, it's nested within a list which I can't seem to index. Thus, poly2nb() is still returning the same error message since it's not seeing the plot order and consequently not seeing the correct list of multiple polygon objects that I have.

– Lathan
Apr 6 at 18:24





I've edited my original question. I've tried grouping my coordinates by a group id (which corresponds to each polygon). However, I'm getting a strange lists within a list issue when I make my SpatialPolygon object. The correct plot order is in my sps object; however, it's nested within a list which I can't seem to index. Thus, poly2nb() is still returning the same error message since it's not seeing the plot order and consequently not seeing the correct list of multiple polygon objects that I have.

– Lathan
Apr 6 at 18:24













You've completely changed the question now. I answered your question about the error you were getting from poly2nb (which didn't even relate to the title about the plot order, but never mind) and now you've added a load of stuff that gives a different error, you've still not shown us some sample data to make a reproducible answer, and I suspect you've left out some important packages necessary to make your code run. I would revert your edits, mark my answer as an answer, and create a new question with your new code, some sample data, and your new error message.

– Spacedman
Apr 7 at 11:03





You've completely changed the question now. I answered your question about the error you were getting from poly2nb (which didn't even relate to the title about the plot order, but never mind) and now you've added a load of stuff that gives a different error, you've still not shown us some sample data to make a reproducible answer, and I suspect you've left out some important packages necessary to make your code run. I would revert your edits, mark my answer as an answer, and create a new question with your new code, some sample data, and your new error message.

– Spacedman
Apr 7 at 11:03










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









draft saved

draft discarded


















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












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











Lathan 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%2f317953%2fthe-slot-for-plotorder-comes-up-as-1-instead-of-a-vector-with-length-specific%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

រឿង រ៉ូមេអូ និង ហ្ស៊ុយលីយេ សង្ខេបរឿង តួអង្គ បញ្ជីណែនាំ

QGIS export composer to PDF scale the map [closed] Planned maintenance scheduled April 23, 2019 at 23:30 UTC (7:30pm US/Eastern) Announcing the arrival of Valued Associate #679: Cesar Manara Unicorn Meta Zoo #1: Why another podcast?Print Composer QGIS 2.6, how to export image?QGIS 2.8.1 print composer won't export all OpenCycleMap base layer tilesSave Print/Map QGIS composer view as PNG/PDF using Python (without changing anything in visible layout)?Export QGIS Print Composer PDF with searchable text labelsQGIS Print Composer does not change from landscape to portrait orientation?How can I avoid map size and scale changes in print composer?Fuzzy PDF export in QGIS running on macSierra OSExport the legend into its 100% size using Print ComposerScale-dependent rendering in QGIS PDF output

PDF-ში გადმოწერა სანავიგაციო მენიუproject page