|
Hi,
If you are using MapInfo/MapBasic 8.0 or 8.5 there is a statement that
will help you a lot.
Nearest [ N | All ]
From { Table fromtable | Variable fromvar } To totable Into intotable [ Type { Spherical | Cartesian }] [ Ignore [ Contains ] [ Min min_value ] [ Max max_value ] Units unitname ] [ Data clause ] It can be used in this way:
...
sAsset_ID = ... 'should be
assigned some value
'**Creating a temp table to store the results of the Nearest
statement
Create Table "OUTPUT___TEMP"
(LCC_MAP_REF Char(100)) 'the size
should fit the size of the column LCC_MAP_REF
Create Map
For OUTPUT___TEMP
CoordSys Table tblWaterLinesTemp
'**Finding the Water line
Select * >From tblWaterLinesTemp Where ASSET_ID = sAsset_ID Into TBL__TEMP NoSelect
'**Making sure a waterline was selected If TableInfo(TBL__TEMP, TAB_INFO_NROWS) > 0 Then
'**Fetching the object from the water line Fetch First >From TBL__TEMP oTemp = TBL__TEMP.OBJ
'**Finding the nearest Map Reference to the water line Nearest 1
From Variable oTemp
To TBLMAPREF
Into OUTPUT___TEMP
Type Cartesian
Data LCC_MAP_REF =
LCC_MAP_REF
'**Reading the Map Reference ID from the nearest Map
Reference
Fetch First From TBLTEMP
sMapReference =
TBLTEMP.LCC_MAP_REF
Else
Note "No water line with the asset ID " &
aAsset_ID & " found!"
End if
If you don't have
MapInfo 8.0/8.5 I think you need to insert some Fetch statement in your current
code, like this:
...
'**Fetching the record from
TBLWATERLINESTEMP and assigning the ID to a variable
Fetch First From
TBLWATERLINESTEMP
sAsset_ID =
TBLWATERLINESTEMP.ASSET_ID 'should be assigned some
value
'**Note: NoSelect speeds thing up and doesn't highlight the selection Select * From tblWaterLinesTemp Where ASSET_ID = sAsset_ID Into TBL__TEMP NoSelect
'**Note let's make sure we found one If TableInfo(TBL__TEMP, TAB_INFO_NROWS) > 0 Then
'**Note: Fetching the object from the water line Fetch First From TBL__TEMP oTemp = TBL__TEMP.OBJ
'Find map reference
str_Map_Reference = "" For
y = 1 to 50000 Step 1
o_buff = Buffer(oTemp, 20, y,
"m") Select * from tblMapRef '**Note: Here you were comparing the tblTemp.OBj to the oBuff, not the tblMapRef.Obj !! Where Obj intersects o_buff into tblMapRefTemp NoSelect
If
(TableInfo(tblMapRefTemp, TAB_INFO_NROWS) > 0)
Then
'This will be the closest Map Reference Grid object closest to the
geometry
str_Map_Reference =
tblMapRefTemp.LCC_Map_Ref
Exit For End
If Close
Table tblMapRefTemp Next Else
Note "No water line with the asset ID "
& aAsset_ID & " found!"
End
if HTH,
Peter Horsbøll Møller From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Hayden Fisher Sent: Thursday, October 12, 2006 4:07 AM To: [email protected] Subject: [MI-L] Find closest region using buffer Hi All, A little help in this area would be
greatly appreciated. I am trying to find the closest region to a line or point,
the line or point may lie within or outside the region. I have used the buffer
function to search out from the line or point. Have done this code for lines,
however doesnt seem to pick anything up. Run Command("Select * From
tblWaterLinesTemp Where Asset_ID = " + Chr$(34) + tblWaterLinesTemp.Asset_ID +
Chr$(34) + " Into tblTemp")
'Find map
reference str_Map_Reference =
"" For y = 1 to 50000 Step
1
o_buff = Buffer(tblTemp.obj,20,y,"m")
Select * from tblMapRef Where tblTemp.Obj intersects o_buff into
tblMapRefTemp
If (TableInfo(tblMapRefTemp, TAB_INFO_NROWS) > 0)
Then
'This will be the closest Map Reference Grid object closest to the
geometry
str_Map_Reference = tblMapRefTemp.LCC_Map_Ref
Exit For
End If
Close Table tblMapRefTemp Next Regards, Hayden
Fisher |
_______________________________________________ MapInfo-L mailing list [email protected] http://www.directionsmag.com/mailman/listinfo/mapinfo-l
