0

I'm using Fiona to write a shapefile containing geometries of US Census congressional districts and census tracts with some computed attributes. Unfortunately, my file is being outputted blank. I am able to see the records in QGIS but not the geometries.

In my code, I take the shapely polygons read in from census shapefiles, compute properties and feed the polygons with the relevant attributes to fiona filewriter.

# schema for the file
myschema = {
'geometry':'Polygon',
'properties':{'is boundary':'int','id':'str', 'district':'int'}
}

with fiona.open(name,'w',crs=from_epsg(4326), driver='ESRI Shapefile', schema=myschema) as output:
...
self.w.write({
                        'geometry':mapping(sg.asShape(self.subunit)),
                        'properties':{'is boundary':int(is_boundary), 'id':str(self.sid), 'district':0},
                        })

self.w is a reference to output after it's passed to an object and self.subunit is a pysal polygon geometry which I convert to shapely in order to write it to my shapefile. Has anyone had problems with this shapefile writing using fiona and know where my problem could be?

Georgy
  • 12,464
  • 7
  • 65
  • 73

2 Answers2

0

First of all: I recommend you to ask these kind of questions in the GIS stack: https://gis.stackexchange.com

Second: I can't comment so I answer here

Be sure that the output of

sg.asShape(self.subunit)

gives a proper geometry object. If you print it what is the output?

ImanolUr
  • 348
  • 2
  • 13
0

The shapefile needs to be explicitely closed (outfile.close()).

In principle opening the file with a with statement should take care of the closing, but since you mention writing it as a reference after having passed it to an object, this may be the issue anyway.

Skippy le Grand Gourou
  • 6,976
  • 4
  • 60
  • 76