Select to view content in your preferred language

Hey What's the proper way to use FindNearestXY?

829
2
09-12-2011 05:36 AM
LastingerBrooks
Deactivated User
Hey Guys!

I got this here 100 foot rectangle, that I have centered around my GPS position.
(Actually it's more of a volume- I added floor and ceiling values of one jillion just to be sure Z values weren't messing this up)

I also have this point layer: "JC_Signs." that contains point objects I want to select from.

So whenever this command fires, what it should do, is search this 100 foot rectangle for the nearest point in JC_Signs, and pop up a message box that contains the OBJECTID of that nearest point to my GPS position, along with a nice purple box around my GPS position that represents the searched range.

All I got returning right now is zeroes.

Is there anyone out there who can show me the light of a working FindNearestXY method?


 'RangeRectangle
  'This creates a my 100 foot rectangle around my position. 

 dim Rectangle100ft
 Set Rectangle100ft = Application.CreateAppObject("rectangle")
  Rectangle100ft.Left = Application.GPS.X - 100
  Rectangle100ft.Right = Application.GPS.X + 100
  Rectangle100ft.Top = Application.GPS.Y + 100
  Rectangle100ft.Bottom = Application.GPS.Y - 100
  Rectangle100ft.Floor = Application.GPS.Z - 1000000000000
  Rectangle100ft.Ceiling = Application.GPS.Z + 1000000000000

 'Rectangle Symbology
  'This creates symbology to symbolize my rectangle.
 Dim pSymbol
 Set pSymbol = Application.CreateAppObject("Symbol")
  pSymbol.LineColor = 8388736
  pSymbol.LineWidth = 4
  pSymbol.BackgroundMode = 1
  psymbol.FillStyle = 1

 'Recordset Gathering
 'This grabs the recordset
 Dim objRecordSet
 Set objRecordSet = Layers("JC_Signs").Records
 Dim ObjRecordSetFields
 Set ObjRecordSetFields = ObjRecordSet.Fields

 'This draws the RangeRectangle
 Call Map.DrawShape (Rectangle100ft, pSymbol)

 'This pops up the message box with the nearest Object ID from "JC_Signs"
 msgbox (ObjRecordSet.FindNearestXY( Application.GPS.X, Application.GPS.Y ,1000000 , [Rectangle100ft]))
Tags (3)
0 Kudos
2 Replies
MelitaKennedy
Esri Notable Contributor
This is just a guess, but are all the data using the same coordinate system? And more importantly, is the GPS data using a foot-based projected coordinate system?

Melita
0 Kudos
EricHajek1
Regular Contributor
I've had bad luck with using the envelope and tolerance parameters, I don't really know why, but they always seems to cause weirdness.

You might try removing those parameters, and checking for them after the record is returned, then spitting out a message box. The DistanceTo() and BearingTo() functions can be used for this pretty easily, although checking in an actual rectangular area might be a bit of a pain unless you're a math person. Pretty cool puzzle though...

Good luck