Java Code Examples for com.vividsolutions.jts.geom.Envelope#intersection()
The following examples show how to use
com.vividsolutions.jts.geom.Envelope#intersection() .
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: GeoServiceImpl.java From geomajas-project-server with GNU Affero General Public License v3.0 | 6 votes |
@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 2
Source File: GeoServiceImpl.java From geomajas-project-server with GNU Affero General Public License v3.0 | 6 votes |
@Override @edu.umd.cs.findbugs.annotations.SuppressWarnings(value = "REC_CATCH_EXCEPTION") public Envelope transform(Envelope source, CrsTransform crsTransform) { try { if (crsTransform.isTransforming()) { Envelope transformableArea = crsTransform.getTransformableEnvelope(); if (null != transformableArea) { source = source.intersection(transformableArea); } if (source.isNull()) { return source; } else { ReferencedEnvelope refEnvelope = new ReferencedEnvelope(source, crsTransform.getSource()); return refEnvelope.transform(crsTransform.getTarget(), true); } } else { return source; } } catch (Exception e) { // NOSONAR typically TopologyException, TransformException or FactoryException logEnvelopeSuggestCrsTransformInfo(crsTransform.getId(), source, e); return new Envelope(); } }
Example 3
Source File: CombineIntersectionService.java From geomajas-project-server with GNU Affero General Public License v3.0 | 5 votes |
public Envelope combine(List<GetLocationResult> results) { Envelope result = null; for (GetLocationResult add : results) { Envelope envelope = add.getEnvelope(); if (null == result) { result = envelope; } else { result = result.intersection(envelope); } } return result; }
Example 4
Source File: TiledRasterLayerService.java From geomajas-project-server with GNU Affero General Public License v3.0 | 4 votes |
private Envelope clipBounds(TiledRasterLayerServiceState tileServiceState, Envelope bounds) { return bounds.intersection(tileServiceState.getMaxBounds()); }
Example 5
Source File: TmsLayer.java From geomajas-project-server with GNU Affero General Public License v3.0 | 4 votes |
@Override public List<RasterTile> paint(CoordinateReferenceSystem boundsCrs, Envelope bounds, double scale) throws GeomajasException { log.debug("Fetching TMS tiles for bounds : {}", bounds.toString()); if (!usable) { retryInit(); } Envelope layerBounds = bounds; double layerScale = scale; CrsTransform layerToMap = null; boolean needTransform = !state.getCrs().equals(boundsCrs); try { // We don't necessarily need to split into same CRS and different CRS cases, the latter implementation uses // identity transform if CRSs are equal for map and layer but might introduce bugs in rounding and/or // conversions. if (needTransform) { layerToMap = geoService.getCrsTransform(state.getCrs(), boundsCrs); CrsTransform mapToLayer = geoService.getCrsTransform(boundsCrs, state.getCrs()); // Translate the map coordinates to layer coordinates, assumes equal x-y orientation layerBounds = geoService.transform(bounds, mapToLayer); layerScale = bounds.getWidth() * scale / layerBounds.getWidth(); } } catch (MismatchedDimensionException e) { throw new GeomajasException(e, ExceptionCode.RENDER_DIMENSION_MISMATCH); } // Clip with maximum bounds and check for null: layerBounds = layerBounds.intersection(state.getMaxBounds()); if (bounds.isNull()) { return new ArrayList<RasterTile>(); } // Get the tile level and it's size in world space: int tileLevel = tileService.getTileLevel(state, 1 / layerScale); double tileWidth = tileService.getTileWidth(state, tileLevel); double tileHeight = tileService.getTileHeight(state, tileLevel); int ymin = (int) Math.floor((layerBounds.getMinY() - state.getMaxBounds().getMinY()) / tileHeight); int ymax = (int) Math.ceil((layerBounds.getMaxY() - state.getMaxBounds().getMinY()) / tileHeight); int xmin = (int) Math.floor((layerBounds.getMinX() - state.getMaxBounds().getMinX()) / tileWidth); int xmax = (int) Math.ceil((layerBounds.getMaxX() - state.getMaxBounds().getMinX()) / tileWidth); double lowerLeftX = state.getMaxBounds().getMinX() + xmin * tileWidth; double lowerLeftY = state.getMaxBounds().getMinY() + ymin * tileHeight; List<RasterTile> result = new ArrayList<RasterTile>(); for (int i = xmin; i < xmax; i++) { for (int j = ymin; j < ymax; j++) { // Get the lower-left corner of each tile: double x = lowerLeftX + (i - xmin) * tileWidth; double y = lowerLeftY + (j - ymin) * tileHeight; // Get the bounding box for each tile: Bbox tileBounds = new Bbox(x, y, tileWidth, tileHeight); if (needTransform) { // Transforming back to map coordinates will only result in a proper grid if the transformation // is nearly affine tileBounds = geoService.transform(tileBounds, layerToMap); } // Rounding to avoid white space between raster tiles lower-left becomes upper-left in inverted y-space Bbox screenBox = new Bbox(Math.round(scale * tileBounds.getX()), -Math.round(scale * tileBounds.getMaxY()), Math.round(scale * tileBounds.getMaxX()) - Math.round(scale * tileBounds.getX()), Math.round(scale * tileBounds.getMaxY()) - Math.round(scale * tileBounds.getY())); RasterTile image = new RasterTile(screenBox, getId() + "." + tileLevel + "." + i + "," + j); TileCode tileCode = new TileCode(tileLevel, i, j); image.setCode(tileCode); image.setUrl(formatUrl(urlBuilder.buildUrl(tileCode, getTmsTargetUrl()))); result.add(image); } } return result; }
Example 6
Source File: WmsLayer.java From geomajas-project-server with GNU Affero General Public License v3.0 | 4 votes |
private Envelope clipBounds(Envelope bounds) { Envelope maxExtent = converterService.toInternal(layerInfo.getMaxExtent()); return bounds.intersection(maxExtent); }
Example 7
Source File: GoogleLayer.java From geomajas-project-server with GNU Affero General Public License v3.0 | 4 votes |
private Envelope clipBounds(Envelope bounds) { return bounds.intersection(maxBounds); }