Exemplo n.º 1
0
def _coordinateReport( hDataset, hTransform, name, x, y, verbose):
    line = "%-11s " % name

    # Transform the point into georeferenced coordinates.
    gt = hDataset.GetGeoTransform(can_return_null = True)
    if gt is not None:
        dfGeoX = gt[0] + gt[1] * x + gt[2] * y
        dfGeoY = gt[3] + gt[4] * x + gt[5] * y

    else:
        line = line + ("(%7.1f,%7.1f)" % (x, y ))
        if verbose: print(line)
        return x, y

    # Report the georeferenced coordinates
    if abs(dfGeoX) < 181 and abs(dfGeoY) < 91:
        line += ( "(%12.7f,%12.7f) " % (dfGeoX, dfGeoY ))

    else:
        line += ( "(%12.3f,%12.3f) " % (dfGeoX, dfGeoY ))

    # Transform to latlong and report
    if hTransform is not None:
        pnt = hTransform.TransformPoint(dfGeoX, dfGeoY, 0)
        if pnt is not None:
            line += ( "(%s," % gdal.DecToDMS( pnt[0], "Long", 2 ) )
            line += ( "%s)" % gdal.DecToDMS( pnt[1], "Lat", 2 ) )

        if verbose: print(line)
    
    return dfGeoX, dfGeoY
Exemplo n.º 2
0
def GDALInfoReportCorner(hDataset, hTransform, corner_name=None, x=0, y=0):

    line = ""  #%-11s " % corner_name
    listToReturn = []

    #/* -------------------------------------------------------------------- */
    #/*      Transform the point into georeferenced coordinates.             */
    #/* -------------------------------------------------------------------- */
    adfGeoTransform = hDataset.GetGeoTransform(can_return_null=True)
    if adfGeoTransform is not None:
        dfGeoX = adfGeoTransform[0] + adfGeoTransform[1] * x \
            + adfGeoTransform[2] * y
        dfGeoY = adfGeoTransform[3] + adfGeoTransform[4] * x \
            + adfGeoTransform[5] * y

    else:
        line = line + ("(%7.1f,%7.1f)" % (x, y))
        listToReturn = [x, y]
        return listToReturn

#/* -------------------------------------------------------------------- */
#/*      Report the georeferenced coordinates.                           */
#/* -------------------------------------------------------------------- */
    if abs(dfGeoX) < 181 and abs(dfGeoY) < 91:
        line = line + ("(%12.7f,%12.7f) " % (dfGeoX, dfGeoY))
        listToReturn.append(float("%12.7f" % dfGeoX))
        listToReturn.append(float("%12.7f" % dfGeoY))
    else:
        line = line + ("(%12.3f,%12.3f) " % (dfGeoX, dfGeoY))
        listToReturn.append(float("%12.3f" % dfGeoX))
        listToReturn.append(float("%12.3f" % dfGeoY))


#/* -------------------------------------------------------------------- */
#/*      Transform to latlong and report.                                */
#/* -------------------------------------------------------------------- */
    if hTransform is not None:
        pnt = hTransform.TransformPoint(dfGeoX, dfGeoY, 0)
        if pnt is not None:
            line = line + ("(%s," % gdal.DecToDMS(pnt[0], "Long", 2))
            line = line + ("%s)" % gdal.DecToDMS(pnt[1], "Lat", 2))
            listToReturn.append(pnt[0])
            listToReturn.append(pnt[1])

    return listToReturn
Exemplo n.º 3
0
def GDALInfoReportCorner( hDataset, hTransform, corner_name, x, y ):


    line = "%-11s " % corner_name

# --------------------------------------------------------------------
#      Transform the point into georeferenced coordinates.
# --------------------------------------------------------------------
    adfGeoTransform = hDataset.GetGeoTransform(can_return_null = True)
    if adfGeoTransform is not None:
        dfGeoX = adfGeoTransform[0] + adfGeoTransform[1] * x \
            + adfGeoTransform[2] * y
        dfGeoY = adfGeoTransform[3] + adfGeoTransform[4] * x \
            + adfGeoTransform[5] * y

    else:
        line = line + ("(%7.1f,%7.1f)" % (x, y ))
        print(line)
        return False

# --------------------------------------------------------------------
#      Report the georeferenced coordinates.
# --------------------------------------------------------------------
    if abs(dfGeoX) < 181 and abs(dfGeoY) < 91:
        line = line + ( "(%12.7f,%12.7f) " % (dfGeoX, dfGeoY ))

    else:
        line = line + ( "(%12.3f,%12.3f) " % (dfGeoX, dfGeoY ))

# --------------------------------------------------------------------
#      Transform to latlong and report.
# --------------------------------------------------------------------
    if hTransform is not None:
        pnt = hTransform.TransformPoint(dfGeoX, dfGeoY, 0)
        if pnt is not None:
            line = line + ( "(%s," % gdal.DecToDMS( pnt[0], "Long", 2 ) )
            line = line + ( "%s)" % gdal.DecToDMS( pnt[1], "Lat", 2 ) )

    print(line)

    return True
Exemplo n.º 4
0
if line is None:
    Usage()

# Open input dataset
indataset = gdal.Open(infile, gdal.GA_ReadOnly)

# Read geotransform matrix and calculate ground coordinates
geomatrix = indataset.GetGeoTransform()
X = geomatrix[0] + geomatrix[1] * pixel + geomatrix[2] * line
Y = geomatrix[3] + geomatrix[4] * pixel + geomatrix[5] * line

# Shift to the center of the pixel
X += geomatrix[1] / 2.0
Y += geomatrix[5] / 2.0

# Build Spatial Reference object based on coordinate system, fetched from the
# opened dataset
srs = osr.SpatialReference()
if srs.ImportFromWkt(indataset.GetProjection()) != 0:
    print("ERROR: Cannot import projection '%s'" % indataset.GetProjection())
    sys.exit(1)

srsLatLong = srs.CloneGeogCS()
ct = osr.CoordinateTransformation(srs, srsLatLong)
(lon, lat, height) = ct.TransformPoint(X, Y)

# Report results
print('pixel: %g\t\t\tline: %g' % (pixel, line))
print('latitude: %fd\t\tlongitude: %fd' % (lat, lon))
print('latitude: %s\t\tlongitude: %s' % (gdal.DecToDMS(lat, 'Lat', 2), gdal.DecToDMS(lon, 'Long', 2)))
Exemplo n.º 5
0
def main(argv):
    infile = None
    pixel = None
    line = None

    # =============================================================================
    # Parse command line arguments.
    # =============================================================================
    i = 1
    while i < len(argv):
        arg = argv[i]

        if pixel is None:
            pixel = float(arg)

        elif line is None:
            line = float(arg)

        elif infile is None:
            infile = arg

        else:
            return Usage()

        i = i + 1

    if infile is None:
        return Usage()
    if pixel is None:
        return Usage()
    if line is None:
        return Usage()

    # Open input dataset
    indataset = gdal.Open(infile, gdal.GA_ReadOnly)

    # Read geotransform matrix and calculate ground coordinates
    geomatrix = indataset.GetGeoTransform()
    X = geomatrix[0] + geomatrix[1] * pixel + geomatrix[2] * line
    Y = geomatrix[3] + geomatrix[4] * pixel + geomatrix[5] * line

    # Shift to the center of the pixel
    X += geomatrix[1] / 2.0
    Y += geomatrix[5] / 2.0

    # Build Spatial Reference object based on coordinate system, fetched from the
    # opened dataset
    srs = osr.SpatialReference()
    if srs.ImportFromWkt(indataset.GetProjection()) != 0:
        print("ERROR: Cannot import projection '%s'" %
              indataset.GetProjection())
        return 1

    srsLatLong = srs.CloneGeogCS()
    ct = osr.CoordinateTransformation(srs, srsLatLong)
    (lon, lat, height) = ct.TransformPoint(X, Y)

    # Report results
    print('pixel: %g\t\t\tline: %g' % (pixel, line))
    print('latitude: %fd\t\tlongitude: %fd' % (lat, lon))
    print('latitude: %s\t\tlongitude: %s' %
          (gdal.DecToDMS(lat, 'Lat', 2), gdal.DecToDMS(lon, 'Long', 2)))

    return 0
Exemplo n.º 6
0
if line is None:
    Usage()

# Open input dataset
indataset = gdal.Open("RADARSAT_2_CALIB:SIGMA0:" + infile + "product.xml",
                      GA_ReadOnly)

# Read geotransform matrix and calculate ground coordinates
geomatrix = indataset.GetGeoTransform()
X = geomatrix[0] + geomatrix[1] * pixel + geomatrix[2] * line
Y = geomatrix[3] + geomatrix[4] * pixel + geomatrix[5] * line

# Shift to the center of the pixel
X += geomatrix[1] / 2.0
Y += geomatrix[5] / 2.0

# Build Spatial Reference object based on coordinate system, fetched from the
# opened dataset
srs = osr.SpatialReference()
srs.ImportFromWkt(indataset.GetProjection())

srsLatLong = srs.CloneGeogCS()
ct = osr.CoordinateTransformation(srs, srsLatLong)
(int, lat, height) = ct.TransformPoint(X, Y)

# Report results
print('pixel: %g\t\t\tline: %g' % (pixel, line))
print('latitude: %fd\t\tlongitude: %fd' % (lat, int))
print('latitude: %s\t\tlongitude: %s' %
      (gdal.DecToDMS(lat, 'Lat', 2), gdal.DecToDMS(int, 'Long', 2)))
Exemplo n.º 7
0
    Usage()
if line is None:
    Usage()

# Open input dataset
indataset = gdal.Open(infile, GA_ReadOnly)

# Read geotransform matrix and calculate ground coordinates
geomatrix = indataset.GetGeoTransform()
X = geomatrix[0] + geomatrix[1] * pixel + geomatrix[2] * line
Y = geomatrix[3] + geomatrix[4] * pixel + geomatrix[5] * line

# Shift to the center of the pixel
X += geomatrix[1] / 2.0
Y += geomatrix[5] / 2.0

# Build Spatial Reference object based on coordinate system, fetched from the
# opened dataset
srs = osr.SpatialReference()
srs.ImportFromWkt(indataset.GetProjection())

srsLatLong = srs.CloneGeogCS()
ct = osr.CoordinateTransformation(srs, srsLatLong)
(int, lat, height) = ct.TransformPoint(X, Y)

# Report results
print('pixel: %g\t\t\tline: %g' % (pixel, line))
print('latitude: %fd\t\tlongitude: %fd' % (lat, int))
print('latitude: ', gdal.DecToDMS(lat, 'Lat', 2), \
    '\tlongitude: ', gdal.DecToDMS(int, 'Long', 2))