I'm creating a Esri Shapefile using Fiona. If I don't add any records, the dbf created by Fiona does not include the headers defined by the schema. My customers claim that results in an invalid shapefile. Is there a configuration option to include headers even with no records? I can't find anything in the documentation. Using Fiona 1.8.
This is where the file is opened:
self.__sink = fiona.open(
self.__path,
mode='w',
driver='ESRI Shapefile',
schema=self.SCHEMA,
layer=self.__path.name,
crs='EPSG:4326',
encoding='utf-8'
)
This is within a method that is called for every instance of a feature. If there are no features, this is never called, and no headers are written.
...
record = {
'geometry': geojson,
'properties': {
...
}
}
# Ensure exclusive access with lock
async with self.__write_lock:
assert self.__sink is not None
self.__sink.write(record)
...
Then the obvious close:
self.__sink.close()
self.__sink = None
Here's the line in Fiona that adds the fields. From how I read it, this should happen irregardless of adding records.
https://github.com/Toblerity/Fiona/blob/1.8.20/fiona/ogrext.pyx#L1221
exc_wrap_int(OGR_L_CreateField(self.cogr_layer, cogr_fielddefn, 1))
I enabled DEBUG logs for Fiona and it appears to be creating the fields
...
[2021-12-06 11:19:17] [DEBUG] [82320] Begin creating field: 'URL' value: 'str:254' [fiona.ogrext] (collection.py:165)
[2021-12-06 11:19:17] [DEBUG] [82320] Field format parsing, value: 'str', fmt: '254' [fiona.ogrext] (collection.py:165)
[2021-12-06 11:19:17] [DEBUG] [82320] End creating field 'URL' [fiona.ogrext] (collection.py:165)