RestoreCentro( )

Purpose
Restore the centroid of a region to the position that MI assigns automatically
 
Author Date of code (original) Updated on Date of page (original) Updated on

Jacques Paris

jacques@paris-pc-gis.com

11June2002

11June2002

 
Restrictions on use
This module is distributed under the terms of the Lesser GNU General Public License. Restrictions on the use of this work in a commercial application or derivative work is described in the Lesser GNU General Public License page at: http://www.fsf.org/copyleft/lesser.html
 
Description

RestoreCentro() replaces the existing region centroid by the point that would have been assigned automatically by MI, while respecting all the region characteristics (geography, style and data).

 
External resources
none
 
Declare statement of sub_function. Include in your program. Copy/Paste if needed.
Declare function RestoreCentro (byval obj_in as object, obj_out as object) as logical
 
Returned value(s) (function only)
True if a region. Object with the "new" centroid is obj_out 
 
Other required declare statement(s). Include in your program. Copy/Paste if needed.

 
MapBasic Code. Copy/Paste if needed.

function restorecentro (byval obj_in as object, obj_out as object) as logical

 

dim obj_temp, centro as object

 

if int(objectinfo(obj_in,1)) <> 7 then

   restorecentro=0

   exit function

end if

 

obj_temp=converttopline(obj_in)

obj_temp=converttoregion(obj_temp)

centro=objectgeography(obj_temp,5)

obj_out=obj_in

alter object obj_out geography 5,centro

restorecentro=1

 

end function

 
Availability for download
 
Example

declare function restorecentro (byval obj_in as object, obj_out as object) as logical

declare sub main

 

sub main

 

dim o, o_nu as object

 

o=selection.obj

if selectioninfo(3)<>1 then

   note "Requires a single object selection"

   exit sub

end if

 

if restorecentro(o, o_nu) then

 update selection set obj=o_nu

end if

 

end sub

 

 
Comments
Argument obj_geo_centroid (code 5) is officially available since version 6.5. However, the define existed in mapbasic.def since version 5.5. Waiting for confirmation of operationallity for these earliest versions.
 
See also