Examples of CentroidPoint


Examples of org.geotools.geometry.iso.util.algorithmND.CentroidPoint

 
    // Point: the point itself
    // MultiPoint: the average of the contained points
    if (this instanceof PointImpl ||
      this instanceof MultiPointImpl) {
      CentroidPoint cp = new CentroidPoint(this.crs);
      cp.add(this);
      return cp.getCentroid();
    } else
     
    // CurveBoundary: the average of start and end point
    if (this instanceof CurveBoundaryImpl) {
      CentroidPoint cp = new CentroidPoint(this.crs);
      cp.add(((CurveBoundaryImpl)this).getStartPoint());
      cp.add(((CurveBoundaryImpl)this).getEndPoint());
      return cp.getCentroid();
     
    } else
    // Curve: the average of the weighted line segments
    // MultiCurve: the average of the weighted line segments of all contained curves
    // Ring: the average of the weighted line segments of the contained curves
    if (this instanceof CurveImpl ||
      this instanceof MultiCurveImpl ||
      this instanceof RingImpl) {
      CentroidLine cl = new CentroidLine(this.crs);
      cl.add(this);
      return cl.getCentroid();
    } else
     
    // SurfaceBoundary: the average of the weighted line segments of all curves of the exterior and interior rings
    if (this instanceof SurfaceBoundaryImpl) {
        CentroidLine cl = new CentroidLine(this.crs);
        cl.add(((SurfaceBoundaryImpl)this).getExterior());
        Iterator<Ring> interiors = ((SurfaceBoundaryImpl)this).getInteriors().iterator();
        while (interiors.hasNext()) {
          cl.add((GeometryImpl) interiors.next());
        }
        return cl.getCentroid();
         
    } else
     
    // Surface: the average of the surface (considers holes)
    // MultiSurface: the average of all contained surfaces (considers holes)
    if (this instanceof SurfaceImpl ||
      this instanceof MultiSurfaceImpl) {
      CentroidArea2D ca = new CentroidArea2D(this.crs);
      ca.add(this);
      return ca.getCentroid();
         
    }
   
    // Missing: CompositePoint, CompositeCurve, CompositeSurface

    // - MultiPrimitive
    // The ISO 19107 specs state that the centroid of a colleciton of primitives
    // should only take into consideration the primitives with the largest
    // dimension (ie: if there are points, lines and polygons, it only considers
    // the polygons).
    if (this instanceof MultiPrimitiveImpl) {
      // First figure out what type of primtives should be considered in this
      // multiprimitive
      int maxD = this.getDimension(null);
     
      // get the centroid point of each element in this multiprimitive that matches
      // the maxD dimension and return the average of the centroid points
      CentroidPoint cp = new CentroidPoint(this.crs);
      Set<? extends Primitive> elems = ((MultiPrimitiveImpl)this).getElements();
      Iterator<? extends Primitive> iter = elems.iterator();
      while (iter.hasNext()) {
        Geometry prim = iter.next();
        if (prim.getDimension(null) == maxD) {
          cp.add(new PointImpl(prim.getCentroid()));
        }
      }
     
      // return the average of the centroid points
      return cp.getCentroid();
     
    }
 
    Assert.isTrue(false, "The centroid operation is not defined for this geometry object");
    return null;
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.