[GIS] Creating polygons from points in Mapinfo

geometry-conversionmapbasicmapinfopolygon-creation

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?

Best Answer

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) ) 
Next 

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

    Fetch Next From MyQuery
Loop 
Related Question