예제 #1
0
파일: mapping.py 프로젝트: jomerson/pysal
def transCRS(xy, src_prj, trt_prj):
    '''
    Re-project a 2D array of xy coordinates from one prj file to another
    ...

    Arguments
    ---------
    xy          : ndarray
                  nx2 array with coordinates to be reprojected. First column
                  is X axis, second is Y axis
    src_prj     : str
                  Path to .prj file of the source Coordinate Reference System
                  (CRS) of `xy`
    trt_prj     : str
                  Path to .prj file of the target Coordinate Reference System
                  (CRS) to reproject `xy`

    Returns
    -------
    xyp         : ndarray
                  nx2 array with reprojected coordinates. First column
                  is X axis, second is Y axis
                  
    '''
    orig = osr.SpatialReference()
    orig.ImportFromWkt(open(src_prj).read())
    target = osr.SpatialReference()
    target.ImportFromWkt(open(trt_prj).read())
    trCRS = osr.CoordinateTransformation(orig, target)
    return np.array(trCRS.TransformPoints(xy))[:, :2]
예제 #2
0
def get_image_wkt(product):

    src = gdal.Open(product)
    ulx, xres, xskew, uly, yskew, yres = src.GetGeoTransform()

    max_x = ulx + (src.RasterXSize * xres)
    min_y = uly + (src.RasterYSize * yres)
    min_x = ulx
    max_y = uly

    source = osr.SpatialReference()
    source.ImportFromWkt(src.GetProjection())

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

    transform = osr.CoordinateTransformation(source, target)

    result_wkt = box(
        transform.TransformPoint(min_x, min_y)[0],
        transform.TransformPoint(min_x, min_y)[1],
        transform.TransformPoint(max_x, max_y)[0],
        transform.TransformPoint(max_x, max_y)[1]).wkt

    return result_wkt
예제 #3
0
def transCRS(db, prj_link, lat='lat', lon='lon'):
    '''
    Re-project 'lon' and 'lat' columns from WGS84 to prj_link and put it in
    'x' and 'y' columns
    ...

    Arguments
    ---------
    db          : DataFrame
                  DataFrame with coordinates to be reprojected
    prj_link    : str
                  Path to .prj to project lon/lat data
    lat         : str
                  Column name in db for lattitude
    lon         : str
                  Column name in db for longitude
    Returns
    -------
    db          : DataFrame
                  Original DataFrame to which columns 'x' and 'y' have been
                  added with projected coordinates
    '''
    orig = osr.SpatialReference()
    orig.SetWellKnownGeogCS("WGS84")
    target = osr.SpatialReference()
    #See link for this hack
    #http://forum.osgearth.org/Proj4-error-No-translation-for-lambert-conformal-conic-to-PROJ-4-format-is-known-td7579032.html
    wkt = (open(prj_link).read()).replace('Lambert_Conformal_Conic', \
            'Lambert_Conformal_Conic_2SP')
    target.ImportFromWkt(wkt)
    #target.ImportFromWkt(open(prj_link).read()) #original
    trCRS = osr.CoordinateTransformation(orig, target)
    prjd_xys = db[['lon', 'lat']].values.tolist()
    prjd_xys = np.array(trCRS.TransformPoints(prjd_xys))[:, :2]
    db['x'] = prjd_xys[:, 0]
    db['y'] = prjd_xys[:, 1]
    return db