我想将Voronoi多边形与地图结合起来,以便稍后用于空间分析.我有多个点和shapefile,我想要组合,然后保存为shapefile /空间多边形.要获得voronoi多边形,我使用本主题中的函数.
我的代码如下:
coords<-data.frame(LONG=c(16.9252,16.9363,16.9408,16.8720,16.9167,16.9461,16.9093,16.9457,16.9171,16.8506,16.9471,16.8723,16.9444,16.9212,16.8809,16.9191,16.8968,16.8719,16.9669,16.8845),
LAT=c(52.4064,52.4266,52.3836,52.3959,52.4496,52.3924,52.4012,52.3924,52.3777,52.4368,52.4574,52.3945,52.4572,52.3962,52.3816,52.3809,52.3956,52.3761,52.4236,52.4539))
Run Code Online (Sandbox Code Playgroud)
我的地图位于:https://docs.google.com/file/d/0B-ZJyVlQBsqlSURiN284dF9YNUk/edit
library(rgdal)
voronoipolygons <- function(x) {
require(deldir)
if (.hasSlot(x, 'coords')) {
crds <- x@coords
} else crds <- x
z <- deldir(crds[,1], crds[,2])
w <- tile.list(z)
polys <- vector(mode='list', length=length(w))
require(sp)
for (i in seq(along=polys)) {
pcrds <- cbind(w[[i]]$x, w[[i]]$y)
pcrds <- rbind(pcrds, pcrds[1,])
polys[[i]] <- Polygons(list(Polygon(pcrds)), ID=as.character(i))
}
SP <- SpatialPolygons(polys)
voronoi <- SpatialPolygonsDataFrame(SP, data=data.frame(x=crds[,1],
y=crds[,2], row.names=sapply(slot(SP, 'polygons'),
function(x) slot(x, 'ID'))))
}
Run Code Online (Sandbox Code Playgroud)
我的代码来获取voronoipolygons:
pzn.coords<-voronoipolygons(coords)
plot(pznall)
plot(pzn.coords,add=T)
points(coords$LONG,coords$LAT)
Run Code Online (Sandbox Code Playgroud)
结果:
我想把我的地图中的这个voronoi多边形作为新的空间多边形. …
Package sp
为不同的空间概念(点,线,多边形)提供了许多类.对于某些类,访问要素坐标很简单,例如SpatialLines
.所有示例均来自各个类帮助页面.
l1 = cbind(c(1,2,3),c(3,2,2))
l1a = cbind(l1[,1]+.05,l1[,2]+.05)
l2 = cbind(c(1,2,3),c(1,1.5,1))
Sl1 = Line(l1)
Sl1a = Line(l1a)
Sl2 = Line(l2)
S1 = Lines(list(Sl1, Sl1a), ID="a")
S2 = Lines(list(Sl2), ID="b")
Sl = SpatialLines(list(S1,S2))
coordinates(Sl)
# [prints a list of two with corresponding segments]
Run Code Online (Sandbox Code Playgroud)
对于SpatialPolygons
,coordinates()
返回多边形中心,如下所示.
Sr1 = Polygon(cbind(c(2,4,4,1,2),c(2,3,5,4,2)))
Sr2 = Polygon(cbind(c(5,4,2,5),c(2,3,2,2)))
Sr3 = Polygon(cbind(c(4,4,5,10,4),c(5,3,2,5,5)))
Sr4 = Polygon(cbind(c(5,6,6,5,5),c(4,4,3,3,4)), hole = TRUE)
Srs1 = Polygons(list(Sr1), "s1")
Srs2 = Polygons(list(Sr2), "s2")
Srs3 = Polygons(list(Sr3, Sr4), "s3/4")
SpP = …
Run Code Online (Sandbox Code Playgroud) 我试图从顶点位置创建一组多边形,以X,Y格式保存.
以下是我的数据示例 - 每行代表一个多边形的顶点.多边形是正方形
square <- rbind(c(255842.4, 4111578, 255862.4, 4111578, 255862.4, 4111558,
255842.4, 4111558, 255842.4, 4111578, 255842.4, 4111578),
c(257397.0, 4111309, 257417.0, 4111309, 257417.0, 4111289,
257397.0, 4111289, 257397.0, 4111309, 257397.0, 4111309))
ID <- c("SJER1", "SJER2")'
Run Code Online (Sandbox Code Playgroud)
我正在使用SpatialPolygons
,因此我的数据需要在列表中.所以我创建了一个循环来尝试从矩阵中将我的数据转换为列表格式.
我创建了一个循环代码,我在本网站的其他一些问题中找到了代码.我打破了每一步,试图理解为什么我只得到一个多边形作为输出,即使我有2组点.
for (i in 1:2) {
pts <- rbind(c(square[i,1], square[i,2]), c(square[i,3], square[i,4]),
c(square[i,5],square[i,6]), c(square[i,7],square[i,8]),
c(square[i,9],square[i,10]))
sp1 <- list(Polygon(pts))
sp2 <- list(Polygons(sp1,i))
sp = SpatialPolygons(sp2)
}
plot(sp)
Run Code Online (Sandbox Code Playgroud)
你能帮我理解我如何调整代码来写出两个多边形而不是一个多边形吗?而且,如果我使用矩阵(方形)作为我的起始数据集,我如何为每个多边形分配ID,如果我指定了一个字符ID,它会将我的所有数据转换为一个字符.
我的最终目标是SpatialPolygons
对象中的两个多边形,第一个具有ID SJER1
,第二个具有SJER2
存储在SpatialPolygons
对象中的ID .
然后我会把它写到shapefile中.
我目前正在开发一个项目,我必须处理sql server 2008地理类型.由于项目的大部分使用NHibernate作为ORM,我想知道使用/扩展NHibernate.Spatial有多少工作用这种类型(据我所知,Nh Spatial仅支持几何类型).顺便说一句.还有其他.net ORM支持这种sql类型吗?谢谢
我有一个3D pointcloud,我想从任意点p(它不一定是存储的pointcloud的一部分)有效地查询距离d内的所有点
查询看起来像
Pointcloud getAllPoints(Point p, float d);
Run Code Online (Sandbox Code Playgroud)
什么加速结构适合这个?范围树似乎仅适用于查询矩形体积,而不是球体体积(当然,我可以查询球体的边界框,然后整理距离大于d的所有顶点 - 但也许有更好的方法可以做到这个??)
谢谢!
根据Novelocrats的建议,我尝试定义结构的所需功能:
SearchStructure Create(Set<Point> cloud)
Set<Point> Query(SearchStructure S, Point p, float maxDistance)
SearchStructure Remove(Point p)
SearchStructure Insert(Point p)
SearchStructure Displace(Set<Point> displacement) //where each value describes an offsetVector to the currently present points
Run Code Online (Sandbox Code Playgroud)
通常,在n次查询之后,这些点会被取代,并且会进行一些(不是很多!)插入和删除.与所有点的边界框相比,偏移矢量非常小
我正在阅读这个问题,我想更多地询问他展示的代码,即
for(i = 0; i < 20; i++)
for(j = 0; j < 10; j++)
a[i] = a[i]*j;
Run Code Online (Sandbox Code Playgroud)
问题是,
那个人说,
"内部循环在访问[i]十次时会调用相同的内存地址,这是我猜的时间局部性的一个例子.但是在上面的循环中是否还有空间局部性?"
我不同意他的猜测.由[a]生成的引用应该是空间局部性(它们将引用块中的下一个元素).我对吗?
想象一下,有一个2D空间,在这个空间中,有些圆圈以不同的恒定速率生长.什么是用于存储这些圆的有效数据结构,这样我可以查询"哪些圆与p
时间点相交t
?".
编辑:我确实意识到我可以在空间数据结构中存储圆的初始状态并进行查询,其中我在p
半径为的点处与圆相交fastest_growth * t
,但是当有少量圆增长时这不是有效的非常快,而大多数生长缓慢.
附加编辑:我可以通过分割圆圈并按增长率对它们进行分组,然后将上述方法应用于每个组来进一步增强上述方法,但这需要有限的时间才能有效.
这两个对象在Microsoft SQL数据库中表示相同Geography数据类型的区别或预期目的是什么?
System.Data.Entity.Spatial.DbGeography
Run Code Online (Sandbox Code Playgroud)
和
Microsoft.SqlServer.Types.SqlGeography
Run Code Online (Sandbox Code Playgroud)
它们不能在彼此之间施放,但SqlGeography
在创建点,多边形等时有额外的命令.
我认为这System.Data.Entity
只是用于实体框架,而直接Microsoft.SqlServer
使用是SqlCommand
直接使用?
几天来,我一直在敲打这个.我有一个非常简单的查询,我试图在C#中运行,它在shell中看起来像这样.
db.runCommand({geoNear: "items", near: {type: "Point", coordinates : [-111.283344899999, 47.4941836]}, spherical : true, distanceMultiplier: 3963.2, maxDistance : 25});
Run Code Online (Sandbox Code Playgroud)
我的收藏看起来像这样
{
"_id" : ObjectId(),
"Title" : "arst",
"Description" : "<p>arst</p>",
"Date" : new Date("11/29/2015 09:28:15"),
"Location" : {
"type" : "Point",
"Coordinates" : [-111.28334489999998, 47.4941836]
},
"Zip" : "59405"
}
Run Code Online (Sandbox Code Playgroud)
根据MongoDB C#API文档中的文档,MongoDB.Driver.Builders.Query对象现在已成为遗产.所以,当我做这样的事情
var point = new GeoJson2DGeographicCoordinates(double.Parse(longitude), double.Parse(latitude)) ;
var query = Query<Item>.Near(x => x.Location, new GeoJsonPoint<GeoJson2DGeographicCoordinates>(point), distance, true);
var result = collection.Find(query);
Run Code Online (Sandbox Code Playgroud)
编译器抱怨它无法从IMongoQuery转换为FilterDefinition.这告诉我新的2.1库不支持旧的Query <>构建器.但是对于我的生活,我在api文档中找不到任何引用替换的文档?
有没有人能指出我在2.1 C#驱动程序中执行这个简单的地理空间查询的正确方向?我很难过.
此外,我确实在集合上创建了一个2dsphere索引,如果我没有shell命令不起作用.这是索引输出.
{ …
Run Code Online (Sandbox Code Playgroud) 我正在使用sf
包(和相关包)在 R 中制作 GIS 地图以读取 shapefile 和ggplot2
(和朋友)进行绘图。这工作正常,但我找不到(自动/以编程方式)为河流和道路等要素创建标签放置的方法。这些特征通常是具有不规则形状的线串。请参阅例如来自维基媒体的图片。
该ggrepel
软件包适用于以自动方式标记点,但这对于不是离散的纬度/经度点的其他地理特征没有多大意义。
我可以想象通过在每个功能上单独放置单独的文本标签来做到这一点,但如果可能的话,我正在寻找更自动化的东西。我意识到这种自动化不是一个小问题,但之前已经解决了(ArcGIS 显然有一种方法可以使用名为 Maplex 的扩展程序来做到这一点,但我无法访问该软件,我想留在R 如果可能)。
有谁知道这样做的方法?
MWE在这里:
#MWE Linestring labeling
library(tidyverse)
library(sf)
library(ggrepel)
set.seed(120)
#pick a county from the built-in North Carolina dataset
BuncombeCounty <- st_read(system.file("shapes/", package="maptools"), "sids") %>%
filter(NAME == "Buncombe")
#pick 4 random points in that county
pts_sf <- data.frame(
x = seq(-82.3, -82.7, by=-0.1) %>%
sample(4),
y = seq(35.5, 35.7, by=0.05) %>%
sample(4),
placenames = c("A", "B", "C", "D")
) %>%
st_as_sf(coords = …
Run Code Online (Sandbox Code Playgroud)