Polygonizing a Non-Topological Vector Data Set / Centroid Calculation using MIGS and MapInfo


Scope
This lab covers issues dealing with polygonizing a non-topological vector data set, creating polygon statistics and analyzing results within MIGS and MapInfo software packages.

Software
Vector Creation / Statistics MIGS
Desktop Mapping MapInfo
Operating System Windows NT

Data Inputs
Region of Interest na
Projection na

Method
The flowchart illustrates the process involved of this lab, in Gane-Sarson notation.

Vector Polygon Statistics

Below is a table of polygon statistics generated from the MIGS system (POLYSTAT), on the created polygon.
# ID Perim Area Centx Centy
1 1 8.559946 3.142901 -3.414283 1.603591
2 2 12.105588 6.285797 -0.907134 -1.739276
3 3 8.559946 3.142901 -2.578567 2.439307
4 4 6.563804 1.571450 -3.414283 -4.664283
5 5 13.574244 9.428700 -2.857139 -2.296420
6 6 6.563804 1.571450 -2.578567 -5.082142
7 7 6.052795 1.571450 0.764299 -5.082142
8 8 6.052793 1.571449 -0.489276 -4.664283
9 9 8.559942 3.142898 -0.071417 -3.410709
10 10 8.559944 3.142899 -0.071417 -0.067843
11 11 6.563804 1.571450 1.182157 1.603591
12 12 11.436496 3.142900 1.182157 -0.903559
13 13 8.559944 3.142899 -0.071417 1.603591
14 14 6.563804 1.571450 1.600016 2.439307
15 15 11.436496 3.142900 1.600016 -2.574992

Below is a table of polygon statistics as generated by MapInfo using the following commands:

update table tri2 set perim=perimeter(obj,"ft");
update table tri2 set perim=area(obj,"sq ft");

mapbasic set coordsys table tri2

update table tri2 set centx=CentroidX(obj);
update table tri2 set centy=CentroidY(obj);
   
ID Perim Area CentX CentY
1 8.56 3.14 -0.90 2.02
2 9.99 6.29 -0.40 -0.90
3 8.56 3.14 -0.90 2.02
4 6.56 1.57 -0.90 -0.90
5 9.99 9.43 -0.90 -0.90
6 6.56 1.57 -0.90 -0.90
7 6.05 1.57 0.76 -0.90
8 6.05 1.57 -0.40 -0.90
9 8.56 3.14 0.14 -0.90
10 8.56 3.14 0.14 -0.40
11 6.56 1.57 1.39 2.02
12 9.99 3.14 1.39 -0.90
13 8.56 3.14 0.14 2.02
14 6.56 1.57 1.39 2.02
15 9.99 3.14 1.39 -0.90

Analysis

When comparing the tabular values to those generated by MapInfo (tables above), as well as the printed map (attached), it is obvious that discrepancies exist between the centroids generated by each respective application. It appears that MapInfo calculates the centroid of the minimum-bounding rectangle of the object when performing such statistics. It also appears that the MapInfo procedure does not handle topology correctly, as converted regions and their subsequent centroids are not indicative of the original intended topology, such as that processed by MIGS.

The formula below calculates the minimum-bounding rectangle of a polygon, followed by a sub routine, which builds a polygon structure from a given MBR, written in Perl language:

sub getMBR {
  my @polygonVertices = @_;
  my $minx = 0;
  my $miny = 0;
  my $maxx = 0;
  my $maxy = 0;

  if (isEvenXYPairs(@polygonVertices) == 1) {
    return "Corrupt inputs, must be even numbered xy vertices";
  }

  if (isPolygonClosed(@polygonVertices) == 1)  {
    return "Corrupt inputs, not a closed polygon";
  }

  for(my $i = 0; $i < (scalar(@polygonVertices) / 2 + 2); $i = $i + 2) {
    # initialize bounding box vals
    $minx = $polygonVertices[$i] if $i == 0;
    $miny = $polygonVertices[$i+1] if $i == 0;
    $maxx = $polygonVertices[$i] if $i == 0;
    $maxy = $polygonVertices[$i+1] if $i == 0;

    # test and set MBR
    $maxx = $polygonVertices[$i] if $polygonVertices[$i] > $maxx;
    $minx = $polygonVertices[$i] if $polygonVertices[$i] < $minx;
    $maxy = $polygonVertices[$i+1] if $polygonVertices[$i+1] > $maxy;
    $miny = $polygonVertices[$i+1] if $polygonVertices[$i+1] < $miny;
  }
  return "$minx,$miny,$maxx,$maxy";
}

sub getPolygonFromMBR {
  my ($minx, $miny, $maxx, $maxy) = split /,/, $_[0];
  my @polyOut = ($minx, $miny, $minx, $maxy, $maxx, $maxy, $maxx, $miny, $minx, $miny);
  my $str  = "$minx,$miny,$minx,$maxy,$maxx,$maxy,$maxx,$miny,$minx,$miny";
  return $str;
}
   
..and an implementation script, which calculates the centroid of a polygon by its vertices and by its minimum bounding rectangle:
my @polygon = (1, 1, 4, 2, 4, 5, 1, 6, 1, 1);

my @poly2 = split /,/, getPolygonFromMBR(getMBR(@polygon));

print getPolygonCentroidTriangular(@poly2) . "\n";

print getPolygonCentroidTriangular(@polygon) . "\n";
   
..which produces the following results:
original polygon: 2.5,3.5
polygon by MBR: 2.375,3.5
   
When testing the formula against a concave polygon, the following output is produced on the polygon:
my @polygon = (1, 1, 1, 5, 3, 3, 5, 4, 4, 1, 1, 1);

original polygon: 3,3
polygon by MBR: 2.85964912280702,2.59649122807018
   

As a result, it appears that MapInfo calculates centroids from derived minimum bounding rectangle calculations, and it also appears that regions, stored as one record in MapInfo, which are calculated in MapInfo may or may not produce correct topological results. MapInfo, by definition does not recognize topology in the manner of ESRI ARC / INFO type of software. That is, it is a desktop mapping software product, compared to the more analytical, geoprocessing heavy ESRI suite of software.

In conclusion, one should be aware of a given GIS software package and its capabilities as well as strengths and weaknesses, as your mileage may vary with regard to performance and processing results.

The library, with functions shown above, is available for download



Analytical and Computer Cartography Home