Skip to content

Instantly share code, notes, and snippets.

@dsummersl
Created March 4, 2018 16:48
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save dsummersl/e8d609be0bd363e09e5471ff3671f5a8 to your computer and use it in GitHub Desktop.
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