Hi Mike,
1. The error telling you to save you table before using the Alter table can be
circumwented by saving the table before using the Alter table. You could even do a
check whether it is nessessary to save the table or not (If TableInfo(szTab,
TAB_INFO_EDITED) Then Commit Table szTab End If)
2. The obvious pitfall when altering objects is that you forget to save the altered
object back to the record you read it from. Here is a simple example:
'**************************************************************
Include "MapBasic.def"
Declare Sub OffsetSinglePolygonAndSaveIt
Declare Sub Main
Sub Main
Call OffsetSinglePolygonAndSaveIt
End Sub
Sub OffsetSinglePolygonAndSaveIt
Dim aObj, aRowID As Alias,
nRowID, nPoly, nNode As Integer,
szTab As String,
fX, fY As Float,
oPolygon As Object
szTab = SelectionInfo(SEL_INFO_SELNAME)
Set CoordSys Table szTab
aObj = szTab & ".OBJ"
aRowID = szTab & ".ROWID"
Fetch First From szTab
oPolygon = aObj
nRowID = nRowID
If not ObjectInfo(oPolygon, OBJ_INFO_TYPE) = OBJ_TYPE_REGION Then
Note "Not a polygon!"
Exit Sub
End If
'**Looping thru each section in the polygon
For nPoly = 1 To ObjectInfo(oPolygon, OBJ_INFO_NPOLYGONS)
'**Looping thru each node in the current section of the polygon
'**Note that when looping thru polygons you should not alter the last
node in the object
'**This node is appearently altered with the first
For nNode = 1 To (ObjectInfo(oPolygon, OBJ_INFO_NPOLYGONS + nPoly) - 1)
fX = ObjectNodeX(oPolygon, nPoly, nNode)
fY = ObjectNodeY(oPolygon, nPoly, nNode)
Alter Object oPolygon
Node Set Position nPoly, nNode (fX + 200, fY + 200)
Next
Next 'nPoly
'**Saving the changed object back to the record
Update szTab
Set OBJ = oPolygon
Where ROWID = nRowID
End Sub
'**************************************************************
HTH,
Peter Horsb�ll M�ller
GIS Developer
Geographical Information & IT
COWI A/S
Odensevej 95
DK-5260 Odense S.
Denmark
Tel +45 6311 4900
Direct +45 6311 4908
Mob +45 5156 1045
Fax +45 6311 4949
E-mail [EMAIL PROTECTED]
http://www.cowi.dk
-----Original Message-----
From: Cummings, Mike [mailto:[EMAIL PROTECTED]
Sent: Friday, April 09, 2004 2:43 AM
To: [EMAIL PROTECTED]
Subject: MI-L Problems with nodes in mapbasic
I've been trying to write code to delete nodes basic on certain
criteria. I can't get the "alter object" code to work. None of the
nodes are deleted, even when I remove the criteria and I loop through
all the nodes.
I'm clearly missing something. (Because I can't get the alter table
command to work either.-halt with an error message about having to save
the file.)
Also, if you have a multi-region object: I know you can determine the
number of polygons and the number of nodes for the object. How do you
determine what nodes are with what polygons? I've been looking for a
reference that explains nodes and the related mapbasic codes and haven't
been too successful. Does anyone have a good reference?
---------------------------------------------------------------------
List hosting provided by Directions Magazine | www.directionsmag.com |
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
Message number: 11345