How to use the fiona.Env 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 / test_datetime.py View on Github external
}
        records = [
            {
                "geometry": GEOMETRY_EXAMPLE,
                "properties": {
                    "time": TIME_EXAMPLE,
                }
            },
            {
                "geometry": GEOMETRY_EXAMPLE,
                "properties": {
                    "time": None,
                }
            },
        ]
        with fiona.Env(), fiona.open(path, "w", driver=driver, schema=schema) as collection:
            collection.writerecords(records)

        with fiona.Env(), fiona.open(path, "r") as collection:
            schema = collection.schema
            features = list(collection)

        shutil.rmtree(temp_dir)

        return schema, features
github Toblerity / Fiona / tests / test_datetime.py View on Github external
"geometry": GEOMETRY_EXAMPLE,
                "properties": {
                    "time": TIME_EXAMPLE,
                }
            },
            {
                "geometry": GEOMETRY_EXAMPLE,
                "properties": {
                    "time": None,
                }
            },
        ]
        with fiona.Env(), fiona.open(path, "w", driver=driver, schema=schema) as collection:
            collection.writerecords(records)

        with fiona.Env(), fiona.open(path, "r") as collection:
            schema = collection.schema
            features = list(collection)

        shutil.rmtree(temp_dir)

        return schema, features
github Toblerity / Fiona / tests / test_datetime.py View on Github external
}
        records = [
            {
                "geometry": GEOMETRY_EXAMPLE,
                "properties": {
                    "date": DATE_EXAMPLE,
                }
            },
            {
                "geometry": GEOMETRY_EXAMPLE,
                "properties": {
                    "date": None,
                }
            },
        ]
        with fiona.Env(), fiona.open(path, "w", driver=driver, schema=schema) as collection:
            collection.writerecords(records)

        with fiona.Env(), fiona.open(path, "r") as collection:
            schema = collection.schema
            features = list(collection)

        shutil.rmtree(temp_dir)

        return schema, features
github fitnr / svgis / svgis / svgis.py View on Github external
unprojected_bounds (tuple): (minx, maxx, miny, maxy) in the layer's coordinate system.
                                        'None' values are OK. "Unprojected" here refers to
                                        the fact that we haven't transformed these bounds yet.
                                        They may well, in fact, be in a projection.
            padding (int): Number of map units by which to pad output bounds.
            scalar (int): map scale
            class_fields (sequence): Fields to turn in the element classes (default: self.class_fields).
            id_field (string): Field to use as element ID (default: self.id_field).

        Returns:
            dict with keys: members, id, class. This is ready to be passed to svgis.svg.group.
        '''
        padding = kwargs.pop('padding', self.padding)
        kwargs['scalar'] = kwargs.get('scalar', self.scalar)
        unprojected_bounds = unprojected_bounds or self.unprojected_bounds
        with fiona.Env():
            self.log.debug('opening %s', path)
            with fiona.open(path) as layer:
                self.log.info('reading %s', layer.name)

                # Set the input CRS, if not yet set.
                self.set_in_crs(layer.crs)

                # When we have passed bounds:
                if unprojected_bounds:
                    # Set the output CRS, if not yet set, using unprojected bounds.
                    self.set_out_crs(unprojected_bounds)

                    # If we haven't set the projected bounds yet, do that.
                    if not self.projected_bounds:
                        self.update_projected_bounds(self.in_crs, self.out_crs, unprojected_bounds, padding)
github geopandas / geopandas / geopandas / io / file.py View on Github external
--------
    >>> df = geopandas.read_file("nybb.shp")

    Returns
    -------
    geodataframe : GeoDataFrame
    """
    if _is_url(filename):
        req = _urlopen(filename)
        path_or_bytes = req.read()
        reader = fiona.BytesCollection
    else:
        path_or_bytes = filename
        reader = fiona.open

    with fiona_env():
        with reader(path_or_bytes, **kwargs) as features:

            # In a future Fiona release the crs attribute of features will
            # no longer be a dict. The following code will be both forward
            # and backward compatible.
            if hasattr(features.crs, "to_dict"):
                crs = features.crs.to_dict()
            else:
                crs = features.crs

            if bbox is not None:
                if isinstance(bbox, GeoDataFrame) or isinstance(bbox, GeoSeries):
                    bbox = tuple(bbox.to_crs(crs).total_bounds)
                assert len(bbox) == 4
                f_filt = features.filter(bbox=bbox)
            else:
github nismod / smif / src / smif / data_layer / file / file_metadata_store.py View on Github external
def _read_spatial_file(filepath) -> List[Dict]:
        try:
            with fiona.Env():
                return _read_spatial_data(filepath)
        except AttributeError:
            # older fiona versions
            with fiona.drivers():
                return _read_spatial_data(filepath)
        except NameError as ex:
            msg = "Could not read spatial dimension definition '%s' " % (filepath)
            msg += "Please install fiona to read geographic data files. Try running: \n"
            msg += "    pip install smif[spatial]\n"
            msg += "or:\n"
            msg += "    conda install fiona shapely rtree\n"
            raise SmifDataReadError(msg) from ex
        except IOError as ex:
            msg = "Could not read spatial dimension definition '%s' " % (filepath)
            msg += "Please verify that the path is correct and "
            msg += "that the file is present on this location."
github Toblerity / Fiona / fiona / fio / main.py View on Github external
"""
    verbosity = verbose - quiet
    configure_logging(verbosity)
    ctx.obj = {}
    ctx.obj["verbosity"] = verbosity
    ctx.obj["aws_profile"] = aws_profile
    envopts = {"CPL_DEBUG": (verbosity > 2)}
    if aws_profile or aws_no_sign_requests:
        session = AWSSession(
            profile_name=aws_profile,
            aws_unsigned=aws_no_sign_requests,
            requester_pays=aws_requester_pays,
        )
    else:
        session = DummySession()
    ctx.obj["env"] = fiona.Env(session=session, **envopts)