使用PROJ.4库使用地面控制点将局部坐标系坐标转换为全局坐标系?


9

我有一个点云,其坐标是相对于局部坐标系的。我也有带有GPS值的地面控制点。是否可以使用PROJ.4或任何其他库将这些局部坐标转换为全局坐标系?

Python中上述问题的任何代码都将提供很大的帮助。


需要一些代码吗?
huckfinn 2014年

GPS坐标通常为WGS84,因此它们可能已经是全球坐标。如果地面控制点位于局部投影中,且基准面与GPS(例如NAD83)不同,则必须转换基准面。据我所知,PROJ4确实支持原点平移。
Oyvind 2014年

这是一个类似的问题,但有更多详细信息:gis.stackexchange.com/questions/357910
trusktr

Answers:


7

您似乎正在寻找在本地坐标系和地理参考坐标系之间进行仿射变换的方法。

仿射变换可转换所有坐标系,并可由下面的矩阵方程式表示。

|x_1 y_1 1| |a d|   |x'_1 y'_1|
|x_2 y_2 1| |b e| = |x'_2 y'_2|
|x_3 y_3 1| |c f|   |x'_3 y'_3|
input     transform.  output
coords    matrix      coords
(n x 3)   (3 x 2)     (n x 2)

但是,您有两个步骤的问题。

  1. 从已知的输入和输出坐标对中找到转换矩阵(您的GPS点及其在本地定义的网格中的相应位置)。
  2. 使用此转换矩阵对您的点云进行地理配准。

Proj.4擅长于#2:在具有已知转换矩阵的地理参考坐标系之间进行转换。据我所知,它不能用于从点数据中找到转换矩阵。但是,通过在Numpy中使用一些轻线性代数(最小二乘矩阵求逆),您可以轻松完成整个操作。我使用了此类的一个版本来减少来自多个现场研究的数据:

import numpy as N 

def augment(a):
    """Add a final column of ones to input data"""
    arr = N.ones((a.shape[0],a.shape[1]+1))
    arr[:,:-1] = a
    return arr

class Affine(object):
    def __init__(self, array=None):
        self.trans_matrix = array

    def transform(self, points):
        """Transform locally projected data using transformation matrix"""
        return N.dot(augment(N.array(points)), self.trans_matrix)

    @classmethod
    def from_tiepoints(cls, fromCoords, toCoords):
        "Produce affine transform by ingesting local and georeferenced coordinates for tie points"""
        fromCoords = augment(N.array(fromCoords))
        toCoords = N.array(toCoords)
        trans_matrix, residuals, rank, sv = N.linalg.lstsq(fromCoords, toCoords)

        affine =  cls(trans_matrix) # Setup affine transform from transformation matrix
        sol = N.dot(fromCoords,affine.trans_matrix) # Compute model solution
        print "Pixel errors:"
        print (toCoords - sol)
        return affine

可以这样使用:

transform = Affine.from_tiepoints(gps_points_local,gps_points_geo)
projected_data = transform.transform(local_point_cloud)

projected_coordinates现在位于WGS84,UTM或GPS记录的任何坐标系中。该方法的主要特点是可以与任意数量的连接点(3个或更多)一起使用,并且使用的连接点越多,精度越高。本质上,您在所有联系点中都找到了最合适的选择。


你好!您提到Proj(Proj4)无法处理自定义转换部分吗?从技术上来说,这是否意味着gis.stackexchange.com/questions/357910上没有纯粹的Proj答案?
trusktr



0

几周前,我陷入了同样的问题,我想出了一个可以提供帮助的python脚本。这里的原始解决方案

import pyproj
import math
import numpy as np
from statistics import mean
import scipy.optimize as optimize

#This function converts the numbers into text
def text_2_CRS(params):
    # print(params)  # <-- you'll see that params is a NumPy array
    x_0, y_0, gamma, alpha, lat_0, lonc = params # <-- for readability you may wish to assign names to the component variables
    pm = '+proj=omerc +lat_0='+ str(lat_0) +' +lonc='+ str(lonc) +' +alpha=' + str(alpha) + ' +gamma=' + str(
        gamma) + ' +k=0.999585495 +x_0=' + str(x_0) + ' +y_0=' + str(y_0) + ' +ellps=GRS80 +units=m +no_defs'
    return pm

#Optimisation function
def convert(params):
    pm = text_2_CRS(params)
    trans_points = []
    #Put your control points in mine grid coordinates here
    points_local = [[5663.648, 7386.58],
                    [20265.326, 493.126],
                    [1000, -10000],
                    [-1000, -10000],
                    [1331.817, 2390.206],
                    [5794, -1033.6],
                    ]
    # Put your control points here mga here
    points_mga = [[567416.145863305, 7434410.3451835],
                  [579090.883705669, 7423265.25196681],
                  [557507.390559793, 7419390.6658927],
                  [555610.407664593, 7420021.64968145],
                  [561731.125709093, 7431037.98474379],
                  [564883.285081307, 7426382.75146683],
                  ]
    for i in range(len(points_local)):
        #note that EPSG:28350 is MGA94 Zone 50
        trans = pyproj.transform(pyproj.Proj(pm), pyproj.Proj("EPSG:28350"), points_local[i][0], points_local[i][1])
        trans_points.append(trans)
    error = []
    #this finds the difference between the control points
    for i in range(len(points_mga)):
        x1 = trans_points[i][0]
        y1 = trans_points[i][1]
        x2 = points_mga[i][0]
        y2 = points_mga[i][1]
        error.append(math.sqrt((x1 - x2) ** 2 + (y1 - y2) ** 2))

    print("Current Params are: ")
    with np.printoptions(precision=3, suppress=True):
        print(params)
    print("Current average error is: " + str(mean(error)) + " meters")
    print("String to use is: " + pm)
    print('')

    return mean(error)


#Add your inital guess
x_0 = 950
y_0 = -1200
gamma = -18.39841101
alpha=-0
lat_0 = -23.2583926082939
lonc = 117.589084840039


#define your control points
points_local = [[5663.648,7386.58],
          [20265.326,493.126],
          [1000,-10000],
          [-1000,-10000],
          [1331.817,2390.206],
          [5794,-1033.6],
          ]

points_mga = [[567416.145863305,7434410.3451835],
          [579090.883705669,7423265.25196681],
          [557507.390559793,7419390.6658927],
          [555610.407664593,7420021.64968145],
          [561731.125709093,7431037.98474379],
          [564883.285081307,7426382.75146683],
          ]


params = [x_0, y_0, gamma,alpha, lat_0, lonc]

error = convert(params)

print(error)

result = optimize.minimize(convert, params, method='Powell')
if result.success:
    fitted_params = result.x
    print(fitted_params)
else:
    raise ValueError(result.message)
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.