Java Code Examples for org.geotools.geometry.jts.ReferencedEnvelope#getHeight()
The following examples show how to use
org.geotools.geometry.jts.ReferencedEnvelope#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: ImageGenerator.java From hortonmachine with GNU General Public License v3.0 | 6 votes |
/** * Draw the map on an image. * * @param bounds the area of interest. * @param imageWidth the width of the image to produce. * @param imageHeight the height of the image to produce. * @param buffer the buffer to add around the map bounds in map units. * @return the image. */ public BufferedImage drawImage( ReferencedEnvelope ref, int imageWidth, int imageHeight, double buffer ) { checkMapContent(); if (buffer > 0.0) ref.expandBy(buffer, buffer); Rectangle2D refRect = new Rectangle2D.Double(ref.getMinX(), ref.getMinY(), ref.getWidth(), ref.getHeight()); Rectangle2D imageRect = new Rectangle2D.Double(0, 0, imageWidth, imageHeight); GeometryUtilities.scaleToRatio(imageRect, refRect, false); ReferencedEnvelope newRef = new ReferencedEnvelope(refRect, ref.getCoordinateReferenceSystem()); Rectangle imageBounds = new Rectangle(0, 0, imageWidth, imageHeight); BufferedImage dumpImage = new BufferedImage(imageWidth, imageHeight, BufferedImage.TYPE_INT_RGB); Graphics2D g2d = dumpImage.createGraphics(); g2d.fillRect(0, 0, imageWidth, imageHeight); g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); synchronized (renderer) { renderer.paint(g2d, imageBounds, newRef); } return dumpImage; }
Example 2
Source File: ImageGenerator.java From hortonmachine with GNU General Public License v3.0 | 6 votes |
public void drawImage( Graphics2D g2d, ReferencedEnvelope ref, int imageWidth, int imageHeight, double buffer ) { checkMapContent(); if (buffer > 0.0) ref.expandBy(buffer, buffer); Rectangle2D refRect = new Rectangle2D.Double(ref.getMinX(), ref.getMinY(), ref.getWidth(), ref.getHeight()); Rectangle2D imageRect = new Rectangle2D.Double(0, 0, imageWidth, imageHeight); GeometryUtilities.scaleToRatio(imageRect, refRect, false); ReferencedEnvelope newRef = new ReferencedEnvelope(refRect, ref.getCoordinateReferenceSystem()); Rectangle imageBounds = new Rectangle(0, 0, imageWidth, imageHeight); Color white = Color.white; g2d.setColor(new Color(white.getRed(), white.getGreen(), white.getBlue(), 0)); g2d.fillRect(0, 0, imageWidth, imageHeight); g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); synchronized (renderer) { content.getViewport().setBounds(newRef); renderer.paint(g2d, imageBounds, newRef); } }
Example 3
Source File: FeatureLayer.java From snap-desktop with GNU General Public License v3.0 | 6 votes |
public FeatureLayer(LayerType layerType, final FeatureCollection<SimpleFeatureType, SimpleFeature> fc, PropertySet configuration) { super(layerType, configuration); crs = fc.getSchema().getGeometryDescriptor().getCoordinateReferenceSystem(); if (crs == null) { // todo - check me! Why can this happen??? (nf) crs = DefaultGeographicCRS.WGS84; } final ReferencedEnvelope envelope = new ReferencedEnvelope(fc.getBounds(), crs); modelBounds = new Rectangle2D.Double(envelope.getMinX(), envelope.getMinY(), envelope.getWidth(), envelope.getHeight()); mapContext = new DefaultMapContext(crs); final Style style = (Style) configuration.getValue(FeatureLayerType.PROPERTY_NAME_SLD_STYLE); mapContext.addLayer(fc, style); renderer = new StreamingRenderer(); workaroundLabelCacheBug(); style.accept(new RetrievingStyleVisitor()); renderer.setContext(mapContext); }
Example 4
Source File: RenderPanelImpl.java From sldeditor with GNU General Public License v3.0 | 5 votes |
/** * Expand envelope. * * @param bounds the bounds */ private void expandEnvelope(ReferencedEnvelope bounds) { Unit<?> unit = CRSUtilities.getUnit(bounds.getCoordinateReferenceSystem().getCoordinateSystem()); double width; double height; if (unit == NonSI.DEGREE_ANGLE) { width = (bounds.getWidth() < BOUNDINGBOX_BUFFER_THRESHOLD_ANGLE) ? BOUNDINGBOX_BUFFER_MIN_ANGLE : (bounds.getWidth() * BOUNDINGBOX_BUFFER_ANGLE); height = (bounds.getHeight() < BOUNDINGBOX_BUFFER_THRESHOLD_ANGLE) ? BOUNDINGBOX_BUFFER_MIN_ANGLE : (bounds.getHeight() * BOUNDINGBOX_BUFFER_ANGLE); } else { width = (bounds.getWidth() < BOUNDINGBOX_BUFFER_THRESHOLD_LINEAR) ? BOUNDINGBOX_BUFFER_MIN_LINEAR : (bounds.getWidth() * BOUNDINGBOX_BUFFER_LINEAR); height = (bounds.getHeight() < BOUNDINGBOX_BUFFER_THRESHOLD_LINEAR) ? BOUNDINGBOX_BUFFER_MIN_LINEAR : (bounds.getHeight() * BOUNDINGBOX_BUFFER_LINEAR); } bounds.expandBy(width, height); }
Example 5
Source File: GamaOsmFile.java From gama with GNU General Public License v3.0 | 5 votes |
public OSMInfo(final URL url, final long modificationStamp) { super(modificationStamp); CoordinateReferenceSystem crs = null; ReferencedEnvelope env2 = new ReferencedEnvelope(); int number = 0; try { final File f = new File(url.toURI()); final GamaOsmFile osmfile = new GamaOsmFile(null, f.getAbsolutePath()); attributes.putAll(osmfile.getOSMAttributes(GAMA.getRuntimeScope())); final SimpleFeatureType TYPE = DataUtilities.createType("geometries", "geom:LineString"); final ArrayList<SimpleFeature> list = new ArrayList<>(); for (final IShape shape : osmfile.iterable(null)) { list.add(SimpleFeatureBuilder.build(TYPE, new Object[] { shape.getInnerGeometry() }, null)); } final SimpleFeatureCollection collection = new ListFeatureCollection(TYPE, list); final SimpleFeatureSource featureSource = DataUtilities.source(collection); env2 = featureSource.getBounds(); number = osmfile.nbObjects; crs = osmfile.getOwnCRS(null); } catch (final Exception e) { DEBUG.ERR("Error in reading metadata of " + url); hasFailed = true; } finally { // approximation of the width and height in meters. width = env2 != null ? env2.getWidth() * (Math.PI / 180) * 6378137 : 0; height = env2 != null ? env2.getHeight() * (Math.PI / 180) * 6378137 : 0; itemNumber = number; this.crs = crs; } }
Example 6
Source File: RasterizedShapefilesFolderNwwLayer.java From hortonmachine with GNU General Public License v3.0 | 5 votes |
private static GTRenderer getRenderer(File shapeFilesFolder) { File[] shpFiles = shapeFilesFolder.listFiles(new FilenameFilter() { @Override public boolean accept(File dir, String name) { return name.toLowerCase().endsWith(".shp"); } }); MapContent mapContent = new MapContent(); for (File shpFile : shpFiles) { try { SimpleFeatureCollection readFC = NwwUtilities.readAndReproject(shpFile.getAbsolutePath()); ReferencedEnvelope tmpBounds = readFC.getBounds(); if (tmpBounds.getWidth() == 0 || tmpBounds.getHeight() == 0) { System.err.println("Ignoring: " + shpFile); continue; } // if (bounds == null) { // bounds = new ReferencedEnvelope(tmpBounds); // } else { // bounds.expandToInclude(tmpBounds); // } Style style = SldUtilities.getStyleFromFile(shpFile); if (style == null) style = SLD.createSimpleStyle(readFC.getSchema()); FeatureLayer layer = new FeatureLayer(readFC, style); mapContent.addLayer(layer); } catch (Exception e) { e.printStackTrace(); } } GTRenderer renderer = new StreamingRenderer(); renderer.setMapContent(mapContent); return renderer; }
Example 7
Source File: MaskFormActions.java From snap-desktop with GNU General Public License v3.0 | 5 votes |
private static Rectangle2D handleVectorMask(Mask mask) { VectorDataNode vectorData = Mask.VectorDataType.getVectorData(mask); ReferencedEnvelope envelope = vectorData.getEnvelope(); if (!envelope.isEmpty()) { return new Rectangle2D.Double(envelope.getMinX(), envelope.getMinY(), envelope.getWidth(), envelope.getHeight()); } return null; }
Example 8
Source File: WebMapsController.java From hortonmachine with GNU General Public License v3.0 | 4 votes |
private void getFinalImage() { int imageWidth = Integer.parseInt(_outputWithField.getText()); int imageHeight = Integer.parseInt(_outputHeightField.getText()); // String filePath = _boundsFileField.getText(); if (readEnvelope == null) { GuiUtilities.showWarningMessage(this, "A bounds file has to be loaded to export to geotiff."); return; } ReferencedEnvelope envelope = readEnvelope; // try { // if (filePath.endsWith(HMConstants.SUPPORTED_VECTOR_EXTENSIONS[0])) { // envelope = OmsVectorReader.readEnvelope(filePath); // } else { // GridCoverage2D raster = OmsRasterReader.readRaster(filePath); // Polygon regionPolygon = CoverageUtilities.getRegionPolygon(raster); // envelope = new ReferencedEnvelope(regionPolygon.getEnvelopeInternal(), raster.getCoordinateReferenceSystem()); // } // } catch (Exception e2) { // e2.printStackTrace(); // GuiUtilities.showErrorMessage(this, "Could not load bounds from file: " + e2.getLocalizedMessage()); // return; // } try { String style = ""; Object selectedStyleObj = _stylesCombo.getSelectedItem(); if (selectedStyleObj != null) { style = selectedStyleObj.toString(); } StyleImpl styleImpl = stylesMap.get(style); String selectedLayer = _layersCombo.getSelectedItem().toString(); Layer layer = name2LayersMap.get(selectedLayer); String selectedFormat = _formatsCombo.getSelectedItem().toString(); String epsg = _crsCombo.getSelectedItem().toString(); CoordinateReferenceSystem crs = getCrs(epsg); ReferencedEnvelope env = envelope.transform(crs, true); GetMapRequest mapRequest = currentWms.getMapRequest(layer, selectedFormat, epsg, imageWidth, imageHeight, env, null, styleImpl); GuiUtilities.copyToClipboard(currentWms.getUrl(mapRequest).toString()); BufferedImage image = currentWms.getImage(mapRequest); if (image != null) { double xRes = env.getWidth() / imageWidth; double yRes = env.getHeight() / imageHeight; RegionMap envParams = CoverageUtilities.makeRegionParamsMap(env.getMaxY(), env.getMinY(), env.getMinX(), env.getMaxX(), xRes, yRes, imageHeight, imageHeight); GridCoverage2D coverage = CoverageUtilities.buildCoverage("wms2tiff", image, envParams, crs); String outPath = _outputFileField.getText(); OmsRasterWriter.writeRaster(outPath, coverage); CoverageUtilities.writeWorldFiles(coverage, outPath); // ImageIO.write(image, "png", new File(outPath)); } else { String message = currentWms.getMessage(mapRequest); if (message.contains("ServiceException")) { final Pattern pattern = Pattern.compile("<ServiceException>(.+?)</ServiceException>", Pattern.DOTALL); final Matcher matcher = pattern.matcher(message); matcher.find(); message = matcher.group(1); if (message != null) { message = message.trim(); GuiUtilities.showWarningMessage(this, message); return; } } GuiUtilities.showWarningMessage(this, "Could not retrieve image for given parameters."); } } catch (Exception e1) { e1.printStackTrace(); GuiUtilities.handleError(this, e1); } }