コード例 #1
0
def main(argv=None):
    #Input is a filename
    if len(sys.argv[1:]) == 1:
        fn = sys.argv[1]
        ext = os.path.splitext(fn)[1].lower()
        #Accept DigitalGlobe image metadata in xml
        if ext == '.xml':
            from dgtools.lib import dglib
            geom = dglib.xml2geom(fn)
        #Want to be better about handling arbitrary gdal formats here
        elif ext == '.tif' or ext == '.ras':
            ds = gdal.Open(fn)
            geom = geolib.ds_geom(ds, t_srs=geolib.wgs_srs)
            #geom = geolib.get_outline(ds, t_srs=geolib.wgs_srs)
    #Input is lat/lon
    elif len(sys.argv[1:]) == 2:
        y = float(sys.argv[1])
        x = float(sys.argv[2])
        #Force longitude -180 to 180 
        x = (x+180) - math.floor((x+180)/360)*360 - 180
        #Check that latitude is valid 
        if y > 90 or y < -90:
            sys.exit('Invalid latitude: %f' % y)
        geom = geolib.xy2geom(x, y)
    else:
        sys.exit("Usage: %s [lat lon]|[raster.tif]" % os.path.basename(sys.argv[0]))

    #Now determine the srs from geom
    srs = geolib.get_proj(geom)
    #And print to stdout
    print(srs.ExportToProj4().strip())
コード例 #2
0
        if site_name not in valid_sites:
            continue

    #Could output json here
    stackdir = os.path.join(outdir, site_name)
    if not os.path.exists(stackdir):
        os.makedirs(stackdir)
    out_fn = os.path.join(stackdir, 'site_%s.csv' % site_name)
    f = open(out_fn, 'w')

    site_geom_orig = site_feat.GetGeometryRef()
    site_geom_orig.AssignSpatialReference(site_shp_srs)

    #This will automatically select appropriate UTM zone or polar stereographic
    if dst_srs is None:
        dst_srs = geolib.get_proj(site_geom_orig)

    geolib.geom_transform(site_geom_orig, dst_srs)

    if buffer is not None:
        site_geom_buff = site_geom_orig.Buffer(buffer)
        site_geom = site_geom_buff
    else:
        site_geom = site_geom_orig

    #This is xmin, xmax, ymin, ymax
    site_extent = geolib.geom_extent(site_geom)
    site_extent_str = ' '.join(map(str, site_extent))

    print("Extent:", site_extent)
    print("Width/Height (km)", np.array(geolib.geom_wh(site_geom)) / 1000.)