MapInfo Pro Developers User Group

Welcome to the MapInfo Pro Developers community!  We are a group dedicated to the discussion and understanding of MapBasic and .Net MapInfoPro AddIn development. Bring your questions and ideas here. This group includes several members of the Pro development team from around the world.

Please feel free to start a discussion in the discussion tab or join in a conversation.

Product Information  Ideas Portal  MapInfo Community Downloads

Discussions

Members

Resources

Events

 View Only
  • 1.  Move geometry using MapBasic without selection

    Posted 09-26-2017 13:29

    The "Objects Move" moves a selected object on the map. Is there some other way to move an object not selected first? Like an update statement to reposition and rotate the geometry based on the objects id?



  • 2.  RE: Move geometry using MapBasic without selection

    Employee
    Posted 09-26-2017 09:50

    Hi Hans

    Yes, there are a couple of functions that come to my mind:

    Offset an object using change in X and Y:

    • OffsetXY( object, xoffset, yoffset, units)
    • CartesianOffsetXY( object, xoffset, yoffset, units )
    • SphericalOffsetXY( object, xoffset, yoffset, units )

    Offset an object using angle and distance:

    • Offset( object, angle, distance, units )
    • CartesianOffset( object, angle, distance, units )
    • SphericalOffset( object, angle, distance, units )

    Rotating:

    • RotateAtPoint( object, angle, anchor_point_object )
    • Rotate( object, angle )

     

    All these are functions that take the object as input and returns the altered object. So you can use them directly in an update statement:

    Update MY_TABLE

    Set OBJ = CartesianOffset(OBJ, 45, 250, "m")

     



  • 3.  RE: Move geometry using MapBasic without selection

    Posted 09-26-2017 10:01

    That is exactly what I need. Thanks.



  • 4.  RE: Move geometry using MapBasic without selection

    Employee
    Posted 09-26-2017 10:12

    Cool, sometimes I feel we need a better way to make people aware of the many functions of the MapBasic language. Even I struggle to find the right function or statement from time to time. I know it's there but I just can't seem to remember the exact name of it



  • 5.  RE: Move geometry using MapBasic without selection

    Posted 09-27-2017 03:45

    I tried this (move object 10 meters east), but the sentence is invalid:

    update MY_TABLE set Obj = OffsetXY(obj, 90, 10, "m") where ID=15575

    I get an error about the Id column in the where statement:

    Cannot perform this operation on field ID.

    How can I apply the move or rotate operation to only some objects and not the whole table?



  • 6.  RE: Move geometry using MapBasic without selection

    Posted 09-27-2017 04:41

    I'm sure @Peter Horsbøll Møller? ? will be able to give a better answer, but here are my 2 cents:

    Why not perform a select of the object into a temporary table and then perform the offset?

    Select the object(s) from myTable into myTemp:

    SELECT * FROM myTable WHERE ID = 15575 INTO myTemp

    and then perform the offset on the object(s) in myTemp:

    UPDATE myTemp SET Obj = OffsetXY(obj, 90, 10, "?m")



  • 7.  RE: Move geometry using MapBasic without selection

    Employee
    Posted 09-27-2017 05:02

    That's how I would do it, @Kobi Irom? 

    The Update statement of the MapBasic SQL does only support a very basic condition: A specific RowID:

    Update table Set column = expr [ , column = expr, ...] 

    [ Where RowID = id ]

    where id is the number of a row in the table

    But of course use the NoSelect keyword so that the query doesn't mess with any current selection and the Hide keyword so that the query doesn't show up in the user interface:

    SELECT * FROM myTable WHERE ID = 15575 INTO myTemp NoSelect Hide

    The Hide keyword we recently learned about in the MapInfo Pro Developer group.