or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

docs

cli.mdcollection-management.mdcrs.mddata-model.mdenvironment.mdfile-io.mdindex.mdschema.mdtransforms.mdutilities.md
tile.json

tessl/pypi-fiona

Fiona reads and writes spatial data files

Workspace
tessl
Visibility
Public
Created
Last updated
Describes
pypipkg:pypi/fiona@1.10.x

To install, run

npx @tessl/cli install tessl/pypi-fiona@1.10.0

index.mddocs/

Fiona

Fiona is a Python library for reading and writing geospatial vector data formats. It provides a minimal, uncomplicated interface to the OGR library, integrating readily with other Python GIS packages like pyproj, Rtree, and Shapely. Fiona streams simple feature data to and from GIS formats like GeoPackage and Shapefile, supporting multi-layered GIS formats, zipped and in-memory virtual file systems, and cloud storage access.

Package Information

  • Package Name: fiona
  • Language: Python
  • Installation: pip install fiona

Core Imports

import fiona

Common pattern for working with collections:

from fiona import open as fiona_open

For specific classes and functions:

from fiona import Feature, Geometry, Properties, bounds, listlayers
from fiona.collection import Collection
from fiona.crs import CRS
from fiona.env import Env

Basic Usage

import fiona

# Reading a shapefile
with fiona.open('data.shp', 'r') as collection:
    # Get basic information
    print(f"Driver: {collection.driver}")
    print(f"CRS: {collection.crs}")
    print(f"Schema: {collection.schema}")
    print(f"Bounds: {collection.bounds}")
    
    # Iterate over features
    for feature in collection:
        print(f"Feature ID: {feature['id']}")
        print(f"Geometry: {feature['geometry']['type']}")
        print(f"Properties: {feature['properties']}")

# Writing a new file
schema = {
    'geometry': 'Point',
    'properties': {'name': 'str', 'value': 'float'}
}

with fiona.open('output.geojson', 'w', driver='GeoJSON', 
                schema=schema, crs='EPSG:4326') as collection:
    # Write a feature
    feature = {
        'geometry': {'type': 'Point', 'coordinates': [-122.5, 37.5]},
        'properties': {'name': 'Test Point', 'value': 42.0}
    }
    collection.write(feature)

Architecture

Fiona's design is built around several key components:

  • Collection: File-like interface to vector datasets, serving as the main entry point for reading and writing geospatial data
  • Feature: GeoJSON-like objects with geometry, properties, and ID representing individual geographic features
  • Geometry/Properties: Specialized mappings for geometry coordinates and feature attributes
  • CRS: Coordinate reference system handling for geographic projections and transformations
  • Environment: GDAL configuration and credential management for various data sources

This architecture provides a clean, Pythonic interface to the powerful GDAL/OGR library while maintaining compatibility with the broader Python geospatial ecosystem.

Capabilities

File I/O Operations

Core functionality for opening, reading, and writing geospatial vector data files. Supports multiple formats including Shapefile, GeoJSON, GeoPackage, and many others through GDAL/OGR drivers.

def open(fp, mode="r", driver=None, schema=None, crs=None, **kwargs): ...
def listlayers(fp, opener=None, vfs=None, **kwargs): ...
def listdir(fp, opener=None): ...
def remove(path_or_collection, driver=None, layer=None, opener=None): ...

File I/O Operations

Data Model Classes

GeoJSON-like data structures for representing geospatial features, geometries, and properties. These classes provide the foundation for working with geospatial data in a familiar, dictionary-like interface.

class Feature:
    def __init__(self, geometry=None, id=None, properties=None, **data): ...
    @classmethod
    def from_dict(cls, ob=None, **kwargs): ...

class Geometry:
    def __init__(self, coordinates=None, type=None, geometries=None, **data): ...
    @classmethod
    def from_dict(cls, ob=None, **kwargs): ...

class Properties:
    def __init__(self, **kwds): ...
    @classmethod
    def from_dict(cls, mapping=None, **kwargs): ...

Data Model

Collection Management

Advanced collection handling including filtering, iteration patterns, schema management, and batch operations for efficient processing of large geospatial datasets.

class Collection:
    def __init__(self, path, mode="r", driver=None, schema=None, crs=None, **kwargs): ...
    def filter(self, *args, **kwds): ...
    def items(self, *args, **kwds): ...
    def keys(self, *args, **kwds): ...
    def write(self, record): ...
    def writerecords(self, records): ...

Collection Management

Coordinate Reference Systems

Comprehensive CRS handling including creation from various formats (EPSG, WKT, PROJ), conversion between formats, and validation. Essential for proper geospatial data processing and coordinate transformations.

class CRS:
    def __init__(self, initialdata=None, **kwargs): ...
    @classmethod
    def from_epsg(cls, code): ...
    @classmethod
    def from_wkt(cls, wkt, morph_from_esri_dialect=False): ...
    def to_dict(self, projjson=False): ...
    def to_wkt(self, morph_to_esri_dialect=False, version=None): ...

Coordinate Reference Systems

Coordinate Transformations

Functions for transforming coordinates and geometries between different coordinate reference systems, essential for integrating data from different sources and projections.

def transform(src_crs, dst_crs, xs, ys): ...
def transform_geom(src_crs, dst_crs, geom, **kwargs): ...

Coordinate Transformations

Environment Management

GDAL environment configuration, credential management for cloud storage access, and driver management for controlling which data formats are available.

class Env:
    def __init__(self, session=None, aws_unsigned=False, profile_name=None, **kwargs): ...
    @classmethod
    def from_defaults(cls, *args, **kwargs): ...
    def drivers(self): ...

Environment Management

Schema and Field Types

Schema definition and validation system for specifying the structure of geospatial data, including field types, geometry types, and validation rules.

def prop_type(text): ...
def prop_width(val): ...

Schema and Field Types

Command Line Interface

Complete command-line interface (fio) for processing geospatial data without writing Python code, including format conversion, data inspection, and spatial analysis operations.

fio info data.shp
fio cat data.shp
fio bounds data.shp
fio ls archive.zip

Command Line Interface

Utility Functions

Helper functions for common geospatial operations including bounds calculation, driver information, and version management.

def bounds(ob): ...

Utility Functions

Error Handling

Comprehensive exception hierarchy for handling various error conditions in geospatial data processing, providing specific error types for different failure modes.

# Base exceptions
class FionaError(Exception): ...
class FionaValueError(FionaError, ValueError): ...

# Specific exceptions  
class DriverError(FionaError): ...
class SchemaError(FionaError): ...
class CRSError(FionaValueError): ...
class DataIOError(FionaError): ...
class TransformError(FionaError): ...
class UnsupportedOperation(FionaError): ...

Types

# Core data types
FeatureDict = dict  # GeoJSON-like feature with geometry, properties, id
GeometryDict = dict  # GeoJSON-like geometry with type, coordinates
PropertiesDict = dict  # Feature properties/attributes

# Bounds type
BoundsTuple = tuple[float, float, float, float]  # (minx, miny, maxx, maxy)

# Schema types
SchemaDict = dict  # Schema definition with geometry and properties
DriverDict = dict  # Driver capabilities and metadata

# CRS types
CRSDict = dict  # PROJ4 parameter dictionary
WKTString = str  # Well-Known Text representation
EPSGCode = int  # EPSG authority code