[GIS] How to change object image in MapInfo using MapBasic

mapbasicmapinfo

I need to change the image of the objects which are in the Selection Table using MapBasic functions. When I say "Image" I mean point object icon on the map.

Best Answer

Not exactly full of best practice but this code should change the current selection to an image of a fire hydrant. Just set NewSymbol to what ever you want to display. You may want to use MakeSymbol instead of MakeCustomSumbol if by "image" you meant a font symbol rather than an image symbol.

Include "mapbasic.def"

Declare Sub Main

Sub Main

Dim RowNumber as integer
Dim NewObject as object
Dim XCoord as float
Dim YCoord as float
Dim NewSymbol as symbol

' Note no protection to ensure if you have a selection.

' Change this to be the desired symbol.  Must be in MapInfo custom symbol folder. Use MakeSymbol for other symbols.
NewSymbol = MakeCustomSymbol("FIRE2-64.BMP", BLUE, 64, 0)


' set the coordinate system to be the same as the table.
run command  "set map "+ tableinfo(selection, tab_info_coordsys_clause)


'Loop over rows in selection
For RowNumber = 1 To SelectionInfo(sel_info_nrows)
    ' Get a row
    fetch rec rownumber from selection
    ' Update point to be new symbol
    XCoord = ObjectGeography(selection.obj, obj_geo_pointx)
    YCoord = ObjectGeography(selection.obj, obj_geo_pointy)
    Create Point Into Variable NewObject (XCoord, YCoord) Symbol NewSymbol
    ' Update row
    Update Selection Set obj = newobject where RowID = RowNumber    
next

End Sub
Related Question