Skip to content

Instantly share code, notes, and snippets.

@dsummersl
Created Mar 4, 2018
Embed
What would you like to do?
Extract population from NC VTD data.

I started with some tract level data:

wget https://www.ncleg.net/GIS/Download/Base_Data/2011/Geo/Census_Features.gdb.zip
unzip Census_Features.gdb.zip
ogr2ogr census_features Census_Features.gdb

There is a good data dictionary on the site at well, where I found that the total population is PL10AA_TOT: https://www.ncleg.net/representation/Content/BaseData/BD2011.aspx

Manual for GDAL to convert to csv: http://www.gdal.org/drv_csv.html

# Compute the centroid for each tract, and force lat/long geometric projection:
ogr2ogr -sql 'select ST_Centroid(geometry) as center,* from Tract' -t_srs crs:84 -dialect sqlite tract_centroid.shp Tract.shp

# Create a CSV with the lat/long, and total population.
ogr2ogr -f CSV -sql 'select PL10AA_TOT from tract_centroid' tract.csv tract_centroid.shp -lco GEOMETRY=AS_XY
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment