polygon from cluster of lat long points in R
I m trying to create polygon from cluster of points boundaries of which would be touching all exterior points. Any help to improve my code would be appreciated.
library(dplyr)
library(sf)
df<- read.table(text ="lon lat
74.03687 30.17482
74.23605 30.23773
74.24127 29.95988
74.29211 30.07575
74.25612 30.17687
74.15972 30.06242
74.06484 30.11025
74.36046 30.02749
74.08133 30.01889
74.26168 30.16881
73.91083 30.01378
74.00881 30.07585
74.40638 29.97712
74.34974 30.22231
74.20501 30.11133
74.18108 30.01113
74.00717 30.11362
73.94891 30.03807
74.18977 30.14367
74.18857 30.13621
74.19862 30.15222
74.19376 30.13425",header= T)
polygon <- df %>%
st_as_sf(coords = c("lon", "lat"), crs = 4326) %>%
summarise(geometry = st_combine(geometry)) %>%
st_cast("POLYGON")
plot(polygon)
Need the output like blue line in a single polygon.
r polygon sf
add a comment |
I m trying to create polygon from cluster of points boundaries of which would be touching all exterior points. Any help to improve my code would be appreciated.
library(dplyr)
library(sf)
df<- read.table(text ="lon lat
74.03687 30.17482
74.23605 30.23773
74.24127 29.95988
74.29211 30.07575
74.25612 30.17687
74.15972 30.06242
74.06484 30.11025
74.36046 30.02749
74.08133 30.01889
74.26168 30.16881
73.91083 30.01378
74.00881 30.07585
74.40638 29.97712
74.34974 30.22231
74.20501 30.11133
74.18108 30.01113
74.00717 30.11362
73.94891 30.03807
74.18977 30.14367
74.18857 30.13621
74.19862 30.15222
74.19376 30.13425",header= T)
polygon <- df %>%
st_as_sf(coords = c("lon", "lat"), crs = 4326) %>%
summarise(geometry = st_combine(geometry)) %>%
st_cast("POLYGON")
plot(polygon)
Need the output like blue line in a single polygon.
r polygon sf
Do you mean like a convex hull? If so, you can have a look here: stats.stackexchange.com/questions/41578/…
– CIAndrews
Nov 23 '18 at 6:17
add a comment |
I m trying to create polygon from cluster of points boundaries of which would be touching all exterior points. Any help to improve my code would be appreciated.
library(dplyr)
library(sf)
df<- read.table(text ="lon lat
74.03687 30.17482
74.23605 30.23773
74.24127 29.95988
74.29211 30.07575
74.25612 30.17687
74.15972 30.06242
74.06484 30.11025
74.36046 30.02749
74.08133 30.01889
74.26168 30.16881
73.91083 30.01378
74.00881 30.07585
74.40638 29.97712
74.34974 30.22231
74.20501 30.11133
74.18108 30.01113
74.00717 30.11362
73.94891 30.03807
74.18977 30.14367
74.18857 30.13621
74.19862 30.15222
74.19376 30.13425",header= T)
polygon <- df %>%
st_as_sf(coords = c("lon", "lat"), crs = 4326) %>%
summarise(geometry = st_combine(geometry)) %>%
st_cast("POLYGON")
plot(polygon)
Need the output like blue line in a single polygon.
r polygon sf
I m trying to create polygon from cluster of points boundaries of which would be touching all exterior points. Any help to improve my code would be appreciated.
library(dplyr)
library(sf)
df<- read.table(text ="lon lat
74.03687 30.17482
74.23605 30.23773
74.24127 29.95988
74.29211 30.07575
74.25612 30.17687
74.15972 30.06242
74.06484 30.11025
74.36046 30.02749
74.08133 30.01889
74.26168 30.16881
73.91083 30.01378
74.00881 30.07585
74.40638 29.97712
74.34974 30.22231
74.20501 30.11133
74.18108 30.01113
74.00717 30.11362
73.94891 30.03807
74.18977 30.14367
74.18857 30.13621
74.19862 30.15222
74.19376 30.13425",header= T)
polygon <- df %>%
st_as_sf(coords = c("lon", "lat"), crs = 4326) %>%
summarise(geometry = st_combine(geometry)) %>%
st_cast("POLYGON")
plot(polygon)
Need the output like blue line in a single polygon.
r polygon sf
r polygon sf
asked Nov 23 '18 at 5:08
aprilianaprilian
1319
1319
Do you mean like a convex hull? If so, you can have a look here: stats.stackexchange.com/questions/41578/…
– CIAndrews
Nov 23 '18 at 6:17
add a comment |
Do you mean like a convex hull? If so, you can have a look here: stats.stackexchange.com/questions/41578/…
– CIAndrews
Nov 23 '18 at 6:17
Do you mean like a convex hull? If so, you can have a look here: stats.stackexchange.com/questions/41578/…
– CIAndrews
Nov 23 '18 at 6:17
Do you mean like a convex hull? If so, you can have a look here: stats.stackexchange.com/questions/41578/…
– CIAndrews
Nov 23 '18 at 6:17
add a comment |
2 Answers
2
active
oldest
votes
I recommend using the concaveman
package for this task:
library(concaveman)
pnts <- df %>%
st_as_sf(coords = c("lon", "lat"), crs = 4326)
polygon <- concaveman(pnts)
plot(polygon, reset = FALSE)
plot(pnts, add = TRUE)
add a comment |
The following code:
plot(df, type='n')
polygon(df)
chx <- chull(df)
chx <- rbind(df = df[chx, ], df[chx[1], ])
lines(chx, col='blue', lwd=4)
Will produce the following plot:
Or remove the polygon(df)
to get:
I hope you find it useful.
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
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: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
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%2fstackoverflow.com%2fquestions%2f53440909%2fpolygon-from-cluster-of-lat-long-points-in-r%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
I recommend using the concaveman
package for this task:
library(concaveman)
pnts <- df %>%
st_as_sf(coords = c("lon", "lat"), crs = 4326)
polygon <- concaveman(pnts)
plot(polygon, reset = FALSE)
plot(pnts, add = TRUE)
add a comment |
I recommend using the concaveman
package for this task:
library(concaveman)
pnts <- df %>%
st_as_sf(coords = c("lon", "lat"), crs = 4326)
polygon <- concaveman(pnts)
plot(polygon, reset = FALSE)
plot(pnts, add = TRUE)
add a comment |
I recommend using the concaveman
package for this task:
library(concaveman)
pnts <- df %>%
st_as_sf(coords = c("lon", "lat"), crs = 4326)
polygon <- concaveman(pnts)
plot(polygon, reset = FALSE)
plot(pnts, add = TRUE)
I recommend using the concaveman
package for this task:
library(concaveman)
pnts <- df %>%
st_as_sf(coords = c("lon", "lat"), crs = 4326)
polygon <- concaveman(pnts)
plot(polygon, reset = FALSE)
plot(pnts, add = TRUE)
answered Nov 23 '18 at 14:22
jstajsta
1,5061520
1,5061520
add a comment |
add a comment |
The following code:
plot(df, type='n')
polygon(df)
chx <- chull(df)
chx <- rbind(df = df[chx, ], df[chx[1], ])
lines(chx, col='blue', lwd=4)
Will produce the following plot:
Or remove the polygon(df)
to get:
I hope you find it useful.
add a comment |
The following code:
plot(df, type='n')
polygon(df)
chx <- chull(df)
chx <- rbind(df = df[chx, ], df[chx[1], ])
lines(chx, col='blue', lwd=4)
Will produce the following plot:
Or remove the polygon(df)
to get:
I hope you find it useful.
add a comment |
The following code:
plot(df, type='n')
polygon(df)
chx <- chull(df)
chx <- rbind(df = df[chx, ], df[chx[1], ])
lines(chx, col='blue', lwd=4)
Will produce the following plot:
Or remove the polygon(df)
to get:
I hope you find it useful.
The following code:
plot(df, type='n')
polygon(df)
chx <- chull(df)
chx <- rbind(df = df[chx, ], df[chx[1], ])
lines(chx, col='blue', lwd=4)
Will produce the following plot:
Or remove the polygon(df)
to get:
I hope you find it useful.
answered Nov 23 '18 at 6:38
TeeKeaTeeKea
3,20851730
3,20851730
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- 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%2fstackoverflow.com%2fquestions%2f53440909%2fpolygon-from-cluster-of-lat-long-points-in-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
Do you mean like a convex hull? If so, you can have a look here: stats.stackexchange.com/questions/41578/…
– CIAndrews
Nov 23 '18 at 6:17