I have a huge number of points(co-ordinates), from which I am required to draw a polygon in Mapinfo.

This required polygon is a square of 200m size. All I have now is the left side lower end of the polygon.

Is there anyway that I can draw a square of 200m from this point automatically using MapInfo MBX files?

  • If you know the size and the one point of origin for the square why not create that polygon manually, provided this is just a one time exercise. – SNT Apr 10 '12 at 6:16
  • Hi Senthil,My exercise involves drawing 23000 polygons from available 23000 points... – Suresh Bitra Apr 10 '12 at 6:57

What you will need to do is write a MapBasic script something like the following.

Firstly, query your table. If you have co-ordinates stored as numbers in the table, the query will be something like this:

select x_column, y_column from yourTable [where condition] into MyQuery

Otherwise you need something like:

select CentroidX(obj), CentroidY(obj) from yourTable [where condition] into MyQuery

Then you need to iterate over the rows using Fetch statements. Then you can draw a polygon based on that point. The following is based on the Fetch() and Create Object() sections of the Mapinfo manual, and will probably have to be extensively altered to suit your case. In particular you may have to pay attention to co-ordinate systems if your data is not already projected in metres:

Fetch First From MyQuery
Do While Not EOT(MyQuery) 

                  Dim obj_region As Object 
Dim x(5), y(5) As Integer
Dim i As Integer 
x(1) = MyQuery.col1
y(1) = MyQuery.col2
x(2) = x(1) + 200
y(2) = y(1)
x(3) = x(1) + 200
y(3) = y(1) + 200
x(4) = x(1)
y(4) = y(1) + 200
x(5) = x(1)
y(5) = y(1)
' First, create an empty region object 
Create Region Into Variable obj_region 0 

' Now add nodes to populate the object: 
For i = 1 to 5 
Alter Object obj_region Node Add ( x(i), y(i) ) 

' Now store the object in the Sites table: 
Insert Into YourNewTable(Object) Values (obj_region)

    Fetch Next From MyQuery
  • Do remember to set your coordinate system to match the coordinate system of your input coordinates – Peter Horsbøll Møller Apr 10 '12 at 9:21
  • 2
    As you know how many nodes your polygon will have you can create it directly in stead of adding one node at a time and you might also wnat to set the controid to the center of your polygon – Peter Horsbøll Møller Apr 10 '12 at 9:23

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.