Skip to content
Commits on Source (9)
......@@ -22,6 +22,7 @@ var/
*.egg-info/
.installed.cfg
*.egg
.libs
# PyInstaller
# Usually these files are written by a python script from a template
......@@ -63,6 +64,7 @@ venv2/
# fiona
VERSION.txt
fiona/_shim.c
fiona/ogrext.c
fiona/_crs.c
fiona/_drivers.c
......@@ -70,7 +72,20 @@ fiona/_err.c
fiona/_geometry.c
fiona/_transform.cpp
fiona/ograpi.pxd
fiona/ogrext.pyx
fiona/_shim1.c
fiona/_shim2.c
fiona/_shim22.c
fiona/_shim.pxd
fiona/_shim.pyx
tests/data/coutwildrnp.json
tests/data/coutwildrnp.tar
tests/data/coutwildrnp.zip
tests/data/coutwildrnp.gpkg
.DS_Store
.ipynb_checkpoints
.pytest_cache
MANIFEST
fiona/_env.c
fiona/ogrext1.c
fiona/ogrext2.c
fiona/schema.c
......@@ -4,6 +4,7 @@ cache:
directories:
- $GDALINST
- ~/.cache/pip
env:
global:
- PIP_WHEEL_DIR=$HOME/.cache/pip/wheels
......@@ -15,6 +16,13 @@ env:
- GDALVERSION="2.0.3"
- GDALVERSION="2.1.4"
- GDALVERSION="2.2.4"
- GDALVERSION="2.3.2"
- GDALVERSION="trunk"
matrix:
allow_failures:
- env: GDALVERSION="trunk"
addons:
apt:
packages:
......@@ -25,11 +33,14 @@ addons:
- libatlas-dev
- libatlas-base-dev
- gfortran
python:
- "2.7"
- "3.5"
- "3.6"
before_install:
- pip install -U pip
- pip install wheel coveralls>=1.1 --upgrade
- pip install setuptools==36.0.1
- pip install wheel
- . ./scripts/travis_gdal_install.sh
......@@ -38,15 +49,21 @@ before_install:
- export GDAL_DATA=$GDALINST/gdal-$GDALVERSION/share/gdal
- export PROJ_LIB=/usr/share/proj
- gdal-config --version
install:
- "if [ $(gdal-config --version) == \"$GDALVERSION\" ]; then echo \"Using gdal $GDALVERSION\"; else echo \"NOT using gdal $GDALVERSION as expected; aborting\"; exit 1; fi"
- "pip wheel -r requirements-dev.txt"
- "pip install -r requirements-dev.txt"
- "python setup.py sdist"
- "pip install --upgrade --force-reinstall --global-option=build_ext --global-option='-I$GDALINST/gdal-$GDALVERSION/include' --global-option='-L$GDALINST/gdal-$GDALVERSION/lib' --global-option='-R$GDALINST/gdal-$GDALVERSION/lib' dist/Fiona*"
- "fio --version"
- "cp -r tests /tmp"
- pip install -r requirements-dev.txt
- if [ "$GDALVERSION" = "trunk" ]; then echo "Using gdal trunk"; elif [ $(gdal-config --version) == "$GDALVERSION" ]; then echo "Using gdal $GDALVERSION"; else echo "NOT using gdal $GDALVERSION as expected; aborting"; exit 1; fi
- pip install --upgrade --force-reinstall --global-option=build_ext --global-option='-I$GDALINST/gdal-$GDALVERSION/include' --global-option='-L$GDALINST/gdal-$GDALVERSION/lib' --global-option='-R$GDALINST/gdal-$GDALVERSION/lib' -e .
- pip install -e .[test]
- fio --version
- gdal-config --version
- fio --gdal-version
script:
- "cd /tmp && coverage run --source=fiona --omit='*.pxd,*.pyx,*/tests/*,*/docs/*,*/examples/*,*/benchmarks/*' -m nose --exclude test_filter_vsi --exclude test_geopackage --exclude test_write_mismatch tests"
- pytest --cov fiona --cov-report term-missing
after_success:
- coveralls || echo "!! intermittent coveralls failure"
before_cache:
- if [ "$GDALVERSION" = "trunk" ]; then rm -rf $GDALINST/gdal-$GDALVERSION; fi
......@@ -3,25 +3,137 @@ Changes
All issue numbers are relative to https://github.com/Toblerity/Fiona/issues.
1.7.13 (2018-07-17)
-------------------
1.8.0 (2018-10-31)
------------------
This is the final 1.8.0 release. Thanks, everyone!
Bug fixes:
In GDAL 2.2, the behavior of GDAL with respect to null fields changed (#460).
A fix in the master (1.8-to-be) branch has been back-ported so that Fiona's
results with GDAL 2.1 and 2.2 are the same. The value reported for unset
integer or string fields will be `None` and not `0` or `""`.
- We cpdef Session.stop so that it has a C version that can be called safely
from __dealloc__, fixing a PyPy issue (#659, #553).
1.7.12 (2018-06-11)
1.8rc1 (2018-10-26)
-------------------
- Require six>=1.7
- Include sqlite 3.24.0 in macosx wheels (frs-wheel-builds 1.8.2).
There are no changes in 1.8rc1 other than more test standardization and the
introduction of a temporary test_collection_legacy.py module to support the
build of fully tested Python 2.7 macosx wheels on Travis-CI.
1.7.11.post2 (2018-04-30)
-------------------------
1.8b2 (2018-10-23)
------------------
Bug fixes:
- The ensure_env_with_credentials decorator will no longer clobber credentials
of the outer environment. This fixes a bug reported to the Rasterio project
and which also existed in Fiona.
- An unused import of the packaging module and the dependency have been
removed (#653).
- The Env class logged to the 'rasterio' hierarchy instead of 'fiona'. This
mistake has been corrected (#646).
- The Mapping abstract base class is imported from collections.abc when
possible (#647).
Refactoring:
- Standardization of the tests on pytest functions and fixtures continues and
is nearing completion (#648, #649, #650, #651, #652).
1.8b1 (2018-10-15)
------------------
Deprecations:
- Collection slicing has been deprecated and will be prohibited in a future
version.
Bug fixes:
- Rasterio CRS objects passed to transform module methods will be converted
to dicts as needed (#590).
- Implicitly convert curve geometries to their linear approximations rather
than failing (#617).
- Migrated unittest test cases in test_collection.py and test_layer.py to the
use of the standard data_dir and path_coutwildrnp_shp fixtures (#616).
- Root logger configuration has been removed from all test scripts (#615).
- An AWS session is created for the CLI context Env only if explicitly
requested, matching the behavior of Rasterio's CLI (#635).
- Dependency on attrs is made explicit.
- Other dependencies are pinned to known good versions in requirements files.
- Unused arguments have been removed from the Env constructor (#637).
Refactoring:
- A with_context_env decorator has been added and used to set up the GDAL
environment for CLI commands. The command functions themselves are now
simplified.
1.8a3 (2018-10-01)
------------------
Deprecations:
- The ``rasterio.drivers()`` context manager is officially deprecated. All
users should switch to ``rasterio.Env()``, which registers format drivers and
manages GDAL configuration in a reversible manner.
Bug fixes:
- The Collection class now filters log messages about skipped fields to
a maximum of one warning message per field (#627).
- The boto3 module is only imported when needed (#507, #629).
- Compatibility with Click 7.0 is achieved (#633).
- Use of %r instead of %s in a debug() call prevents UnicodeDecodeErrors
(#620).
1.8a2 (2018-07-24)
------------------
New features:
- 64-bit integers are the now the default for int type fields (#562, #564).
- 'http', 's3', 'zip+http', and 'zip+s3' URI schemes for datasets are now
supported (#425, #426).
- We've added a ``MemoryFile`` class which supports formatted in-memory
feature collections (#501).
- Added support for GDAL 2.x boolean field sub-type (#531).
- A new ``fio rm`` command makes it possible to cleanly remove multi-file
datasets (#538).
- The geometry type in a feature collection is more flexible. We can now
specify not only a single geometry type, but a sequence of permissible types,
or "Any" to permit any geometry type (#539).
- Support for GDAL 2.2+ null fields has been added (#554).
- The new ``gdal_open_vector()`` function of our internal API provides much
improved error handling (#557).
Bug fixes:
- The bug involving OrderedDict import on Python 2.7 has been fixed (#533).
- An ``AttributeError`` raised when the ``--bbox`` option of fio-cat is used
with more than one input file has been fixed (#543, #544).
- Obsolete and derelict fiona.tool module has been removed.
- Revert the change in 0a2bc7c that discards Z in geometry types when a
collection's schema is reported (#541).
- Require six version 1.7 or higher (#550).
- A regression related to "zip+s3" URIs has been fixed.
- Debian's GDAL data locations are now searched by default (#583).
1.8a1 (2017-11-06)
------------------
New features:
- Each call of ``writerecords()`` involves one or more transactions of up to
20,000 features each. This improves performance when writing GeoPackage files
as the previous transaction size was only 200 features (#476, #491).
Packaging:
- This post-release adds GPKG (geopackage) support to manylinux1 wheels
and upgrades the included GDAL library to 2.2.4.
- Fiona's Cython source files have been refactored so that there are no longer
separate extension modules for GDAL 1.x and GDAL 2.x. Instead there is a base
extension module based on GDAL 2.x and shim modules for installations that
use GDAL 1.x.
1.7.11.post1 (2018-01-08)
-------------------------
......
If you use Fiona for any published work, please cite it using the reference
below:
@Misc{,
author = {Sean Gillies and others},
organization = {Toblerity},
title = {Fiona is OGR's neat, nimble, no-nonsense API},
year = {2011--},
url = "https://github.com/Toblerity/Fiona"
}
......@@ -4,36 +4,54 @@ Credits
Fiona is written by:
- Sean Gillies <sean.gillies@gmail.com>
- Rene Buffat <buffat@gmail.com>
- René Buffat <buffat@gmail.com>
- Joshua Arnott <josh@snorfalorpagus.net>
- Kevin Wurster <wursterk@gmail.com>
- Micah Cochran <micah@micahcochran.net>
- Micah Cochran <micahcochran@users.noreply.github.com>
- Matthew Perry <perrygeo@gmail.com>
- Joshua Arnott <josh@snorfalorpagus.net>
- Elliott Sales de Andrade <quantum.analyst@gmail.com>
- Kelsey Jordahl <kjordahl@enthought.com>
- Patrick Young <patrick.mckendree.young@gmail.com>
- Simon Norris <snorris@hillcrestgeo.ca>
- Hannes Gräuler <graeuler@geoplex.de>
- Johan Van de Wauw <johan.vandewauw@gmail.com>
- Jacob Wasserman <jwasserman@gmail.com>
- Ryan Grout <rgrout@continuum.io>
- Michael Weisman <mweisman@gmail.com>
- fredj <frederic.junod@camptocamp.com>
- Ryan Grout <rgrout@continuum.io>
- Bas Couwenberg <sebastic@xs4all.nl>
- Brendan Ward <bcward@consbio.org>
- Hannes <kannes@users.noreply.github.com>
- Michele Citterio <michele@citterio.net>
- Miro Hrončok <miro@hroncok.cz>
- Sid Kapur <sid-kap@users.noreply.github.com>
- Tim Tröndle <tim.troendle@usys.ethz.ch>
- fredj <frederic.junod@camptocamp.com>
- qinfeng <guo.qinfeng+github@gmail.com>
- Michael Weisman <michael@urbanmapping.com>
- Ariel Nunez <ingenieroariel@gmail.com>
- Ariki <Ariki@users.noreply.github.com>
- Brandon Liu <bdon@bdon.org>
- Chris Mutel <cmutel@gmail.com>
- Denis Rykov <rykovd@gmail.com>
- Efrén <chefren@users.noreply.github.com>
- Egor Fedorov <egor.fedorov@emlid.com>
- Even Rouault <even.rouault@mines-paris.org>
- Filipe Fernandes <ocefpaf@gmail.com>
- Géraud <galak75@users.noreply.github.com>
- Hannes Gräuler <hgraeule@uos.de>
- Jesse Crocker <jesse@gaiagps.com>
- Juan Luis Cano Rodríguez <Juanlu001@users.noreply.github.com>
- Ludovic Delauné <ludotux@gmail.com>
- Martijn Visser <mgvisser@gmail.com>
- Ariel Nunez <ingenieroariel@gmail.com>
- Matthew Perry <perrygeo@users.noreply.github.com>
- Michael Weisman <michael@urbanmapping.com>
- Oliver Tonnhofer <olt@bogosoft.com>
- Stefano Costa <steko@iosa.it>
- Stephane Poss <stephposs@gmail.com>
- dimlev <dimlev@gmail.com>
- wilsaj <wilson.andrew.j+github@gmail.com>
- Jesse Crocker <jesse@gaiagps.com>
- Arne Schlüter
The GeoPandas project (Joris Van den Bossche et al.) has been a major driver
for new features in 1.8.0.
Fiona would not be possible without the great work of Frank Warmerdam and other
GDAL/OGR developers.
......
<!--
WELCOME ABOARD!
Hi and welcome to the Fiona project. We appreciate bug reports, questions
about documentation, and suggestions for new features. This issue template
isn't intended to ward you off; only to intercept and redirect one particular
category of reports, and to collect a few important facts that issue reporters
often omit.
You think you've found something? We believe you.
Please note: Fiona contains extension modules and is thus susceptible to
C library compatibility issues. If you are reporting an installation or module
import issue, please note that this project only accepts reports about problems
with packages downloaded from the Python Package Index. Conda users should take
issues to one of the following trackers:
- https://github.com/ContinuumIO/anaconda-issues/issues
- https://github.com/conda-forge/fiona-feedstock
-->
## Expected behavior and actual behavior.
For example: I expected to read 10 features from a file and an exception occurred
on the 3rd.
## Steps to reproduce the problem.
For example: a script with required data.
## Operating system
For example: Mac OS X 10.12.3.
## Fiona and GDAL version and provenance
For example: the 1.7.10.post1 manylinux1 wheel installed from PyPI using pip version 9.0.1.
For example: GDAL 2.1.0 installed via Homebrew
......@@ -8,6 +8,5 @@ recursive-include docs *.rst *.txt
recursive-include tests *.py
recursive-include tests/data *
include fiona/*.c fiona/*.cpp
exclude fiona/ogrext.c
include CHANGES.txt CREDITS.txt LICENSE.txt VERSION.txt README.rst
include benchmark.py setup.py requirements.txt
......@@ -2,11 +2,14 @@
Fiona
=====
Fiona is OGR's neat, nimble, no-nonsense API for Python programmers.
Fiona is OGR's neat and nimble API for Python programmers.
.. image:: https://travis-ci.org/Toblerity/Fiona.png?branch=master
:target: https://travis-ci.org/Toblerity/Fiona
.. image:: https://ci.appveyor.com/api/projects/status/github/Toblerity/Fiona?svg=true
:target: https://ci.appveyor.com/project/sgillies/fiona/branch/master
.. image:: https://coveralls.io/repos/Toblerity/Fiona/badge.png
:target: https://coveralls.io/r/Toblerity/Fiona
......@@ -16,6 +19,7 @@ and protocols such as files, dictionaries, mappings, and iterators instead of
classes specific to OGR. Fiona can read and write real-world data using
multi-layered GIS formats and zipped virtual file systems and integrates
readily with other Python GIS packages such as pyproj_, Rtree_, and Shapely_.
Fiona is supported only on CPython versions 2.7 and 3.4+.
For more details, see:
......@@ -40,15 +44,11 @@ file, change their geometry attributes, and write them to a new data file.
import fiona
# Register format drivers with a context manager
with fiona.drivers():
# Open a file for reading. We'll call this the "source."
with fiona.open('tests/data/coutwildrnp.shp') as source:
with fiona.open('tests/data/coutwildrnp.shp') as src:
# The file we'll write to, the "sink", must be initialized
# The file we'll write to, the "destination", must be initialized
# with a coordinate system, a format driver name, and
# a record schema. We can get initial values from the open
# collection's ``meta`` property and then modify them as
......@@ -61,7 +61,7 @@ file, change their geometry attributes, and write them to a new data file.
# coordinate reference system as the source. The ``meta``
# mapping fills in the keyword parameters of fiona.open().
with fiona.open('test_write.shp', 'w', **meta) as sink:
with fiona.open('test_write.shp', 'w', **meta) as dst:
# Process only the records intersecting a box.
for f in source.filter(bbox=(-107.0, 37.0, -105.0, 39.0)):
......@@ -75,20 +75,11 @@ file, change their geometry attributes, and write them to a new data file.
# Write the record out.
sink.write(f)
dst.write(f)
# The sink's contents are flushed to disk and the file is
# The destination's contents are flushed to disk and the file is
# closed when its ``with`` block ends. This effectively
# executes ``sink.flush(); sink.close()``.
# At the end of the ``with fiona.drivers()`` block, context
# manager exits and all drivers are de-registered.
The fiona.drivers() function and context manager are new in 1.1. The
example above shows the way to use it to register and de-register
drivers in a deterministic and efficient way. Code written for Fiona 1.0
will continue to work: opened collections may manage the global driver
registry if no other manager is present.
# executes ``dst.flush(); dst.close()``.
Reading Multilayer data
-----------------------
......@@ -100,8 +91,6 @@ provides an index ordered list of layer names.
.. code-block:: python
with fiona.drivers():
for layername in fiona.listlayers('tests/data'):
with fiona.open('tests/data', layer=layername) as src:
print(layername, len(src))
......@@ -114,8 +103,6 @@ Layer can also be specified by index. In this case, ``layer=0`` and
.. code-block:: python
with fiona.drivers():
for i, layername in enumerate(fiona.listlayers('tests/data')):
with fiona.open('tests/data', layer=i) as src:
print(i, layername, len(src))
......@@ -131,8 +118,6 @@ writing.
.. code-block:: python
with fiona.drivers():
with open('tests/data/cowildrnp.shp') as src:
meta = src.meta
f = next(src)
......@@ -170,21 +155,25 @@ and write zipped Shapefiles.
.. code-block:: python
with fiona.drivers():
for i, layername in enumerate(
fiona.listlayers(
'/',
vfs='zip://tests/data/coutwildrnp.zip')):
with fiona.open(
'/',
vfs='zip://tests/data/coutwildrnp.zip',
layer=i) as src:
fiona.listlayers('zip://tests/data/coutwildrnp.zip'):
with fiona.open('zip://tests/data/coutwildrnp.zip', layer=i) as src:
print(i, layername, len(src))
# Output:
# (0, u'coutwildrnp', 67)
Fiona can also read from more exotic file systems. For instance, a
zipped shape file in S3 can be accessed like so:
.. code-block:: python
with fiona.open('zip+s3://mapbox/rasterio/coutwildrnp.zip') as src:
print(len(src))
# Output:
# 67
Fiona CLI
=========
......@@ -242,7 +231,7 @@ gdal``).
Python Requirements
-------------------
Fiona depends on the modules ``six``, ``cligj``, ``munch``, ``argparse``, and
Fiona depends on the modules ``enum34``, ``six``, ``cligj``, ``munch``, ``argparse``, and
``ordereddict`` (the two latter modules are standard in Python 2.7+). Pip will
fetch these requirements for you, but users installing Fiona from a Windows
installer must get them separately.
......@@ -265,14 +254,15 @@ install gdal`` using Homebrew on OS X), installation is this simple.
If gdal-config is not available or if GDAL/OGR headers and libs aren't
installed to a well known location, you must set include dirs, library dirs,
and libraries options via the setup.cfg file or setup command line as shown
below (using ``git``). You must also specify the major version of the GDAL API
(1 or 2) on the setup command line.
below (using ``git``). You must also specify the version of the GDAL API on the
command line using the ``--gdalversion`` argument (see example below) or with
the ``GDAL_VERSION`` environment variable (e.g. ``export GDAL_VERSION=2.1``).
.. code-block:: console
(fiona_env)$ git clone git://github.com/Toblerity/Fiona.git
(fiona_env)$ cd Fiona
(fiona_env)$ python setup.py build_ext -I/path/to/gdal/include -L/path/to/gdal/lib -lgdal install --gdalversion 1
(fiona_env)$ python setup.py build_ext -I/path/to/gdal/include -L/path/to/gdal/lib -lgdal install --gdalversion 2.1
Or specify that build options and GDAL API version should be provided by a
particular gdal-config program.
......@@ -296,20 +286,28 @@ cannot rely on gdal-config, which is only present on UNIX systems, to discover
the locations of header files and libraries that Fiona needs to compile its
C extensions. On Windows, these paths need to be provided by the user.
You will need to find the include files and the library files for gdal and
use setup.py as follows. You must also specify the major version of the GDAL
API (1 or 2) on the setup command line.
use setup.py as follows. You must also specify the version of the GDAL API on the
command line using the ``--gdalversion`` argument (see example below) or with
the ``GDAL_VERSION`` environment variable (e.g. ``set GDAL_VERSION=2.1``).
.. code-block:: console
$ python setup.py build_ext -I<path to gdal include files> -lgdal_i -L<path to gdal library> install --gdalversion 1
$ python setup.py build_ext -I<path to gdal include files> -lgdal_i -L<path to gdal library> install --gdalversion 2.1
Note: The GDAL DLL (``gdal111.dll`` or similar) and gdal-data directory need to
be in your Windows PATH otherwise Fiona will fail to work.
Note: The GDAL dll (gdal111.dll) and gdal-data directory need to be in your
Windows PATH otherwise Fiona will fail to work.
The [Appveyor CI build](https://ci.appveyor.com/project/sgillies/fiona/history)
uses the GISInternals GDAL binaries to build Fiona. This produces a binary wheel
for successful builds, which includes GDAL and other dependencies, for users
wanting to try an unstable development version.
The [Appveyor configuration file](appveyor.yml) may be a useful example for
users building from source on Windows.
Development and testing
=======================
Building from the source requires Cython. Tests require Nose. If the GDAL/OGR
Building from the source requires Cython. Tests require `pytest <http://pytest.org>`_. If the GDAL/OGR
libraries, headers, and `gdal-config`_ program are installed to well known
locations on your system (via your system's package manager), you can do this::
......@@ -317,7 +315,7 @@ locations on your system (via your system's package manager), you can do this::
(fiona_env)$ cd Fiona
(fiona_env)$ pip install cython
(fiona_env)$ pip install -e .[test]
(fiona_env)$ nosetests
(fiona_env)$ py.test
Or you can use the ``pep-518-install`` script::
......@@ -329,7 +327,7 @@ If you have a non-standard environment, you'll need to specify the include and
lib dirs and GDAL library on the command line::
(fiona_env)$ python setup.py build_ext -I/path/to/gdal/include -L/path/to/gdal/lib -lgdal --gdalversion 2 develop
(fiona_env)$ nosetests
(fiona_env)$ py.test
.. _OGR: http://www.gdal.org/ogr
.. _pyproj: http://pypi.python.org/pypi/pyproj/
......
......@@ -14,13 +14,40 @@ environment:
GDAL_HOME: "C:\\gdal"
matrix:
# - PYTHON: "C:\\Python27.10-x64"
# PYTHON_VERSION: "2.7.10"
# PYTHON_ARCH: "64"
- PYTHON: "C:\\Python27-x64"
PYTHON_VERSION: "2.7.14"
PYTHON_ARCH: "64"
GDAL_VERSION: "1.11.4"
GIS_INTERNALS: "release-1800-x64-gdal-1-11-4-mapserver-6-4-3.zip"
GIS_INTERNALS_LIBS: "release-1800-x64-gdal-1-11-4-mapserver-6-4-3-libs.zip"
- PYTHON: "C:\\Python36-x64"
PYTHON_VERSION: "3.6.4"
PYTHON_ARCH: "64"
GDAL_VERSION: "1.11.4"
GIS_INTERNALS: "release-1800-x64-gdal-1-11-4-mapserver-6-4-3.zip"
GIS_INTERNALS_LIBS: "release-1800-x64-gdal-1-11-4-mapserver-6-4-3-libs.zip"
- PYTHON: "C:\\Python36-x64"
PYTHON_VERSION: "3.6.4"
PYTHON_ARCH: "64"
GDAL_VERSION: "2.2.3"
GIS_INTERNALS: "release-1911-x64-gdal-2-2-3-mapserver-7-0-7.zip"
GIS_INTERNALS_LIBS: "release-1911-x64-gdal-2-2-3-mapserver-7-0-7-libs.zip"
- PYTHON: "C:\\Python36-x64"
PYTHON_VERSION: "3.6.4"
PYTHON_ARCH: "64"
GDAL_VERSION: "2.3.0"
GIS_INTERNALS: "release-1911-x64-gdal-2-3-0-mapserver-7-0-7.zip"
GIS_INTERNALS_LIBS: "release-1911-x64-gdal-2-3-0-mapserver-7-0-7-libs.zip"
- PYTHON: "C:\\Python34-x64"
PYTHON_VERSION: "3.4.3"
- PYTHON: "C:\\Python36-x64"
PYTHON_VERSION: "3.6.4"
PYTHON_ARCH: "64"
GDAL_VERSION: "2.4.0"
GIS_INTERNALS: "release-1911-x64-gdal-mapserver.zip"
GIS_INTERNALS_LIBS: "release-1911-x64-gdal-mapserver-libs.zip"
install:
......@@ -58,12 +85,13 @@ install:
- ps: mkdir C:\build | out-null
- ps: mkdir C:\gdal | out-null
- curl http://download.gisinternals.com/sdk/downloads/release-1600-x64-gdal-1-11-4-mapserver-6-4-3.zip --output gdalbin.zip
- curl http://download.gisinternals.com/sdk/downloads/%GIS_INTERNALS% --output gdalbin.zip
- 7z x gdalbin.zip -oC:\gdal
- curl http://download.gisinternals.com/sdk/downloads/release-1600-x64-gdal-1-11-4-mapserver-6-4-3-libs.zip --output gdallibs.zip
- curl http://download.gisinternals.com/sdk/downloads/%GIS_INTERNALS_LIBS% --output gdallibs.zip
- 7z x gdallibs.zip -oC:\gdal
- "SET PATH=C:\\gdal;C:\\gdal\\bin;C:\\gdal\\data;C:\\gdal\\bin\\gdal\\apps;%PATH%"
- "SET GDAL_DATA=C:\\gdal\\bin\\gdal-data"
- "SET PACKAGE_DATA=1"
- ECHO "Filesystem C:/GDAL:"
- ps: "ls \"C:/GDAL\""
......@@ -89,11 +117,34 @@ build_script:
- cmd: echo %PYTHONPATH%
- "%CMD_IN_ENV% python setup.py build_ext -IC:\\gdal\\include -lgdal_i -LC:\\gdal\\lib install --gdalversion 1.11.4"
# copy gisinternal gdal librarys into .libs
- cmd: xcopy C:\gdal\bin\*.dll fiona\.libs\
- cmd: xcopy C:\gdal\*.rtf fiona\.libs\licenses\
# build fiona and create a wheel
- "%CMD_IN_ENV% python setup.py build_ext -IC:\\gdal\\include -lgdal_i -LC:\\gdal\\lib bdist_wheel --gdalversion %GDAL_VERSION%"
# install the wheel
- ps: python -m pip install --upgrade pip
- ps: pip install --force-reinstall --ignore-installed (gci dist\*.whl | % { "$_" })
- ps: move fiona fiona.build
test_script:
# Run the project tests
- cmd: SET
- "%CMD_IN_ENV% nosetests --exclude test_filter_vsi --exclude test_geopackage"
- ps: python -c "import fiona"
# TODO: return to running test_write_gb18030 when GDAL build is updated.
# GenericWriting test is skipped on Appveyor because our Windows GDAL doesn't
# have iconv support and can't encode field names.
- "%CMD_IN_ENV% python -m pytest -k \"not test_write_gb18030 and not GenericWritingTest\" --cov fiona --cov-report term-missing"
matrix:
allow_failures:
- GDAL_VERSION: 2.4.0
artifacts:
- path: dist\*.whl
name: wheel
fiona (1.7.13-2) UNRELEASED; urgency=medium
fiona (1.8.0-1) unstable; urgency=medium
* Team upload.
* New upstream release.
* Bump Standards-Version to 4.2.1, no changes.
* Use pytest instead of nose.
* Refresh patches.
* Add python{,3}-{attr,boto3} to build dependencies.
* Don't remove fiona/ogrext.pyx in clean target.
* Update skipped tests for switch from nose to pytest.
-- Bas Couwenberg <sebastic@debian.org> Tue, 28 Aug 2018 09:50:35 +0200
-- Bas Couwenberg <sebastic@debian.org> Wed, 31 Oct 2018 20:19:57 +0100
fiona (1.7.13-1) unstable; urgency=medium
......
......@@ -13,6 +13,10 @@ Build-Depends: debhelper (>= 9),
python3-all,
python-all-dev,
python3-all-dev,
python-attr,
python3-attr,
python-boto3,
python3-boto3,
python-click-plugins,
python3-click-plugins,
python-cligj,
......@@ -20,8 +24,6 @@ Build-Depends: debhelper (>= 9),
python-enum34,
python-munch,
python3-munch,
python-nose,
python3-nose,
python-pytest,
python3-pytest,
python-setuptools,
......
......@@ -9,7 +9,7 @@ There is already another package providing a binary "fio" (fio).
--- a/setup.py
+++ b/setup.py
@@ -265,7 +265,7 @@ setup_args = dict(
@@ -296,7 +296,7 @@ setup_args = dict(
packages=['fiona', 'fiona.fio'],
entry_points='''
[console_scripts]
......
......@@ -8,13 +8,16 @@ Subject: Remove outside reference possible-privacy-breach
--- a/README.rst
+++ b/README.rst
@@ -4,12 +4,6 @@ Fiona
@@ -4,15 +4,6 @@ Fiona
Fiona is OGR's neat, nimble, no-nonsense API for Python programmers.
Fiona is OGR's neat and nimble API for Python programmers.
-.. image:: https://travis-ci.org/Toblerity/Fiona.png?branch=master
- :target: https://travis-ci.org/Toblerity/Fiona
-
-.. image:: https://ci.appveyor.com/api/projects/status/github/Toblerity/Fiona?svg=true
- :target: https://ci.appveyor.com/project/sgillies/fiona/branch/master
-
-.. image:: https://coveralls.io/repos/Toblerity/Fiona/badge.png
- :target: https://coveralls.io/r/Toblerity/Fiona
-
......
......@@ -6,7 +6,7 @@ Author: Bas Couwenberg <sebastic@debian.org>
--- a/setup.py
+++ b/setup.py
@@ -247,11 +247,8 @@ if sys.version_info < (3, 4):
@@ -278,11 +278,8 @@ extras_require['all'] = list(set(it.chai
setup_args = dict(
cmdclass={'sdist': sdist_multi_gdal},
......
......@@ -12,32 +12,37 @@ DEB_BUILD_ARCH ?= $(shell dpkg-architecture -qDEB_BUILD_ARCH)
export PYBUILD_NAME=fiona
export PYBUILD_AFTER_BUILD_python2 = PYTHONPATH={build_dir} http_proxy='127.0.0.1:9' /usr/share/sphinx/scripts/python2/sphinx-build -N -bhtml -D today="$(BUILD_DATE)" docs/ build/html
export PYBUILD_TEST_NOSE=1
export PYBUILD_TEST_PYTEST=1
export PYBUILD_BEFORE_TEST=cp -r {dir}/tests {build_dir}
export PYBUILD_AFTER_TEST=rm -rf {build_dir}/tests
#fio_load and cli are excluded as these only work after installation
export PYBUILD_TEST_ARGS=--exclude cli \
--exclude fio_load \
--exclude fiona \
--exclude test_bytescollection \
--exclude test_collection \
--exclude test_feature \
--exclude test_filter_vsi \
--exclude test_fio_info \
--exclude test_fio_ls \
--exclude test_geopackage \
--exclude test_layer \
--exclude test_listing \
--exclude test_profile \
--exclude test_unicode \
--exclude test_vfs
export PYBUILD_TEST_ARGS=--ignore tests/test_bytescollection.py \
--ignore tests/test_collection.py \
--ignore tests/test_feature.py \
--ignore tests/test_filter_vsi.py \
--ignore tests/test_fio_bounds.py \
--ignore tests/test_fio_calc.py \
--ignore tests/test_fio_cat.py \
--ignore tests/test_fio_collect.py \
--ignore tests/test_fio_distrib.py \
--ignore tests/test_fio_dump.py \
--ignore tests/test_fio_filter.py \
--ignore tests/test_fio_info.py \
--ignore tests/test_fio_load.py \
--ignore tests/test_fio_ls.py \
--ignore tests/test_fio_rm.py \
--ignore tests/test_geopackage.py \
--ignore tests/test_layer.py \
--ignore tests/test_listing.py \
--ignore tests/test_profile.py \
--ignore tests/test_unicode.py \
--ignore tests/test_vfs.py
%:
dh $@ --with python2,python3,sphinxdoc --buildsystem pybuild
override_dh_clean:
dh_clean
rm -rf fiona/*.so gdal-config.txt fiona/*.c VERSION.txt fiona/*.cpp Fiona.egg-info/ fiona/ogrext.pyx
rm -rf fiona/*.so gdal-config.txt fiona/*.c VERSION.txt fiona/*.cpp Fiona.egg-info/
override_dh_auto_test:
# Ignore test failures on problematic architectures only
......
......@@ -13,20 +13,24 @@ Fiona's new command line interface is a program named "fio".
-v, --verbose Increase verbosity.
-q, --quiet Decrease verbosity.
--version Show the version and exit.
--gdal-version Show the version and exit.
--python-version Show the version and exit.
--help Show this message and exit.
Commands:
bounds Print the extent of GeoJSON objects
buffer Buffer geometries on all sides by a fixed distance.
calc Calculate GeoJSON property by Python expression
cat Concatenate and print the features of datasets
collect Collect a sequence of features.
distrib Distribute features from a collection
distrib Distribute features from a collection.
dump Dump a dataset to GeoJSON.
env Print information about the fio environment.
filter Filter GeoJSON features by python expression
filter Filter GeoJSON features by python expression.
info Print information about a dataset.
insp Open a dataset and start an interpreter.
load Load GeoJSON to a dataset in another format.
ls List layers in a datasource.
rm Remove a datasource or an individual layer.
It is developed using the ``click`` package and is new in 1.1.6.
......@@ -55,6 +59,28 @@ Using ``--with-id`` gives you
> | fio bounds --with-id
{"id": "0", "bbox": [0.735, 51.357216, 0.947778, 51.444717]}
calc
----
New in 1.7b1
The calc command creates a new property on GeoJSON features using the
specified expression.
The expression is evaluated in a restricted namespace containing 4 functions
(`sum`, `pow`, `min`, `max`), the `math` module, the shapely `shape` function,
type conversions (`bool`, `int`, `str`, `len`, `float`), and an object `f`
representing the feature to be evaluated. This `f` object allows access in
javascript-style dot notation for convenience.
The expression will be evaluated for each feature and its return value will be
added to the properties as the specified property_name. Existing properties
will not be overwritten by default (an `Exception` is raised).
.. code-block:: console
$ fio cat data.shp | fio calc sumAB "f.properties.A + f.properties.B"
cat
---
......@@ -112,7 +138,7 @@ dump
----
The dump command reads a vector dataset and writes a GeoJSON feature collection
to stdout. Its output can be piped to ``rio load`` (see below).
to stdout. Its output can be piped to ``fio load`` (see below).
.. code-block:: console
......@@ -251,15 +277,28 @@ access in javascript-style dot notation for convenience.
If the expression evaluates to a "truthy" value, the feature is printed verbatim.
Otherwise, the feature is excluded from the output.
For example
.. code-block:: console
fio cat data.shp \
| fio filter "f.properties.area > 1000.0" \
| fio collect > large_polygons.geojson
$ fio cat data.shp \
> | fio filter "f.properties.area > 1000.0" \
> | fio collect > large_polygons.geojson
Would create a geojson file with only those features from `data.shp` where the
area was over a given threshold.
rm
--
The ``fio rm`` command deletes an entire datasource or a single layer in a
multi-layer datasource. If the datasource is composed of multiple files
(e.g. an ESRI Shapefile) all of the files will be removed.
.. code-block:: console
$ fio rm countries.shp
$ fio rm --layer forests land_cover.gpkg
New in 1.8.0.
Coordinate Reference System Transformations
-------------------------------------------
......
......@@ -124,6 +124,14 @@ fiona.fio.options module
:undoc-members:
:show-inheritance:
fiona.fio.rm module
-------------------
.. automodule:: fiona.fio.rm
:members:
:undoc-members:
:show-inheritance:
Module contents
---------------
......
......@@ -119,7 +119,7 @@ the Fiona repository for use in this and other examples.
with fiona.open('docs/data/test_uk.shp', 'r') as source:
# Copy the source schema and add two new properties.
sink_schema = source.schema.copy()
sink_schema = source.schema
sink_schema['properties']['s_area'] = 'float'
sink_schema['properties']['timestamp'] = 'datetime'
......@@ -301,6 +301,8 @@ Features of a collection may also be accessed by index.
'properties': OrderedDict([(u'CAT', 232.0), (u'FIPS_CNTRY', u'UK'), (u'CNTRY_NAME', u'United Kingdom'), (u'AREA', 244820.0), (u'POP_CNTRY', 60270708.0)]),
'type': 'Feature'}
Note that these indices are controlled by GDAL, and do not always follow Python conventions. They can start from 0, 1 (e.g. geopackages), or even other values, and have no guarantee of contiguity. Negative indices will only function correctly if indices start from 0 and are contiguous.
Closing Files
-------------
......@@ -711,9 +713,10 @@ Features Access) installed, you can see this in by verifying the following.
Some files may contain vectors that are :dfn:`invalid` from a simple
features standpoint due to accident (inadequate quality control on the
producer's end) or intention ("dirty" vectors saved to a file for special
treatment). Fiona doesn't sniff for or attempt to clean dirty data, so make
sure you're getting yours from a clean source.
producer's end), intention ("dirty" vectors saved to a file for special
treatment) or discrepancies of the numeric precision models (Fiona can't
handle fixed precision models yet). Fiona doesn't sniff for or attempt to
clean dirty data, so make sure you're getting yours from a clean source.
Writing Vector Data
===================
......@@ -813,16 +816,16 @@ iterator) of records.
You may also call :py:meth:`flush` periodically to write the buffer contents
to disk.
Writing New Files
-----------------
Creating files of the same structure
------------------------------------
Writing a new file is more complex than appending to an existing file because
the file CRS, format, and schema have not yet been defined and must be done so
by the programmer. Still, it's not very complicated. A schema is just
a mapping, as described above. A CRS is also just a mapping, and the possible
formats are enumerated in the :py:attr:`fiona.drivers` list.
formats are enumerated in the :py:attr:`fiona.supported_drivers` list.
Copy the parameters of our demo file.
Review the parameters of our demo file.
.. sourcecode:: pycon
......@@ -843,7 +846,7 @@ Copy the parameters of our demo file.
'AREA': 'float:15.2',
'POP_CNTRY': 'float:15.2'}}
And now create a new file using them.
We can create a new file using them.
.. sourcecode:: pycon
......@@ -898,6 +901,86 @@ a file's meta properties even easier.
>>> source = fiona.open('docs/data/test_uk.shp')
>>> sink = fiona.open('/tmp/foo.shp', 'w', **source.meta)
Writing new files from scratch
-------------------------------
To write a new file from scratch we have to define our own specific driver, crs and schema.
To ensure the order of the attribute fields is predictable, in both the schema and the actual manifestation as feature attributes, we will use ordered dictionaries.
.. sourcecode:: pycon
>>> from collections import OrderedDict
Consider the following record, structured in accordance to the `Python geo protocol <https://gist.github.com/sgillies/2217756>`__, representing the Eiffel Tower using a point geometry with UTM coordinates in zone 31N.
.. sourcecode:: pycon
>>> eiffel_tower = {
... 'geometry': {
... 'type': 'Point',
... 'coordinates': (448252, 5411935)
... },
... 'properties': OrderedDict([
... ('name', 'Eiffel Tower'),
... ('height', 300.01),
... ('view', 'scenic'),
... ('year', 1889)
... ])
... }
A corresponding scheme could be:
.. sourcecode:: pycon
>>> landmarks_schema = {
... 'geometry': 'Point',
... 'properties': OrderedDict([
... ('name', 'str'),
... ('height', 'float'),
... ('view', 'str'),
... ('year', 'int')
... ])
... }
The coordinate reference system of these landmark coordinates is ETRS89 / UTM zone 31N which is referenced in the EPSG database as EPSG:25831.
.. sourcecode:: pycon
>>> from fiona.crs import from_epsg
>>> landmarks_crs = from_epsg(25831)
An appropriate driver could be:
.. sourcecode:: pycon
>>> output_driver = "GeoJSON"
Having specified schema, crs and driver, we are ready to open a file for writing our record:
.. sourcecode:: pycon
>>> with fiona.open(
... '/tmp/foo.geojson',
... 'w',
... driver=output_driver,
... crs=landmarks_crs,
... schema=landmarks_schema) as c:
... c.write(eiffel_tower)
...
>>> import pprint
>>> with fiona.open('/tmp/foo.geojson') as source:
... for record in source:
... pprint.pprint(record)
{'geometry': {'coordinates': (448252.0, 5411935.0), 'type': 'Point'},
'id': '0',
'properties': OrderedDict([('name', 'Eiffel Tower'),
('height', 300.01),
('view', 'scenic'),
('year', 1889)]),
'type': 'Feature'}
Ordering Record Fields
......................
......@@ -954,6 +1037,81 @@ Point' schema geometry, for example) a default z value of 0 will be provided.
Advanced Topics
===============
OGR configuration options
-------------------------
GDAL/OGR has a large number of features that are controlled by global or
thread-local configuration options. Fiona allows you to configure these options
using a context manager, ``fiona.Env``. This class's constructor takes GDAL/OGR
configuration options as keyword arguments. To see debugging information from
GDAL/OGR, for example, you may do the following.
.. sourcecode:: python
import logging
import fiona
logging.basicConfig(level=logging.DEBUG)
with fiona.Env(CPL_DEBUG=True):
fiona.open('tests/data/coutwildrnp.shp')
The following extra messages will appear in the Python logger's output.::
DEBUG:fiona._env:CPLE_None in GNM: GNMRegisterAllInternal
DEBUG:fiona._env:CPLE_None in GNM: RegisterGNMFile
DEBUG:fiona._env:CPLE_None in GNM: RegisterGNMdatabase
DEBUG:fiona._env:CPLE_None in GNM: GNMRegisterAllInternal
DEBUG:fiona._env:CPLE_None in GNM: RegisterGNMFile
DEBUG:fiona._env:CPLE_None in GNM: RegisterGNMdatabase
DEBUG:fiona._env:CPLE_None in GDAL: GDALOpen(tests/data/coutwildrnp.shp, this=0x1683930) succeeds as ESRI Shapefile.
If you call ``fiona.open()`` with no surrounding ``Env`` environment, one will
be created for you.
When your program exits the environent's with block the configuration reverts
to its previous state.
Cloud storage credentials
-------------------------
One of the most important uses of ``fiona.Env`` is to set credentials for
accessing data stored in AWS S3 or another cloud storage system.
.. sourcecode:: python
from fiona.session import AWSSession
import fiona
with fiona.Env(
session=AWSession(
aws_access_key_id="key",
aws_secret_access_key="secret",
)
):
fiona.open("zip+s3://example-bucket/example.zip")
The AWSSession class is currently the only credential session manager in Fiona.
The source code has an example of how classes for other cloud storage providers
may be implemented. AWSSession relies upon boto3 and botocore, which will be
installed as extra dependencies of Fiona if you run ``pip install fiona[s3]``.
If you call ``fiona.open()`` with no surrounding ``Env`` and pass a path to an
S3 object, a session will be created for you using code equivalent to the
following code.
.. sourcecode:: python
import boto3
from fiona.session import AWSSession
import fiona
with fiona.Env(session=AWSSession(boto3.Session())):
fiona.open('zip+s3://fiona-testing/coutwildrnp.zip')
Slicing and masking iterators
-----------------------------
......
name: _fiona
channels:
- defaults
- conda-forge
dependencies:
- python>=3.5
- cython
- libgdal
......@@ -62,17 +62,37 @@ Because Fiona collections are context managers, they are closed and (in
writing modes) flush contents to disk when their ``with`` blocks end.
"""
from contextlib import contextmanager
import logging
import os
import sys
import warnings
from six import string_types
from fiona.collection import Collection, BytesCollection, vsi_path
from fiona._drivers import driver_count, GDALEnv
try:
from pathlib import Path
except ImportError: # pragma: no cover
class Path:
pass
if sys.platform == "win32":
libdir = os.path.join(os.path.dirname(__file__), ".libs")
os.environ["PATH"] = os.environ["PATH"] + ";" + libdir
from fiona.collection import BytesCollection, Collection
from fiona.drvsupport import supported_drivers
from fiona.env import ensure_env_with_credentials, Env
from fiona.errors import FionaDeprecationWarning
from fiona._env import driver_count
from fiona.compat import OrderedDict
from fiona.ogrext import _bounds, _listlayers, FIELD_TYPES_MAP, _remove
from fiona.io import MemoryFile
from fiona.ogrext import _bounds, _listlayers, FIELD_TYPES_MAP, _remove, _remove_layer
from fiona.ogrext import (
calc_gdal_version_num, get_gdal_version_num, get_gdal_release_name)
calc_gdal_version_num, get_gdal_version_num, get_gdal_release_name,
get_gdal_version_tuple)
from fiona.path import ParsedPath, parse_path, vsi_path
from fiona.vfs import parse_paths as vfs_parse_paths
# These modules are imported by fiona.ogrext, but are also import here to
# help tools like cx_Freeze find them automatically
......@@ -81,25 +101,19 @@ import uuid
__all__ = ['bounds', 'listlayers', 'open', 'prop_type', 'prop_width']
__version__ = "1.7.13"
__gdal_version__ = get_gdal_release_name().decode('utf-8')
__version__ = "1.8.0"
__gdal_version__ = get_gdal_release_name()
gdal_version = get_gdal_version_tuple()
log = logging.getLogger(__name__)
def open(
path,
mode='r',
driver=None,
schema=None,
crs=None,
encoding=None,
layer=None,
vfs=None,
enabled_drivers=None,
crs_wkt=None):
"""Open file at ``path`` in ``mode`` "r" (read), "a" (append), or
"w" (write) and return a ``Collection`` object.
@ensure_env_with_credentials
def open(fp, mode='r', driver=None, schema=None, crs=None, encoding=None,
layer=None, vfs=None, enabled_drivers=None, crs_wkt=None,
**kwargs):
"""Open a collection for read, append, or write
In write mode, a driver name such as "ESRI Shapefile" or "GPX" (see
OGR docs or ``ogr2ogr --help`` on the command line) and a schema
......@@ -133,11 +147,6 @@ def open(
When the provided path is to a file containing multiple named layers
of data, a layer can be singled out by ``layer``.
A virtual filesystem can be specified. The ``vfs`` parameter may be
an Apache Commons VFS style string beginning with "zip://" or
"tar://"". In this case, the ``path`` must be an absolute path
within that container.
The drivers enabled for opening datasets may be restricted to those
listed in the ``enabled_drivers`` parameter. This and the ``driver``
parameter afford much control over opening of files.
......@@ -151,18 +160,96 @@ def open(
fiona.open(
'example.shp', enabled_drivers=['GeoJSON', 'ESRI Shapefile'])
Parameters
----------
fp : URI (str or pathlib.Path), or file-like object
A dataset resource identifier or file object.
mode : str
One of 'r', to read (the default); 'a', to append; or 'w', to
write.
driver : str
In 'w' mode a format driver name is required. In 'r' or 'a'
mode this parameter has no effect.
schema : dict
Required in 'w' mode, has no effect in 'r' or 'a' mode.
crs : str or dict
Required in 'w' mode, has no effect in 'r' or 'a' mode.
encoding : str
Name of the encoding used to encode or decode the dataset.
layer : int or str
The integer index or name of a layer in a multi-layer dataset.
vfs : str
This is a deprecated parameter. A URI scheme such as "zip://"
should be used instead.
enabled_drivers : list
An optional list of driver names to used when opening a
collection.
crs_wkt : str
An optional WKT representation of a coordinate reference
system.
kwargs : mapping
Other driver-specific parameters that will be interpreted by
the OGR library as layer creation or opening options.
Returns
-------
Collection
"""
if mode == 'r' and hasattr(fp, 'read'):
@contextmanager
def fp_reader(fp):
memfile = MemoryFile(fp.read())
dataset = memfile.open()
try:
yield dataset
finally:
dataset.close()
memfile.close()
return fp_reader(fp)
elif mode == 'w' and hasattr(fp, 'write'):
if schema:
# Make an ordered dict of schema properties.
this_schema = schema.copy()
this_schema['properties'] = OrderedDict(schema['properties'])
else:
this_schema = None
@contextmanager
def fp_writer(fp):
memfile = MemoryFile()
dataset = memfile.open(
driver=driver, crs=crs, schema=schema, layer=layer,
encoding=encoding, enabled_drivers=enabled_drivers,
**kwargs)
try:
yield dataset
finally:
dataset.close()
memfile.seek(0)
fp.write(memfile.read())
memfile.close()
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:
# Parse the vfs into a vsi and an archive path.
path, vsi, archive = parse_paths(path, vfs)
path, scheme, archive = vfs_parse_paths(fp, vfs=vfs)
path = ParsedPath(path, archive, scheme)
else:
path = parse_path(fp)
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)
layer=layer, enabled_drivers=enabled_drivers, **kwargs)
elif mode == 'w':
if schema:
# Make an ordered dict of schema properties.
......@@ -171,17 +258,18 @@ def open(
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)
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
collection = open
def remove(path_or_collection, driver=None):
def remove(path_or_collection, driver=None, layer=None):
"""Deletes an OGR data source
The required ``path`` argument may be an absolute or relative file path.
......@@ -203,11 +291,13 @@ def remove(path_or_collection, driver=None):
collection.close()
else:
path = path_or_collection
if driver is None:
raise ValueError("The driver argument is required when removing a path")
if layer is None:
_remove(path, driver)
else:
_remove_layer(path, layer, driver)
@ensure_env_with_credentials
def listlayers(path, vfs=None):
"""Returns a list of layer names in their index order.
......@@ -224,29 +314,14 @@ def listlayers(path, vfs=None):
if vfs and not isinstance(vfs, string_types):
raise TypeError("invalid vfs: %r" % vfs)
path, vsi, archive = parse_paths(path, vfs)
if archive:
if not os.path.exists(archive):
raise IOError("no such archive file: %r" % archive)
elif not os.path.exists(path):
raise IOError("no such file or directory: %r" % path)
with drivers():
return _listlayers(vsi_path(path, vsi, archive))
def parse_paths(path, vfs=None):
archive = vsi = None
if vfs:
parts = vfs.split("://")
vsi = parts.pop(0) if parts else None
archive = parts.pop(0) if parts else None
pobj_vfs = parse_path(vfs)
pobj_path = parse_path(path)
pobj = ParsedPath(pobj_path.path, pobj_vfs.path, pobj_vfs.scheme)
else:
parts = path.split("://")
path = parts.pop() if parts else None
vsi = parts.pop() if parts else None
return path, vsi, archive
pobj = parse_path(path)
return _listlayers(vsi_path(pobj))
def prop_width(val):
......@@ -279,13 +354,18 @@ def prop_type(text):
def drivers(*args, **kwargs):
"""Returns a context manager with registered drivers."""
"""Returns a context manager with registered drivers.
DEPRECATED
"""
warnings.warn("Use fiona.Env() instead.", FionaDeprecationWarning, stacklevel=2)
if driver_count == 0:
log.debug("Creating a chief GDALEnv in drivers()")
return GDALEnv(**kwargs)
return Env(**kwargs)
else:
log.debug("Creating a not-responsible GDALEnv in drivers()")
return GDALEnv(**kwargs)
return Env(**kwargs)
def bounds(ob):
......