How to use the fiona.crs.to_string function in fiona

To help you get started, we’ve selected a few fiona examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github bukun / book_python_gis / part010 / ch03_ogr / sec5_fiona / test_2_reading_x_x.py View on Github external
###############################################################################
try:
    with fiona.open('/gdata/GSHHS_c.shp') as c:
        print(len(list(c)))
except:
    print(c.closed)
    raise

###############################################################################
c = fiona.open('/gdata/GSHHS_c.shp')
c.driver
###############################################################################
c.crs
###############################################################################
from fiona.crs import to_string
to_string(c.crs)
###############################################################################
from fiona.crs import from_string
from_string(
    "+datum=WGS84 +ellps=WGS84 +no_defs +proj=longlat")
###############################################################################
from fiona.crs import from_epsg
from_epsg(3857)
###############################################################################
len(c)
###############################################################################
c.bounds
github Toblerity / Fiona / tests / test_crs.py View on Github external
def test_to_string_epsg():
    val = {'init': 'epsg:4326', 'no_defs': True}
    assert crs.to_string(val) == "+init=epsg:4326 +no_defs"
github Toblerity / Fiona / tests / test_crs.py View on Github external
def test_to_string_utm():
    # Make a string from a mapping with a few bogus items
    val = {
        'proj': 'utm', 'ellps': 'WGS84', 'zone': 13,
        'no_defs': True, 'foo': True, 'axis': False, 'belgium': [1, 2]}
    assert crs.to_string(
        val) == "+ellps=WGS84 +no_defs +proj=utm +zone=13"
github Toblerity / Fiona / fiona / fio / info.py View on Github external
When working with a multi-layer dataset the first layer is used by default.
    Use the '--layer' option to select a different layer.
    """

    logger = logging.getLogger(__name__)
    try:
        with fiona.open(input, layer=layer) as src:
            info = src.meta
            info.update(bounds=src.bounds, name=src.name)
            try:
                info.update(count=len(src))
            except TypeError:
                info.update(count=None)
                logger.debug("Setting 'count' to None/null - layer does "
                             "not support counting")
            proj4 = fiona.crs.to_string(src.crs)
            if proj4.startswith('+init=epsg'):
                proj4 = proj4.split('=')[1].upper()
            info['crs'] = proj4
            if meta_member:
                if isinstance(info[meta_member], (list, tuple)):
                    click.echo(" ".join(map(str, info[meta_member])))
                else:
                    click.echo(info[meta_member])
            else:
                click.echo(json.dumps(info, indent=indent))

    except Exception:
        logger.exception("Exception caught during processing")
        raise click.Abort()
github fitnr / svgis / svgis / projection.py View on Github external
Returns:
        (str) proj4 string
    '''
    if bounds is None or file_crs is None:
        raise ValueError('generatecrs missing bounds and file crs')

    is_longlat = _is_longlat(file_crs)

    if method == 'default':
        # Check if file_crs _is_longlat, if not use that.
        # Option to continue returning default if we didn't get a file_crs
        if is_longlat:
            method = 'local'
        else:
            return fiona.crs.to_string(file_crs)

    if is_longlat:
        longlat_bounds = bounds
    else:
        longlat_bounds = bounding.transform(file_crs, DEFAULT_GEOID, bounds)

    minx, miny, maxx, maxy = longlat_bounds

    if method == 'utm':
        midx = (minx + maxx) / 2
        midy = (miny + maxy) / 2

        return utm_proj4(midx, midy)

    elif method == 'local':
        # Create a custom TM projection
github fitnr / svgis / svgis / cli.py View on Github external
def project(bounds, method, crs):
    '''Get a local Transverse Mercator or UTM projection for a bounding box. Expects WGS84 coordinates.'''
    if crs in projection.METHODS:
        click.echo('CRS must be an EPSG code, a Proj4 string, or file containing a Proj4 string.', err=1)
        return

    if len(bounds) == 2:
        bounds = bounds + bounds

    if len(bounds) != 4:
        click.echo('Either two or four bounds required', err=True)
        return

    result = fiona.crs.to_string(projection.pick(method, file_crs=crs, bounds=bounds))
    click.echo(result.encode('utf-8'))
github NLeSC / PattyAnalytics / scripts / viaappia.py View on Github external
# Example script to work with the footprint shapefiles

# shapefile library to read the footprints
# http://toblerity.org/fiona/manual.html
import fiona
import fiona.crs

# Geometric objects, predicates, and operations: ie. boundinbox, union, etc.
# of the footprints
# https://pypi.python.org/pypi/Shapely
from shapely.geometry import shape


footprints_sf = fiona.open('../data/footprints/VIA_APPIA_SITES.shp')

print(fiona.crs.to_string(footprints_sf.crs))
print(footprints_sf.schema)

for point in footprints_sf:
    print(shape(point['geometry']))

footprints_sf.close()
github zackw / active-geolocator / maps / make_geog_baseline.py View on Github external
def process_geometry(self, sense, geom):
        assert sense == '+' or sense == '-'
        name = os.path.splitext(os.path.basename(geom.name))[0]
        self.geoms.append((sense, name))

        sys.stderr.write("Processing {} (crs={})...\n"
                         .format(name, fiona.crs.to_string(geom.crs)))

        # unary_union does not accept generators
        inner_boundary = shapely.ops.unary_union([
            shapely.geometry.shape(g['geometry'])
            for g in geom])

        # It is (marginally) more efficient to transform the inner
        # boundary to the desired "raw WGS84 lat/long" coordinate
        # system after combining it into one shape.
        inner_boundary = shapely.ops.transform(
            functools.partial(
                pyproj.transform,
                pyproj.Proj(geom.crs),
                pyproj.Proj(proj="latlong", datum="WGS84", ellps="WGS84")),
            inner_boundary)