Python osgeo.gdal.AllRegister() Examples

The following are code examples for showing how to use osgeo.gdal.AllRegister(). They are from open source Python projects. You can vote up the examples you like or vote down the ones you don't like.

Example 1
Project: YunoSeeMe   Author: superbob   File: profile_server.py    BSD 2-Clause "Simplified" License 6 votes vote down vote up
def main():
    """Main entrypoint"""
    config = ConfigParser.ConfigParser()
    config.read('config.ini')
    config_dem_location = config.get('dem', 'location')

    parser = argparse.ArgumentParser(description=__doc__, formatter_class=argparse.RawDescriptionHelpFormatter)
    parser.add_argument('-d', '--dem', help="DEM file location, ex: '/path/to/file/EUD_CP-DEMS_3500025000-AA.tif'")
    args = parser.parse_args()

    LOGGER.debug("using the following DEM: %s", args.dem)

    # register all of the drivers
    gdal.AllRegister()
    # open the image
    dem_location = args.dem or config_dem_location
    data_source = gdal.Open(dem_location, GA_ReadOnly)

    cherrypy.quickstart(Profile(data_source), '/profile') 
Example 2
Project: PostgreSQL-GeoPackage   Author: EOX-A   File: gpkg-pg_dump.py    MIT License 5 votes vote down vote up
def create_gpkg(
    gpkg_name, proj_string, size=(1, 1), geotransform=[0, 1, 0, 0, 0, -1],
    creation_options=None
):
    if os.path.exists("%s.gpkg" % gpkg_name):
        sys.stderr.write(
            "ERROR: SQLite GeoPackage '%s.gpkg' already exists.\n" % gpkg_name
        )
        sys.exit(1)

    gdal.AllRegister()
    drv = gdal.GetDriverByName("GPKG")
    try:
        gpkg = drv.Create(
            "%s.gpkg" % gpkg_name, size[0], size[1], 1, gdal.GDT_Byte,
            creation_options
        )

        proj = osr.SpatialReference()
        res = proj.SetWellKnownGeogCS(proj_string)
        if res != 0:
            if proj_string[0:4] == 'EPSG':
                proj.ImportFromEPSG(int(proj_string[5:]))
        gpkg.SetProjection(proj.ExportToWkt())
        gpkg.SetGeoTransform(geotransform)
        gpkg = None
    except Exception as e:
        sys.stderr.write(
            "ERROR: Cannot create SQLite GeoPackage '%s.gpkg'. "
            "Error message was: '%s'.\n" % (gpkg_name, e.message)
        )
        sys.exit(1) 
Example 3
Project: YunoSeeMe   Author: superbob   File: elevation.py    BSD 2-Clause "Simplified" License 5 votes vote down vote up
def main():
    """Main entrypoint"""

    config = ConfigParser.ConfigParser()
    config.read('config.ini')
    config_dem_location = config.get('dem', 'location')

    parser = argparse.ArgumentParser(description=__doc__, formatter_class=argparse.RawDescriptionHelpFormatter)
    parser.add_argument('lat', type=float, help="latitude, ex: 43.561725")
    parser.add_argument('long', type=float, help="longitude, ex: 1.444796")
    parser.add_argument('-d', '--dem', help="DEM file location, ex: '/path/to/file/EUD_CP-DEMS_3500025000-AA.tif'",
                        default=config_dem_location)
    args = parser.parse_args()

    LOGGER.debug("requesting elevation for wgs84 lat: %f, long: %f using the following DEM: %s", args.lat, args.long,
                 args.dem)

    # register all of the drivers
    gdal.AllRegister()
    # open the image
    data_source = gdal.Open(args.dem, GA_ReadOnly)

    # get the value
    value = geods.read_ds_value_from_wgs84(data_source, args.lat, args.long)

    print "elevation for coordinates: %f, %f is %f" % (args.lat, args.long, value) 
Example 4
Project: YunoSeeMe   Author: superbob   File: profile_output.py    BSD 2-Clause "Simplified" License 4 votes vote down vote up
def main():
    """Main entrypoint"""
    config = ConfigParser.ConfigParser()
    config.read('config.ini')
    config_dem_location = config.get('dem', 'location')

    args = parse_args()

    kwargs = {}
    if args.offset_sea1 is not None:
        kwargs['height1'] = args.offset_sea1
        kwargs['above_ground1'] = False
    elif args.offset_ground1 is not None:
        kwargs['height1'] = args.offset_ground1
        kwargs['above_ground1'] = True

    if args.offset_sea2 is not None:
        kwargs['height2'] = args.offset_sea2
        kwargs['above_ground2'] = False
    elif args.offset_ground1 is not None:
        kwargs['height2'] = args.offset_ground2
        kwargs['above_ground2'] = True

    LOGGER.debug("using the following DEM: %s", args.dem)
    LOGGER.debug("requesting profile for the following 'GPS' coordinates")
    LOGGER.debug("first wgs84 lat: %f, long: %f", args.lat1, args.long1)
    LOGGER.debug("second wgs84 lat: %f, long: %f", args.lat2, args.long2)

    # register all of the drivers
    gdal.AllRegister()
    # open the DEM
    dem_location = args.dem or config_dem_location
    data_source = gdal.Open(dem_location, GA_ReadOnly)

    profile_data = profiler.profile(data_source, args.lat1, args.long1, args.lat2, args.long2, **kwargs)

    if args.output_format == 'png':
        if args.style == 'detailed':
            output_format = profile_format.PNG_detailed
        elif args.style == 'curved_sight':
            output_format = profile_format.PNG_curved_sight
        else:
            output_format = profile_format.PNG

        default_filename = "profile.png"
    else:
        output_format = profile_format.JSON
        default_filename = "profile.json"

    if args.stdout:
        output_format.write_to_fd(profile_data, sys.stdout)
    else:
        filename = args.filename or default_filename
        output_format.write_to_filename(profile_data, filename)