Fiona는 GeoPackage 및 Shapefile과 같은 GIS 형식 간에 간단한 기능 데이터를 스트리밍합니다.
Fiona는 다층 GIS 형식, 압축 및 메모리 내 가상 파일 시스템을 사용하여 하드 드라이브나 클라우드 스토리지의 파일에서 실제 데이터를 읽고 쓸 수 있습니다. 이 프로젝트에는 Python 모듈과 명령줄 인터페이스(CLI)가 포함되어 있습니다.
Fiona는 GDAL에 의존하지만 GDAL 자체 바인딩과는 다릅니다. Fiona는 생산성이 높고 읽기 쉬운 코드를 쉽게 작성할 수 있도록 설계되었습니다.
Fiona에는 libgdal과 연결되는 여러 확장 모듈이 있습니다. 이로 인해 설치가 복잡해집니다. libgdal 및 자체 종속성을 포함하는 바이너리 배포판(휠)은 Python 패키지 색인에서 제공되며 pip를 사용하여 설치할 수 있습니다.
pip install fiona
이 휠은 주로 생산용이 아닌 간단한 용도로 쉽게 설치할 수 있도록 고안되었습니다. 다른 모든 바이너리 휠, conda 패키지 또는 QGIS와의 호환성 테스트를 거치지 않았으며 GDAL의 선택적 형식 드라이버 중 상당수가 생략되었습니다. 예를 들어 GML 지원이 필요한 경우 소스 배포판에서 Fiona를 빌드하고 설치해야 합니다. pip(버전 >= 22.3) 및 --no-binary 옵션을 사용하여 소스에서 Fiona를 설치할 수 있습니다. GDAL_CONFIG 환경 변수를 설정하여 특정 GDAL 설치를 선택할 수 있습니다.
pip install -U pip
pip install --no-binary fiona fiona
많은 사용자는 Anaconda와 conda-forge가 Fiona를 설치하고 더 많은 선택적 형식 드라이버(예: GML)에 액세스할 수 있는 좋은 방법이라고 생각합니다.
Fiona 1.10에는 Python 3.8 이상 및 GDAL 3.4 이상이 필요합니다.
기능은 fiona.open()
함수에서 반환된 파일과 유사한 Collection
객체에서 읽고 기록됩니다. 기능은 GeoJSON 형식을 기반으로 모델링된 데이터 클래스입니다. 자체 공간 방법이 없으므로 변환하려면 Shapely 또는 이와 유사한 것이 필요합니다. 다음은 Fiona를 사용하여 하나의 데이터 파일에서 일부 기능을 읽고, Shapely를 사용하여 해당 형상 속성을 변경하고, 이를 새 데이터 파일에 쓰는 예입니다.
import fiona
from fiona import Feature , Geometry
from shapely . geometry import mapping , shape
# Open a file for reading. We'll call this the source.
with fiona . open (
"zip+https://github.com/Toblerity/Fiona/files/11151652/coutwildrnp.zip"
) as src :
# The file we'll write to must be initialized with a coordinate
# system, a format driver name, and a record schema. We can get
# initial values from the open source's profile property and then
# modify them as we need.
profile = src . profile
profile [ "schema" ][ "geometry" ] = "Point"
profile [ "driver" ] = "GPKG"
# Open an output file, using the same format driver and coordinate
# reference system as the source. The profile mapping fills in the
# keyword parameters of fiona.open.
with fiona . open ( "centroids.gpkg" , "w" , ** profile ) as dst :
# Process only the feature records intersecting a box.
for feat in src . filter ( bbox = ( - 107.0 , 37.0 , - 105.0 , 39.0 )):
# Get the feature's centroid.
centroid_shp = shape ( feat . geometry ). centroid
new_geom = Geometry . from_dict ( centroid_shp )
# Write the feature out.
dst . write (
Feature ( geometry = new_geom , properties = f . properties )
)
# The destination's contents are flushed to disk and the file is
# closed when its with block ends. This effectively
# executes ``dst.flush(); dst.close()``.
"fio"라는 Fiona의 명령줄 인터페이스는 docs/cli.rst에 문서화되어 있습니다. CLI에는 다양한 명령이 있습니다. fio cat
명령은 모든 데이터세트에서 GeoJSON 기능을 스트리밍합니다.
$ fio cat --compact tests/data/coutwildrnp.shp | jq -c ' . '
{"geometry":{"coordinates":[[[-111.73527526855469,41.995094299316406],...]]}}
...
이 프로젝트에 대한 자세한 내용은 다음을 참조하세요.