How to use the fiona.collection.Collection 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_collection.py View on Github external
def test_write_numeric_layer(self):
        with pytest.raises(ValueError):
            Collection("foo", mode='w', layer=1)
github Toblerity / Fiona / tests / test_feature.py View on Github external
def setup(self):
        self.tempdir = tempfile.mkdtemp()
        schema = {'geometry': 'Point', 'properties': {'title': 'str'}}
        self.c = Collection(os.path.join(self.tempdir, "foo.shp"),
                            "w", driver="ESRI Shapefile", schema=schema)
github Toblerity / Fiona / tests / test_collection.py View on Github external
def test_write_geojson_layer(self):
        with pytest.raises(ValueError):
            Collection("foo", mode='w', driver='GeoJSON', layer='foo')
github Toblerity / Fiona / tests / test_collection.py View on Github external
def test_append_geojson(self):
        with pytest.raises(ValueError):
            Collection("foo", mode='w', driver='ARCGEN')
github Toblerity / Fiona / tests / test_collection.py View on Github external
def test_archive(self):
        with pytest.raises(TypeError):
            Collection("foo", mode='r', archive=1)
github Toblerity / Fiona / tests / test_collection.py View on Github external
def test_driver(self):
        with pytest.raises(TypeError):
            Collection("foo", mode='w', driver=1)
github Toblerity / Fiona / tests / test_collection.py View on Github external
def test_layer(self):
        with pytest.raises(TypeError):
            Collection("foo", mode='r', layer=0.5)
github Toblerity / Fiona / fiona / __init__.py View on Github external
return fp_writer(fp)

    else:
        # If a pathlib.Path instance is given, convert it to a string path.
        if isinstance(fp, Path):
            fp = str(fp)

        if vfs:
            warnings.warn("The vfs keyword argument is deprecated. Instead, pass a URL that uses a zip or tar (for example) scheme.", FionaDeprecationWarning, stacklevel=2)
            path, scheme, archive = vfs_parse_paths(fp, vfs=vfs)
            path = ParsedPath(path, archive, scheme)
        else:
            path = parse_path(fp)

        if mode in ('a', 'r'):
            c = Collection(path, mode, driver=driver, encoding=encoding,
                           layer=layer, enabled_drivers=enabled_drivers, **kwargs)
        elif mode == 'w':
            if schema:
                # Make an ordered dict of schema properties.
                this_schema = schema.copy()
                this_schema['properties'] = OrderedDict(schema['properties'])
            else:
                this_schema = None
            c = Collection(path, mode, crs=crs, driver=driver, schema=this_schema,
                           encoding=encoding, layer=layer, enabled_drivers=enabled_drivers, crs_wkt=crs_wkt,
                           **kwargs)
        else:
            raise ValueError(
                "mode string must be one of 'r', 'w', or 'a', not %s" % mode)

        return c
github Toblerity / Fiona / fiona / collection.py View on Github external
valid_types.add("Multi" + geom_type)

    return valid_types


def get_filetype(bytesbuf):
    """Detect compression type of bytesbuf.

    ZIP only. TODO: add others relevant to GDAL/OGR."""
    if bytesbuf[:4].startswith(b'PK\x03\x04'):
        return 'zip'
    else:
        return ''


class BytesCollection(Collection):
    """BytesCollection takes a buffer of bytes and maps that to
    a virtual file that can then be opened by fiona.
    """
    def __init__(self, bytesbuf, sharing=True, **kwds):
        """Takes buffer of bytes whose contents is something we'd like
        to open with Fiona and maps it to a virtual file.
        """
        if not isinstance(bytesbuf, binary_type):
            raise ValueError("input buffer must be bytes")

        # Hold a reference to the buffer, as bad things will happen if
        # it is garbage collected while in use.
        self.bytesbuf = bytesbuf

        # Map the buffer to a file. If the buffer contains a zipfile
        # we take extra steps in naming the buffer and in opening
github dheerajchand / ubuntu-django-nginx-ansible / projectenv / lib / python2.7 / site-packages / fiona / __init__.py View on Github external
# Trying first the GeoJSON driver, then the Shapefile driver,
      # the following succeeds:
      fiona.open(
          'example.shp', enabled_drivers=['GeoJSON', 'ESRI Shapefile'])

    """
    # Parse the vfs into a vsi and an archive path.
    path, vsi, archive = parse_paths(path, vfs)
    if mode in ('a', 'r'):
        if archive:
            if not os.path.exists(archive):
                raise IOError("no such archive file: %r" % archive)
        elif path != '-' and not os.path.exists(path):
            raise IOError("no such file or directory: %r" % path)
        c = Collection(path, mode, driver=driver, encoding=encoding,
                       layer=layer, vsi=vsi, archive=archive,
                       enabled_drivers=enabled_drivers)
    elif mode == 'w':
        if schema:
            # Make an ordered dict of schema properties.
            this_schema = schema.copy()
            this_schema['properties'] = OrderedDict(schema['properties'])
        else:
            this_schema = None
        c = Collection(path, mode, crs=crs, driver=driver, schema=this_schema,
                       encoding=encoding, layer=layer, vsi=vsi, archive=archive,
                       enabled_drivers=enabled_drivers, crs_wkt=crs_wkt)
    else:
        raise ValueError(
            "mode string must be one of 'r', 'w', or 'a', not %s" % mode)
    return c