Fiona: CRS is lost when save in BytesIO only with crs_wkt

Created on 1 Jun 2020  路  2Comments  路  Source: Toblerity/Fiona

import fiona
import io

example_schema = {
    'geometry': 'Point',
    'properties': [('title', 'str')],
}

example_features = [
    {
        "geometry": {"type": "Point", "coordinates": [0.0, 0.0]},
        "properties": {"title": "One"},
    },
    {
        "geometry": {"type": "Point", "coordinates": [1.0, 2.0]},
        "properties": {"title": "Two"},
    },
    {
        "geometry": {"type": "Point", "coordinates": [3.0, 4.0]},
        "properties": {"title": "Three"},
    },
]

crs_wkt = (
'PROJCRS["WGS 84 / UTM zone 11N",'
    'BASEGEOGCRS["WGS 84",'
        'DATUM["World Geodetic System 1984",'
            'ELLIPSOID["WGS 84",6378137,298.257223563,LENGTHUNIT["metre",1]]],'
        'PRIMEM["Greenwich",0,ANGLEUNIT["degree",0.0174532925199433]],'
        'ID["EPSG",4326]],'
    'CONVERSION["UTM zone 11N",'
        'METHOD["Transverse Mercator",ID["EPSG",9807]],'
        'PARAMETER["Latitude of natural origin",0,ANGLEUNIT["degree",0.0174532925199433],ID["EPSG",8801]],'
        'PARAMETER["Longitude of natural origin",-117,ANGLEUNIT["degree",0.0174532925199433],ID["EPSG",8802]],'
        'PARAMETER["Scale factor at natural origin",0.9996,SCALEUNIT["unity",1],ID["EPSG",8805]],'
        'PARAMETER["False easting",500000,LENGTHUNIT["metre",1],ID["EPSG",8806]],'
        'PARAMETER["False northing",0,LENGTHUNIT["metre",1],ID["EPSG",8807]]],'
    'CS[Cartesian,2],'
    'AXIS["(E)",east,'
        'ORDER[1],'
        'LENGTHUNIT["metre",1]],'
    'AXIS["(N)",north,'
        'ORDER[2],'
        'LENGTHUNIT["metre",1]],'
    'USAGE['
        'SCOPE["unknown"],'
        'AREA["World - N hemisphere - 120掳W to 114掳W - by country"],'
        'BBOX[0,-120,84,-114]],'
    'ID["EPSG",32611]]'
)


with io.BytesIO() as fd:
    with fiona.open(fd, 'w',
        driver='GPKG',
        schema=example_schema,
        # crs=example_crs
        crs_wkt=crs_wkt
    ) as dst:
            dst.writerecords(example_features)
    fd.seek(0)
    with fiona.open(fd) as src:
        assert src.crs

Actual behavior: assertion error
Expected behavior: everything ok

bug

All 2 comments

I think the issue is that crs_wkt is not being passed through to memfile.open on those lines:

https://github.com/Toblerity/Fiona/blob/7f6f9dc3e466036ca196138efc49fc3c281c59b1/fiona/__init__.py#L229-L232

Thanks @habibutsu @jorisvandenbossche for doing the investigation & having a really nice example.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

klonuo picture klonuo  路  3Comments

huevosabio picture huevosabio  路  8Comments

mmngreco picture mmngreco  路  4Comments

dazza-codes picture dazza-codes  路  3Comments

sgillies picture sgillies  路  8Comments