The following piece of code returns a shp following the driver and crs of a model .shp.
import numpy as np #just to test I correctly handle data types
import fiona
from shapely.geometry import Polygon, mapping
with fiona.open('model.shp') as source:
source_driver = source.driver
source_crs = source.crs
#source_schema = source.schema
source_schema = {'geometry': 'Polygon',
'properties': {'field_name': 'float'}} #Beware: field names cannot be longer than 10 characters!
#writing a new file
with fiona.open('output.shp',
'w',
driver=source_driver,
crs=source_crs,
schema=source_schema) as collection:
rec = {}
rec['geometry'] = mapping(Polygon([(0,0),(1,0),(1,1),(0,0)]))
rec['properties'] = {'field_name': float(np.float(0.3))}
collection.write(rec)
The written record can be checked in this way:
collection = fiona.open('output.shp')
rec = collection.next()
print rec
Which returns: {'geometry': {'type': 'Polygon', 'coordinates': [[(0.0, 0.0), (1.0, 1.0), (1.0, 0.0), (0.0, 0.0)]]}, 'type': 'Feature', 'id': '0', 'properties': OrderedDict([(u'field_name', 0.3)])}
I followed @genes' hints from this post and @sgillies' recommendations below.