Created
September 2, 2012 05:36
-
-
Save mapmeld/3595104 to your computer and use it in GitHub Desktop.
BlockInfo
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Quick QGIS scripts to extract housing and population data from Census blocks | |
# get the active layer (Census blocks) | |
from PyQt4 import QtCore | |
activeLayer = qgis.utils.iface.activeLayer() | |
provider = activeLayer.dataProvider() | |
allAttrs = provider.attributeIndexes() | |
provider.select(allAttrs) | |
feat = QgsFeature() | |
while provider.nextFeature(feat): | |
# fetch geometry | |
attributes = feat.attributeMap() | |
blocknumber = str( attributes[4].toString() ) | |
blocknumber = blocknumber.replace('13021', '', 1) | |
houses = str( attributes[6].toString() ) | |
people = str( attributes[7].toString() ) | |
if(houses != "0" or people != "0"): | |
print '"' + blocknumber + '": [ ' + houses + ', ' + people + '],' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment