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

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

本文整理了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

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

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

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

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

@Override
  public Geometry applyInset(Geometry footprint, Geometry granuleBounds, double inset) {
    if (footprint == null) {
      return null;
    }
    return footprint.buffer(-inset);
  }
},

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

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

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

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

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

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

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

private Geometry buffer(List<? extends Geometry> geometries, double distance) {
  List<Geometry> polygons = new ArrayList<Geometry>();
  for (Geometry g : geometries) {
    Geometry buffered = g.buffer(distance);
    polygons.add(buffered);
  }
  return CascadedPolygonUnion.union(polygons);
}

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

static Geometry repairInvalidPolygon(Geometry p) {
  if (p instanceof Polygon || p instanceof MultiPolygon) {
    // apply zero buffer trick
    Geometry ret = p.buffer(0);
    if (ret.getArea() > 0) {
      return ret;
    }
    LOGGER.fine("unable to repair invalid polygon");
    return null;
  }
  return p;
}

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

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

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

@Override
public Shape build() {
 Geometry geom = buildLineStringGeom();
 if (bufDistance != 0.0) {
  geom = geom.buffer(bufDistance);
 }
 return makeShape(geom);
}

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

private Geometry getConflictBounds(Geometry bounds, int spaceAround) {
  // apply the space around (with a negative one we might end up with nothing as the result)
  Geometry conflictBounds = bounds;
  if (spaceAround != 0) {
    conflictBounds = bounds.buffer(spaceAround);
    if (conflictBounds.isEmpty() || conflictBounds.getArea() == 0) {
      conflictBounds = null;
    } else {
      conflictBounds = new MinimumDiameter(conflictBounds).getMinimumRectangle();
    }
  }
  return conflictBounds;
}

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

private Geometry getGeometryBounds(
    Icon icon, Mark mark, Shape shape, double markSize, Object feature) {
  Geometry bounds;
  if (icon != null) {
    bounds = new GeometryBuilder().box(0, 0, icon.getIconWidth(), icon.getIconHeight());
  } else {
    // the shape can be very complicated, go for the MBR. Wanted to use ShapeReader, but it
    // blindly assumes the shape is a polygon, while it may not be. Building a multipoint
    // instead
    AffineTransform at = AffineTransform.getScaleInstance(markSize, -markSize);
    Shape ts = at.createTransformedShape(shape);
    Geometry shapeGeometry = JTS.toGeometry(ts);
    bounds = new MinimumDiameter(shapeGeometry).getMinimumRectangle();
  }
  // grow by the stroke size, if this is a mark
  if (icon == null && mark != null) {
    Stroke stroke = factory.getStroke(mark.getStroke(), feature);
    if (stroke instanceof BasicStroke) {
      float width = ((BasicStroke) stroke).getLineWidth() / 2 + 1;
      if (width > 0) {
        Geometry buffered = bounds.buffer(width);
        bounds = new MinimumDiameter(buffered).getMinimumRectangle();
      }
    }
  }
  return bounds;
}

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

mappedMask = mappedMask.buffer(maskingBuffer);
mappedMaskBox = mappedMaskBox.buffer(maskingBuffer);
mappedMask = mappedMask.intersection(mappedMaskBox);

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

/** Converts a distance buffer op to an intersects againt the buffered input geometry */
private Object visitDistanceBufferOperator(
    DistanceBufferOperator filter, boolean truth, Object extraData) {
  // SDE can assert only one way, we need to invert from contains to within in case the
  // assertion is the other way around
  PropertyName property;
  Literal literal;
  {
    Expression expression1 = filter.getExpression1();
    Expression expression2 = filter.getExpression2();
    if (expression1 instanceof PropertyName && expression2 instanceof Literal) {
      property = (PropertyName) expression1;
      literal = (Literal) expression2;
    } else if (expression2 instanceof PropertyName && expression1 instanceof Literal) {
      property = (PropertyName) expression2;
      literal = (Literal) expression1;
    } else {
      // not supported
      throw new IllegalArgumentException(
          "expected propertyname/literal, got " + expression1 + "/" + expression2);
    }
  }
  final Geometry geom = literal.evaluate(null, Geometry.class);
  final double distance = filter.getDistance();
  final Geometry buffer = geom.buffer(distance);
  FilterFactory2 ff = CommonFactoryFinder.getFilterFactory2();
  BinarySpatialOperator intersects = ff.intersects(property, ff.literal(buffer));
  addSpatialFilter(intersects, SeFilter.METHOD_II_OR_ET, truth, extraData);
  return extraData;
}

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

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

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

g = new GeometrySnapper(g).snapTo(g, tol).buffer(0);
roiGeometry = new ROIGeometry(g, setupJAIHints(hints));
roi = roi.intersect(roiGeometry);
if (!isValid) {
  double tol = GeometrySnapper.computeOverlaySnapTolerance(g);
  g = new GeometrySnapper(g).snapTo(g, tol).buffer(0);
  roi = new ROIGeometry(g, setupJAIHints(hints));
  roi = roi.intersect(roiGeometry);

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

public boolean hasNext() {
  while (next == null && delegate.hasNext()) {
    SimpleFeature f = delegate.next();
    for (Object value : f.getAttributes()) {
      if (value instanceof Geometry) {
        Double fDistance = distance;
        if (this.attribute != null) {
          fDistance =
              Converters.convert(
                  f.getAttribute(this.attribute), Double.class);
        }
        if (fDistance != null && fDistance != 0.0) {
          value = ((Geometry) value).buffer(fDistance);
        }
      }
      fb.add(value);
    }
    next = fb.buildFeature("" + count);
    count++;
    fb.reset();
  }
  return next != null;
}

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

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

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

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

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

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

相关文章