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?

  • I look forword to the solution :) . Well I found something that might be useful for you on mapbasic reference guide Chapter 10 page 759 using toolHandler with commandinfo() – kinkajou Oct 17 '11 at 9:35
  • @Kitex Thanks for that. I'm having some problems - it's creating the circle at slightly the wrong size in slightly the wrong place! I've added it to my Github account anyway (github.com/mrchimp/JakesMapbasicToolbars). Feel free to join in! – Mr_Chimp Oct 19 '11 at 15:37

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" 
HelpMsg "Click on map" 
Calling get_map_click 

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.


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.

  • Thanks for the response. I have been re-tasked so probably won't get to look at this til tomorrow now. – Mr_Chimp Oct 17 '11 at 13:14
  • @Kitex - cheers, I knew I'd forgotten something – Hairy Oct 18 '11 at 8:09

Perhaps you can use the MapCAD tool Circle from Center and Radius/Diameter for this. For programmatically retrieving coordinates you can use the CommandInfo() function in MapBasic.

  • Bit expensive just for drawing a circle though! – Mr_Chimp Oct 17 '11 at 14:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.