How to use fiona - 10 common examples

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 / test_layer.py View on Github external
def test_write_invalid_numeric_layer(path_coutwildrnp_shp, tmpdir):
    with pytest.raises(ValueError):
        fiona.open(str(tmpdir.join("test-no-iter.shp")), mode='w', layer=0)
github Toblerity / Fiona / tests / test_props.py 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:
        f.write(data)

    with fiona.open(filename) 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 / test_schema.py 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 fiona.open(name, 'w', **kwargs) as dst:
        rec = {}
        rec['geometry'] = {'type': 'Point', 'coordinates': (0, 0)}
        rec['properties'] = {'a_fieldname': 3.0}
        dst.write(rec)

    with fiona.open(name) as src:
        first = next(iter(src))
        assert first['geometry'] == {'type': 'Point', 'coordinates': (0, 0)}
        assert first['properties']['a_fieldnam'] == 3.0
github Toblerity / Fiona / tests / test_crs.py View on Github external
def test_from_epsg_neg():
    try:
        crs.from_epsg(-1)
    except ValueError:
        pass
    except:
        raise
github geopandas / geopandas / tests / test_geocode.py View on Github external
def test_forward(self):
        with mock.patch('geopy.geocoders.googlev3.GoogleV3.geocode',
                        ForwardMock()) as m:
            g = geocode(self.locations, provider='googlev3', timeout=2)
            self.assertEqual(len(self.locations), m.call_count)

        n = len(self.locations)
        self.assertIsInstance(g, gpd.GeoDataFrame)
        expected = GeoSeries([Point(float(x)+0.5, float(x)) for x in range(n)],
                             crs=from_epsg(4326))
        assert_geoseries_equal(expected, g['geometry'])
        tm.assert_series_equal(g['address'],
                               pd.Series(self.locations, name='address'))
github Toblerity / Fiona / tests / test_drivers.py View on Github external
def test_options(tmpdir, path_coutwildrnp_shp):
    """Test that setting CPL_DEBUG=ON works and that a warning is raised."""
    logfile = str(tmpdir.mkdir('tests').join('test_options.log'))
    logger = logging.getLogger()
    logger.setLevel(logging.DEBUG)
    fh = logging.FileHandler(logfile)
    fh.setLevel(logging.DEBUG)
    logger.addHandler(fh)

    # fiona.drivers() will be deprecated.
    with pytest.warns(FionaDeprecationWarning):
        with fiona.drivers(CPL_DEBUG=True):
            c = fiona.open(path_coutwildrnp_shp)
            c.close()
            with open(logfile, "r") as f:
                log = f.read()
            if fiona.gdal_version.major >= 2:
                assert "GDALOpen" in log
            else:
                assert "OGROpen" in log
github Toblerity / Fiona / tests / test_crs.py View on Github external
def test_towgs84():
    """+towgs84 is preserved"""
    proj4 = ('+proj=lcc +lat_1=49 +lat_2=46 +lat_0=47.5 '
             '+lon_0=13.33333333333333 +x_0=400000 +y_0=400000 +ellps=bessel '
             '+towgs84=577.326,90.129,463.919,5.137,1.474,5.297,2.4232 '
             '+units=m +wktext +no_defs')
    assert 'towgs84' in crs.from_string(proj4)
github Toblerity / Fiona / tests / test_crs.py View on Github external
def test_wktext():
    """Test +wktext parameter is preserved."""
    proj4 = ('+proj=merc +a=6378137 +b=6378137 +lat_ts=0.0 +lon_0=0.0 '
             '+x_0=0.0 +y_0=0 +k=1.0 +units=m +nadgrids=@null +wktext '
             '+no_defs')
    assert 'wktext' in crs.from_string(proj4)
github bukun / book_python_gis / part010 / ch03_ogr / sec5_fiona / test_2_reading_x_x.py View on Github external
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_collection.py View on Github external
def test_write_numeric_layer(self):
        with pytest.raises(ValueError):
            Collection("foo", mode='w', layer=1)