Java Code Examples for com.vividsolutions.jts.geom.Envelope#expandBy()

The following examples show how to use com.vividsolutions.jts.geom.Envelope#expandBy() . 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: GeometryEditPanel.java    From jts with GNU Lesser General Public License v2.1 6 votes vote down vote up
public void zoom(Envelope zoomEnv) {
  if (zoomEnv == null)
    return;

  if (zoomEnv.isNull()) {
    viewport.zoomToInitialExtent();
    return;
  }
  double averageExtent = (zoomEnv.getWidth() + zoomEnv.getHeight()) / 2d;
  // fix to allow zooming to points
  if (averageExtent == 0.0)
    averageExtent = 1.0;
  double buffer = averageExtent * 0.1;
  zoomEnv.expandBy(buffer);
  viewport.zoom(zoomEnv);
}
 
Example 2
Source File: JTSModel.java    From OpenMapKitAndroid with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private Envelope createTapEnvelope(Coordinate coord, double lat, double lng, float zoom) {
    Envelope envelope = new Envelope(coord);

    // Creating a reasonably sized envelope around the tap location.
    // Tweak the TAP_PIXEL_TOLERANCE to get a better sized box for your needs.
    double degreesLngPerPixel = degreesLngPerPixel(zoom);
    double deltaX = degreesLngPerPixel * TAP_PIXEL_TOLERANCE;
    double deltaY = scaledLatDeltaForMercator(deltaX, lat);
    envelope.expandBy(deltaX, deltaY);
    return envelope;
}
 
Example 3
Source File: ConformingDelaunayTriangulator.java    From jts with GNU Lesser General Public License v2.1 5 votes vote down vote up
private void computeBoundingBox() {
	Envelope vertexEnv = computeVertexEnvelope(initialVertices);
	Envelope segEnv = computeVertexEnvelope(segVertices);

	Envelope allPointsEnv = new Envelope(vertexEnv);
	allPointsEnv.expandToInclude(segEnv);

	double deltaX = allPointsEnv.getWidth() * 0.2;
	double deltaY = allPointsEnv.getHeight() * 0.2;

	double delta = Math.max(deltaX, deltaY);

	computeAreaEnv = new Envelope(allPointsEnv);
	computeAreaEnv.expandBy(delta);
}
 
Example 4
Source File: ConformingDelaunayTriangulator.java    From jts with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Given a set of points stored in the kd-tree and a line segment defined by
 * two points in this set, finds a {@link Coordinate} in the circumcircle of
 * the line segment, if one exists. This is called the Gabriel point - if none
 * exists then the segment is said to have the Gabriel condition. Uses the
 * heuristic of finding the non-Gabriel point closest to the midpoint of the
 * segment.
 * 
 * @param p
 *          start of the line segment
 * @param q
 *          end of the line segment
 * @return a point which is non-Gabriel
 * or null if no point is non-Gabriel
 */
private Coordinate findNonGabrielPoint(Segment seg) {
	Coordinate p = seg.getStart();
	Coordinate q = seg.getEnd();
	// Find the mid point on the line and compute the radius of enclosing circle
	Coordinate midPt = new Coordinate((p.x + q.x) / 2.0, (p.y + q.y) / 2.0);
	double segRadius = p.distance(midPt);

	// compute envelope of circumcircle
	Envelope env = new Envelope(midPt);
	env.expandBy(segRadius);
	// Find all points in envelope
	List result = kdt.query(env);

	// For each point found, test if it falls strictly in the circle
	// find closest point
	Coordinate closestNonGabriel = null;
	double minDist = Double.MAX_VALUE;
	for (Iterator i = result.iterator(); i.hasNext();) {
		KdNode nextNode = (KdNode) i.next();
		Coordinate testPt = nextNode.getCoordinate();
		// ignore segment endpoints
		if (testPt.equals2D(p) || testPt.equals2D(q))
			continue;

		double testRadius = midPt.distance(testPt);
		if (testRadius < segRadius) {
			// double testDist = seg.distance(testPt);
			double testDist = testRadius;
			if (closestNonGabriel == null || testDist < minDist) {
				closestNonGabriel = testPt;
				minDist = testDist;
			}
		}
	}
	return closestNonGabriel;
}
 
Example 5
Source File: KdTree.java    From jts with GNU Lesser General Public License v2.1 4 votes vote down vote up
public Envelope queryEnvelope() {
  Envelope queryEnv = new Envelope(p);
  queryEnv.expandBy(tolerance);
  return queryEnv;
}