Hello Everyone
Please help me with this
I have Arcmap 9.3
On this i have 2 layer points witch i need to calculate the distance between all the point on layer 0 and other point on layer 2
But i need to tdo this in vba of Arcmap by this logic situation
-get the all the point in layer 0 and storied them in an array
get all the point in layer 2 and stored them in a nother array
no calculate the distance for each point on layer 0 to each point on layer 2
this is a formula : dist_layerp = Sqr((x2 - x1) ^ 2 + (y2 - y1) ^ 2)
IF the distance between point on layer 0 and point on layer 2 is 50 or - 50 create a field on table with value 0
But the trick is that i need to search in layer 2 if the point to point is another 50 end then stop it he distance from next point is more then 50
the picture Bellow shows what i need.
Thankyou very much for your help
Alternatively you may use buffer query to find all points within 50 meter.
You know i was goindg to do that but the problem was that i need a flag to stop if prevision point is no longer 50 metter from the next point
You can apply spatial filter to your Layer 2 with 50 meter buffer circle from point in layer 0. This will return list of point features as a feature cursor from layer 2 which are within 50 meter distance.
Than you can do whatever you want with this points.
I think you want to do this for each feature in layer 0, so you have to iterate all feature in layer 0 and apply spatial filter.
Interesting think
I will try to do that and give you a feetback
Thankyou for your help
Can you please give me a hint to this one
i have a fucntion that get the distance from x,y layer 0 and x,y layer 2
but the proble is that i need to to that for each point not only on,because the resol show only one point
So how to itterante thru this
Function is :
Dim pMxDoc As IMxDocument
Set pMxDoc = ThisDocument
Dim pMap As IMap
Set pMap = pMxDoc.FocusMap
Dim i As Integer
Dim pLayer As ILayer
Dim pLayer2 As ILayer
Set pLayer = pMap.layer(0)
Set pLayer2 = pMap.layer(2)
Dim pFLayer As IFeatureLayer
Dim pFLayer2 As IFeatureLayer
Set pFLayer = pLayer
Set pFLayer2 = pLayer2
Dim pFClass As IFeatureClass
Dim pFClass2 As IFeatureClass
Set pFClass = pFLayer.FeatureClass
Set pFClass2 = pFLayer2.FeatureClass
Dim pFeature As IFeature
Dim pFeature2 As IFeature
Dim pFCursor As IFeatureCursor
Dim pFCursor2 As IFeatureCursor
Set pFCursor = pFClass.Search(Nothing, False)
Set pFCursor2 = pFClass2.Search(Nothing, False)
Set pFeature = pFCursor.NextFeature
Set pFeature2 = pFCursor2.NextFeature
Dim pPointOne As IPoint
Dim pPointMany As IPoint
Set pPointOne = pFeature.Shape
Set pPointMany = pFeature2.Shape
Dim dblX1 As Double
Dim dblY1 As Double
Dim dblX2 As Double
Dim dblY2 As Double
dblX1 = pPointOne.x
dblY1 = pPointOne.y
dblX2 = pPointMany.x
dblY2 = pPointMany.y
Dim dblDistance As Double
Set pFeature = pFCursor.NextFeature
Set pFeature2 = pFCursor2.NextFeature
dblDistance = Sqr((dblX1 - dblX2) ^ 2 + (dblY1 - dblY2) ^ 2)
You can create a function to get features within 50 meter buffer from layer 2
Then you can call this function for each feature in layer 0. You will get a list of selected feature within 50 meter distance to calculate actual distance. This will be much faster than iterating all features in layer 2.
Dim pTopoOp as ITopologicalOperator
Set pTopoOp = pGeom
Dim pSpQuery as ISpatialFilter
Set pSpQuery = New SpatialFilter
With pSpQuery
Set .Geometry = pTopoOp.Buffer(50)
.SpatialRel = esriSpatialRelIntersects
.GeometryField = pFeatureLayer.FeatureClass.ShapeFieldName
End With
Dim pFeatSelection as IFeatureSelection
Set pFeatSelection = pFeatureLayer
'Add features to current selection
pFeatSelection.SelectFeatures pSpQuery, esriSelectionResultsAdd, False
Sorry i am new to ARcmap
So far from what you show me is that an ew to define pGeom beause i get an error and then
so i made the function calc witch has data from what i posted and then with waht you gived me i need to create a nother function witch contains this ?:
Dim pTopoOp as ITopologicalOperator
Set pTopoOp = pGeom
Dim pSpQuery as ISpatialFilter
Set pSpQuery = New SpatialFilter
With pSpQuery
Set .Geometry = pTopoOp.Buffer(50)
.SpatialRel = esriSpatialRelIntersects
.GeometryField = pFeatureLayer.FeatureClass.ShapeFieldName
End With
Dim pFeatSelection as IFeatureSelection
Set pFeatSelection = pFeatureLayer
'Add features to current selection
pFeatSelection.SelectFeatures pSpQuery, esriSelectionResultsAdd, False