将经度纬度坐标(WGS)转换为具有等距轴的网格(在给定区域中) [英] Convert longitude latitude coordinates (WGS) to grid with equidistant axes (in given area)
问题描述
我在拖曳数据集中有很多地理坐标,并且想要运行最近邻居搜索。
我遇到了包'RANN',函数 nn2(x,y)
运行速度非常快。
现在存在这样的问题,那当然在伦敦地区,北方的学位比西方的学位要长一些。 b
我现在的想法是将位置坐标转换为某个网格,其中x方向上的一个步骤与y方向上的一个步骤几乎相同。该地区是伦敦(中心-0.1045,51.489)。
$ b
library(RANN)
xyunf< - 结构(c(-0.19117,-0.173862,-0.187623,-0.187623,-0.192366,
-0.176224,51.489096,51.482442,51.50226,51.50226,51.491632,
51.495429),.Dim = c(6L,2L),.Dimnames = list(c(1,2,3,
4,6,7),c(Longitude纬度)))
xyosm < - 结构(c(-0.1966434,-0.1097162,-0.2023061,-0.198467,-0.4804301,
-0.4286548,51.6511198,51.6134576,51.6042042,51.5186019,51.3757395,
51.3351355),.Dim = c(6L,2L),.Dimnames = list(NULL,c(lon,
lat)))
res< - nn2(data = xyunf,query = xyosm,k = 1)
res $ nn.dists
res $ nn.idx
如果您阅读了R Spatial Task视图,您可以找到关于Spatial对象的所有信息 - 这些是点,网格,线或多边形可以有一个关联的坐标参照系。
一旦你有了这些,你可以使用 spTransform
在坐标系之间转换。因此,要将经纬度为lat / lon的数据帧从lat-long转换为Ordnance Survey Grid Coordinates:
coordinates(ptsLL)=〜 Longitude + Latitude#将一个数据帧转换成SpatialPointsDataFrame
proj4string(ptsLL)= CRS(+ init = epsg:4326)#告诉它是lat-long WGS84
ptsOS = spTransform(ptsLL,CRS (+ init = epsg:27700))#转换为英国网格系统
ptsOS = pts @ coords
现在关于epsg:27700的一点是,它是一个以米为单位的正方形网格,因此适用于此。如果您需要再次转换为经纬度,请再次 spTransform
。
还有其他方形网格坐标系世界其他地区,所以不要把它用于澳大利亚!
I have a lot of geocoordinates in tow data sets and want to run a nearest-neighbor-search.
I came across the package 'RANN' and the function nn2(x,y)
runs really fast.
Now there is the problem, that of course in the area of London a degree to the north is a quite a longer way then a degree to the west.
My idea now was to convert the location coordinates to some grid where one step in the direction of x is nearly the same as one step in the direction of y. The area is London (Center -0.1045,51.489). How can I perform this transformation?
library(RANN)
xyunf <- structure(c(-0.19117, -0.173862, -0.187623, -0.187623, -0.192366,
-0.176224, 51.489096, 51.482442, 51.50226, 51.50226, 51.491632,
51.495429), .Dim = c(6L, 2L), .Dimnames = list(c("1", "2", "3",
"4", "6", "7"), c("Longitude", "Latitude")))
xyosm <- structure(c(-0.1966434, -0.1097162, -0.2023061, -0.198467, -0.4804301,
-0.4286548, 51.6511198, 51.6134576, 51.6042042, 51.5186019, 51.3757395,
51.3351355), .Dim = c(6L, 2L), .Dimnames = list(NULL, c("lon",
"lat")))
res <- nn2(data=xyunf, query=xyosm, k=1)
res$nn.dists
res$nn.idx
If you read the R Spatial Task view you can find out all about Spatial objects - these are points, grids, lines, or polygons that can have a coordinate reference system associated.
Once you've got those, you can use spTransform
to convert between coordinate systems. So to convert a dataframe with lat/lon items from lat-long to Ordnance Survey Grid Coordinates:
coordinates(ptsLL) = ~Longitude+Latitude # turns a dataframe into a SpatialPointsDataFrame
proj4string(ptsLL) = CRS("+init=epsg:4326") # tells it to be lat-long WGS84
ptsOS = spTransform(ptsLL, CRS("+init=epsg:27700")) # converts to UK Grid system
ptsOS = pts@coords
Now the thing about epsg:27700 is that it is a square grid in metres, so work with that. If you need to convert back to lat-long, spTransform
again.
There are other square grid coordinate systems for other parts of the world, so don't use this for Australia!
这篇关于将经度纬度坐标(WGS)转换为具有等距轴的网格(在给定区域中)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!