Generating random points within series of polygons according to density using ROpenLayers generate random...
Why is the underscore command _ useful?
Bayes factor vs P value
Which big number is bigger?
Conditionally enable edit in lightning:datatable
I preordered a game on my Xbox while on the home screen of my friend's account. Which of us owns the game?
Nails holding drywall
How to find if a column is referenced in a computed column?
My bank got bought out, am I now going to have to start filing tax returns in a different state?
"The cow" OR "a cow" OR "cows" in this context
Why does Arg'[1. + I] return -0.5?
Combinatorics problem, right solution?
How can I wire a 9-position switch so that each position turns on one more LED than the one before?
Contradiction proof for inequality of P and NP?
A faster way to compute the largest prime factor
"My boss was furious with me and I have been fired" vs. "My boss was furious with me and I was fired"
How to pronounce 'c++' in Spanish
"Whatever a Russian does, they end up making the Kalashnikov gun"? Are there any similar proverbs in English?
Why did C use the -> operator instead of reusing the . operator?
Will I lose my paid in full property
Why do distances seem to matter in the Foundation world?
How do I produce this symbol: Ϟ in pdfLaTeX?
All ASCII characters with a given bit count
What to do with someone that cheated their way through university and a PhD program?
Can I criticise the more senior developers around me for not writing clean code?
Generating random points within series of polygons according to density using R
OpenLayers generate random polygonGenerate random location within specified distance of a given pointHow to create randomly points within polygons for each row of a dataframe matching a Polygon ID with RAdding attribute data together within multiple polygons in QGIS?Creating random points using density-QGISCreate multiple random points based on attributes from a different shapefileHow to create multiple points inside polygon in QGISRandom selection within subsetCalculating expected number of points within polygons of different size under hypothesis of random distribution?how to generate random points influenced by underlaying variable in R?
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ margin-bottom:0;
}
I have a city that is made up of a number of wards, each with an unequal population. I would like to generate a set of "random" points within the city, but the randomness is influenced by the population size, eg wards with greater populations are likley to have more points within them. Here is some mock code:
library(rgdal)
library(sp)
remove(list = ls())
square <- rbind(c(0,10,10,0,0,0,10,10),
c(10,20,20,10,0,0,10,10),
c(0,10,10,0,10,10,20,20),
c(10,20,20,10,10,10,20,20),
c(20,40,40,20,0,0,40,40))
ID <- c("A","B","C","D","E")
polys.sp <- SpatialPolygons(list(
Polygons(list(Polygon(matrix(square[1, ], ncol=2, byrow=FALSE))), ID[1]),
Polygons(list(Polygon(matrix(square[2, ], ncol=2, byrow=FALSE))), ID[2]),
Polygons(list(Polygon(matrix(square[3, ], ncol=2, byrow=FALSE))), ID[3]),
Polygons(list(Polygon(matrix(square[4, ], ncol=2, byrow=FALSE))), ID[4]),
Polygons(list(Polygon(matrix(square[5, ], ncol=2, byrow=FALSE))), ID[5])
))
plot(polys.sp)
sample.df <- data.frame(population=c(500,250,100,100,50))
rownames(sample.df) <- ID
polys.spdf <- SpatialPolygonsDataFrame(polys.sp,data=sample.df)
Since ward A is the most populous (50%) it should get roughly half the random points within it. If I have 17 random points to generate, it should have either 8 or 9 points. I have thought about generating eg 17 * (xi/(500+250+100+100+50)) points, where xi is the ward population, in each ward, but due to rounding, this will not allways sum to 17 over the 5 wards. This is important, it must sum to the required number of points.
r polygon point random
add a comment |
I have a city that is made up of a number of wards, each with an unequal population. I would like to generate a set of "random" points within the city, but the randomness is influenced by the population size, eg wards with greater populations are likley to have more points within them. Here is some mock code:
library(rgdal)
library(sp)
remove(list = ls())
square <- rbind(c(0,10,10,0,0,0,10,10),
c(10,20,20,10,0,0,10,10),
c(0,10,10,0,10,10,20,20),
c(10,20,20,10,10,10,20,20),
c(20,40,40,20,0,0,40,40))
ID <- c("A","B","C","D","E")
polys.sp <- SpatialPolygons(list(
Polygons(list(Polygon(matrix(square[1, ], ncol=2, byrow=FALSE))), ID[1]),
Polygons(list(Polygon(matrix(square[2, ], ncol=2, byrow=FALSE))), ID[2]),
Polygons(list(Polygon(matrix(square[3, ], ncol=2, byrow=FALSE))), ID[3]),
Polygons(list(Polygon(matrix(square[4, ], ncol=2, byrow=FALSE))), ID[4]),
Polygons(list(Polygon(matrix(square[5, ], ncol=2, byrow=FALSE))), ID[5])
))
plot(polys.sp)
sample.df <- data.frame(population=c(500,250,100,100,50))
rownames(sample.df) <- ID
polys.spdf <- SpatialPolygonsDataFrame(polys.sp,data=sample.df)
Since ward A is the most populous (50%) it should get roughly half the random points within it. If I have 17 random points to generate, it should have either 8 or 9 points. I have thought about generating eg 17 * (xi/(500+250+100+100+50)) points, where xi is the ward population, in each ward, but due to rounding, this will not allways sum to 17 over the 5 wards. This is important, it must sum to the required number of points.
r polygon point random
1
Your code had a few problems with it which I think I've fixed. It runs when cut n paste into an R session now, unlike before when it had syntax errors and invalid library calls. Please check its okay now.
– Spacedman
40 mins ago
add a comment |
I have a city that is made up of a number of wards, each with an unequal population. I would like to generate a set of "random" points within the city, but the randomness is influenced by the population size, eg wards with greater populations are likley to have more points within them. Here is some mock code:
library(rgdal)
library(sp)
remove(list = ls())
square <- rbind(c(0,10,10,0,0,0,10,10),
c(10,20,20,10,0,0,10,10),
c(0,10,10,0,10,10,20,20),
c(10,20,20,10,10,10,20,20),
c(20,40,40,20,0,0,40,40))
ID <- c("A","B","C","D","E")
polys.sp <- SpatialPolygons(list(
Polygons(list(Polygon(matrix(square[1, ], ncol=2, byrow=FALSE))), ID[1]),
Polygons(list(Polygon(matrix(square[2, ], ncol=2, byrow=FALSE))), ID[2]),
Polygons(list(Polygon(matrix(square[3, ], ncol=2, byrow=FALSE))), ID[3]),
Polygons(list(Polygon(matrix(square[4, ], ncol=2, byrow=FALSE))), ID[4]),
Polygons(list(Polygon(matrix(square[5, ], ncol=2, byrow=FALSE))), ID[5])
))
plot(polys.sp)
sample.df <- data.frame(population=c(500,250,100,100,50))
rownames(sample.df) <- ID
polys.spdf <- SpatialPolygonsDataFrame(polys.sp,data=sample.df)
Since ward A is the most populous (50%) it should get roughly half the random points within it. If I have 17 random points to generate, it should have either 8 or 9 points. I have thought about generating eg 17 * (xi/(500+250+100+100+50)) points, where xi is the ward population, in each ward, but due to rounding, this will not allways sum to 17 over the 5 wards. This is important, it must sum to the required number of points.
r polygon point random
I have a city that is made up of a number of wards, each with an unequal population. I would like to generate a set of "random" points within the city, but the randomness is influenced by the population size, eg wards with greater populations are likley to have more points within them. Here is some mock code:
library(rgdal)
library(sp)
remove(list = ls())
square <- rbind(c(0,10,10,0,0,0,10,10),
c(10,20,20,10,0,0,10,10),
c(0,10,10,0,10,10,20,20),
c(10,20,20,10,10,10,20,20),
c(20,40,40,20,0,0,40,40))
ID <- c("A","B","C","D","E")
polys.sp <- SpatialPolygons(list(
Polygons(list(Polygon(matrix(square[1, ], ncol=2, byrow=FALSE))), ID[1]),
Polygons(list(Polygon(matrix(square[2, ], ncol=2, byrow=FALSE))), ID[2]),
Polygons(list(Polygon(matrix(square[3, ], ncol=2, byrow=FALSE))), ID[3]),
Polygons(list(Polygon(matrix(square[4, ], ncol=2, byrow=FALSE))), ID[4]),
Polygons(list(Polygon(matrix(square[5, ], ncol=2, byrow=FALSE))), ID[5])
))
plot(polys.sp)
sample.df <- data.frame(population=c(500,250,100,100,50))
rownames(sample.df) <- ID
polys.spdf <- SpatialPolygonsDataFrame(polys.sp,data=sample.df)
Since ward A is the most populous (50%) it should get roughly half the random points within it. If I have 17 random points to generate, it should have either 8 or 9 points. I have thought about generating eg 17 * (xi/(500+250+100+100+50)) points, where xi is the ward population, in each ward, but due to rounding, this will not allways sum to 17 over the 5 wards. This is important, it must sum to the required number of points.
r polygon point random
r polygon point random
edited 9 mins ago
PolyGeo♦
54.1k1782247
54.1k1782247
asked 53 mins ago
Stephen ClarkStephen Clark
123
123
1
Your code had a few problems with it which I think I've fixed. It runs when cut n paste into an R session now, unlike before when it had syntax errors and invalid library calls. Please check its okay now.
– Spacedman
40 mins ago
add a comment |
1
Your code had a few problems with it which I think I've fixed. It runs when cut n paste into an R session now, unlike before when it had syntax errors and invalid library calls. Please check its okay now.
– Spacedman
40 mins ago
1
1
Your code had a few problems with it which I think I've fixed. It runs when cut n paste into an R session now, unlike before when it had syntax errors and invalid library calls. Please check its okay now.
– Spacedman
40 mins ago
Your code had a few problems with it which I think I've fixed. It runs when cut n paste into an R session now, unlike before when it had syntax errors and invalid library calls. Please check its okay now.
– Spacedman
40 mins ago
add a comment |
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
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fgis.stackexchange.com%2fquestions%2f320880%2fgenerating-random-points-within-series-of-polygons-according-to-density-using-r%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
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.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fgis.stackexchange.com%2fquestions%2f320880%2fgenerating-random-points-within-series-of-polygons-according-to-density-using-r%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
1
Your code had a few problems with it which I think I've fixed. It runs when cut n paste into an R session now, unlike before when it had syntax errors and invalid library calls. Please check its okay now.
– Spacedman
40 mins ago