當前位置: 首頁>>代碼示例>>Python>>正文


Python osr.CoordinateTransformation方法代碼示例

本文整理匯總了Python中osr.CoordinateTransformation方法的典型用法代碼示例。如果您正苦於以下問題:Python osr.CoordinateTransformation方法的具體用法?Python osr.CoordinateTransformation怎麽用?Python osr.CoordinateTransformation使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在osr的用法示例。


在下文中一共展示了osr.CoordinateTransformation方法的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: loadMetadata

# 需要導入模塊: import osr [as 別名]
# 或者: from osr import CoordinateTransformation [as 別名]
def loadMetadata(self):
        # open the raster and its spatial reference
        self.src = gdal.Open(self.tif_path)

        if self.src is None:
            raise Exception('Could not load GDAL file "%s"' % self.tif_path)
        spatial_reference_raster = osr.SpatialReference(self.src.GetProjection())

        # get the WGS84 spatial reference
        spatial_reference = osr.SpatialReference()
        spatial_reference.ImportFromEPSG(4326)  # WGS84

        # coordinate transformation
        self.coordinate_transform = osr.CoordinateTransformation(spatial_reference, spatial_reference_raster)
        gt = self.geo_transform = self.src.GetGeoTransform()
        dev = (gt[1] * gt[5] - gt[2] * gt[4])
        self.geo_transform_inv = (gt[0], gt[5] / dev, -gt[2] / dev,
                                  gt[3], -gt[4] / dev, gt[1] / dev) 
開發者ID:Jorl17,項目名稱:open-elevation,代碼行數:20,代碼來源:gdal_interfaces.py

示例2: to_wkt

# 需要導入模塊: import osr [as 別名]
# 或者: from osr import CoordinateTransformation [as 別名]
def to_wkt(self, target_wkt):
        # If we're going from WGS84 -> Spherical Mercator, use PyProj, because
        #  there seems to be a bug in OGR that gives us an offset. (GDAL
        #  does fine, though.
        if target_wkt == self.wkt:
            return self
        import osr
        dstSpatialRef = osr.SpatialReference()
        dstSpatialRef.ImportFromEPSG(d_name_to_epsg[target_wkt])
        # dstSpatialRef.ImportFromWkt(d_name_to_wkt[target_wkt])
        srcSpatialRef = osr.SpatialReference()
        srcSpatialRef.ImportFromEPSG(d_name_to_epsg[self.wkt])
        # srcSpatialRef.ImportFromWkt(self.wkt_)
        coordTransform = osr.CoordinateTransformation(srcSpatialRef, dstSpatialRef)
        a, b, c = coordTransform.TransformPoint(self.lon, self.lat)
        return Point(b, a, wkt=target_wkt) 
開發者ID:creare-com,項目名稱:pydem,代碼行數:18,代碼來源:my_types.py

示例3: get_pixel_latlon

# 需要導入模塊: import osr [as 別名]
# 或者: from osr import CoordinateTransformation [as 別名]
def get_pixel_latlon(raster, x, y):
    """For a given pixel in raster, gets the lat-lon value in EPSG 4326."""
    # TODO: Move to coordinate_manipulation
    native_projection = osr.SpatialReference()
    native_projection.ImportFromWkt(raster.GetProjection())
    latlon_projection = osr.SpatialReference()
    latlon_projection.ImportFromEPSG(4326)
    transformer = osr.CoordinateTransformation(native_projection, latlon_projection)

    geotransform = raster.GetGeoTransform()
    x_geo, y_geo = cm.pixel_to_point_coordinates([y,x], geotransform)  # Why did I do this reverse?
    lon, lat, _ = transformer.TransformPoint(x_geo, y_geo)
    return lat, lon 
開發者ID:clcr,項目名稱:pyeo,代碼行數:15,代碼來源:terrain_correction.py

示例4: _generate_latlon_transformer

# 需要導入模塊: import osr [as 別名]
# 或者: from osr import CoordinateTransformation [as 別名]
def _generate_latlon_transformer(raster):
    native_projection = osr.SpatialReference()
    native_projection.ImportFromWkt(raster.GetProjection())
    latlon_projection = osr.SpatialReference()
    latlon_projection.ImportFromEPSG(4326)
    geotransform = raster.GetGeoTransform()
    return osr.CoordinateTransformation(native_projection, latlon_projection), geotransform 
開發者ID:clcr,項目名稱:pyeo,代碼行數:9,代碼來源:terrain_correction.py

示例5: reproject_dataset

# 需要導入模塊: import osr [as 別名]
# 或者: from osr import CoordinateTransformation [as 別名]
def reproject_dataset(dataset, output_file_name, wkt_from="+proj=sinu +lon_0=0 +x_0=0 +y_0=0 +a=6371007.181 +b=6371007.181 +units=m +no_defs", epsg_to=32643, pixel_spacing=1000, file_format='GTiff'):
    '''
    :param dataset: Modis subset name use gdal.GetSubdatasets()
    :param output_file_name: file location along with proper extension
    :param wkt_from: Modis wkt (default)
    :param epsg_to: integer default(32643)
    :param pixel_spacing: in metres
    :param file_format: default GTiff
    :return:
    '''
    wgs84 = osr.SpatialReference()
    wgs84.ImportFromEPSG(epsg_to)
    modis = osr.SpatialReference()
    modis.ImportFromProj4(wkt_from)
    tx = osr.CoordinateTransformation(modis, wgs84)
    g = gdal.Open(dataset)
    geo_t = g.GetGeoTransform()
    print geo_t
    x_size = g.RasterXSize
    y_size = g.RasterYSize
    (ulx, uly, ulz) = tx.TransformPoint(geo_t[0], geo_t[3])
    (lrx, lry, lrz) = tx.TransformPoint(geo_t[0] + (geo_t[1]*x_size), geo_t[3]+ (geo_t[5]*y_size))
    mem_drv = gdal.GetDriverByName(file_format)
    dest = mem_drv.Create(output_file_name, int((lrx-ulx)/pixel_spacing), int((uly - lry)/pixel_spacing), 1, gdal.GDT_Float32)
    new_geo = ([ulx, pixel_spacing, geo_t[2], uly, geo_t[4], -pixel_spacing])
    dest.SetGeoTransform(new_geo)
    dest.SetProjection(wgs84.ExportToWkt())
    gdal.ReprojectImage(g, dest, modis.ExportToWkt(), wgs84.ExportToWkt(), gdal.GRA_Bilinear)
    print "reprojected" 
開發者ID:Kirubaharan,項目名稱:hydrology,代碼行數:31,代碼來源:modis_tg_halli.py

示例6: reproject_geometry

# 需要導入模塊: import osr [as 別名]
# 或者: from osr import CoordinateTransformation [as 別名]
def reproject_geometry(geom, inproj4, out_epsg):
    '''Reproject a wkt geometry based on EPSG code

    Args:
        geom (ogr-geom): an ogr geom objecct
        inproj4 (str): a proj4 string
        out_epsg (str): the EPSG code to which the geometry should transformed

    Returns
        geom (ogr-geometry object): the transformed geometry

    '''

    geom = ogr.CreateGeometryFromWkt(geom)
    # input SpatialReference
    spatial_ref_in = osr.SpatialReference()
    spatial_ref_in.ImportFromProj4(inproj4)

    # output SpatialReference
    spatial_ref_out = osr.SpatialReference()
    spatial_ref_out.ImportFromEPSG(int(out_epsg))

    # create the CoordinateTransformation
    coord_transform = osr.CoordinateTransformation(spatial_ref_in,
                                                   spatial_ref_out)
    try:
        geom.Transform(coord_transform)
    except:
        print(' ERROR: Not able to transform the geometry')
        sys.exit()

    return geom 
開發者ID:ESA-PhiLab,項目名稱:OpenSarToolkit,代碼行數:34,代碼來源:vector.py

示例7: transform_to_wgs

# 需要導入模塊: import osr [as 別名]
# 或者: from osr import CoordinateTransformation [as 別名]
def transform_to_wgs(getLong, getLat, EPSGa):
    source = osr.SpatialReference()
    source.ImportFromEPSG(EPSGa)

    target = osr.SpatialReference()
    target.ImportFromEPSG(4326)

    transform = osr.CoordinateTransformation(source, target)

    point = ogr.CreateGeometryFromWkt("POINT (" + str(getLong[0]) + " " + str(getLat[0]) + ")")
    point.Transform(transform)
    return [point.GetX(), point.GetY()] 
開發者ID:opendatacube,項目名稱:cube-in-a-box,代碼行數:14,代碼來源:utils.py

示例8: transform_shape

# 需要導入模塊: import osr [as 別名]
# 或者: from osr import CoordinateTransformation [as 別名]
def transform_shape(shape, ssrs, tsrs):
    """ Transform shape from ssrs to tsrs (all wkt) and return as wkt """
    ogrgeom = CreateGeometryFromWkt(shape)
    trans = CoordinateTransformation(SpatialReference(ssrs), SpatialReference(tsrs))
    ogrgeom.Transform(trans)
    wkt = ogrgeom.ExportToWkt()
    ogrgeom = None
    return wkt 
開發者ID:gipit,項目名稱:gips,代碼行數:10,代碼來源:utils.py

示例9: __init__

# 需要導入模塊: import osr [as 別名]
# 或者: from osr import CoordinateTransformation [as 別名]
def __init__(self, tile_path):
    """Initializes the Tile Information.

    Inputs:
      tile_path: path the tile file.
    """
    self.tile_path = tile_path

    ds = gdal.Open(tile_path)
    self.width = ds.RasterXSize
    self.height = ds.RasterYSize

    # Gets the gdal geo transformation tuples
    gdal_version = osgeo.gdal.__version__
    self._txf = ds.GetGeoTransform()
    if gdal_version[0] == '1':
      self._inv_txf = gdal.InvGeoTransform(self._txf)[1]
    else:
      self._inv_txf = gdal.InvGeoTransform(self._txf)
    # Gets the transformation from lat/lon to coordinates
    wgs84_ref = osr.SpatialReference()
    wgs84_ref.ImportFromEPSG(4326)   # WGS84
    sref = osr.SpatialReference()
    sref.ImportFromWkt(ds.GetProjection())
    self._transform = osr.CoordinateTransformation(wgs84_ref, sref)
    inv_transform = osr.CoordinateTransformation(sref, wgs84_ref)
    # Find a loose lat/lon bounding box  for quick check without
    # having to do full coordinates transformation
    corners = []
    for x in [0, self.width]:
      for y in [0, self.height]:
        corners.append([self._txf[0] + self._txf[1] * x + self._txf[2] * y,
                        self._txf[3] + self._txf[4] * x + self._txf[5] * y])
    self.max_lat = -100
    self.min_lat = 100
    self.max_lon = -500
    self.min_lon = 500
    for c in corners:
      p = inv_transform.TransformPoint(c[0], c[1])
      if p[0] > self.max_lon:
        self.max_lon = p[0]
      if p[0] < self.min_lon:
        self.min_lon = p[0]
      if p[1] > self.max_lat:
        self.max_lat = p[1]
      if p[1] < self.min_lat:
        self.min_lat = p[1]

    # Close file
    ds = None 
開發者ID:Wireless-Innovation-Forum,項目名稱:Spectrum-Access-System,代碼行數:52,代碼來源:nlcd_origin.py


注:本文中的osr.CoordinateTransformation方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。