@Override public void run(){
  amIActive=true;
  String inputFile;
  String outputFile;
  double x, y;
  int progress;
  int i, j, k;
  int featureNum, numFeatures;
  int filterSize, halfFilterSize;
  double[][] geometry;
  int numPoints, numParts, part, startingPointInPart, endingPointInPart;
  int numPointsInFilter;
  ShapeType shapeType;
  ShapeFileRecord outputRecord;
  double sumX, sumY;
  if (args.length <= 0) {
    showFeedback("Plugin parameters have not been set.");
    return;
  }
  inputFile=args[0];
  outputFile=args[1];
  filterSize=Integer.parseInt(args[2]);
  if (filterSize < 3) {
    filterSize=3;
  }
  if (filterSize % 2 == 0) {
    showFeedback("The filter size must be an odd number. The specified value " + "has been incremented by one.");
    filterSize++;
  }
  halfFilterSize=(int)Math.floor(filterSize / 2.0);
  if ((inputFile == null) || (outputFile == null)) {
    showFeedback("One or more of the input parameters have not been set properly.");
    return;
  }
  try {
    ShapeFile input=new ShapeFile(inputFile);
    shapeType=input.getShapeType();
    if (shapeType.getBaseType() != ShapeType.POLYLINE && shapeType.getBaseType() != ShapeType.POLYGON) {
      showFeedback("This tool only works with shapefiles of a polyline or polygon base shape type.");
      return;
    }
    ShapeFile output=new ShapeFile(outputFile,shapeType);
    FileUtilities.copyFile(new File(input.getDatabaseFile()),new File(output.getDatabaseFile()));
    output.setProjectionStringFromOtherShapefile(input);
    numFeatures=input.getNumberOfRecords();
    featureNum=0;
    for (    ShapeFileRecord record : input.records) {
      featureNum++;
      PointsList points=new PointsList();
      geometry=getXYFromShapefileRecord(record);
      numPoints=geometry.length;
      numParts=partData.length;
      for (part=0; part < numParts; part++) {
        startingPointInPart=partData[part];
        if (part < numParts - 1) {
          endingPointInPart=partData[part + 1];
        }
 else {
          endingPointInPart=numPoints;
        }
        if (geometry[startingPointInPart][0] == geometry[endingPointInPart - 1][0] && geometry[startingPointInPart][1] == geometry[endingPointInPart - 1][1]) {
          for (i=startingPointInPart; i < endingPointInPart; i++) {
            numPointsInFilter=0;
            sumX=0;
            sumY=0;
            for (j=i - halfFilterSize; j <= i + halfFilterSize; j++) {
              k=j;
              if (k < startingPointInPart) {
                k=endingPointInPart + k - 1;
              }
              if (k >= endingPointInPart) {
                k=startingPointInPart + (k - endingPointInPart) + 1;
              }
              if (k >= startingPointInPart && k < endingPointInPart) {
                numPointsInFilter++;
                sumX+=geometry[k][0];
                sumY+=geometry[k][1];
              }
            }
            x=sumX / numPointsInFilter;
            y=sumY / numPointsInFilter;
            points.addPoint(x,y);
          }
        }
 else {
          for (i=startingPointInPart; i < endingPointInPart; i++) {
            numPointsInFilter=0;
            sumX=0;
            sumY=0;
            for (j=i - halfFilterSize; j <= i + halfFilterSize; j++) {
              if (j >= startingPointInPart && j < endingPointInPart) {
                numPointsInFilter++;
                sumX+=geometry[j][0];
                sumY+=geometry[j][1];
              }
            }
            x=sumX / numPointsInFilter;
            y=sumY / numPointsInFilter;
            points.addPoint(x,y);
          }
        }
      }
switch (shapeType) {
case POLYLINE:
        PolyLine line=new PolyLine(partData,points.getPointsArray());
      output.addRecord(line);
    break;
case POLYLINEZ:
  PolyLineZ polyLineZ=(PolyLineZ)(record.getGeometry());
PolyLineZ linez=new PolyLineZ(partData,points.getPointsArray(),polyLineZ.getzArray(),polyLineZ.getmArray());
output.addRecord(linez);
break;
case POLYLINEM:
PolyLineM polyLineM=(PolyLineM)(record.getGeometry());
PolyLineM linem=new PolyLineM(partData,points.getPointsArray(),polyLineM.getmArray());
output.addRecord(linem);
break;
case POLYGON:
Polygon poly=new Polygon(partData,points.getPointsArray());
output.addRecord(poly);
break;
case POLYGONZ:
PolygonZ polygonZ=(PolygonZ)(record.getGeometry());
PolygonZ polyz=new PolygonZ(partData,points.getPointsArray(),polygonZ.getzArray(),polygonZ.getmArray());
output.addRecord(polyz);
break;
case POLYGONM:
PolygonM polygonM=(PolygonM)(record.getGeometry());
PolygonM polym=new PolygonM(partData,points.getPointsArray(),polygonM.getmArray());
output.addRecord(polym);
break;
}
if (cancelOp) {
cancelOperation();
return;
}
progress=(int)(featureNum * 100.0 / numFeatures);
updateProgress(progress);
}
output.write();
returnData(outputFile);
}
 catch (OutOfMemoryError oe) {
myHost.showFeedback("An out-of-memory error has occurred during operation.");
}
catch (Exception e) {
myHost.showFeedback("An error has occurred during operation. See log file for details.");
myHost.logException("Error in " + getDescriptiveName(),e);
}
 finally {
updateProgress("Progress: ",0);
amIActive=false;
myHost.pluginComplete();
}
}

@ Override public void run ( ) { amIActive = true ; String inputFile ; String outputFile ; double x , y ; int progress ; int i , j , k ; int featureNum , numFeatures ; int filterSize , halfFilterSize ; double [ ] [ ] geometry ; int numPoints , numParts , part , startingPointInPart , endingPointInPart ; int numPointsInFilter ; ShapeType shapeType ; ShapeFileRecord outputRecord ; double sumX , sumY ; if ( args . length <= 0 ) { showFeedback ( "Plugin parameters have not been set." ) ; return ; } inputFile = args [ 0 ] ; outputFile = args [ 1 ] ; filterSize = Integer . parseInt ( args [ 2 ] ) ; if ( filterSize < 3 ) { filterSize = 3 ; } if ( filterSize % 2 == 0 ) { showFeedback ( "The filter size must be an odd number. The specified value " + "has been incremented by one." ) ; filterSize ++ ; } halfFilterSize = ( int ) Math . floor ( filterSize / 2.0 ) ; if ( ( inputFile == null ) || ( outputFile == null ) ) { showFeedback ( "One or more of the input parameters have not been set properly." ) ; return ; } try { ShapeFile input = new ShapeFile ( inputFile ) ; shapeType = input . getShapeType ( ) ; if ( shapeType . getBaseType ( ) != ShapeType . POLYLINE && shapeType . getBaseType ( ) != ShapeType . POLYGON ) { showFeedback ( "This tool only works with shapefiles of a polyline or polygon base shape type." ) ; return ; } ShapeFile output = new ShapeFile ( outputFile , shapeType ) ; FileUtilities . copyFile ( new File ( input . getDatabaseFile ( ) ) , new File ( output . getDatabaseFile ( ) ) ) ; output . setProjectionStringFromOtherShapefile ( input ) ; numFeatures = input . getNumberOfRecords ( ) ; featureNum = 0 ; for ( ShapeFileRecord record : input . records ) { featureNum ++ ; PointsList points = new PointsList ( ) ; geometry = getXYFromShapefileRecord ( record ) ; numPoints = geometry . length ; numParts = partData . length ; for ( part = 0 ; part < numParts ; part ++ ) { startingPointInPart = partData [ part ] ; if ( part < numParts - 1 ) { endingPointInPart = partData [ part + 1 ] ; } else { endingPointInPart = numPoints ; } if ( geometry [ startingPointInPart ] [ 0 ] == geometry [ endingPointInPart - 1 ] [ 0 ] && geometry [ startingPointInPart ] [ 1 ] == geometry [ endingPointInPart - 1 ] [ 1 ] ) { for ( i = startingPointInPart ; i < endingPointInPart ; i ++ ) { numPointsInFilter = 0 ; sumX = 0 ; sumY = 0 ; for ( j = i - halfFilterSize ; j <= i + halfFilterSize ; j ++ ) { k = j ; if ( k < startingPointInPart ) { k = endingPointInPart + k - 1 ; } if ( k >= endingPointInPart ) { k = startingPointInPart + ( k - endingPointInPart ) + 1 ; } if ( k >= startingPointInPart && k < endingPointInPart ) { numPointsInFilter ++ ; sumX += geometry [ k ] [ 0 ] ; sumY += geometry [ k ] [ 1 ] ; } } x = sumX / numPointsInFilter ; y = sumY / numPointsInFilter ; points . addPoint ( x , y ) ; } } else { for ( i = startingPointInPart ; i < endingPointInPart ; i ++ ) { numPointsInFilter = 0 ; sumX = 0 ; sumY = 0 ; for ( j = i - halfFilterSize ; j <= i + halfFilterSize ; j ++ ) { if ( j >= startingPointInPart && j < endingPointInPart ) { numPointsInFilter ++ ; sumX += geometry [ j ] [ 0 ] ; sumY += geometry [ j ] [ 1 ] ; } } x = sumX / numPointsInFilter ; y = sumY / numPointsInFilter ; points . addPoint ( x , y ) ; } } } switch ( shapeType ) { case POLYLINE : PolyLine line = new PolyLine ( partData , points . getPointsArray ( ) ) ; output . addRecord ( line ) ; break ; case POLYLINEZ : PolyLineZ polyLineZ = ( PolyLineZ ) ( record . getGeometry ( ) ) ; PolyLineZ linez = new PolyLineZ ( partData , points . getPointsArray ( ) , polyLineZ . getzArray ( ) , polyLineZ . getmArray ( ) ) ; output . addRecord ( linez ) ; break ; case POLYLINEM : PolyLineM polyLineM = ( PolyLineM ) ( record . getGeometry ( ) ) ; PolyLineM linem = new PolyLineM ( partData , points . getPointsArray ( ) , polyLineM . getmArray ( ) ) ; output . addRecord ( linem ) ; break ; case POLYGON : Polygon poly = new Polygon ( partData , points . getPointsArray ( ) ) ; output . addRecord ( poly ) ; break ; case POLYGONZ : PolygonZ polygonZ = ( PolygonZ ) ( record . getGeometry ( ) ) ; PolygonZ polyz = new PolygonZ ( partData , points . getPointsArray ( ) , polygonZ . getzArray ( ) , polygonZ . getmArray ( ) ) ; output . addRecord ( polyz ) ; break ; case POLYGONM : PolygonM polygonM = ( PolygonM ) ( record . getGeometry ( ) ) ; PolygonM polym = new PolygonM ( partData , points . getPointsArray ( ) , polygonM . getmArray ( ) ) ; output . addRecord ( polym ) ; break ; } if ( cancelOp ) { cancelOperation ( ) ; return ; } progress = ( int ) ( featureNum * 100.0 / numFeatures ) ; updateProgress ( progress ) ; } output . write ( ) ; returnData ( outputFile ) ; } catch ( OutOfMemoryError oe ) { myHost . showFeedback ( "An out-of-memory error has occurred during operation." ) ; } catch ( Exception e ) { myHost . showFeedback ( "An error has occurred during operation. See log file for details." ) ; myHost . logException ( "Error in " + getDescriptiveName ( ) , e ) ; } finally { updateProgress ( "Progress: " , 0 ) ; amIActive = false ; myHost . pluginComplete ( ) ; } }
used to execute this plugin tool .
