Skip to content

Instantly share code, notes, and snippets.

@ImreSamu
Created November 13, 2022 01:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ImreSamu/fe3abea82f388135671824d704b239e3 to your computer and use it in GitHub Desktop.
Save ImreSamu/fe3abea82f388135671824d704b239e3 to your computer and use it in GitHub Desktop.
extending ne_10m_admin_0_countries.shp
from shapely.geometry import mapping, shape
import fiona
with fiona.open('./10m_cultural/ne_10m_admin_0_countries.shp', 'r', encoding='utf-8' ) as input:
schema = input.schema.copy()
input_crs = input.crs
# add area_sqkm property if not present in the schema add it
if not hasattr( schema['properties'], 'area_sqkm'):
schema['properties']['area_sqkm'] = 'float:22.2'
#add population
if not hasattr( schema['properties'], 'population'):
schema['properties']['population'] = 'int:12'
with fiona.open('./10m_cultural/ne2_10m_admin_0_countries.shp', 'w', 'ESRI Shapefile', schema, input_crs, encoding='utf-8' ) as output:
for elem in input:
elem['properties']['area_sqkm']= 0.0
elem['properties']['population']= 0
output.write({'properties':elem['properties'],'geometry': mapping(shape(elem['geometry']))})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment