python gdal 地心坐标系转wgs84坐标系

from osgeo import osr,ogr
import numpy as np

class Osr_Coord_Convert(object):

    source = osr.SpatialReference()
    source.ImportFromProj4("+proj=geocent +datum=WGS84 +units=m +no_defs")
    target = osr.SpatialReference()
    target.ImportFromEPSG(4326)
    # target.ImportFromProj4("+proj=longlat +datum=WGS84 +no_defs")
    coordTrans = osr.CoordinateTransformation(source, target)

    """docstring for Osr_Coord_Convert"""
    def __init__(self, pop_path):
        self.xyz2llh_mat, self.llh2xyz_mat = self.read_pop_from_pop(pop_path)


    def read_pop_from_pop(self,pop_path_or_data):
        with open(pop_path_or_data) as f:
            f.readline()
            data = f.readline().strip()

            local2gcs_mat = np.mat(data)
            local2gcs_mat.resize((4, 4))
            # local2gcs_mat = local2gcs_mat.T
            gcs2local_mat = local2gcs_mat.I

            return local2gcs_mat, gcs2local_mat

    def local2llh(self, x,y,z):
        mat = self.xyz2llh_mat
        geoc_xyz = (
        x * mat[0, 0] + y * mat[0, 1] + z * mat[0, 2] + mat[0, 3],
        x * mat[1, 0] + y * mat[1, 1] + z * mat[1, 2] + mat[1, 3],
        x * mat[2, 0] + y * mat[2, 1] + z * mat[2, 2] + mat[2, 3],
            )
        des_blh = list(self.coordTrans.TransformPoint(geoc_xyz[0],geoc_xyz[1],geoc_xyz[2]))
        return des_blh

你可能感兴趣的:(python gdal 地心坐标系转wgs84坐标系)