[GIS] Drawing a circle of a given area in MapInfo

mapbasicmapinfo

I would like to draw a circle in MapInfo exactly 0.9Ha in area.

I've done it by working out the corresponding radius should be, drawing a circle of arbitrary size, double clicking on it and then entering the radius. Is there a tool to do this?

If there isn't a tool for this then I'm going to make one, so I have another question: how do you programmatically get the geographic coordinates of a mouseclick?

Best Answer

Just sue the CreateCircle method in the MapBasic window, or just put it behind a quick and dirty dialogue with all the maths worked out behind the scene

Create circle in MapBasic

CreateCircle( x, y, radius )  

x is a float value of the circle's center. 
y is a float value of the circle's center. 
radius is a float value, indicating the circle radius. 

As for capturing a mouse click, Read the MapBasic Manual especially "Create ButtonPad statement", but you'd have to write some custom code for this, a bit like this:

Use the CommandInfo() function with the CMD_INFO_X and CMD_INFO_Y parameters and you can retrieve the info from the point you click on

from here, you can bring up a dialogue/code, with which you can then add the createCircle functionality Ex.

Include "mapbasic.def"
Include "icons.def"

Declare Sub Main
Declare Sub get_map_click

Sub Main
  Alter ButtonPad "Tools" 
Add 
Separator 
ToolButton 
Icon MI_ICON_CROSSHAIR 
HelpMsg "Click on map" 
Cursor MI_CURSOR_CROSSHAIR 
DrawMode DM_CUSTOM_POINT 
Calling get_map_click 
Show

End Sub


Sub get_map_click 
    Note "x:" + Round(CommandInfo(CMD_INFO_X), 0.1) + Chr$(10) + "y:" + Round(CommandInfo(CMD_INFO_Y), 0.1) 
    'add code to create a circle to whatever layer you want
End Sub 

You'd have to click the button each time you wanted to capture a point.

EDIT

Please note, I have not written MapBasic code for a couple of three years, so please have a look at the user/reference guide before you commit this to production data or anything silly like that. I am sure this is how you'd do it, but make sure first please.

Related Question