Java Code Examples for com.vividsolutions.jts.geom.Envelope#getWidth()
The following examples show how to use
com.vividsolutions.jts.geom.Envelope#getWidth() .
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: OsmLayerTest.java From geomajas-project-server with GNU Affero General Public License v3.0 | 6 votes |
@Test public void testReprojectOne() throws Exception { Envelope googleEnvelope = new Envelope(10000, 10010, 5000, 5010); // back-transform envelope to latlon Crs google = geoService.getCrs2("EPSG:900913"); Crs latlon = geoService.getCrs2("EPSG:4326"); Envelope latlonEnvelope = geoService.transform(JTS.toGeometry(googleEnvelope), google, latlon) .getEnvelopeInternal(); // back-transform scale to latlon double latlonScale = ZOOMED_IN_SCALE * googleEnvelope.getWidth() / latlonEnvelope.getWidth(); // paint with reprojection (affine is fine for now...:-) List<RasterTile> tiles = osm.paint(latlon, latlonEnvelope, latlonScale); Assert.assertEquals(1, tiles.size()); RasterTile tile = tiles.get(0); Assert.assertEquals("http://a.tile.openstreetmap.org/4/8/7.png", tile.getUrl()); Assert.assertEquals(4, tile.getCode().getTileLevel()); Assert.assertEquals(8, tile.getCode().getX()); Assert.assertEquals(7, tile.getCode().getY()); Assert.assertEquals(0.0, tile.getBounds().getX(), DELTA); Assert.assertEquals(-244.0, tile.getBounds().getY(), DELTA); Assert.assertEquals(244.0, tile.getBounds().getHeight(), DELTA); Assert.assertEquals(250.0, tile.getBounds().getWidth(), DELTA); }
Example 2
Source File: GridLayerData.java From gama with GNU General Public License v3.0 | 6 votes |
@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 3
Source File: GeometryEditPanel.java From jts with GNU Lesser General Public License v2.1 | 6 votes |
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 4
Source File: WmsLayerTest.java From geomajas-project-server with GNU Affero General Public License v3.0 | 6 votes |
@Test public void testNormalEncoded() throws Exception { Envelope googleEnvelope = new Envelope(10000, 10010, 5000, 5010); // back-transform envelope to latlon Crs google = geoService.getCrs2(MERCATOR); Crs latlon = geoService.getCrs2(LONLAT); Envelope latlonEnvelope = geoService.transform(JTS.toGeometry(googleEnvelope), google, latlon) .getEnvelopeInternal(); // back-transform scale to latlon double latlonScale = ZOOMED_IN_SCALE * googleEnvelope.getWidth() / latlonEnvelope.getWidth(); // paint with re-projection (affine is fine for now...:-) List<RasterTile> tiles = escapeBlue.paint(latlon, latlonEnvelope, latlonScale); Assert.assertEquals(1, tiles.size()); RasterTile tile = tiles.get(0); // ZOOMED_IN_SCALE 1E-4 corresponds to level 4 with current algorithm !!!! assertThat(tile.getUrl()).isEqualTo("http://apps.geomajas.org/geoserver/wms?SERVICE=WMS&" + "layers=geomajas%3Abluemarble&WIDTH=512&HEIGHT=512&bbox=0,0,45,45&format=image/png&version=1.1.1&" + "srs=EPSG%3A4326&styles=&what%3F=value%2Bmore%21&request=GetMap"); }
Example 5
Source File: LocalProfile.java From geomajas-project-server with GNU Affero General Public License v3.0 | 6 votes |
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 6
Source File: OsmLayerTest.java From geomajas-project-server with GNU Affero General Public License v3.0 | 5 votes |
@Test public void testReprojectSeveral() throws Exception { // move up north to test latlon flattening Envelope googleEnvelope = new Envelope(10000, 13000, 6005000, 6008000); // back-transform envelope to latlon Crs google = geoService.getCrs2("EPSG:900913"); Crs latlon = geoService.getCrs2("EPSG:4326"); Envelope latlonEnvelope = geoService.transform(JTS.toGeometry(googleEnvelope), google, latlon) .getEnvelopeInternal(); // back-transform scale to latlon double latlonScale = MAX_LEVEL_SCALE * googleEnvelope.getWidth() / latlonEnvelope.getWidth(); // paint with reprojection (affine is fine for now...:-) List<RasterTile> tiles = osm.paint(latlon, latlonEnvelope, latlonScale); Assert.assertEquals(4, tiles.size()); Assert.assertEquals("http://a.tile.openstreetmap.org/14/8196/5735.png", tiles.get(0).getUrl()); Assert.assertEquals("http://a.tile.openstreetmap.org/14/8196/5736.png", tiles.get(1).getUrl()); Assert.assertEquals("http://a.tile.openstreetmap.org/14/8197/5735.png", tiles.get(2).getUrl()); Assert.assertEquals("http://a.tile.openstreetmap.org/14/8197/5736.png", tiles.get(3).getUrl()); // test first tile double width = tiles.get(0).getBounds().getWidth(); double height = tiles.get(0).getBounds().getHeight(); double x = tiles.get(0).getBounds().getX(); double y = tiles.get(0).getBounds().getY(); Assert.assertEquals(245, width, DELTA); Assert.assertEquals(166, height, DELTA); Assert.assertEquals(978, x, DELTA); Assert.assertEquals(-527802, y, DELTA); // test alignment on grid for (int i = 0; i <= 1; i++) { for (int j = 0; j <= 1; j++) { Assert.assertEquals(x + i * width, tiles.get(2 * i + j).getBounds().getX(), DELTA); Assert.assertEquals(y + j * height, tiles.get(2 * i + j).getBounds().getY(), DELTA); Assert.assertEquals(width, tiles.get(2 * i + j).getBounds().getWidth(), DELTA); Assert.assertEquals(height, tiles.get(2 * i + j).getBounds().getHeight(), DELTA); } } }
Example 7
Source File: StressTestHarness.java From jts with GNU Lesser General Public License v2.1 | 5 votes |
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 8
Source File: PreparedPolygonIntersectsStressTest.java From jts with GNU Lesser General Public License v2.1 | 5 votes |
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 9
Source File: WmsLayerTest.java From geomajas-project-server with GNU Affero General Public License v3.0 | 5 votes |
@Test public void testProxyOne() throws Exception { Envelope googleEnvelope = new Envelope(10000, 10010, 5000, 5010); // back-transform envelope to latlon Crs google = geoService.getCrs2(MERCATOR); Crs latlon = geoService.getCrs2(LONLAT); Envelope latlonEnvelope = geoService.transform(JTS.toGeometry(googleEnvelope), google, latlon) .getEnvelopeInternal(); // back-transform scale to latlon double latlonScale = ZOOMED_IN_SCALE * googleEnvelope.getWidth() / latlonEnvelope.getWidth(); // paint with re-projection (affine is fine for now...:-) List<RasterTile> tiles = proxyWms.paint(latlon, latlonEnvelope, latlonScale); Assert.assertEquals(1, tiles.size()); RasterTile tile = tiles.get(0); Assert.assertEquals("./d/wms/proxyBlue/?SERVICE=WMS&layers=bluemarble&WIDTH=512&HEIGHT=512&bbox" + "=-20,-28,12,4&format=image/jpeg&version=1.3.0&crs=EPSG%3A4326&styles=&request=GetMap", tile.getUrl()); Assert.assertEquals(4, tile.getCode().getTileLevel()); Assert.assertEquals(5, tile.getCode().getX()); Assert.assertEquals(12, tile.getCode().getY()); Assert.assertEquals(-223.0, tile.getBounds().getX(), DELTA); Assert.assertEquals(-45.0, tile.getBounds().getY(), DELTA); Assert.assertEquals(357.0, tile.getBounds().getHeight(), DELTA); Assert.assertEquals(357.0, tile.getBounds().getWidth(), DELTA); // Assert.assertEquals("./d/wms/proxyBlue/?SERVICE=WMS&layers=bluemarble&WIDTH=512&HEIGHT=512&" // + "bbox=-20.032430835865227,-28.207099921352835,11.947593278789554,3.7729241933019466&" // + "format=image/jpeg&version=1.3.0&crs=EPSG%3A4326&styles=&request=GetMap", tile.getUrl()); // Assert.assertEquals(4, tile.getCode().getTileLevel()); // Assert.assertEquals(5, tile.getCode().getX()); // Assert.assertEquals(12, tile.getCode().getY()); // Assert.assertEquals(-223.0, tile.getBounds().getX(), DELTA); // Assert.assertEquals(-42.0, tile.getBounds().getY(), DELTA); // Assert.assertEquals(356.0, tile.getBounds().getHeight(), DELTA); // Assert.assertEquals(356.0, tile.getBounds().getWidth(), DELTA); }
Example 10
Source File: ConformingDelaunayTriangulator.java From jts with GNU Lesser General Public License v2.1 | 5 votes |
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 11
Source File: CreateRandomShapeFunctions.java From jts with GNU Lesser General Public License v2.1 | 5 votes |
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 12
Source File: WmsLayerTest.java From geomajas-project-server with GNU Affero General Public License v3.0 | 5 votes |
@Test public void testNormalOne() throws Exception { Envelope googleEnvelope = new Envelope(10000, 10010, 5000, 5010); // back-transform envelope to latlon Crs google = geoService.getCrs2(MERCATOR); Crs latlon = geoService.getCrs2(LONLAT); Envelope latlonEnvelope = geoService.transform(JTS.toGeometry(googleEnvelope), google, latlon) .getEnvelopeInternal(); // back-transform scale to latlon double latlonScale = ZOOMED_IN_SCALE * googleEnvelope.getWidth() / latlonEnvelope.getWidth(); // paint with re-projection (affine is fine for now...:-) List<RasterTile> tiles = wms.paint(latlon, latlonEnvelope, latlonScale); Assert.assertEquals(1, tiles.size()); RasterTile tile = tiles.get(0); // ZOOMED_IN_SCALE 1E-4 corresponds to level 4 with current algorithm !!!! Assert.assertEquals("http://apps.geomajas.org/geoserver/wms?SERVICE=WMS&layers=bluemarble&" + "WIDTH=512&HEIGHT=512&bbox=-20,-28,12,4&format=image/jpeg&version=1.1.1&srs=EPSG%3A4326&" + "styles=&request=GetMap", tile.getUrl()); // Assert.assertEquals("http://apps.geomajas.org/geoserver/wms?SERVICE=WMS&" // + "layers=bluemarble&WIDTH=512&HEIGHT=512&" // + "bbox=-20.032430835865227,-28.207099921352835,11.947593278789554,3.7729241933019466&" // + "format=image/jpeg&version=1.1.1&srs=EPSG%3A4326&styles=&request=GetMap", tile.getUrl()); Assert.assertEquals(4, tile.getCode().getTileLevel()); Assert.assertEquals(5, tile.getCode().getX()); Assert.assertEquals(12, tile.getCode().getY()); Assert.assertEquals(-223.0, tile.getBounds().getX(), DELTA); // Assert.assertEquals(-42.0, tile.getBounds().getY(), DELTA); Assert.assertEquals(-45.0, tile.getBounds().getY(), DELTA); // Assert.assertEquals(356.0, tile.getBounds().getHeight(), DELTA); Assert.assertEquals(357.0, tile.getBounds().getHeight(), DELTA); // Assert.assertEquals(356.0, tile.getBounds().getWidth(), DELTA); Assert.assertEquals(357.0, tile.getBounds().getWidth(), DELTA); }
Example 13
Source File: ProjectionFactory.java From gama with GNU General Public License v3.0 | 5 votes |
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 14
Source File: EnvelopeUtil.java From jts with GNU Lesser General Public License v2.1 | 5 votes |
public static double minExtent(Envelope env) { double w = env.getWidth(); double h = env.getHeight(); if (w < h) return w; return h; }
Example 15
Source File: Viewport.java From jts with GNU Lesser General Public License v2.1 | 5 votes |
public void zoom(Envelope zoomEnv) { double xScale = getWidthInView() / zoomEnv.getWidth(); double yScale = getHeightInView() / zoomEnv.getHeight(); double zoomScale = Math.min(xScale, yScale); setScale(zoomScale); double xCentering = (getWidthInModel() - zoomEnv.getWidth()) / 2d; double yCentering = (getHeightInModel() - zoomEnv.getHeight()) / 2d; setOrigin(zoomEnv.getMinX() - xCentering, zoomEnv.getMinY() - yCentering); }
Example 16
Source File: GamaQuadTree.java From gama with GNU General Public License v3.0 | 5 votes |
public QuadNode(final Envelope bounds) { this.bounds = bounds; final double hw = bounds.getWidth(); final double hh = bounds.getHeight(); halfx = bounds.getMinX() + hw / 2; halfy = bounds.getMinY() + hh / 2; canSplit = hw > minSize && hh > minSize; }
Example 17
Source File: GamaQuadTree.java From gama with GNU General Public License v3.0 | 5 votes |
private GamaQuadTree(final Envelope bounds, final boolean sync) { // AD To address Issue 804, explictely converts the bounds to an // Envelope 2D, so that all computations are made // in 2D in the QuadTree this.parallel = sync; root = new QuadNode(new Envelope(bounds)); minSize = bounds.getWidth() / 100d; // GamaPreferences.External.QUADTREE_SYNCHRONIZATION.onChange((v) -> { // parallel = v; // root.synchronizeChanged(); // }); }
Example 18
Source File: WmsLayerTest.java From geomajas-project-server with GNU Affero General Public License v3.0 | 4 votes |
@Test public void testDefaultsOne() throws Exception { Envelope googleEnvelope = new Envelope(10000, 10010, 5000, 5010); // back-transform envelope to latlon Crs google = geoService.getCrs2(MERCATOR); Crs latlon = geoService.getCrs2(LONLAT); Envelope latlonEnvelope = geoService.transform(JTS.toGeometry(googleEnvelope), google, latlon) .getEnvelopeInternal(); // back-transform scale to latlon double latlonScale = ZOOMED_IN_SCALE * googleEnvelope.getWidth() / latlonEnvelope.getWidth(); // paint with re-projection (affine is fine for now...:-) List<RasterTile> tiles = defaultWms.paint(latlon, latlonEnvelope, latlonScale); Assert.assertEquals(1, tiles.size()); RasterTile tile = tiles.get(0); Assert.assertEquals("http://apps.geomajas.org/geoserver/wms?SERVICE=WMS&layers=bluemarble&WIDTH=512&HEIGHT" + "=512&bbox=-20,-28,12,4&format=image/png&version=1.1.1&srs=EPSG%3A4326&styles=&request=GetMap", tile.getUrl()); Assert.assertEquals(4, tile.getCode().getTileLevel()); Assert.assertEquals(5, tile.getCode().getX()); Assert.assertEquals(12, tile.getCode().getY()); Assert.assertEquals(-223.0, tile.getBounds().getX(), DELTA); Assert.assertEquals(-45.0, tile.getBounds().getY(), DELTA); Assert.assertEquals(357.0, tile.getBounds().getHeight(), DELTA); Assert.assertEquals(357.0, tile.getBounds().getWidth(), DELTA); // Assert.assertEquals("http://apps.geomajas.org/geoserver/wms?SERVICE=WMS&layers=bluemarble&" // + "WIDTH=512&HEIGHT=512&bbox=-20.032430835865227,-28.207099921352835,11.947593278789554," // + "3.7729241933019466&format=image/png&version=1.1.1&srs=EPSG%3A4326&styles=&request=GetMap", // tile.getUrl()); // Assert.assertEquals(4, tile.getCode().getTileLevel()); // Assert.assertEquals(5, tile.getCode().getX()); // Assert.assertEquals(12, tile.getCode().getY()); // Assert.assertEquals(-223.0, tile.getBounds().getX(), DELTA); // Assert.assertEquals(-42.0, tile.getBounds().getY(), DELTA); // Assert.assertEquals(356.0, tile.getBounds().getHeight(), DELTA); // Assert.assertEquals(356.0, tile.getBounds().getWidth(), DELTA); }
Example 19
Source File: TiledFeatureService.java From geomajas-project-server with GNU Affero General Public License v3.0 | 2 votes |
/** * 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); }
Example 20
Source File: DtoConverterServiceImpl.java From geomajas-project-server with GNU Affero General Public License v3.0 | 2 votes |
/** * 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()); }