How to use the 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 Toblerity / Fiona / tests / View on Github external
def test_write_invalid_numeric_layer(path_coutwildrnp_shp, tmpdir):
    with pytest.raises(ValueError):"test-no-iter.shp")), mode='w', layer=0)
github Toblerity / Fiona / tests / View on Github external
"latitude": 45.66894,
          "longitude": 87.91166
        "tricky": "{gotcha"
    tmpdir = tempfile.mkdtemp()
    filename = os.path.join(tmpdir, 'test.json')

    with open(filename, 'w') as f:

    with as src:
        ftr = next(iter(src))
        props = ftr['properties']
        assert props['upperLeftCoordinate']['latitude'] == 45.66894
        assert props['upperLeftCoordinate']['longitude'] == 87.91166
        assert props['tricky'] == "{gotcha"
github Toblerity / Fiona / tests / View on Github external
def test_field_truncation_issue177(tmpdir):
    name = str(tmpdir.join('output.shp'))

    kwargs = {
        'driver': 'ESRI Shapefile',
        'crs': 'EPSG:4326',
        'schema': {
            'geometry': 'Point',
            'properties': [('a_fieldname', 'float')]}}

    with, 'w', **kwargs) as dst:
        rec = {}
        rec['geometry'] = {'type': 'Point', 'coordinates': (0, 0)}
        rec['properties'] = {'a_fieldname': 3.0}

    with as src:
        first = next(iter(src))
        assert first['geometry'] == {'type': 'Point', 'coordinates': (0, 0)}
        assert first['properties']['a_fieldnam'] == 3.0
github Humpheh / twied / scripts / dbfillers / View on Github external
c.execute('''CREATE TABLE IF NOT EXISTS countries (
    poly BLOB,
    fips TEXT,
    iso2 TEXT,
    iso3 TEXT,
    un INT,
    area INT,
    lon REAL,
    lat REAL
c.execute('CREATE INDEX IF NOT EXISTS countryname ON countries (name)')

import fiona
fi ="D:/ds/tm_world/TM_WORLD_BORDERS-0.3.shp", 'r')

count = 0
while True:
        a =

    di = a['properties']
    di['poly'] = str(a['geometry'])

    count += 1
    c.execute("INSERT INTO countries VALUES (:NAME, :poly, :FIPS, :ISO2, :ISO3, :UN, :AREA, :LON, :LAT)", di)

    print (count)
github pyviz-topics / EarthSim / earthsim / View on Github external
def save_shapefile(cdsdata, path, template):
    Accepts bokeh ColumnDataSource data and saves it as a shapefile,
    using an existing template to determine the required schema.
    collection =
    arrays = [np.column_stack([xs, ys]) for xs, ys in zip(cdsdata['xs'], cdsdata['ys'])]
    polys = gv.Polygons(arrays, crs=ccrs.GOOGLE_MERCATOR)
    projected = gv.operation.project_path(polys, projection=ccrs.PlateCarree())
    data = [list(map(tuple, arr)) for arr in projected.split(datatype='array')]
    shape_data = list(collection.items())[0][1]
    shape_data['geometry']['coordinates'] = data
    with, 'w', collection.driver, collection.schema, as c:
github openstreams / wflow / wflow-py / Scripts / wtools_py / View on Github external
def catchment_boundaries(catch_path):
    """Collect all catchment boundaries into a MultiLineString"""
    geoms = []
    with as c:
        for f in c:
            g = sg.shape(f["geometry"]).boundary

    return unary_union(geoms)
github boland1992 / SeisSuite / ambient / sort_later / View on Github external
def shape_(input_shape):
    with as fiona_collection:
        # In this case, we'll assume the shapefile only has one record/layer 
        shapefile_record =
        # Use Shapely to create the polygon
        return geometry.asShape( shapefile_record['geometry'] )
github stefanw / verkehrsunfallstatistik / View on Github external
def main(shapefile):
    with, 'r') as shp:
        streets = collect_streets(shp)


    first = True
    for street, segments in cluster_streets(streets):
        for segment in segments:
            if first:
                first = False
            json.dump(segment.geojson(), sys.stdout)
github LSDtopotools / LSDMappingTools / View on Github external
def ReadShapeFile(ShapeFile):

    Open shapefile and create Polygon dictionary
    returns dictionary of shapely Polygons



    #open shapefile and read shapes
    Shapes =

    # get the input coordinate system
    Input_CRS = Proj(

    # Create a dictionary of shapely polygons
    PolygonDict = {}

    # loop through shapes and add to dictionary
    for Feature in Shapes:
        if Feature['geometry']['type'] == 'MultiPolygon':
            Shape = MultiPolygon(shape(Feature['geometry']))
            Value = float(Feature['properties']['ID'])
        elif Feature['geometry']['type'] == 'Polygon':
            Shape = Polygon(shape(Feature['geometry']))
            Value = float(Feature['properties']['ID'])
github nismod / digital_comms / scripts / View on Github external
def load_local_authority_districts():
    Load in Local Authority District (LAD) shapes and extract id information.

    lads = []

    lad_shapes = os.path.join(
        SHAPES_INPUT_PATH, 'lad_uk_2016-12', 'lad_uk_2016-12.shp'

    with, 'r') as lad_shape:
        for lad in lad_shape:
            if not lad['properties']['name'].startswith((