<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Select by location using VBA in ArcObjects SDK Questions</title>
    <link>https://community.esri.com/t5/arcobjects-sdk-questions/select-by-location-using-vba/m-p/396120#M10567</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hi Jerry,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;If you want to do what the geo processing tool does why not simply use it? In VBA you access it via the IGeoprocessor interface.&amp;nbsp; The following link takes you to a thread where IGeoProcessor is calling the SelectByLocation tool. You would simply re-jig the parameters array with your layers and selection criteria.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;A href="http://forums.esri.com/Thread.asp?c=93&amp;amp;f=983&amp;amp;t=249267&amp;amp;mc=4#msgid762216"&gt;http://forums.esri.com/Thread.asp?c=93&amp;amp;f=983&amp;amp;t=249267&amp;amp;mc=4#msgid762216&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Duncan&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Fri, 01 Oct 2010 20:45:28 GMT</pubDate>
    <dc:creator>DuncanHornby</dc:creator>
    <dc:date>2010-10-01T20:45:28Z</dc:date>
    <item>
      <title>Select by location using VBA</title>
      <link>https://community.esri.com/t5/arcobjects-sdk-questions/select-by-location-using-vba/m-p/396119#M10566</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hello,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp; I am trying to write some code that will select a polygon from layer1 "SSESarea" and then select by location all polygons from layer2 "Parcels" with their centroid within the polygon selected from layer1.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I have the first part of the code complete and working but I could use some advice on the select by location part.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;The following code selects the polygon that I need from Layer1, then opens the select by location tool in its own window like it does when you open it in arcmap . I would like to have the select by location tool automatically run instead of poping up on the screen.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Private Sub UIButtonControl1_Click()&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; ' SELECT BY ATTRIBUTES&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp; Dim pMxDoc As IMxDocument&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp; Dim pMap As IMap&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp; Dim pActiveView As IActiveView&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp; Dim pFeatureLayer As IFeatureLayer&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp; Dim pFeatureSelection As IFeatureSelection&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp; Dim pQueryFilter As IQueryFilter&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp; Set pMxDoc = Application.Document&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp; Set pMap = pMxDoc.FocusMap&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp; Set pActiveView = pMap&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp; If Not TypeOf pMap.Layer(0) Is IFeatureLayer Then Exit Sub&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp; Set pFeatureLayer = pMap.Layer(0)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp; Set pFeatureSelection = pFeatureLayer 'QI&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp; 'Create the query filter&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp; Set pQueryFilter = New QueryFilter&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp; pQueryFilter.WhereClause = "ProjectName = 'LSP - Arcadia'"&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp; 'Invalidate only the selection cache&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp; 'Flag the original selection&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp; pActiveView.PartialRefresh esriViewGeoSelection, Nothing, Nothing&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp; 'Perform the selection&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp; pFeatureSelection.SelectFeatures pQueryFilter, esriSelectionResultNew, False&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp; 'Flag the new selection&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp; pActiveView.PartialRefresh esriViewGeoSelection, Nothing, Nothing&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp; ' ZOOM TO SELECTED FEATURES&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp; Dim pCmdItem As ICommandItem&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Set pCmdItem = Application.Document.CommandBars.Find(ArcID.Query_ZoomToSelected)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; pCmdItem.Execute&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp; ' MAP SCALE&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp; 'Dim pMxDoc As IMxDocument&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;'Dim pMap As IMap&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Set pMxDoc = ThisDocument&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Set pMap = pMxDoc.FocusMap&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; pMap.MapScale = 3000&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; pMxDoc.ActiveView.Refresh&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;' EXPORT TO JPEG&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;'Dim pMxDoc As IMxDocument (it is necessary while using separately)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;'Dim pActiveView As IActiveView (it is necessary while using separately)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Dim pExport As IExport&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Dim pPixelBoundsEnv As IEnvelope&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Dim exportRECT As tagRECT&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Dim iOutputResolution As Integer&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Dim iScreenResolution As Integer&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Dim hDC As Long&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Set pMxDoc = ThisDocument&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Set pActiveView = pMxDoc.ActiveView&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Set pExport = New ExportJPEG&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;pExport.ExportFileName = "C:\ExportMap." &amp;amp; Right(pExport.Filter, 3)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;iScreenResolution = 150&amp;nbsp; 'default screen resolution is usually 96dpi&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;iOutputResolution = 150&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;pExport.Resolution = iOutputResolution&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;With exportRECT&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;.Left = 0&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;.Top = 0&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;.Right = pActiveView.ExportFrame.Right * (iOutputResolution / iScreenResolution)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;.bottom = pActiveView.ExportFrame.bottom * (iOutputResolution / iScreenResolution)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;End With&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Set pPixelBoundsEnv = New Envelope&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;pPixelBoundsEnv.PutCoords exportRECT.Left, exportRECT.Top, exportRECT.Right, exportRECT.bottom&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;pExport.PixelBounds = pPixelBoundsEnv&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;hDC = pExport.StartExporting&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;pActiveView.Output hDC, pExport.Resolution, exportRECT, Nothing, Nothing&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;pExport.FinishExporting&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;pExport.Cleanup&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;'*************&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;'Pops up select by location tool&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Set pCmdItem = Application.Document.CommandBars.Find(Query_SelectByLayer)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;pCmdItem.Execute&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;'**********************&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;End Sub&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I found the following code on another forum and think it might be a start but I cannot figure out how to configure it.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;************************************************************************&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Since "have their center in" is unfortunately not an esri spatial relation that you can use with a spatial filter, I use a work around that will get the same results probably 99.99% of the time in arcobjects. Basically I get a small negative (inside) buffer on the geometry and then create a spatial filter using esriSpatialRelIntersects. The negative buffer distance is very, very small; ~1 meter. You may have to change this value depending on the map units of your data. You can see how this works in the code below, where pGeom is the polygon that I want to search within, and pFeatureLayer is a featurelayer that has the features you want to select &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Dim pTopoOp as ITopologicalOperator&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Set pTopoOp = pGeom&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Dim pSpQuery as ISpatialFilter&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Set pSpQuery = New SpatialFilter&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;With pSpQuery&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp; 'the value inside buffer should be very small map unit&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp; Set .Geometry = pTopoOp.Buffer(-1)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp; .SpatialRel = esriSpatialRelIntersects&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp; .GeometryField = pFeatureLayer.FeatureClass.ShapeFieldName&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;End With&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Dim pFeatSelection as IFeatureSelection&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Set pFeatSelection = pFeatureLayer&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;'Add features to current selection&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;pFeatSelection.SelectFeatures pSpQuery, esriSelectionResultsAdd, False&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;**************************************************************************&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 01 Oct 2010 15:04:50 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcobjects-sdk-questions/select-by-location-using-vba/m-p/396119#M10566</guid>
      <dc:creator>JerryBiedenbender</dc:creator>
      <dc:date>2010-10-01T15:04:50Z</dc:date>
    </item>
    <item>
      <title>Re: Select by location using VBA</title>
      <link>https://community.esri.com/t5/arcobjects-sdk-questions/select-by-location-using-vba/m-p/396120#M10567</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hi Jerry,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;If you want to do what the geo processing tool does why not simply use it? In VBA you access it via the IGeoprocessor interface.&amp;nbsp; The following link takes you to a thread where IGeoProcessor is calling the SelectByLocation tool. You would simply re-jig the parameters array with your layers and selection criteria.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;A href="http://forums.esri.com/Thread.asp?c=93&amp;amp;f=983&amp;amp;t=249267&amp;amp;mc=4#msgid762216"&gt;http://forums.esri.com/Thread.asp?c=93&amp;amp;f=983&amp;amp;t=249267&amp;amp;mc=4#msgid762216&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Duncan&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 01 Oct 2010 20:45:28 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcobjects-sdk-questions/select-by-location-using-vba/m-p/396120#M10567</guid>
      <dc:creator>DuncanHornby</dc:creator>
      <dc:date>2010-10-01T20:45:28Z</dc:date>
    </item>
  </channel>
</rss>

