Hi Terry,
"Add Column "FacMast" (Zone) From BusZoner Set To ZoneNumber Where Contains"
Add Column doesn't add a column. It is the way of saying "Where an object from
BusZoner Contains an object from FacMast, fill in the values from the
ZoneNumber column into the Zone column"
Try it like this:
Open Mapbasic window
Goto Menu Table->Update Column
Select the table to update in the first box (FacMast), the column(Zone) in the
second and the table from which you get the values in the third box (BusZoner)
and (ZoneNumber) in the fourth. Then press the button to the right -
connect/merge (I've got a danish version of MI - so I can't tell the excact
name)
Then select the second method to merge the tables and in the drop-down use
"Contains"
Then watch the MB-window ;-)
Don't be nervous - you can make a rollback table if it's wrong ;-)
BTW, note the "Else" part in my suggestion. Wouldn't you like move objects back
to the origin if the user presses 'No'? If the user presses 'No' objects are
moved but not updated in the table. Next time, however, all columns are updated
if the user presses 'Yes' including those that the user thought would not...
And questions 2&3: Well, it is faster. And a set coordinates in your table is
connected to your object. If it isn't moved, an update won't harm it. And if it
is moved, it has to be updated.
You could say that the object already knows where it is, and this piece of
information is only displayed to you in a map. Then if you want the coordinates
displayed then the table should always show you the right pair - also if it's
moved.
HTH
Venligst/regards
Søren Breddam
Stevns Kommune - www.stevns.dk
Vallø-Stevns fusion:
www.valloe-stevns.dk
* Tlf.: 5656 1891
* GSM.: 2895 3034
-----Oprindelig meddelelse-----
Fra: Terry McDonnell [mailto:[EMAIL PROTECTED]
Sendt: 16. maj 2006 14:05
Til: Søren Breddam; [EMAIL PROTECTED]
Emne: RE: [MI-L] Moving an object and it gets duplicated (part II)
Hi Søren
Thanks very much for the code and advice. To deal with a simple question first:
Close Window Message ' ??? Wasn't it Close Window Info? And why here, if you're
suspicious - do it in the beginning...
No, I'm closing the message window cos at the top of the save loop I display a
user message:
Print "Saving changes to position(s) of Facility(ies) ..."
and this needs to be closed after update complete. I don't close the Info
window because I haven't automatically opened it. I do so manually when
testing but this isn't a desired feature of the system.
As to why I don't do the update in the clever one-piece SQL you've provided:
1) My skill in using the MB GIS super-set of SQL isn't yet that keen that I
would have even thought of doing it that way
2) As they say "if it ain't broke don't fix it", well the purist in me says "if
it ain't changed don't update it". I'd have assumed that such a block update
of the whole table would be asking for transaction errors to be more likely to
creep in, the more the data changed.
3) I didn't know that doing such a global update would be quicker than doing
such selected update(s) in the loop
4) I don't understand why your SQL adds a column Facmast.Zone when that column
already exists
"Add Column "FacMast" (Zone) From BusZoner"
5) I didn't know that the "contains" clause could be used without its object
params (from Help):
objectA Contains objectB first object contains the centroid of second
object
whereas you have :
"Set To ZoneNumber Where Contains"
It doesn't look viable to me.
6) True, it would obviate a lot of the code, but it's already written, and it
doesn't take an appreciable length of time to run.
All the same I'm intrigued by the succinctness of the code but, because of my
queries 5 and 6 above I'd be very chary of implementing such. Are you sure
it's correct and harmless?
Cheers
Terry
-----Original Message-----
From: Søren Breddam [mailto:[EMAIL PROTECTED]
Sent: 16 May 2006 12:31
To: Terry McDonnell
Subject: Re: [MI-L] Moving an object and it gets duplicated (part II)
Hi Terry,
It's not in your Save Sub the problem is located. However, I wonder why you do
the update in a loop. You could increase your performance and get rid of a lot
of code (all the loop stuff) if you just update your table: It's excactly the
same thing that happens...
****
Sub SAVE_FAC_MAST
OnError Goto OOPS
If ASK( "Save changes to position(s) of Facility(ies)?", "Yes", "No") then
Print "Saving changes to position(s) of Facility(ies) ..."
Set CoordSys Table FacMast
Update FacMast Set YCo_ord=INT( ROUND( CentroidY(Obj), 1)) , XCo_ord=INT(
ROUND( CentroidX(Obj), 1))
Add Column "FacMast" (Zone) From BusZoner Set To ZoneNumber Where Contains
Close Window Message ' ??? Wasn't it Close Window Info? And why here, if you're
suspicious - do it in the beginning...
Set Map Layer "FacMast"
Selectable On
Editable off Label Visibility Zoom( 0, 1) Units "km"
Commit table FacMast
Else
Rollback Table FacMast
End If
Exit Sub
OOPS:
Note "Something went wrong: "+Error$()
Resume Next
End Sub 'SAVE_FAC_MAST
**************
Venligst
Søren Breddam
Stevns Kommune - www.stevns.dk
Vallø-Stevns fusion:
www.valloe-stevns.dk
* Tlf.: 5656 1891
* GSM.: 2895 3034
-----Oprindelig meddelelse-----
Fra: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] vegne af Terry McDonnell
Sendt: 15. maj 2006 17:35
Til: [EMAIL PROTECTED]
Emne: [MI-L] Moving an object and it gets duplicated (part II)
Hello again List
Further to my previous post on this moving-duplication problem, I include the
orig. message, below, plus some more details:
My problem is that I was moving objects around and somehow I ended up with 3
recs the same (one hidden underneath another, such that there only appeared to
be 2). At the time I probably had the Info dialog open, as I was testing my
software's ability to change the lat/long integer fields, according to the x/y
where the object ended up, at Save time. I have not been able to reproduce this
"glitch", nor did I notice when it happened.
Anyone got any ideas how this can happen ?
Thing is, there's no code involved in the moving of the objects; I merely
allow that layer to be editable (thererfore the objects movable).
When the user clicks on "save" I loop through the table, checking if any of the
stored numerical X and Y co-ords are different from those of the graphical
objects and, if they are (showing that the object has moved), setting them to
the new position's X/Y. I also check if an object (a
Facility) has been moved into another zone (another layer of irregular
polygons) and, if so, change the Faciliy's stored Zone.
Andrew Hare, some time back, said he'd had similar duplicate frecs created hen
he had the Info Tool open. When I was testing the rewriting of moved X/Y vals
I had my Info tool open at some time(s) but I don't know if this has any
bearing, and Andrew was inserting data when his problem happened.
Below is the "save" code:
'________________________________________________
Sub SAVE_FAC_MAST
'________________
Dim loObj as Object,
lnZoneNo as SmallInt,
lnNewX, lnNewY as Integer
If ASK( "Save changes to position(s) of Facility(ies)?", "Yes", "No") then
Print "Saving changes to position(s) of Facility(ies) ..."
Fetch first from FacMast
Do while not EOT( FacMast)
loObj = FacMast.Obj
lnNewX = INT( ROUND( CentroidX(
loObj), 1))
lnNewY = INT( ROUND( CentroidY(
loObj), 1))
If lnNewX <> FacMast.XCo_ord
Or lnNewY <> FacMast.YCo_ord then ' If centroid
X/Y different from stored X/Y (E & N)
lnRowID = FacMast.RowID
Set CoordSys Table FacMast
Update FacMast
Set YCo_ord = lnNewY,
XCo_ord = lnNewX
where RowID = lnRowID ' Change the N/E
values to the new Y/X coords in the OBJ
Select ZoneNumber from BusZoner
where loObj within BusZoner.Obj
into csrTemp NOSELECT ' What if
Facility moved over a Zone boundary?
lnZoneNo = csrTemp.ZoneNumber
Close Table csrTemp
If FacMast.Zone <> lnZoneNo then ' .. It HAS
moved to new zone
Update FacMast
Set Zone = lnZoneNo
where RowID = lnRowID ' Store new Zone
# in FacMast
End If
End If
Fetch Next from FacMast
Loop
Close Window Message
Set Map Layer "FacMast"
Selectable On
Editable off Label Visibility Zoom( 0, 1) Units "km"
Commit table FacMast
End if
End Sub
_______________________________________________
MapInfo-L mailing list
[email protected]
http://www.directionsmag.com/mailman/listinfo/mapinfo-l
_______________________________________________
MapInfo-L mailing list
[email protected]
http://www.directionsmag.com/mailman/listinfo/mapinfo-l