org.geotools.geometry.jts.JTS.removeCollinearVertices()方法的使用及代码示例

x33g5p2x  于2022-01-21 转载在 其他  
字(3.4k)|赞(0)|评价(0)|浏览(276)

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

JTS.removeCollinearVertices介绍

[英]Removes collinear vertices from the provided Geometry.

For the moment this implementation only accepts, Polygon, LineString and MultiPolygon It will throw an exception if the geometry is not one of those types
[中]从提供的几何图形中删除共线顶点。
目前,此实现仅接受多边形、线字符串和多边形,如果几何体不是这些类型之一,则会引发异常

代码示例

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

/**
 * Removes collinear vertices from the provided {@link Geometry}.
 *
 * <p>For the moment this implementation only accepts, {@link Polygon}, {@link LineString} and
 * {@link MultiPolygon} It will throw an exception if the geometry is not one of those types
 *
 * @param g the instance of a {@link Geometry} to remove collinear vertices from.
 * @return a new instance of the provided {@link Geometry} without collinear vertices.
 */
public static Geometry removeCollinearVertices(final Geometry g) {
  if (g == null) {
    throw new NullPointerException("The provided Geometry is null");
  }
  if (g instanceof LineString) {
    return removeCollinearVertices((LineString) g);
  } else if (g instanceof Polygon) {
    return removeCollinearVertices((Polygon) g);
  } else if (g instanceof MultiPolygon) {
    MultiPolygon mp = (MultiPolygon) g;
    Polygon[] parts = new Polygon[mp.getNumGeometries()];
    for (int i = 0; i < mp.getNumGeometries(); i++) {
      Polygon part = (Polygon) mp.getGeometryN(i);
      part = removeCollinearVertices(part);
      parts[i] = part;
    }
    return g.getFactory().createMultiPolygon(parts);
  }
  throw new IllegalArgumentException(
      "This method can work on LineString, Polygon and Multipolygon: " + g.getClass());
}

代码示例来源: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

return removeCollinearVertices((LineString) geometry);
} else if (geometry instanceof Polygon) {
  return removeCollinearVertices((Polygon) geometry);
} else if (geometry instanceof MultiPolygon) {
  MultiPolygon mp = (MultiPolygon) geometry;
  for (int i = 0; i < mp.getNumGeometries(); i++) {
    Polygon part = (Polygon) mp.getGeometryN(i);
    part = removeCollinearVertices(part);
    parts[i] = part;

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

JTS.removeCollinearVertices(
    polygon);
JTS.removeCollinearVertices(
    polygon);

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

final Shape shape = new java.awt.Polygon(xPoints, yPoints, nPoints);
final Geometry original = JTS.toGeometry(shape);
final Geometry reduced = JTS.removeCollinearVertices(original);
assertEquals(10, original.getNumPoints());
assertEquals(5, reduced.getNumPoints());

相关文章