Customer Service | Training | Contact Us
You are here: Home > User Forums > arcgis desktop discussion forums > Thread Replies

ArcGIS Desktop Discussion Forums

ArcGIS Desktop - ArcObjects Visual Basic for Application (VBA) forum

Polygon Density Map   Keith Anderson Mar 28, 2002
Re: Polygon Density Map   Kirk Kuykendall Mar 28, 2002
Re: Polygon Density Map   Keith Anderson Mar 29, 2002
Re: Polygon Density Map   Kirk Kuykendall Mar 29, 2002
Re: Polygon Density Map   John Farren Jul 01, 2005
Re: Polygon Density Map   John Farren Jul 01, 2005
Report Inappropriate Content • Top • Print • Reply    
Subject Polygon Density Map 
Author Keith Anderson 
Date Mar 28, 2002 
Message I need to create a Density polygon map through code. The current 3.x code creates a user defined polygon grid over the exiting point shape file. It counts the incidents within each polygon and then classifies the polygon counts to make the density map.

If anyone has some similar code, I would be greatful. 
  Keith Anderson
LOGIS (763-543-2641)
kanderson@logis.org 
   
Report Inappropriate Content • Top • Print • Reply    
Subject Re: Polygon Density Map 
Author Kirk Kuykendall 
Date Mar 28, 2002 
Message The code below can be used to count the number of features in the first layer that are contained within each polygon in the second layer.

See the classbreaks renderer thread for suggestions on rendering this stuff.
http://forums.esri.com/Thread.asp?c=93&f=982&t=58128&mc=8#146428

If most polygons contain no features inside them then a faster approach might be to loop through each feature and increment the count on the polygon that it falls within.

kkeywords ispatialfilter
 
 
Option Explicit
Sub Test()
    Dim pMxDoc As IMxDocument
    Set pMxDoc = ThisDocument
    
    Dim pPolyFLayer As IFeatureLayer
    Set pPolyFLayer = pMxDoc.FocusMap.Layer(1)
    
    Dim pPointFlayer As IFeatureLayer
    Set pPointFlayer = pMxDoc.FocusMap.Layer(0)
    
    Dim pEditor As IEditor, pUID As New UID
    pUID.Value = "esricore.Editor"
    
    Set pEditor = Application.FindExtensionByCLSID(pUID)
    If pEditor.EditState = esriStateEditing Then
        pEditor.StartOperation
        CountFeatures pPolyFLayer.FeatureClass, pPointFlayer.FeatureClass, _
                     esriSpatialRelContains, "POP1990"
        pEditor.StopOperation "PolygonDensity"
    Else
        Debug.Print "no edit session"
    End If
End Sub

Sub CountFeatures(pFC1 As IFeatureClass, _
                 pFC2 As IFeatureClass, _
                 lSpatialRel As esriSpatialRelEnum, _
                 strCountFld As String)
                 
    Dim pFCur As IFeatureCursor
    Set pFCur = pFC1.Search(Nothing, False)
    
    Dim lFld As Long
    lFld = pFC1.FindField(strCountFld)
    If lFld = -1 Then
        Debug.Print "field not found: " & strCountFld
        Exit Sub
    End If
    
    Dim pFeat As IFeature
    Set pFeat = pFCur.NextFeature
    Do While Not pFeat Is Nothing
    
        Dim pSF As ISpatialFilter
        Set pSF = New SpatialFilter
        Set pSF.Geometry = pFeat.ShapeCopy
        pSF.SpatialRel = lSpatialRel
        pSF.GeometryField = pFC2.ShapeFieldName
        
        pFeat.Value(lFld) = pFC2.FeatureCount(pSF)
        Debug.Print "OID: " & pFeat.OID & ", count: " & pFeat.Value(lFld)
        pFeat.Store
        Set pFeat = pFCur.NextFeature
    Loop

End Sub

 
  Kirk Kuykendall
AmberGIS Programming Services & Sales
web: http://www.ambergis.com
blog: http://ambergis.wordpress.com/
LinkedIn: http://www.linkedin.com/in/kirkkuykendall 
   
Report Inappropriate Content • Top • Print • Reply    
Subject Re: Polygon Density Map 
Author Keith Anderson 
Date Mar 29, 2002 
Message Thanks again for the jump start. 
  Keith Anderson
LOGIS (763-543-2641)
kanderson@logis.org 
   
Report Inappropriate Content • Top • Print • Reply    
Subject Re: Polygon Density Map 
Author Kirk Kuykendall 
Date Mar 29, 2002 
Message Forgot to mention, for generating a grid you can use the GenerateGrid script posted in ArcScripts:
http://gis.esri.com/arcscripts/index.cfm?action=details&CFGRIDKEY=DFDFCEAC-F4D2-11D5-944D00508B0CB419 
  Kirk Kuykendall
AmberGIS Programming Services & Sales
web: http://www.ambergis.com
blog: http://ambergis.wordpress.com/
LinkedIn: http://www.linkedin.com/in/kirkkuykendall 
   
Report Inappropriate Content • Top • Print • Reply    
Subject Re: Polygon Density Map 
Author John Farren 
Date Jul 01, 2005 
Message Kirk, do you have an updated version of modGenGrid for version 9 with updates replacing the esricore libraries? 
   
Report Inappropriate Content • Top • Print • Reply    
Subject Re: Polygon Density Map 
Author John Farren 
Date Jul 01, 2005 
Message Never mind, apparently a control-H (replace) the word "esricore" with "esriGeometry" brings it all back. Nice piece of code, thank you for sharing it.