Is This Content Helpful?
How can we make this better? Please provide as much detail as possible.
Instructions provided describe how to calculate the distances from all points in a shapefile to a single point in another shapefile.
Note: Both shapefiles must be in the same Projected Coordinate System, using linear units, e.g., feet or meters.
Note: Support for Visual Basic for Applications (VBA) for ArcMap and ArcCatalog ended with the ArcGIS 10.2.2 release, and Esri has not included VBA compatibility setups since version 10.5. See: ArcGIS Desktop and VBA Moving Forward.The Visual Basic for Applications (VBA) script below calculates the distances from all points in a shapefile to a single point in another shapefile.
Dim pMxDoc As IMxDocument Set pMxDoc = ThisDocument Dim pMap As IMap Set pMap = pMxDoc.FocusMap Dim pLayer as Ilayer Set pLayer = pMap.Layer(0) Dim pFLayer as IFeatureLayer Set pFLayer = pLayer Dim pFClass as IFeatureClass Set pFClass = pFLayer.FeatureClass Dim pFeature as IFeature Set pFeature = pFClass.GetFeature(0) Dim pPointOne As IPoint Set pPointOne = pFeature.shape Dim dblX1 as Double Dim dblY1 as Double dblX1 = pPointOne.X dblY1 = pPointOne.Y Dim pGeometry As IGeometry Set pGeometry = [Shape] Dim dblDistance as Double Dim dblX2 as Double Dim dblY2 as Double If (Not IsNull([Shape])) Then Set pGeometry = [Shape] If (Not pGeometry.IsEmpty) Then Dim pPointMany As IPoint Set pPointMany = [Shape] dblX2 = pPointMany.X dblY2 = pPointMany.Y dblDistance = SQR( (dblX1-dblX2)^2 + (dblY1-dblY2)^2 ) End If End If
Note: To convert U. S. Survey feet to miles, multiply DISTANCE*0.0001893939 OR divide DISTANCE/5280 To convert meters to miles, multiply DISTANCE*0.0006213711922