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

x33g5p2x  于2022-01-19 转载在 其他  
字(7.6k)|赞(0)|评价(0)|浏览(764)

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

Geometry.buffer介绍

[英]Computes a buffer area around this geometry having the given width. The buffer of a Geometry is the Minkowski sum or difference of the geometry with a disc of radius abs(distance).

Mathematically-exact buffer area boundaries can contain circular arcs. To represent these arcs using linear geometry they must be approximated with line segments. The buffer geometry is constructed using 8 segments per quadrant to approximate the circular arcs. The end cap style is CAP_ROUND.

The buffer operation always returns a polygonal result. The negative or zero-distance buffer of lines and points is always an empty Polygon. This is also the result for the buffers of degenerate (zero-area) polygons.
[中]计算此几何体周围具有给定宽度的缓冲区。几何体的缓冲区是半径为[$0$]的圆盘的几何体的Minkowski和或差。
数学上精确的缓冲区边界可以包含圆弧。要使用线性几何体表示这些圆弧,必须使用线段近似这些圆弧。缓冲区几何体使用每个象限8个分段来近似圆弧。端盖样式为CAP_ROUND
缓冲区操作始终返回多边形结果。直线和点的负距离或零距离缓冲区始终为空多边形。这也是退化(零面积)多边形缓冲区的结果。

代码示例

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

  1. public static Geometry bufferWithSegments(Geometry arg0, Double arg1, Integer arg2) {
  2. if (arg0 == null || arg1 == null || arg2 == null) return null;
  3. Geometry _this = arg0;
  4. return _this.buffer(arg1, arg2);
  5. }

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

  1. public static Geometry buffer(Geometry arg0, Double arg1) {
  2. if (arg0 == null || arg1 == null) return null;
  3. Geometry _this = arg0;
  4. return _this.buffer(arg1);
  5. }

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

  1. @Override
  2. public Geometry applyInset(Geometry footprint, Geometry granuleBounds, double inset) {
  3. if (footprint == null) {
  4. return null;
  5. }
  6. return footprint.buffer(-inset);
  7. }
  8. },

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

  1. public Geometry buffer(double distance, int quadrantSegments) {
  2. return geometry.buffer(distance, quadrantSegments);
  3. }

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

  1. public Geometry buffer(double distance, int quadrantSegments, int endCapStyle) {
  2. return geometry.buffer(distance, quadrantSegments, endCapStyle);
  3. }

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

  1. public Geometry buffer(double distance) {
  2. return geometry.buffer(distance);
  3. }

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

  1. private Geometry buffer(List<? extends Geometry> geometries, double distance) {
  2. List<Geometry> polygons = new ArrayList<Geometry>();
  3. for (Geometry g : geometries) {
  4. Geometry buffered = g.buffer(distance);
  5. polygons.add(buffered);
  6. }
  7. return CascadedPolygonUnion.union(polygons);
  8. }

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

  1. static Geometry repairInvalidPolygon(Geometry p) {
  2. if (p instanceof Polygon || p instanceof MultiPolygon) {
  3. // apply zero buffer trick
  4. Geometry ret = p.buffer(0);
  5. if (ret.getArea() > 0) {
  6. return ret;
  7. }
  8. LOGGER.fine("unable to repair invalid polygon");
  9. return null;
  10. }
  11. return p;
  12. }

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

  1. @Override
  2. public JtsGeometry getBuffered(double distance, SpatialContext ctx) {
  3. //TODO doesn't work correctly across the dateline. The buffering needs to happen
  4. // when it's transiently unrolled, prior to being sliced.
  5. return this.ctx.makeShape(geom.buffer(distance), true, true);
  6. }

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

  1. @Override
  2. public Shape build() {
  3. Geometry geom = buildLineStringGeom();
  4. if (bufDistance != 0.0) {
  5. geom = geom.buffer(bufDistance);
  6. }
  7. return makeShape(geom);
  8. }

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

  1. private Geometry getConflictBounds(Geometry bounds, int spaceAround) {
  2. // apply the space around (with a negative one we might end up with nothing as the result)
  3. Geometry conflictBounds = bounds;
  4. if (spaceAround != 0) {
  5. conflictBounds = bounds.buffer(spaceAround);
  6. if (conflictBounds.isEmpty() || conflictBounds.getArea() == 0) {
  7. conflictBounds = null;
  8. } else {
  9. conflictBounds = new MinimumDiameter(conflictBounds).getMinimumRectangle();
  10. }
  11. }
  12. return conflictBounds;
  13. }

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

  1. private Geometry getGeometryBounds(
  2. Icon icon, Mark mark, Shape shape, double markSize, Object feature) {
  3. Geometry bounds;
  4. if (icon != null) {
  5. bounds = new GeometryBuilder().box(0, 0, icon.getIconWidth(), icon.getIconHeight());
  6. } else {
  7. // the shape can be very complicated, go for the MBR. Wanted to use ShapeReader, but it
  8. // blindly assumes the shape is a polygon, while it may not be. Building a multipoint
  9. // instead
  10. AffineTransform at = AffineTransform.getScaleInstance(markSize, -markSize);
  11. Shape ts = at.createTransformedShape(shape);
  12. Geometry shapeGeometry = JTS.toGeometry(ts);
  13. bounds = new MinimumDiameter(shapeGeometry).getMinimumRectangle();
  14. }
  15. // grow by the stroke size, if this is a mark
  16. if (icon == null && mark != null) {
  17. Stroke stroke = factory.getStroke(mark.getStroke(), feature);
  18. if (stroke instanceof BasicStroke) {
  19. float width = ((BasicStroke) stroke).getLineWidth() / 2 + 1;
  20. if (width > 0) {
  21. Geometry buffered = bounds.buffer(width);
  22. bounds = new MinimumDiameter(buffered).getMinimumRectangle();
  23. }
  24. }
  25. }
  26. return bounds;
  27. }

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

  1. mappedMask = mappedMask.buffer(maskingBuffer);
  2. mappedMaskBox = mappedMaskBox.buffer(maskingBuffer);
  3. mappedMask = mappedMask.intersection(mappedMaskBox);

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

  1. /** Converts a distance buffer op to an intersects againt the buffered input geometry */
  2. private Object visitDistanceBufferOperator(
  3. DistanceBufferOperator filter, boolean truth, Object extraData) {
  4. // SDE can assert only one way, we need to invert from contains to within in case the
  5. // assertion is the other way around
  6. PropertyName property;
  7. Literal literal;
  8. {
  9. Expression expression1 = filter.getExpression1();
  10. Expression expression2 = filter.getExpression2();
  11. if (expression1 instanceof PropertyName && expression2 instanceof Literal) {
  12. property = (PropertyName) expression1;
  13. literal = (Literal) expression2;
  14. } else if (expression2 instanceof PropertyName && expression1 instanceof Literal) {
  15. property = (PropertyName) expression2;
  16. literal = (Literal) expression1;
  17. } else {
  18. // not supported
  19. throw new IllegalArgumentException(
  20. "expected propertyname/literal, got " + expression1 + "/" + expression2);
  21. }
  22. }
  23. final Geometry geom = literal.evaluate(null, Geometry.class);
  24. final double distance = filter.getDistance();
  25. final Geometry buffer = geom.buffer(distance);
  26. FilterFactory2 ff = CommonFactoryFinder.getFilterFactory2();
  27. BinarySpatialOperator intersects = ff.intersects(property, ff.literal(buffer));
  28. addSpatialFilter(intersects, SeFilter.METHOD_II_OR_ET, truth, extraData);
  29. return extraData;
  30. }

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

  1. if (quadrantSegments == null) quadrantSegments = BufferParameters.DEFAULT_QUADRANT_SEGMENTS;
  2. if (capStyle == null) capStyle = BufferCapStyle.Round;
  3. return geom.buffer(distance, quadrantSegments, capStyle.value);

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

  1. g = new GeometrySnapper(g).snapTo(g, tol).buffer(0);
  2. roiGeometry = new ROIGeometry(g, setupJAIHints(hints));
  3. roi = roi.intersect(roiGeometry);
  4. if (!isValid) {
  5. double tol = GeometrySnapper.computeOverlaySnapTolerance(g);
  6. g = new GeometrySnapper(g).snapTo(g, tol).buffer(0);
  7. roi = new ROIGeometry(g, setupJAIHints(hints));
  8. roi = roi.intersect(roiGeometry);

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

  1. public boolean hasNext() {
  2. while (next == null && delegate.hasNext()) {
  3. SimpleFeature f = delegate.next();
  4. for (Object value : f.getAttributes()) {
  5. if (value instanceof Geometry) {
  6. Double fDistance = distance;
  7. if (this.attribute != null) {
  8. fDistance =
  9. Converters.convert(
  10. f.getAttribute(this.attribute), Double.class);
  11. }
  12. if (fDistance != null && fDistance != 0.0) {
  13. value = ((Geometry) value).buffer(fDistance);
  14. }
  15. }
  16. fb.add(value);
  17. }
  18. next = fb.buildFeature("" + count);
  19. count++;
  20. fb.reset();
  21. }
  22. return next != null;
  23. }

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

  1. @Test
  2. public void testInsidePolygon() throws Exception {
  3. Geometry g = wkt.read("POINT(5 5)").buffer(2);
  4. Geometry clipped = clipper.clip(g, false);
  5. assertTrue(g.equalsExact(clipped));
  6. showResult("Polygon inside", g, clipped);
  7. }

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

  1. @Test
  2. public void testOutsidePolygon() throws Exception {
  3. Geometry g = wkt.read("POINT(5 5)").buffer(10);
  4. Geometry clipped = clipper.clip(g, false);
  5. assertTrue(boundsPoly.equalsTopo(clipped));
  6. showResult("Polygon outside", g, clipped);
  7. }

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

  1. while (fi.hasNext()) {
  2. SimpleFeature f = fi.next();
  3. fb.add(((Geometry) f.getDefaultGeometry()).buffer(distance));
  4. result.add(fb.buildFeature(null));

相关文章