Difference between revisions of "Main Page/Research/Smart Maps/dwelling units"

From phurvitz
Jump to: navigation, search
 
(3 intermediate revisions by the same user not shown)
Line 1: Line 1:
 
Create a smart map raster that represents the count or density of dwelling units  
 
Create a smart map raster that represents the count or density of dwelling units  
  
# In Access (for faster processing)
+
# add a field to the table for dwelling units per km<sup>2</sup>.
## decide on a cell size in advance
+
#: greater precision than per ft<sup>2</sup>
### if the cell size is 10 m, then the area of the cell is 100 m<sup>2</sup> = 1076 ft<sup>2</sup>
+
# calculate the field, e.g.
## prepare parcel data with number of dwelling units per parcel (I used precision 18 scale 10)
+
#: <tt>du_per_km2 = [num_units]*10763910.42/[shape_area]</tt>
## add a field for du_per_[cell] (e.g., du_per_10m_cell)
+
# convert to raster using the field
### calculate as dwelling_units * conversion / shape_area
+
#: make a note of cell size, e.g., 10 m cell size = 32.808 ft
###: e.g., for 10 m<sup>2</sup> cells, the conversion will be 1076
+
# focalsum of the raster
###: to give the number of dwelling units per cell<sup>2</sup>
+
#: note the radius, e.g., 10 cells = 100 m
# In ArcGIS (for spatial operation)
+
#: gives sum of du/km<sup>2</sup> for the circle
## convert to raster at 10 m spacing (32.808 ft), call it <tt>[du_per_cell]</tt>
+
# divide by area of the circle to give density
## convert the raster to points
+
#: note unit conversions
##: now there is a data set of points where each point has the value of the number of dwelling units per cell/point
+
 
## simple density moving window analysis with 833 m (2734 ft) radius and population field = grid_code, units square meters (call this grid '''simple_dens''')
+
The following source code can be used. Requirements:
## multiply '''simple_dens''' by the radius area to obtain focal count (following this analysis, <tt>[simple_dens] * sqr (833) * pi</tt>
+
# Existence of drive W for output. Use <tt>subst</tt> in Windows for this.
 +
# Modify script in ArcToolbox to include arguments/parameters, matching the <tt>sys.argv[]</tt> lines.
 +
 
 +
Note: this assumes you want the density to be in units/ha.
 +
 
 +
 
 +
 
 +
<source lang="python">
 +
# ---------------------------------------------------------------------------
 +
# focal_du_per_ha.py
 +
# Created on: Tue May 18 2010 02:48:36 PM
 +
#  (generated by ArcGIS/ModelBuilder)
 +
# Usage: focal_du_per_ha <parcels> <Value_field> <Cellsize> <Neighborhood> <du_per_ha>  
 +
# ---------------------------------------------------------------------------
 +
 
 +
# Import system modules
 +
import sys, string, os, arcgisscripting
 +
 
 +
# Create the Geoprocessor object
 +
gp = arcgisscripting.create()
 +
 
 +
# Check out any necessary licenses
 +
gp.CheckOutExtension("spatial")
 +
 
 +
# Load required toolboxes...
 +
gp.AddToolbox("C:/Program Files (x86)/ArcGIS/ArcToolbox/Toolboxes/Spatial Analyst Tools.tbx")
 +
gp.AddToolbox("C:/Program Files (x86)/ArcGIS/ArcToolbox/Toolboxes/Conversion Tools.tbx")
 +
 
 +
# output dir
 +
outdir = "w:/"
 +
if os.path.exists(outdir) == 0:
 +
gp.AddMessage("Path does not exist.")
 +
exit()
 +
 +
# Script arguments...
 +
parcels = sys.argv[1]
 +
if parcels == '#':
 +
parcels = "PIN_ADDRESS" # provide a default value if unspecified
 +
 
 +
Value_field = sys.argv[2]
 +
if Value_field == '#':
 +
Value_field = "du_per_km2" # provide a default value if unspecified
 +
 
 +
Cellsize = sys.argv[3]
 +
if Cellsize == '#':
 +
Cellsize = "32.808" # provide a default value if unspecified
 +
StrCellAreaMeters = str((float(Cellsize) / 3.2808)**2)
 +
 
 +
Neighborhood = sys.argv[4]
 +
if Neighborhood == '#':
 +
Neighborhood = "Circle 10 CELL" # provide a default value if unspecified
 +
 
 +
du_per_ha = sys.argv[5]
 +
if du_per_ha == '#':
 +
du_per_ha = outdir + "du_per_ha.img" # provide a default value if unspecified
 +
 
 +
# Local variables...
 +
duperkm2 = outdir + "duperkm2.img"
 +
FocalSumR = outdir + "FocalSumR.img"
 +
 
 +
# Process: Polygon to Raster...
 +
gp.AddMessage("Polygon to raster\n")
 +
gp.PolygonToRaster_conversion(parcels, Value_field, duperkm2, "CELL_CENTER", "NONE", Cellsize)
 +
 
 +
# Process: Focal Sum...
 +
gp.AddMessage("FocalSum\n")
 +
gp.FocalStatistics_sa(duperkm2, FocalSumR, Neighborhood, "SUM", "DATA")
 +
 
 +
# Process: DU per hectare...
 +
gp.AddMessage("Du per ha\n")
 +
gp.SingleOutputMapAlgebra_sa(FocalSumR + " /  ( (Pi) * sqr( " + StrCellAreaMeters + " ))", du_per_ha)
 +
</source>

Latest revision as of 23:54, 18 May 2010

Create a smart map raster that represents the count or density of dwelling units

  1. add a field to the table for dwelling units per km2.
    greater precision than per ft2
  2. calculate the field, e.g.
    du_per_km2 = [num_units]*10763910.42/[shape_area]
  3. convert to raster using the field
    make a note of cell size, e.g., 10 m cell size = 32.808 ft
  4. focalsum of the raster
    note the radius, e.g., 10 cells = 100 m
    gives sum of du/km2 for the circle
  5. divide by area of the circle to give density
    note unit conversions

The following source code can be used. Requirements:

  1. Existence of drive W for output. Use subst in Windows for this.
  2. Modify script in ArcToolbox to include arguments/parameters, matching the sys.argv[] lines.

Note: this assumes you want the density to be in units/ha.


<source lang="python">

  1. ---------------------------------------------------------------------------
  2. focal_du_per_ha.py
  3. Created on: Tue May 18 2010 02:48:36 PM
  4. (generated by ArcGIS/ModelBuilder)
  5. Usage: focal_du_per_ha <parcels> <Value_field> <Cellsize> <Neighborhood> <du_per_ha>
  6. ---------------------------------------------------------------------------
  1. Import system modules

import sys, string, os, arcgisscripting

  1. Create the Geoprocessor object

gp = arcgisscripting.create()

  1. Check out any necessary licenses

gp.CheckOutExtension("spatial")

  1. Load required toolboxes...

gp.AddToolbox("C:/Program Files (x86)/ArcGIS/ArcToolbox/Toolboxes/Spatial Analyst Tools.tbx") gp.AddToolbox("C:/Program Files (x86)/ArcGIS/ArcToolbox/Toolboxes/Conversion Tools.tbx")

  1. output dir

outdir = "w:/" if os.path.exists(outdir) == 0: gp.AddMessage("Path does not exist.") exit()

  1. Script arguments...

parcels = sys.argv[1] if parcels == '#':

parcels = "PIN_ADDRESS" # provide a default value if unspecified

Value_field = sys.argv[2] if Value_field == '#':

Value_field = "du_per_km2" # provide a default value if unspecified

Cellsize = sys.argv[3] if Cellsize == '#':

Cellsize = "32.808" # provide a default value if unspecified

StrCellAreaMeters = str((float(Cellsize) / 3.2808)**2)

Neighborhood = sys.argv[4] if Neighborhood == '#':

Neighborhood = "Circle 10 CELL" # provide a default value if unspecified

du_per_ha = sys.argv[5] if du_per_ha == '#':

du_per_ha = outdir + "du_per_ha.img" # provide a default value if unspecified
  1. Local variables...

duperkm2 = outdir + "duperkm2.img" FocalSumR = outdir + "FocalSumR.img"

  1. Process: Polygon to Raster...

gp.AddMessage("Polygon to raster\n") gp.PolygonToRaster_conversion(parcels, Value_field, duperkm2, "CELL_CENTER", "NONE", Cellsize)

  1. Process: Focal Sum...

gp.AddMessage("FocalSum\n") gp.FocalStatistics_sa(duperkm2, FocalSumR, Neighborhood, "SUM", "DATA")

  1. Process: DU per hectare...

gp.AddMessage("Du per ha\n") gp.SingleOutputMapAlgebra_sa(FocalSumR + " / ( (Pi) * sqr( " + StrCellAreaMeters + " ))", du_per_ha) </source>