Clean Polygon Data

Many times when performing calculations with polygons it is useful to remove any consecutively matching points and any null displacements that occur between three points in the array of points of a polygon. A null displacement is when you travel from point A to point B and then back to point A. To check if there are consecutively matching points we have to loop through the array of points that make up the polygon and compare consecutive points. If a match is found one of the points are removed from the data array. To check if there are any null displacements we will need to see if the first and third point of a series of three points is equal. If they are we have we will remove the second and third point from the data array.


The algorithm to clean the data of a polygon will take in an array of VELatLongs and will return an array VELatLongs of the same size or less.

function cleanData(points)
for(var i=0;i<points.length-1;i++)
if((points[i].Latitude==points[i+1].Latitude) && (points[i].Longitude==points[i+1].Longitude))

if((points[i].Latitude==points[i+2].Latitude) && (points[i].Longitude==points[i+2].Longitude))


return points;

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s