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

The following examples show how to use com.vividsolutions.jts.geom.Envelope#getHeight() . 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: LocalProfile.java    From geomajas-project-server with GNU Affero General Public License v3.0 6 votes vote down vote up
public LocalProfile(Envelope bounds, int minTileSize) {
	this.origin = new Coordinate(bounds.getMinX(), bounds.getMinY());
	this.bounds = bounds;
	tileWidth = minTileSize;
	tileHeight = minTileSize;
	double ratio = bounds.getWidth() / bounds.getHeight();
	if (ratio >= 1) {
		tileWidth = (int) Math.ceil(tileHeight * ratio);
		maxResolution = bounds.getHeight() / tileHeight;
	} else {
		tileHeight = (int) Math.ceil(tileWidth / ratio);
		maxResolution = bounds.getWidth() / tileWidth;
	}
	for (int i = 0; i < 30; i++) {
		resolutions[i] = getResolution(i);
	}
}
 
Example 2
Source File: GeoServiceImpl.java    From geomajas-project-server with GNU Affero General Public License v3.0 6 votes vote down vote up
@Override
@edu.umd.cs.findbugs.annotations.SuppressWarnings(value = "REC_CATCH_EXCEPTION")
public Bbox transform(Bbox source, CrsTransform crsTransform) {
	try {
		if (crsTransform.isTransforming()) {
			Envelope envelope = new Envelope(source.getX(), source.getMaxX(), source.getY(), source.getMaxY());
			Envelope transformableArea = crsTransform.getTransformableEnvelope();
			if (null != transformableArea) {
				envelope = envelope.intersection(transformableArea);
			}
			if (envelope.isNull()) {
				return new Bbox();
			} else {
				ReferencedEnvelope refEnvelope = new ReferencedEnvelope(envelope, crsTransform.getSource());
				envelope = refEnvelope.transform(crsTransform.getTarget(), true);
				return new Bbox(envelope.getMinX(), envelope.getMinY(), envelope.getWidth(), envelope.getHeight());
			}
		} else {
			return source;
		}
	} catch (Exception e) { // NOSONAR typically TopologyException, TransformException or FactoryException
		logBboxSuggestCrsTransformInfo(crsTransform.getId(), source, e);
		return new Bbox();
	}
}
 
Example 3
Source File: GridLayerData.java    From gama with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void compute(final IScope scope, final IGraphics g) throws GamaRuntimeException {
	if (grid == null) {
		final IPopulation<? extends IAgent> gridPop = scope.getAgent().getPopulationFor(name);
		if (gridPop == null) {
			throw error("No grid species named " + name + " can be found", scope);
		} else if (!gridPop.isGrid()) { throw error("Species named " + name + " is not a grid", scope); }
		grid = (IGrid) gridPop.getTopology().getPlaces();
		// final Envelope env = grid.getEnvironmentFrame().getEnvelope();
		final Envelope env2 = scope.getSimulation().getEnvelope();
		final double width = env2.getWidth();
		final double height = env2.getHeight();
		// final double width2 = env2.getWidth();
		// final double height2 = env2.getHeight();
		final double cols = grid.getCols(scope);
		final double rows = grid.getRows(scope);
		cellSize = new GamaPoint(width / cols, height / rows);
	}
	super.compute(scope, g);
	if (shouldComputeImage) {
		computeImage(scope, g);
	}
}
 
Example 4
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 5
Source File: CreateRandomShapeFunctions.java    From jts with GNU Lesser General Public License v2.1 6 votes vote down vote up
public static Geometry randomRadialPoints(Geometry g, int nPts) {
  Envelope env = FunctionsUtil.getEnvelopeOrDefault(g);
  GeometryFactory geomFact = FunctionsUtil.getFactoryOrDefault(g);
  double xLen = env.getWidth();
  double yLen = env.getHeight();
  double rMax = Math.min(xLen, yLen) / 2.0;
  
  double centreX = env.getMinX() + xLen/2;
  double centreY = env.getMinY() + yLen/2;
  
  List pts = new ArrayList();

  for (int i = 0; i < nPts; i++) {
    double rand = Math.random();
    // use rand^2 to accentuate radial distribution
    double r = rMax * rand * rand;
    // produces even distribution
    //double r = rMax * Math.sqrt(rand);
    double ang = 2 * Math.PI * Math.random();
    double x = centreX + r * Math.cos(ang);
    double y = centreY + r * Math.sin(ang);
    pts.add(geomFact.createPoint(new Coordinate(x, y)));
  }
  return geomFact.buildGeometry(pts);
}
 
Example 6
Source File: CreateRandomShapeFunctions.java    From jts with GNU Lesser General Public License v2.1 6 votes vote down vote up
public static Geometry haltonPointsWithBases(Geometry g, int nPts, int basei, int basej)
{
  Envelope env = FunctionsUtil.getEnvelopeOrDefault(g);
  Coordinate[] pts = new Coordinate[nPts];
  double baseX = env.getMinX();
  double baseY = env.getMinY();
  
  int i = 0;
  while (i < nPts) {
    double x = baseX + env.getWidth() * haltonOrdinate(i + 1, basei);
    double y = baseY + env.getHeight() * haltonOrdinate(i + 1, basej);
    Coordinate p = new Coordinate(x, y);
    if (! env.contains(p))
      continue;
    pts[i++] = p;
  }
  return FunctionsUtil.getFactoryOrDefault(g).createMultiPoint(pts);
}
 
Example 7
Source File: CreateRandomShapeFunctions.java    From jts with GNU Lesser General Public License v2.1 6 votes vote down vote up
public static Geometry randomSegments(Geometry g, int nPts) {
  Envelope env = FunctionsUtil.getEnvelopeOrDefault(g);
  GeometryFactory geomFact = FunctionsUtil.getFactoryOrDefault(g);
  double xLen = env.getWidth();
  double yLen = env.getHeight();

  List lines = new ArrayList();

  for (int i = 0; i < nPts; i++) {
    double x0 = env.getMinX() + xLen * Math.random();
    double y0 = env.getMinY() + yLen * Math.random();
    double x1 = env.getMinX() + xLen * Math.random();
    double y1 = env.getMinY() + yLen * Math.random();
    lines.add(geomFact.createLineString(new Coordinate[] {
        new Coordinate(x0, y0), new Coordinate(x1, y1) }));
  }
  return geomFact.buildGeometry(lines);
}
 
Example 8
Source File: CreateRandomShapeFunctions.java    From jts with GNU Lesser General Public License v2.1 6 votes vote down vote up
public static Geometry randomSegmentsInGrid(Geometry g, int nPts) {
  Envelope env = FunctionsUtil.getEnvelopeOrDefault(g);
  GeometryFactory geomFact = FunctionsUtil.getFactoryOrDefault(g);

  int nCell = (int) Math.sqrt(nPts) + 1;

  double xLen = env.getWidth() / nCell;
  double yLen = env.getHeight() / nCell;

  List lines = new ArrayList();

  for (int i = 0; i < nCell; i++) {
    for (int j = 0; j < nCell; j++) {
      double x0 = env.getMinX() + i * xLen + xLen * Math.random();
      double y0 = env.getMinY() + j * yLen + yLen * Math.random();
      double x1 = env.getMinX() + i * xLen + xLen * Math.random();
      double y1 = env.getMinY() + j * yLen + yLen * Math.random();
      lines.add(geomFact.createLineString(new Coordinate[] {
          new Coordinate(x0, y0), new Coordinate(x1, y1) }));
    }
  }
  return geomFact.buildGeometry(lines);
}
 
Example 9
Source File: AbstractTopology.java    From gama with GNU General Public License v3.0 5 votes vote down vote up
protected void createVirtualEnvironments() {
	adjustedXYVector = new double[8][2];
	final Envelope environmentEnvelope = environment.getEnvelope();

	final double environmentWidth = environmentEnvelope.getWidth();
	final double environmentHeight = environmentEnvelope.getHeight();

	// NORTH virtual environment
	adjustedXYVector[0][0] = 0.0;
	adjustedXYVector[0][1] = environmentHeight;

	// NORTH-WEST virtual environment
	adjustedXYVector[1][0] = environmentWidth;
	adjustedXYVector[1][1] = environmentHeight;

	// WEST virtual environment
	adjustedXYVector[2][0] = environmentWidth;
	adjustedXYVector[2][1] = 0.0;

	// SOUTH-WEST virtual environment
	adjustedXYVector[3][0] = environmentWidth;
	adjustedXYVector[3][1] = -environmentHeight;

	// SOUTH virtual environment
	adjustedXYVector[4][0] = 0.0;
	adjustedXYVector[4][1] = -environmentHeight;

	// SOUTH-EAST virtual environment
	adjustedXYVector[5][0] = -environmentWidth;
	adjustedXYVector[5][1] = -environmentHeight;

	// EAST virtual environment
	adjustedXYVector[6][0] = -environmentWidth;
	adjustedXYVector[6][1] = 0.0;

	// NORTH-EAST virtual environment
	adjustedXYVector[7][0] = -environmentWidth;
	adjustedXYVector[7][1] = environmentHeight;

}
 
Example 10
Source File: StressTestHarness.java    From jts with GNU Lesser General Public License v2.1 5 votes vote down vote up
Geometry createRandomTestGeometry(Envelope env, double size, int nPts)
{
	double width = env.getWidth();
	double xOffset = width * Math.random();
	double yOffset = env.getHeight() * Math.random();
  Coordinate basePt = new Coordinate(
  				env.getMinX() + xOffset,
  				env.getMinY() + yOffset);
  Geometry test = createTestCircle(basePt, size, nPts);
  if (test instanceof Polygon && Math.random() > 0.5) {
  	test = test.getBoundary();
  }
  return test;
}
 
Example 11
Source File: PreparedPolygonIntersectsStressTest.java    From jts with GNU Lesser General Public License v2.1 5 votes vote down vote up
LineString createTestLine(Envelope env, double size, int nPts)
{
	double width = env.getWidth();
	double xOffset = width * Math.random();
	double yOffset = env.getHeight() * Math.random();
  Coordinate basePt = new Coordinate(
  				env.getMinX() + xOffset,
  				env.getMinY() + yOffset);
  LineString line = createTestLine(basePt, size, nPts);
  return line;
}
 
Example 12
Source File: Quadtree.java    From jts with GNU Lesser General Public License v2.1 5 votes vote down vote up
private void collectStats(Envelope itemEnv)
{
  double delX = itemEnv.getWidth();
  if (delX < minExtent && delX > 0.0)
    minExtent = delX;

  double delY = itemEnv.getHeight();
  if (delY < minExtent && delY > 0.0)
    minExtent = delY;
}
 
Example 13
Source File: Key.java    From jts with GNU Lesser General Public License v2.1 5 votes vote down vote up
public static int computeQuadLevel(Envelope env)
{
  double dx = env.getWidth();
  double dy = env.getHeight();
  double dMax = dx > dy ? dx : dy;
  int level = DoubleBits.exponent(dMax) + 1;
  return level;
}
 
Example 14
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 15
Source File: CreateRandomShapeFunctions.java    From jts with GNU Lesser General Public License v2.1 5 votes vote down vote up
public static Geometry randomLineString(Geometry g, int nPts) {
  Envelope env = FunctionsUtil.getEnvelopeOrDefault(g);
  GeometryFactory geomFact = FunctionsUtil.getFactoryOrDefault(g);
  double width = env.getWidth();
  double hgt = env.getHeight();

  Coordinate[] pts = new Coordinate[nPts];

  for (int i = 0; i < nPts; i++) {
    double xLen = width * Math.random();
    double yLen = hgt * Math.random();
    pts[i] = randomPtInRectangleAround(env.centre(), xLen, yLen);
  }
  return geomFact.createLineString(pts);
}
 
Example 16
Source File: EnvelopeUtil.java    From jts with GNU Lesser General Public License v2.1 5 votes vote down vote up
public static double maxExtent(Envelope env)
{
	double w = env.getWidth();
	double h = env.getHeight();
	if (w > h) return w;
	return h;
}
 
Example 17
Source File: EnvelopeUtil.java    From jts with GNU Lesser General Public License v2.1 5 votes vote down vote up
public static double minExtent(Envelope env)
{
	double w = env.getWidth();
	double h = env.getHeight();
	if (w < h) return w;
	return h;
}
 
Example 18
Source File: ProjectionFactory.java    From gama with GNU General Public License v3.0 5 votes vote down vote up
public void testConsistency(final IScope scope, final CoordinateReferenceSystem crs, final Envelope env) {
	if (!(crs instanceof DefaultProjectedCRS)) {
		if (env.getHeight() > 180 || env.getWidth() > 180) {
			throw GamaRuntimeException.error(
					"Inconsistency between the data and the CRS: The CRS " + crs
							+ " corresponds to a not projected one, whereas the data seem to be already projected.",
					scope);
		}
	}
}
 
Example 19
Source File: DtoConverterServiceImpl.java    From geomajas-project-server with GNU Affero General Public License v3.0 2 votes vote down vote up
/**
 * Convert JTS envelope into a {@link Bbox}.
 * 
 * @param envelope
 *            JTS envelope
 * @return Geomajas {@link Bbox}
 */
public Bbox toDto(Envelope envelope) {
	return new Bbox(envelope.getMinX(), envelope.getMinY(), envelope.getWidth(), envelope.getHeight());
}
 
Example 20
Source File: TiledFeatureService.java    From geomajas-project-server with GNU Affero General Public License v3.0 2 votes vote down vote up
/**
 * The test that checks if clipping is needed.
 *
 * @param f
 *            feature to test
 * @param scale
 *            scale
 * @return true if clipping is needed
 */
private boolean exceedsScreenDimensions(InternalFeature f, double scale) {
	Envelope env = f.getBounds();
	return (env.getWidth() * scale > MAXIMUM_TILE_COORDINATE) ||
			(env.getHeight() * scale > MAXIMUM_TILE_COORDINATE);
}