VECQueryNearest

Demonstrates how to query to find the nearest shape id from a 2D point location.

Remarks

This example illustrates how to find the nearest shape to a target, and display the value of the name field in that shape.

Code

 local int nearest_shape, Vertex target
 local int tfid, int segment_num

 target.x = 432608.0
 target.y = 3725824.0

 segment_num = 25
 printf "Target point 432608E and 3725824 N\n"
 try
    tfid = DBOpen(GetPCIHOME()+"/demo/irvine.pix", "r")

    nearest_shape = VECQueryNearest( tfid, segment_num, target )
    if( nearest_shape = -1 ) then
        printf "No findable shape in this layer.\n"
    else
        printf "Shape `%d' nearest to location (%d,%d).\n", 
              VECGetField( tfid, segment_num, nearest_shape, 2 ),
              target.x, target.y
    endif
    call DBClose(tfid)
 onerror
    print "Error: ", GetLastErrorMessage()
 endonerror

Output

 Target point 432608E and 3725824 N
 Shape `1462' nearest to location (432608,3725824).

See also

DBClose()

DBOpen()

VECQueryNearest()

© PCI Geomatics Enterprises, Inc.®, 2026. All rights reserved.