# 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.

Application

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))        {            points.splice(i,1);            i--;        }                if(i+2<points.length-1)        {            if((points[i].Latitude==points[i+2].Latitude) && (points[i].Longitude==points[i+2].Longitude))            {                points.splice(i,2);                i-=2;            }        }    }        if((points[0].Latitude==points[points.length-1].Latitude)&&(points[0].Longitude==points[points.length-1].Longitude))        points.splice(points[points.length-1],1);            return points;}`