org.locationtech.jts.geom.Polygon.getFactory()方法的使用及代码示例

x33g5p2x  于2022-01-26 转载在 其他  
字(9.2k)|赞(0)|评价(0)|浏览(199)

本文整理了Java中org.locationtech.jts.geom.Polygon.getFactory()方法的一些代码示例,展示了Polygon.getFactory()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Polygon.getFactory()方法的具体详情如下:
包路径:org.locationtech.jts.geom.Polygon
类名称:Polygon
方法名:getFactory

Polygon.getFactory介绍

暂无

代码示例

代码示例来源:origin: geoserver/geoserver

/**
 * Crops the coverage to the specified bounds
 *
 * @param coverage
 * @param bounds
 */
public static GridCoverage2D crop(final GridCoverage2D coverage, final Envelope bounds) {
  // checks
  final ReferencedEnvelope cropBounds = new ReferencedEnvelope(bounds);
  final ReferencedEnvelope coverageBounds = new ReferencedEnvelope(coverage.getEnvelope());
  if (cropBounds.contains((org.locationtech.jts.geom.Envelope) coverageBounds)) {
    return coverage;
  }
  Polygon polygon = JTS.toGeometry(cropBounds);
  Geometry roi = polygon.getFactory().createMultiPolygon(new Polygon[] {polygon});
  // perform the crops
  final ParameterValueGroup param = PROCESSOR.getOperation("CoverageCrop").getParameters();
  param.parameter("Source").setValue(coverage);
  param.parameter("Envelope").setValue(bounds);
  param.parameter("ROI").setValue(roi);
  return (GridCoverage2D) PROCESSOR.doOperation(param);
}

代码示例来源:origin: geotools/geotools

public GeometryFactory getFactory() {
  return polygon.getFactory();
}

代码示例来源:origin: geotools/geotools

/**
 * Collects all sub-polygons into the specified geometry and returns them either as a single
 * polygon, or as a multipolygon, shaving off any other lower dimension geometry
 *
 * @param geometry
 * @return
 */
private Geometry collectPolygons(Geometry geometry) {
  if (geometry.isEmpty()) {
    return geometry;
  }
  final List<Polygon> polygons = new ArrayList<Polygon>();
  geometry.apply(
      new GeometryComponentFilter() {
        @Override
        public void filter(Geometry geom) {
          if (geom instanceof Polygon && !geom.isEmpty()) {
            polygons.add((Polygon) geom);
          }
        }
      });
  if (polygons.isEmpty()) {
    return geometry.getFactory().createMultiPolygon(new Polygon[0]);
  } else if (polygons.size() == 1) {
    return polygons.get(0);
  } else {
    Polygon[] array = (Polygon[]) polygons.toArray(new Polygon[polygons.size()]);
    return array[0].getFactory().createMultiPolygon(array);
  }
}

代码示例来源:origin: geotools/geotools

buffer.append("MDSYS.SDO_ORDINATE_ARRAY(");
CoordinateSequenceFactory fact = polygon.getFactory().getCoordinateSequenceFactory();
CoordinateSequence exterior = polygon.getExteriorRing().getCoordinateSequence();
CoordinateSequence coordSeq = SDO.counterClockWise(fact, exterior);

代码示例来源:origin: geotools/geotools

return poly.getFactory().createMultiPolygon(polys);
  Polygon[] polys = new Polygon[1];
  polys[0] = (Polygon) clip;
  return poly.getFactory().createMultiPolygon(polys);
return poly.getFactory().createMultiPolygon(polys.toArray(new Polygon[1]));

代码示例来源:origin: geotools/geotools

/**
 * Clips a polygon using the Liang-Barsky helper routine. Does not generate, in general, valid
 * polygons (but still does generate polygons good enough for rendering)
 *
 * @param polygon
 * @return
 */
private Geometry clipPolygon(Polygon polygon) {
  final GeometryFactory gf = polygon.getFactory();
  LinearRing exterior = (LinearRing) polygon.getExteriorRing();
  LinearRing shell = polygonClip(exterior);
  shell = cleanupRings(shell);
  if (shell == null) {
    return null;
  }
  List<LinearRing> holes = new ArrayList<LinearRing>();
  for (int i = 0; i < polygon.getNumInteriorRing(); i++) {
    LinearRing hole = (LinearRing) polygon.getInteriorRingN(i);
    hole = polygonClip(hole);
    hole = cleanupRings(hole);
    if (hole != null) {
      holes.add(hole);
    }
  }
  return gf.createPolygon(shell, (LinearRing[]) holes.toArray(new LinearRing[holes.size()]));
}

代码示例来源:origin: geotools/geotools

/**
 * Removes collinear vertices from the provided {@link Polygon}.
 *
 * @param polygon the instance of a {@link Polygon} to remove collinear vertices from.
 * @return a new instance of the provided {@link Polygon} without collinear vertices.
 */
static Polygon removeCollinearVertices(final Polygon polygon) {
  if (polygon == null) {
    throw new NullPointerException("The provided Polygon is null");
  }
  // reuse existing factory
  final GeometryFactory gf = polygon.getFactory();
  // work on the exterior ring
  LineString exterior = polygon.getExteriorRing();
  LineString shell = removeCollinearVertices(exterior);
  if ((shell == null) || shell.isEmpty()) {
    return null;
  }
  // work on the holes
  List<LineString> holes = new ArrayList<LineString>();
  final int size = polygon.getNumInteriorRing();
  for (int i = 0; i < size; i++) {
    LineString hole = polygon.getInteriorRingN(i);
    hole = removeCollinearVertices(hole);
    if ((hole != null) && !hole.isEmpty()) {
      holes.add(hole);
    }
  }
  return gf.createPolygon((LinearRing) shell, holes.toArray(new LinearRing[holes.size()]));
}

代码示例来源:origin: geotools/geotools

Polygon item = result.get(i);
if (item.getNumInteriorRing() > 0) {
  GeometryFactory factory = item.getFactory();
  Polygon noHoles =
      factory.createPolygon((LinearRing) item.getExteriorRing(), null);

代码示例来源:origin: geotools/geotools

/**
 * Finds a centroid for a polygon catching any exceptions resulting from generalization or other
 * polygon irregularities.
 *
 * @param geom The polygon.
 * @return The polygon centroid, or null if it can't be found.
 */
public static Point getPolygonCentroid(Polygon geom) {
  Point centroid;
  try {
    centroid = geom.getCentroid();
  } catch (Exception e) {
    // generalized polygons causes problems - this
    // tries to hide them.
    try {
      centroid = geom.getExteriorRing().getCentroid();
    } catch (Exception ee) {
      try {
        centroid = geom.getFactory().createPoint(geom.getCoordinate());
      } catch (Exception eee) {
        return null; // we're hooped
      }
    }
  }
  return centroid;
}

代码示例来源:origin: geotools/geotools

if (polygon.getFactory().getSRID() != SRID_NULL) {

代码示例来源:origin: geotools/geotools

/**
 * Add ordinates for polygon - with hole support.
 *
 * <p>Ensure ordinates are added in the correct orientation as External or Internal polygons.
 *
 * @param list List to add coordiantes to
 * @param polygon Polygon to be encoded
 */
private static void addCoordinatesInterpretation1(List list, Polygon polygon) {
  int holes = polygon.getNumInteriorRing();
  if (!polygon.isEmpty()) {
    addCoordinates(
        list,
        counterClockWise(
            polygon.getFactory().getCoordinateSequenceFactory(),
            polygon.getExteriorRing().getCoordinateSequence()));
    for (int i = 0; i < holes; i++) {
      addCoordinates(
          list,
          clockWise(
              polygon.getFactory().getCoordinateSequenceFactory(),
              polygon.getInteriorRingN(i).getCoordinateSequence()));
    }
  }
}

代码示例来源:origin: geotools/geotools

gf = geom.getFactory();

代码示例来源:origin: geotools/geotools

return polygon.getFactory().createPolygon(shell, holes);
} else {
  return polygon;

代码示例来源:origin: geotools/geotools

/**
 * Create a nice Polygon from the given Polygon. Will ensure that shells are clockwise and holes
 * are counter-clockwise. Capiche?
 *
 * @param p The Polygon to make "nice".
 * @return The "nice" Polygon.
 */
public static final Polygon makeGoodShapePolygon(Polygon p) {
  GeometryFactory factory = p.getFactory();
  LinearRing outer;
  LinearRing[] holes = new LinearRing[p.getNumInteriorRing()];
  Coordinate[] coords;
  coords = p.getExteriorRing().getCoordinates();
  if (CGAlgorithms.isCCW(coords)) {
    outer = reverseRing((LinearRing) p.getExteriorRing());
  } else {
    outer = (LinearRing) p.getExteriorRing();
  }
  for (int t = 0, tt = p.getNumInteriorRing(); t < tt; t++) {
    coords = p.getInteriorRingN(t).getCoordinates();
    if (!(CGAlgorithms.isCCW(coords))) {
      holes[t] = reverseRing((LinearRing) p.getInteriorRingN(t));
    } else {
      holes[t] = (LinearRing) p.getInteriorRingN(t);
    }
  }
  return factory.createPolygon(outer, holes);
}

代码示例来源:origin: geotools/geotools

MultiPolygon mask =
    beforeAntiMeridian
        .getFactory()
        .createMultiPolygon(
            new Polygon[] {beforeAntiMeridian, afterAntiMeridian});

代码示例来源:origin: orbisgis/h2gis

/**
   * Create a new polygon without hole.
   *
   * @param polygon
   * @return
   */
  public static Polygon removeHolesPolygon(Polygon polygon) {
    return new Polygon((LinearRing) polygon.getExteriorRing(), null, polygon.getFactory());
  }
}

代码示例来源:origin: orbisgis/h2gis

/**
 * Drape a polygon on a set of triangles
 * @param p
 * @param triangles
 * @param sTRtree
 * @return 
 */
public static Geometry drapePolygon(Polygon p, Geometry triangles, STRtree sTRtree) {
  GeometryFactory factory = p.getFactory();
  //Split the triangles in lines to perform all intersections
  Geometry triangleLines = LinearComponentExtracter.getGeometry(triangles, true);        
  Polygon splittedP = processPolygon(p, triangleLines, factory);
  CoordinateSequenceFilter drapeFilter = new DrapeFilter(sTRtree);
  splittedP.apply(drapeFilter);
  return splittedP;
}

代码示例来源:origin: locationtech/jts

public Polygon getResult()
{
 GeometryFactory gf = poly.getFactory();
 Polygon shell = gf.createPolygon(poly.getExteriorRing());
 
 List holes = new ArrayList();
 for (int i = 0; i < poly.getNumInteriorRing(); i++) {
  LinearRing hole = poly.getInteriorRingN(i);
  if (! isRemoved.value(hole)) {
   holes.add(hole);
  }
 }
 // all holes valid, so return original
 if (holes.size() == poly.getNumInteriorRing())
  return poly;
 
 // return new polygon with covered holes only
 Polygon result = gf.createPolygon(poly.getExteriorRing(),
   GeometryFactory.toLinearRingArray(holes));
 return result;
}

代码示例来源:origin: Geomatys/geotoolkit

@Override
public MultiPolygon apply(Polygon object) throws UnconvertibleObjectException {
  final MultiPolygon geom = object.getFactory().createMultiPolygon(new Polygon[]{object});
  geom.setSRID(object.getSRID());
  geom.setUserData(object.getUserData());
  return geom;
}

代码示例来源:origin: locationtech/jts

public Polygon getResult()
{
 GeometryFactory gf = poly.getFactory();
 Polygon shell = gf.createPolygon(poly.getExteriorRing());
 PreparedGeometry shellPrep = PreparedGeometryFactory.prepare(shell);
 
 List holes = new ArrayList();
 for (int i = 0; i < poly.getNumInteriorRing(); i++) {
  LinearRing hole = poly.getInteriorRingN(i);
  if (shellPrep.covers(hole)) {
   holes.add(hole);
  }
 }
 // all holes valid, so return original
 if (holes.size() == poly.getNumInteriorRing())
  return poly;
 
 // return new polygon with covered holes only
 Polygon result = gf.createPolygon(poly.getExteriorRing(),
   GeometryFactory.toLinearRingArray(holes));
 return result;
}

相关文章