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

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

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

JTS.smooth介绍

[英]Creates a smoothed copy of the input Geometry. This is only useful for polygonal and lineal geometries. Point objects will be returned unchanged. The smoothing algorithm inserts new vertices which are positioned using Bezier splines. All vertices of the input Geometry will be present in the output Geometry.

The fit parameter controls how tightly the smoothed lines conform to the input line segments, with a value of 1 being tightest and 0 being loosest. Values outside this range will be adjusted up or down as required.

The input Geometry can be a simple type (e.g. LineString, Polygon), a multi-type (e.g. MultiLineString, MultiPolygon) or a GeometryCollection. The returned object will be of the same type.
[中]创建输入几何图形的平滑副本。这仅对多边形和线性几何图形有用。点对象将原封不动地返回。平滑算法插入使用Bezier样条线定位的新顶点。输入几何体的所有顶点都将出现在输出几何体中。
“拟合”参数控制平滑线与输入线段的吻合程度,值1表示最紧密,值0表示最松散。超出此范围的值将根据需要向上或向下调整。
输入几何图形可以是简单类型(例如,线串、多边形)、多类型(例如,多线串、多多边形)或GeometryCollection。返回的对象将是相同的类型。

代码示例

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

/**
 * Creates a smoothed copy of the input Geometry. This is only useful for polygonal and lineal
 * geometries. Point objects will be returned unchanged. The smoothing algorithm inserts new
 * vertices which are positioned using Bezier splines. All vertices of the input Geometry will
 * be present in the output Geometry.
 *
 * <p>The {@code fit} parameter controls how tightly the smoothed lines conform to the input
 * line segments, with a value of 1 being tightest and 0 being loosest. Values outside this
 * range will be adjusted up or down as required.
 *
 * <p>The input Geometry can be a simple type (e.g. LineString, Polygon), a multi-type (e.g.
 * MultiLineString, MultiPolygon) or a GeometryCollection. The returned object will be of the
 * same type.
 *
 * @param geom the input geometry
 * @param fit tightness of fit from 0 (loose) to 1 (tight)
 * @return a new Geometry object of the same class as {@code geom}
 * @throws IllegalArgumentException if {@code geom} is {@code null}
 */
public static Geometry smooth(final Geometry geom, double fit) {
  return smooth(geom, fit, new GeometryFactory());
}

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

/**
 * Creates a smoothed copy of the input Geometry. This is only useful for polygonal and lineal
 * geometries. Point objects will be returned unchanged. The smoothing algorithm inserts new
 * vertices which are positioned using Bezier splines. All vertices of the input Geometry will
 * be present in the output Geometry.
 *
 * <p>The {@code fit} parameter controls how tightly the smoothed lines conform to the input
 * line segments, with a value of 1 being tightest and 0 being loosest. Values outside this
 * range will be adjusted up or down as required.
 *
 * <p>The input Geometry can be a simple type (e.g. LineString, Polygon), a multi-type (e.g.
 * MultiLineString, MultiPolygon) or a GeometryCollection. The returned object will be of the
 * same type.
 *
 * @param geom the input geometry
 * @param fit tightness of fit from 0 (loose) to 1 (tight)
 * @param factory the GeometryFactory to use for creating smoothed objects
 * @return a new Geometry object of the same class as {@code geom}
 * @throws IllegalArgumentException if either {@code geom} or {@code factory} is {@code null}
 */
public static Geometry smooth(final Geometry geom, double fit, final GeometryFactory factory) {
  ensureNonNull("geom", geom);
  ensureNonNull("factory", factory);
  // Adjust fit if necessary
  fit = Math.max(0.0, Math.min(1.0, fit));
  return smooth(geom, fit, factory, new GeometrySmoother(factory));
}

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

private static Geometry smoothGeometryCollection(
    GeometryFactory factory, GeometrySmoother smoother, Geometry geom, double fit) {
  final int N = geom.getNumGeometries();
  Geometry[] smoothed = new Geometry[N];
  for (int i = 0; i < N; i++) {
    smoothed[i] = smooth(geom.getGeometryN(i), fit, factory, smoother);
  }
  return factory.createGeometryCollection(smoothed);
}

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

@Test(expected = IllegalArgumentException.class)
public void smoothWithNullGeometry() {
  JTS.smooth(null, 0);
}

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

@Test(expected = IllegalArgumentException.class)
public void smoothWithNullFactory() {
  LineString line = factory.createLineString(getLineCoords());
  JTS.smooth(line, 0, null);
}

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

@Test
public void smoothPointReturnsSameObject() {
  Point point = factory.createPoint(new Coordinate());
  Geometry smoothed = JTS.smooth(point, 0);
  assertTrue(smoothed == point);
}

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

@Test
public void smoothMultiPointReturnsSameObject() {
  Coordinate[] coords = getLineCoords();
  MultiPoint mpoint = factory.createMultiPoint(coords);
  Geometry smoothed = JTS.smooth(mpoint, 0);
  assertTrue(smoothed == mpoint);
}

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

@Test
public void smoothLinearRing() {
  Coordinate[] coords = getPolyCoords();
  LineString line = factory.createLinearRing(coords);
  Geometry smoothed = JTS.smooth(line, 0);
  assertTrue(smoothed instanceof LinearRing);
  CoordList list = new CoordList(smoothed.getCoordinates());
  assertTrue(list.containsAll(coords));
  Envelope lineEnv = line.getEnvelopeInternal();
  Envelope smoothEnv = smoothed.getEnvelopeInternal();
  assertTrue(smoothEnv.covers(lineEnv));
}

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

@Test
public void smoothLineString() {
  Coordinate[] coords = getLineCoords();
  LineString line = factory.createLineString(coords);
  Geometry smoothed = JTS.smooth(line, 0);
  assertTrue(smoothed instanceof LineString);
  CoordList list = new CoordList(smoothed.getCoordinates());
  assertTrue(list.containsAll(coords));
  Envelope lineEnv = line.getEnvelopeInternal();
  Envelope smoothEnv = smoothed.getEnvelopeInternal();
  assertTrue(smoothEnv.covers(lineEnv));
}

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

@Test
public void smoothPolygon() {
  Coordinate[] coords = getPolyCoords();
  Polygon poly = factory.createPolygon(factory.createLinearRing(coords), null);
  Geometry smoothed = JTS.smooth(poly, 0);
  assertTrue(smoothed instanceof Polygon);
  CoordList list = new CoordList(smoothed.getCoordinates());
  assertTrue(list.containsAll(coords));
  Envelope polyEnv = poly.getEnvelopeInternal();
  Envelope smoothEnv = smoothed.getEnvelopeInternal();
  assertTrue(smoothEnv.covers(polyEnv));
}

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

@Test
public void smoothMultiLineString() {
  LineString[] lines = new LineString[3];
  lines[0] = factory.createLineString(getLineCoords(0));
  lines[1] = factory.createLineString(getLineCoords(10));
  lines[2] = factory.createLineString(getLineCoords(20));
  MultiLineString mls = factory.createMultiLineString(lines);
  Geometry smoothed = JTS.smooth(mls, 0);
  assertTrue(smoothed instanceof MultiLineString);
  assertEquals(3, smoothed.getNumGeometries());
  Envelope mlsEnv = mls.getEnvelopeInternal();
  Envelope smoothEnv = smoothed.getEnvelopeInternal();
  assertTrue(smoothEnv.covers(mlsEnv));
}

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

@Test
public void smoothMultiPolygon() {
  Polygon[] polys = new Polygon[3];
  polys[0] = factory.createPolygon(factory.createLinearRing(getPolyCoords(0)), null);
  polys[1] = factory.createPolygon(factory.createLinearRing(getPolyCoords(10)), null);
  polys[2] = factory.createPolygon(factory.createLinearRing(getPolyCoords(20)), null);
  MultiPolygon mp = factory.createMultiPolygon(polys);
  Geometry smoothed = JTS.smooth(mp, 0);
  assertTrue(smoothed instanceof MultiPolygon);
  assertEquals(3, smoothed.getNumGeometries());
  Envelope mpEnv = mp.getEnvelopeInternal();
  Envelope smoothEnv = smoothed.getEnvelopeInternal();
  assertTrue(smoothEnv.covers(mpEnv));
}

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

Geometry smoothed = JTS.smooth(gc, 0);
assertTrue(smoothed instanceof GeometryCollection);
assertEquals(3, smoothed.getNumGeometries());

相关文章