从r中的线创建多边形
我有一个数据集,其中包含起点的坐标和轨迹的停止点。
首先,我创建了一个SF对象,如下所示,每个点的几何形状为“ line”:
crswgs84 = crs(“ +proj = longlat +datum = wgs84 +no_defs) +ellps = wgs84 +towgs84 = 0,0,0“)
df $ geom = sprintf(“ linestring(%s%s,%s%s)”,df $ start_lon,df $ start_lat,df $ stop_lon,df $ stop_lon,df $ stop_lat,df $ stop_lat ) df_sf = st_as_sf(df,wkt =“ geom”,crs = crswgs84)
然后,当我绘制几何形状时,我获得了所有线的图,这是我寻找的结果,因为我想从一开始就拥有轨迹,停止。但是,我希望能够连接线的终点以构建多边形。
有可能吗?
谢谢
I have a dataset that contains coordinates of the start point and the stop point of a trajectory.
First, I have created a sf object as follow to have the geometry of each point as "line" :
CRSWGS84 = CRS("+proj=longlat +datum=WGS84 +no_defs
+ellps=WGS84 +towgs84=0,0,0")
df$geom = sprintf("LINESTRING(%s %s, %s %s)", df$start_lon, df$start_lat, df$stop_lon, df$stop_lat)
df_sf = st_as_sf(df, wkt = "geom", crs = CRSWGS84)
Then when I plot the geometry I obtain a graph of all the lines which is the result i am looking for since I want to have the trajectory from the start to the stop. However, I would like to be able to connect the end point of the lines in order to construct a polygon.
Is it possible to do it ?
Thank you
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
当然,这不仅可能,而且非常简单。您需要做的就是
sf :: ST_CAST()
您的行对象类型“ Polygon”
。考虑此代码,线对象是从
“>计数sf linestress在r
Sure, it is not only possible but also quite straightforward. All you need to do is
sf::st_cast()
your line object to geometry type"POLYGON"
.Consider this code, with the lines object borrowed from Count number of times that sf linestrings intersect grid cell in r