Fiona สตรีมข้อมูลคุณสมบัติอย่างง่ายเข้าและออกจากรูปแบบ GIS เช่น GeoPackage และ Shapefile
Fiona สามารถอ่านและเขียนข้อมูลในโลกแห่งความเป็นจริงโดยใช้รูปแบบ GIS หลายเลเยอร์ ระบบไฟล์เสมือนแบบซิปและในหน่วยความจำ จากไฟล์บนฮาร์ดไดรฟ์ของคุณหรือในพื้นที่เก็บข้อมูลบนคลาวด์ โปรเจ็กต์นี้มีโมดูล Python และอินเทอร์เฟซบรรทัดคำสั่ง (CLI)
ฟิโอน่าขึ้นอยู่กับ GDAL แต่แตกต่างจากการเชื่อมโยงของ GDAL เอง Fiona ได้รับการออกแบบให้มีประสิทธิผลสูงและช่วยให้เขียนโค้ดได้ง่ายซึ่งอ่านง่าย
Fiona มีโมดูลส่วนขยายหลายโมดูลที่เชื่อมโยงกับ libgdal การติดตั้งนี้ซับซ้อน การแจกแจงแบบไบนารี (วงล้อ) ที่มี libgdal และการขึ้นต่อกันของตัวมันเองนั้นหาได้จาก Python Package Index และสามารถติดตั้งได้โดยใช้ pip
pip install fiona
ล้อเหล่านี้มีจุดประสงค์หลักเพื่อให้การติดตั้งง่ายสำหรับการใช้งานที่เรียบง่าย ไม่ใช่เพื่อการผลิตมากนัก ไม่ได้รับการทดสอบความเข้ากันได้กับล้อไบนารี แพ็คเกจ conda หรือ QGIS อื่นๆ ทั้งหมด และละเว้นไดรเวอร์รูปแบบเสริมของ GDAL จำนวนมาก ตัวอย่างเช่น หากคุณต้องการการสนับสนุน GML คุณจะต้องสร้างและติดตั้ง Fiona จากการกระจายแหล่งที่มา เป็นไปได้ที่จะติดตั้ง Fiona จากแหล่งที่มาโดยใช้ pip (เวอร์ชัน >= 22.3) และตัวเลือก --no-binary สามารถเลือกการติดตั้ง GDAL เฉพาะได้โดยการตั้งค่าตัวแปรสภาพแวดล้อม GDAL_CONFIG
pip install -U pip
pip install --no-binary fiona fiona
ผู้ใช้หลายคนพบว่า Anaconda และ conda-forge เป็นวิธีที่ดีในการติดตั้ง Fiona และเข้าถึงไดรเวอร์รูปแบบเสริมเพิ่มเติม (เช่น GML)
Fiona 1.10 ต้องใช้ Python 3.8 หรือสูงกว่า และ GDAL 3.4 หรือสูงกว่า
คุณสมบัติจะถูกอ่านและเขียนไปยังอ็อบเจ็กต์คอ Collection
ที่เหมือนไฟล์ที่ส่งคืนจากฟังก์ชัน fiona.open()
คุณลักษณะคือคลาสข้อมูลที่จำลองในรูปแบบ 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()``.
อินเทอร์เฟซบรรทัดคำสั่งของ Fiona ชื่อ "fio" ได้รับการบันทึกไว้ที่ docs/cli.rst CLI มีคำสั่งที่แตกต่างกันจำนวนหนึ่ง คำสั่ง fio cat
จะสตรีมคุณสมบัติ GeoJSON จากชุดข้อมูลใดๆ
$ fio cat --compact tests/data/coutwildrnp.shp | jq -c ' . '
{"geometry":{"coordinates":[[[-111.73527526855469,41.995094299316406],...]]}}
...
สำหรับรายละเอียดเพิ่มเติมเกี่ยวกับโครงการนี้ โปรดดู: