简体   繁体   English

将纬度/经度转换为州平面坐标

[英]Convert latitude/longitude to state plane coordinates

I've got a dataset with latitude and longitude which I'd like to convert to the state plane coordinates for Illinois East, using EPSG 2790 ( http://spatialreference.org/ref/epsg/2790/ ) or maybe ESRI 102672 ( http://spatialreference.org/ref/esri/102672/ ). 我有一个纬度和经度的数据集,我想转换为伊利诺斯东部的州平面坐标,使用EPSG 2790( http://spatialreference.org/ref/epsg/2790/ )或者ESRI 102672( http://spatialreference.org/ref/esri/102672/ )。

This has definitely been asked before; 这肯定在之前被问过; my code is based on the answers here ( "Non Finite Transformation Detected" in spTransform in rgdal R Package and http://r-sig-geo.2731867.n2.nabble.com/Converting-State-Plane-Coordinates-td5457204.html ). 我的代码基于这里的答案( rgdal R包中的spTransform中的“非有限变换检测”http://r-sig-geo.2731867.n2.nabble.com/Converting-State-Plane-Coordinates-td5457204。 HTML )。

But for some reason I can't get it to work: 但由于某种原因,我不能让它工作:

library(rgdal)
library(sp)
data = data.frame(long=c(41.20,40.05), lat=c(-86.14,-88.15))
coordinates(data) <- ~ long + lat
proj4string(data) <- CRS("+init=epsg:4326") # latitude/longitude
data.proj <- spTransform(data, CRS("+init=epsg:2790")) # illinois east

Gives: 得到:

non finite transformation detected:
  long    lat               
 41.20 -86.14    Inf    Inf 
Error in spTransform(data, CRS("+init=epsg:2790")) : failure in points 1
In addition: Warning message:
In spTransform(data, CRS("+init=epsg:2790")) :
  2 projected point(s) not finite

Here's some more working code that clarifies what's going on: 这里有一些更有用的代码可以澄清发生了什么:

# convert a state-plane coordinate to lat/long
data = data.frame(x=400000,y=0)
coordinates(data) <- ~ x+y
proj4string(data) <- CRS("+init=epsg:2804")
latlong = data.frame(spTransform(data, CRS("+init=epsg:4326")))
setnames(latlong,c("long","lat"))
latlong

gives: 得到:

  long      lat
 1  -77 37.66667

and: 和:

# convert a lat/long to state-plane
data = latlong
coordinates(data) <- ~ long+lat
proj4string(data) <- CRS("+init=epsg:4326")
xy = data.frame(spTransform(data, CRS("+init=epsg:2804")))
setnames(xy,c("y","x"))
xy

gives: 得到:

> xy
      y             x
1 4e+05 -2.690839e-08

And here's a function: 这是一个功能:

# this is for Maryland
lat_long_to_xy = function(lat,long) {
  library(rgdal)
  library(sp)
  data = data.frame(long=long, lat=lat)
  coordinates(data) <- ~ long+lat
  proj4string(data) <- CRS("+init=epsg:4326")
  xy = data.frame(spTransform(data, CRS("+init=epsg:2804")))
  setnames(xy,c("y","x"))
  return(xy[,c("x","y")])
}

When you set the coordinates for your data, you have to set the latitude before the longitude. 设置数据coordinates ,必须在经度之前设置纬度。

In other words, change: 换句话说,改变:

coordinates(data) <- ~ long + lat

to

coordinates(data) <- ~ lat+long

And it should work. 它应该工作。

library(rgdal)
library(sp)
data = data.frame(long=c(41.20,40.05), lat=c(-86.14,-88.15))
coordinates(data) <- ~ lat+long
proj4string(data) <- CRS("+init=epsg:4326")
data.proj <- spTransform(data, CRS("+init=epsg:2790"))
data.proj

Gave me this output: 给我这个输出:

SpatialPoints:
          lat     long
[1,] 483979.0 505572.6
[2,] 315643.7 375568.0
Coordinate Reference System (CRS) arguments: +init=epsg:2790 +proj=tmerc
+lat_0=36.66666666666666 +lon_0=-88.33333333333333 +k=0.9999749999999999 +x_0=300000
+y_0=0 +ellps=GRS80 +units=m +no_defs 

I had an issue converting in the other direction and found this response on GIS Stack Exchange which may be helpful to future seekers. 我有一个问题转向另一个方向,并在GIS Stack Exchange上找到了这个响应,这可能对未来的搜索者有所帮助。 Depending on whether your coordinate system is NAD83 or NAD83 (HARN), the spatial reference epsg code will differ. 根据您的坐标系是NAD83还是NAD83(HARN),空间参考epsg代码会有所不同。 If you use the wrong system, it may not be able to convert the point to values beyond the limits of any coordinate plane. 如果使用错误的系统,则可能无法将该点转换为超出任何坐标平面限制的值。

https://gis.stackexchange.com/questions/64654/choosing-the-correct-value-for-proj4string-for-shape-file-reading-in-r-maptools https://gis.stackexchange.com/questions/64654/choosing-the-correct-value-for-proj4string-for-shape-file-reading-in-r-maptools

Reading in lat+long versus long+lat does make a difference in the output- in my case (going from State Plane to WGS84) I had to write 在lat + long和long + lat中读取确实会对输出产生影响 - 在我的情况下(从State Plane到WGS84)我必须写

coordinates(data) <- ~ long+lat

You can confirm this by plotting a known reference point to determine if it converted correctly. 您可以通过绘制已知参考点来确认是否正确转换。

The esri code (102649) in rgdal didn't work for me, I had to manually code it in from the proj4js page to go from state plane (0202 Arizona Central) to WGS84: rgdal中的esri代码(102649)对我不起作用,我不得不从proj4js页面手动编写代码,从州飞机(0202 Arizona Central)到WGS84:

d<- data.frame(lon=XCord, lat=YCord)
coordinates(d) <- c("lon", "lat")
proj4string(d) <- CRS("+proj=tmerc +lat_0=31 +lon_0=-111.9166666666667 +k=0.9999 +x_0=213360 +y_0=0 +ellps=GRS80 +datum=NAD83 +to_meter=0.3048006096012192 +no_defs")
CRS.new <- CRS("+init=epsg:4326") # WGS 84
d.ch102649 <- spTransform(d, CRS.new)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM