Alter Object statement - MapBasic - 2023

MapInfo MapBasic Reference

Product type
Software
Portfolio
Locate
Product family
MapInfo
Product
MapInfo > MapBasic
Version
2023
Language
English
Product name
MapBasic
Title
MapInfo MapBasic Reference
First publish date
1985
Last updated
2023-09-12
Published on
2023-09-12T16:32:32.686312

Purpose

Modifies the shape, position, or graphical style of an object. You can issue this statement from the MapBasic window in MapInfo Pro.

Syntax

Alter Object obj
	{ Info object_info_code, new_info_value | 
		Geography object_geo_code , new_geo_value | 
		Node { 
			Add [ Position polygon_num, node_num ] ( x, y ) | 
			Set Position polygon_num, node_num ( x , y ) | 
			Remove Position polygon_num, node_num } } 

obj is an object variable.

object_info_code is an integer code relating to the ObjectInfo() function (e.g., OBJ_INFO_PEN).

new_info_value specifies the new object_info_code attribute to apply (e.g., a new Pen style).

object_geo_code is an integer code relating to the ObjectGeography() function (e.g., OBJ_GEO_POINTX).

new_geo_value specifies the new object_geo_code value to apply (e.g., the new x-coordinate).

polygon_num is a integer value (one or larger), identifying one polygon from a region object or one section from a polyline object.

node_num is a integer value (one or larger), identifying one node from a polyline or polygon.

x, y are x- and y-coordinates of a node.

Description

The Alter Object statement alters the shape, position, or graphical style of an object.

The effect of an Alter Object statement depends on whether the statement includes an Info clause, a Node clause, or a Geography clause. If the statement includes an Info clause, MapBasic alters the object's graphical style (e.g., the object's Pen and Brush styles). If the statement includes a Node clause, MapBasic adds, removes, or repositions a node (this applies only to polyline or region objects). If the statement includes a Geography clause, MapBasic alters a geographical attribute for objects other than polylines and regions (e.g., the x- or y-coordinate of a point object).

Info clause

By issuing an Alter Object statement with an Info clause, you can reset an object's style (e.g., the Pen or Brush). The Info clause lets you modify the same style attributes that you can query through the ObjectInfo() function.

For example, you can determine an object's current Brush style by calling the ObjectInfo() function:

Dim b_fillstyle As Brush
b_fillstyle = ObjectInfo(Selection.obj, OBJ_INFO_BRUSH)

Conversely, the following Alter Object statement allows you to reset the Brush style:

Alter Object obj_variable_name 
	Info OBJ_INFO_BRUSH, b_fillstyle

Note that you use the same code (e.g., OBJ_INFO_BRUSH) in both the ObjectInfo() function and the Alter Object statement.

The table below summarizes the values you can specify in the Info clause to perform various types of style alterations. Note that the obj_info_code values are defined in the standard MapBasic definitions file, MAPBASIC.DEF. Accordingly, your program should Include "MAPBASIC.DEF" if you intend to use the Alter Object...Info statement.

obj_info_code Value ID Result of Alter Object
OBJ_INFO_PEN 2 Resets object's Pen style; new_info_value must be a Pen expression.
OBJ_INFO_SYMBOL 2 Resets a Point object's Symbol style; new_info_value must be a Symbol expression.
OBJ_INFO_BRUSH 3 Resets object's Brush style; new_info_value must be a Brush expression.
OBJ_INFO_SMOOTH 4 Resets a Polyline object's smoothed/unsmoothed setting; new_info_value must be a logical expression.
OBJ_INFO_FRAMEWIN 4 Changes which window is displayed in a layout frame; new_info_value must be an integer window ID.
OBJ_INFO_FRAMETITLE 6 Changes the title of a Frame object; new_info_value must be a string.
OBJ_INFO_TEXTFONT 2 Resets a Text object's Font style; new_info_value must be a Font expression.
OBJ_INFO_TEXTSTRING 3 Changes the text string that comprises a Text object; new_info_value must be a string expression.
OBJ_INFO_TEXTSPACING 4 Changes a Text object's line spacing; new_info_value must be a float value of 1, 1.5, or 2.
OBJ_INFO_TEXTJUSTIFY 5 Changes a Text object's alignment; new_info_value must be 0 for left-justified, 1 for center-justified, or 2 for right-justified.
OBJ_INFO_TEXTARROW 6 Changes a Text object's label line setting; new_info_value must be 0 for no line, 1 for simple line, or 2 for a line with an arrow.

Geography clause

By issuing an Alter Object statement with a Geography clause, you can alter an object's geographical coordinates. The Geography clause applies to all object types except for polylines and regions. To alter the coordinates of a polyline or region object, use the Node clause (described below) instead of the Geography clause.

The Geography clause lets you modify the same attributes that you can query through the ObjectGeography() function. For example, you can obtain a line object's end coordinates by calling the ObjectGeography() function:

Dim o_cable As Object
Dim x, y As Float 
x = ObjectGeography(o_cable, OBJ_GEO_LINEENDX)
y = ObjectGeography(o_cable, OBJ_GEO_LINEENDY) 

Conversely, the following Alter Object statements let you alter the line object's end coordinates:

Alter Object o_cable 
	Geography OBJ_GEO_LINEENDX, x 
Alter Object o_cable
	Geography OBJ_GEO_LINEENDY, y 
Note: You use the same codes (e.g., OBJ_GEO_LINEENDX) in both the ObjectGeography() function and the Alter Object statement.

The table below summarizes the values you can specify in the Geography clause in order to perform various types of geographic alterations. Note that the obj_geo_code values are defined in the standard MapBasic definitions file, MAPBASIC.DEF. Your program should Include "MAPBASIC.DEF" if you intend to use the Alter Object...Geography statement.

obj_geo_code Value ID Result of Alter Object
OBJ_GEO_MINX 1 Alters object's minimum bounding rectangle.
OBJ_GEO_MINY 2 Alters object's MBR.
OBJ_GEO_MAXX 3 Alters object's MBR; does not apply to Point objects.
OBJ_GEO_MAXY 4 Alters object's MBR; does not apply to Point objects.
OBJ_GEO_ARCBEGANGLE 5 Alters beginning angle of an Arc object.
OBJ_GEO_ARCENDANGLE 6 Alters ending angle of an Arc object.
OBJ_GEO_LINEBEGX 1 Alters a Line object's starting node.
OBJ_GEO_LINEBEGY 2 Alters a Line object's starting node.
OBJ_GEO_LINEENDX 3 Alters a Line object's ending node.
OBJ_GEO_LINEENDY 4 Alters a Line object's ending node.
OBJ_GEO_POINTX 1 Alters a Point object's x coordinate.
OBJ_GEO_POINTY 2 Alters a Point object's y coordinate.
OBJ_GEO_ROUNDRADIUS 5 Alters the diameter of the circle that defines the rounded corner of a Rounded Rectangle object.
OBJ_GEO_TEXTLINEX 5 Alters x coordinate of the end of a Text object's label line.
OBJ_GEO_TEXTLINEY 6 Alters y coordinate of the end of a Text object's label line.
OBJ_GEO_TEXTANGLE 7 Alters rotation angle of a Text object.

Node clause

By issuing an Alter Object statement with a Node clause, you can add, remove, or reposition nodes in a polyline or region object.

If the Node clause includes an Add sub-clause, the Alter Object statement adds a node to the object. If the Node clause includes a Remove sub-clause, the statement removes a node. If the Node clause includes a Set Position sub-clause, the statement repositions a node.

The Alter Object statement's Node clause is often used in conjunction with the Create Pline statement and the Create Region statement. Create statements allow you to create new polyline and region objects. However, Create statements are somewhat restrictive, because they force you to state at compile time the number of nodes that will comprise the object. In some situations, you may not know how many nodes should go into an object until run-time.

If your program will not know until run-time how many nodes should comprise an object, you can issue a Create Pline statement or a Create Region statement which creates an "empty" object (an object with zero nodes). Your program can then issue an appropriate number of Alter Object...Node Add statements, to add nodes as needed.

Within the Node clause, the Position sub-clause includes two parameters, polygon_num and node_num, that let you specify exactly which node you want to reposition or remove. The Position sub-clause is optional when you are adding a node. The polygon_num and node_num parameters should always be 1 (one) or greater.

The polygon_num parameter specifies which polygon in a multiple-polygon region (or which section in a multiple-section polyline) should be modified.

Region Centroids

The Centroid of a Region can be set by using the Alter Object command with the syntax noted below:

Alter Object Obj Geography OBJ_GEO_CENTROID, PointObj

Note that PointObj is a point object. This differs from other values input by Alter Object Geography, which are all scalars. A point is needed in this instance because we need two values which define a point. The Point that is input is checked to make sure it is a valid Centroid (for example, it is inside the region). If the Obj is not a region, or if PointObj is not a point object, or if the point is not a valid centroid, then an error is returned.

An easy way to center an X and Y value for a centroid is as follows:

Alter Object Obj Geography OBJ_GEO_CENTROID, CreatePoint(X, Y)

The user can also query the centroid by using the ObjectGeography() function as follows:

PointObj = ObjectGeography(Obj, OBJ_GEO_CENTROID)

There are other ways to get the Centroid, including the Centroid() function, CentroidX() function, and CentroidY() function.

OBJ_GEO_CENTROID is defined in MAPBASIC.DEF.

Multipoint Objects and Collections

The Alter Object statement supports the following object types.

  • Multipoint: sets a Multipoint symbol as shown in the following:
	Alter Object obj_variable_mpoint 
		Info OBJ_INFO_SYMBOL, NewSymbol
  • Collection: By issuing an Alter Object statement with an Info clause, you can reset collection parts (Region, Polyline or Multipoint) inside the collection object. The Info clause allows you to modify the same attributes that you can query through the ObjectInfo() function. For example, you can determine a collection object's region part by calling the ObjectInfo() function:
	Dim ObjRegion As Object
	ObjRegion = ObjectInfo(Selection.obj, OBJ_INFO_REGION)

Also, the following Alter Object statement allows you to reset the region part of a collection object:

	Alter Object obj_variable_name 
	Info OBJ_INFO_REGION, ObjRegion
Note: You use the same code (e.g., OBJ_INFO_REGION) in both the ObjectInfo() function and the Alter Object statement.

The Alter Object statement inserts and deletes nodes to/from Multipoint objects.

	Alter Object obj Node statement

To insert nodes within a Multipoint object:

Dim mpoint_obj as object
Create Multipoint Into Variable mpoint_obj 0
Alter Object mpoint_obj Node Add (0,1)
Alter Object mpoint_obj Node Add (2,1)
Note: Nodes for Multipoint are always added at the end.

To delete nodes from a Multipoint object:

Alter Object mpoint_obj Node Remove Position polygon_num, node_num

mpoint_obj is a Multipoint object variable.

polygon_num is ignored for Multipoint, it is advisable to set it to 1.

node_num is the number of a node to be removed.

To set nodes inside a Multipoint object:

Alter Object mpoint_obj Node Set Position polygon_num, node_num (x,y)

mpoint_obj is a Multipoint object variable.

polygon_num is ignored for Multipoint, it is advisable to set it to 1.

node_num is the number of a node to be changed.

x and y are the new coordinates of the node node_num.

Example

Dim myobj As Object, i As Integer
Create Region Into Variable myobj 0
For i = 1 to 10
	Alter Object myobj
		Node Add (Rnd(1) * 100, Rnd(1) * 100)
	Next 
Note: After using the Alter Object statement to modify an object, use an Insert statement or an Update statement to store the object in a table.

See Also:

Create Pline statement, Create Region statement, Insert statement, ObjectGeography() function, ObjectInfo() function, Update statement