I am trying to iterate JSON objects and append selected features to new GeoJSON using geojson
Python library. When hardcoded the script works fine. But when append method is used in a for loop I get this error.
TypeError: string indices must be integers
Why does this work (polygon variable hardcoded and taken from print statement in the loop)...
polygon = Polygon([[[-112.30701948248064, 33.65181795979867], [-112.30701798409073, 33.651669879089], ...[-112.30701948248064, 33.65181795979867]]])
features = []
features.append(Feature(geometry=polygon, properties={"country": "Spain"}))
feature_collection = FeatureCollection(features)
But this does not...
with open(subs) as f:
data = json.load(f)
for feature in data['features']:
if feature['properties']['PUC'] == '0261':
polygon = 'Polygon(' + str(feature['geometry']['coordinates']) + ')'
features.append(Feature(geometry=polygon, properties={"country": "Spain"}))