Java Code Examples for com.vividsolutions.jts.geom.Geometry#buffer()

The following examples show how to use com.vividsolutions.jts.geom.Geometry#buffer() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: JTSServiceImpl.java    From geowe-core with GNU General Public License v3.0 6 votes vote down vote up
@Override
public List<String> getEnvelope(final List<String> wkts)
		throws IllegalArgumentException {
	Geometry resultGeometry = null;

	final List<String> result = new ArrayList<String>();

	for (final String wkt : wkts) {
		Geometry geom = getGeometry(wkt);
		geom = geom.buffer(TOLERANCIA_ENVELOPE);

		if (resultGeometry == null) {
			resultGeometry = geom;
		} else {
			resultGeometry = resultGeometry.union(geom);
		}
	}

	if (resultGeometry != null) {
		result.add(resultGeometry.getEnvelope().toText());
	}

	return result;
}
 
Example 2
Source File: GeometryUtils.java    From gama with GNU General Public License v3.0 6 votes vote down vote up
public static Geometry cleanGeometry(final Geometry g) {
	//follow the proposition of https://locationtech.github.io/jts/jts-faq.html#G1
	if (g == null || g.isEmpty()) return g; 
	Geometry g2 = g.buffer(0.0, BufferParameters.DEFAULT_QUADRANT_SEGMENTS,
			BufferParameters.CAP_FLAT);
	if (g2.isEmpty()) {
		if (g instanceof Polygon) {
			Polygon p = (Polygon) g;
			Geometry g3 = GeometryUtils.GEOMETRY_FACTORY.createPolygon(p.getExteriorRing().getCoordinates());
			for (int i = 0; i < p.getNumInteriorRing(); i++) {
				Geometry g4 = GeometryUtils.GEOMETRY_FACTORY.createPolygon(p.getInteriorRingN(i).getCoordinates());
				g3 = g3.difference(g4);
			}
			return g3;
		}else {
			return GeometryUtils.GEOMETRY_FACTORY.createGeometry(g);
		}
	}
	return g2;
}
 
Example 3
Source File: SimpleDemo.java    From jts with GNU Lesser General Public License v2.1 6 votes vote down vote up
private void showPoland() {
	WKTReader r = new WKTReader();
	try {
		Geometry g = r.read(s);
		g.setSRID(4326);

		Geometry g2 = g.buffer(1);
		Geometry g3 = g2.difference(g);

		JavaScriptObject f1 = parseWKT(g.toString());
		JavaScriptObject f2 = parseWKT(g3.toString());
		JsArray<JavaScriptObject> fs = JsArray.createArray().cast();
		fs.push(f1);
		fs.push(f2);

		addFeatures(mMap, fs);
	} catch (ParseException e) {
		sLogger.log(Level.WARNING, "Unable to parse wkb", e);
	}
}
 
Example 4
Source File: GeometryUtils.java    From gama with GNU General Public License v3.0 5 votes vote down vote up
private static IList<IShape> filterGeoms(final GeometryCollection geom, final Geometry clip, final double sizeTol,
		final boolean approxClipping) {
	if (geom == null) { return null; }
	final double elevation = getContourCoordinates(clip).averageZ();
	final boolean setZ = elevation != 0.0;
	final IList<IShape> result = GamaListFactory.create(Types.GEOMETRY);
	final Geometry bufferClip = sizeTol != 0.0 ? clip.buffer(sizeTol, 5, 0) : clip;
	final PreparedGeometry buffered = PREPARED_GEOMETRY_FACTORY.create(bufferClip);
	final Envelope3D env = Envelope3D.of(buffered.getGeometry());
	try {
		for (int i = 0; i < geom.getNumGeometries(); i++) {
			final Geometry gg = geom.getGeometryN(i);
			if (!clip.covers(gg.getCentroid())) continue;
			final Coordinate[] coord = gg.getCoordinates();
			boolean cond = env.covers(gg.getCentroid().getCoordinate());
			cond = cond && (approxClipping
					? buffered.covers(gg.getCentroid()) && buffered.covers(GEOMETRY_FACTORY.createPoint(coord[0]))
							&& buffered.covers(GEOMETRY_FACTORY.createPoint(coord[1]))
							&& buffered.covers(GEOMETRY_FACTORY.createPoint(coord[2]))
					: bufferClip.covers(gg));
			if (cond) {
				if (setZ) {
					final ICoordinates cc = getContourCoordinates(gg);
					cc.setAllZ(elevation);
					gg.geometryChanged();
				}
				result.add(new GamaShape(gg));
			}
		}
	} finally {
		env.dispose();
	}
	/*
	 * applyToInnerGeometries(geom, (gg) -> { final ICoordinates cc = getContourCoordinates(gg); if
	 * (cc.isCoveredBy(env) && buffered.covers(gg)) {
	 *
	 * } });
	 */
	return result;
}
 
Example 5
Source File: GamaGeometryType.java    From gama with GNU General Public License v3.0 5 votes vote down vote up
public static IShape buildCircle(final double radius, final ILocation location) {
	final Geometry geom = GeometryUtils.GEOMETRY_FACTORY
			.createPoint(location == null ? new GamaPoint(0, 0) : (GamaPoint) location);
	final Geometry g = geom.buffer(radius);
	if (location != null) {
		final Coordinate[] coordinates = g.getCoordinates();
		for (int i = 0; i < coordinates.length; i++) {
			coordinates[i].z = ((GamaPoint) location).z;
		}
	}
	return new GamaShape(g);
}
 
Example 6
Source File: PolygonCleaner.java    From jts with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Override
public Geometry edit(Geometry geometry, GeometryFactory targetFactory) {
  if (geometry instanceof Polygonal) {
    return geometry.buffer(0);
  }
  return geometry;
}
 
Example 7
Source File: BufferFunctions.java    From jts with GNU Lesser General Public License v2.1 5 votes vote down vote up
public static Geometry bufferValidated(Geometry g, double distance)
{
  Geometry buf = g.buffer(distance);
  String errMsg = BufferResultValidator.isValidMsg(g, distance, buf);
  if (errMsg != null)
    throw new IllegalStateException("Buffer Validation error: " + errMsg);
  return buf;
}
 
Example 8
Source File: BufferFunctions.java    From jts with GNU Lesser General Public License v2.1 5 votes vote down vote up
public static Geometry bufferValidatedGeom(Geometry g, double distance)
{
  Geometry buf = g.buffer(distance);
  BufferResultValidator validator = new BufferResultValidator(g, distance, buf);    
  boolean isValid = validator.isValid();
  return validator.getErrorIndicator();
}
 
Example 9
Source File: BufferResultValidatorTest.java    From jts with GNU Lesser General Public License v2.1 5 votes vote down vote up
void runTest(String wkt, double dist)
throws Exception
{
	Geometry g = rdr.read(wkt);
	Geometry buf = g.buffer(dist);
  BufferResultValidator validator = new BufferResultValidator(g, dist, buf);
  
  if (! validator.isValid()) {
    String msg = validator.getErrorMessage();

    System.out.println(msg);
    System.out.println(WKTWriter.toPoint(validator.getErrorLocation()));
  }
	assertTrue(validator.isValid());
}
 
Example 10
Source File: FileBufferResultValidatorTest.java    From jts with GNU Lesser General Public License v2.1 5 votes vote down vote up
void runBuffer(Geometry g, double dist)
{
	Geometry buf = g.buffer(dist);
  BufferResultValidator validator = new BufferResultValidator(g, dist, buf);
  
  if (! validator.isValid()) {
    String msg = validator.getErrorMessage();

    System.out.println(msg);
    System.out.println(WKTWriter.toPoint(validator.getErrorLocation()));
    System.out.println(g);
  }
	assertTrue(validator.isValid());
}
 
Example 11
Source File: SnapRoundOverlayFunctions.java    From jts with GNU Lesser General Public License v2.1 4 votes vote down vote up
private static Geometry clean(Geometry geom) {
  // TODO: only buffer if it is a polygonal geometry
  if (! (geom instanceof Polygonal) ) return geom;
  return geom.buffer(0);
}
 
Example 12
Source File: GeometryEditPanel.java    From jts with GNU Lesser General Public License v2.1 4 votes vote down vote up
private Geometry flashPointGeom(Geometry g)
{
  double ptRadius = viewport.toModel(4);
  return g.buffer(ptRadius);
}
 
Example 13
Source File: BufferFunctions.java    From jts with GNU Lesser General Public License v2.1 votes vote down vote up
public static Geometry buffer(Geometry g, double distance)		{		return g.buffer(distance);	}