Why below code does not work-

import fiona
from fiona.crs import from_epsg

my_schema = {'geometry': 'Point', 'properties': {'mean_in': 'str', 'total_h1': 'str', 'total_h2': 'str', 'LOS': 'str', 'id': 'str', 'index': 'str', 'Junctio': 'str', 'intLanes': ':str', 'flow': 'str', 'incLanes': 'str', 'interva1': 'str', 'y': 'str', 'x': 'str', 'entered': 'str', 'type': 'str', 'Incomin': 'str', 'interva2': 'str'}}
wr_dict = {'geometry': {'type': 'Point', 'coordinates': (488901.97760411515, 5078198.250875515)}, 'properties': {'mean_in': '0', 'index': '0', 'Junctio': '0', 'intLanes': ':A_0_0 :A_1_0', 'flow': '0', 'total_h1': '0', 'total_h2': '0', 'LOS': '0', 'incLanes': 'B-A_0 A0-A_0', 'interva1': '0', 'y': '39.18', 'x': '31.72', 'entered': '0', 'type': 'unregulated', 'id': 'A', 'Incomin': '0', 'interva2': '0'}}

with fiona.open("my_shp_clean1.shp", mode='w', driver='ESRI Shapefile', schema=my_schema,crs =from_epsg(32632)) as output:

Rather raises exception as below-

File "C:\Python27\ArcGIS10.3\Lib\site-packages\fiona__init__.py", line 183, in open enabled_drivers=enabled_drivers, crs_wkt=crs_wkt) File "C:\Python27\ArcGIS10.3\Lib\site-packages\fiona\collection.py", line 161, in init self.session.start(self, **kwargs) File "C:\Python27\ArcGIS10.3\Lib\site-packages\fiona\ogrext.pyd", line 890, in fiona.ogrext.WritingSession.start (fiona/ogrext.c:15383)

ValueError: invalid literal for int() with base 10: 'str'

N.B. I am with Fiona (1.6.2),Shapely (1.5.13),GDAL (1.11.3) and python 2.7 in windows 8


I guess its because you have a typo in your schema properties : 'intLanes': ':str' should be changed to 'intLanes': 'str' (the colon before str).

| improve this answer | |
  • Thanks, What about the second part of the question, why ValueError: invalid literal for int() with base 10: 'str' is raised? – SIslam Jan 16 '16 at 5:19
  • You might find that fiona (and underneath ogr) default to an int datatype when they don't understand the schema. You'd have to check the source to be sure though. – om_henners Jan 16 '16 at 8:54
  • 1
    Because, with your schema, Fiona don't know what is the ':str'format and, by defaut, it choose the first format that is int – gene Jan 16 '16 at 17:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.