List of usage examples for java.awt.geom Rectangle2D getHeight
public abstract double getHeight();
From source file:genlab.gui.jfreechart.EnhancedSpiderWebPlot.java
/** * Returns a cartesian point from a polar angle, length and bounding box * * @param bounds the area inside which the point needs to be. * @param angle the polar angle, in degrees. * @param length the relative length. Given in percent of maximum extend. * * @return The cartesian point./*from w w w. jav a2 s .c o m*/ */ protected Point2D getWebPoint(Rectangle2D bounds, double angle, double length) { double angrad = Math.toRadians(angle); double x = Math.cos(angrad) * length * bounds.getWidth() / 2; double y = -Math.sin(angrad) * length * bounds.getHeight() / 2; return new Point2D.Double(bounds.getX() + x + bounds.getWidth() / 2, bounds.getY() + y + bounds.getHeight() / 2); }
From source file:org.photovault.imginfo.PhotoInfo.java
@Transient public Dimension getCroppedSize() { double rot = processing.getRotation() * Math.PI / 180.0; double origWidth = original.getWidth(); double origHeight = original.getHeight(); double rotSin = Math.abs(Math.sin(rot)); double rotCos = Math.abs(Math.cos(rot)); double rotWidth = origWidth * rotCos + origHeight * rotSin; double rotHeight = origWidth * rotSin + origHeight * rotCos; Rectangle2D crop = processing.getCropping(); Dimension ret = new Dimension((int) (rotWidth * crop.getWidth()), (int) (rotHeight * crop.getHeight())); return ret;/* ww w . j av a 2 s . c o m*/ }
From source file:org.geotools.utils.imagemosaic.MosaicIndexBuilder.java
/** * This method is responsible for computing the resolutions in for the * provided grid geometry in the provided crs. * /* www . j a v a2s. c o m*/ * <P> * It is worth to note that the returned resolution array is of length of 2 * and it always is lon, lat for the moment.<br> * It might be worth to remove the axes reordering code when we are * confident enough with the code to handle the north-up crs. * <p> * TODO use orthodromic distance? * * @param envelope * the GeneralEnvelope * @param dim * @param crs * @throws DataSourceException */ protected final double[] getResolution(GeneralEnvelope envelope, Rectangle2D dim, CoordinateReferenceSystem crs) throws DataSourceException { double[] requestedRes = null; try { if (dim != null && envelope != null) { // do we need to transform the originalEnvelope? final CoordinateReferenceSystem crs2D = CRSUtilities .getCRS2D(envelope.getCoordinateReferenceSystem()); if (crs != null && !CRS.equalsIgnoreMetadata(crs, crs2D)) { final MathTransform tr = CRS.findMathTransform(crs2D, crs); if (!tr.isIdentity()) envelope = CRS.transform(tr, envelope); } requestedRes = new double[2]; requestedRes[0] = envelope.getLength(0) / dim.getWidth(); requestedRes[1] = envelope.getLength(1) / dim.getHeight(); } return requestedRes; } catch (TransformException e) { throw new DataSourceException("Unable to get the resolution", e); } catch (FactoryException e) { throw new DataSourceException("Unable to get the resolution", e); } }
From source file:org.geoserver.wps.gs.download.DownloadProcessTest.java
/** * Test download of selected bands of raster data, scald and using a ROI area. * Result contains only band 1.//from w w w . jav a2s. c o m * * @throws Exception the exception */ @Test public void testDownloadRasterSelectedBandsScaledWithROI() throws Exception { // Estimator process for checking limits DownloadEstimatorProcess limits = new DownloadEstimatorProcess(new StaticDownloadServiceConfiguration(), getGeoServer()); final WPSResourceManager resourceManager = getResourceManager(); // Creates the new process for the download DownloadProcess downloadProcess = new DownloadProcess(getGeoServer(), limits, resourceManager); /////////////////////////////////////// // test full coverage // /////////////////////////////////////// Polygon roi = (Polygon) new WKTReader2().read("POLYGON (( " + "-127.57473954542964 54.06575021619523, " + "-130.88669845369998 52.00807146727025, " + "-129.50812897394974 49.85372324691927, " + "-130.5300633861675 49.20465679591609, " + "-129.25955033314003 48.60392508062591, " + "-128.00975216684665 50.986137055052474, " + "-125.8623089087404 48.63154492960477, " + "-123.984159178178 50.68231871628503, " + "-126.91186316993704 52.15307567440926, " + "-125.3444367403868 53.54787804784162, " + "-127.57473954542964 54.06575021619523 " + "))"); roi.setSRID(4326); // Download the coverage as tiff File rasterZip = downloadProcess.execute(getLayerId(MockData.USA_WORLDIMG), // layerName null, // filter "image/tiff", // outputFormat null, // targetCRS CRS.decode("EPSG:4326", true), // roiCRS roi, // roi false, // cropToGeometry null, // interpolation 40, // targetSizeX 40, // targetSizeY new int[] { 1 }, // bandSelectIndices new NullProgressListener() // progressListener ); // Final checks on the result Assert.assertNotNull(rasterZip); GeoTiffReader reader = null; GridCoverage2D gc = null; try { final File[] tiffFiles = extractTIFFFile(rasterZip); Assert.assertNotNull(tiffFiles); Assert.assertTrue(tiffFiles.length > 0); reader = new GeoTiffReader(tiffFiles[0]); gc = reader.read(null); Assert.assertNotNull(gc); // check bands Assert.assertEquals(1, gc.getNumSampleDimensions()); Rectangle2D originalGridRange = (GridEnvelope2D) reader.getOriginalGridRange(); Assert.assertEquals(40, Math.round(originalGridRange.getWidth())); Assert.assertEquals(40, Math.round(originalGridRange.getHeight())); // check envelope Assert.assertEquals(-130.88669845369998, gc.getEnvelope().getLowerCorner().getOrdinate(0), 1E-6); Assert.assertEquals(48.611129008700004, gc.getEnvelope().getLowerCorner().getOrdinate(1), 1E-6); Assert.assertEquals(-123.95304462109999, gc.getEnvelope().getUpperCorner().getOrdinate(0), 1E-6); Assert.assertEquals(54.0861661371, gc.getEnvelope().getUpperCorner().getOrdinate(1), 1E-6); } finally { if (gc != null) { CoverageCleanerCallback.disposeCoverage(gc); } if (reader != null) { reader.dispose(); } // clean up process resourceManager.finished(resourceManager.getExecutionId(true)); } }
From source file:org.gumtree.vis.hist2d.Hist2DPanel.java
@Override public void moveSelectedMask(int direction) { Abstract2DMask selectedMask = getSelectedMask(); if (selectedMask == null) { return;/* w w w . j ava 2s . c om*/ } double blockWidth = 0; double blockHeight = 0; try { XYBlockRenderer render = (XYBlockRenderer) ((XYPlot) getChart().getPlot()).getRenderer(); blockWidth = render.getBlockWidth(); blockHeight = render.getBlockHeight(); if (getChart().getXYPlot().getDomainAxis().isInverted()) { blockWidth = -blockHeight; } if (getChart().getXYPlot().getRangeAxis().isInverted()) { blockHeight = -blockHeight; } } catch (Exception e) { e.printStackTrace(); return; } Rectangle2D frame = selectedMask.getRectangleFrame(); switch (direction) { case SWT.ARROW_UP: selectedMask.setRectangleFrame(new Rectangle2D.Double(frame.getMinX(), frame.getMinY() + blockHeight, frame.getWidth(), frame.getHeight())); break; case SWT.ARROW_LEFT: selectedMask.setRectangleFrame(new Rectangle2D.Double(frame.getMinX() - blockWidth, frame.getMinY(), frame.getWidth(), frame.getHeight())); break; case SWT.ARROW_RIGHT: selectedMask.setRectangleFrame(new Rectangle2D.Double(frame.getMinX() + blockWidth, frame.getMinY(), frame.getWidth(), frame.getHeight())); break; case SWT.ARROW_DOWN: selectedMask.setRectangleFrame(new Rectangle2D.Double(frame.getMinX(), frame.getMinY() - blockHeight, frame.getWidth(), frame.getHeight())); break; default: break; } repaint(); fireMaskUpdateEvent(getSelectedMask()); }
From source file:org.gumtree.vis.hist2d.Hist2DPanel.java
private void moveMask(Point2D point) { if (maskMovePoint != null && getSelectedMask() != null) { Rectangle2D frame = getSelectedMask().getRectangleFrame(); getSelectedMask().setRectangleFrame(new Rectangle2D.Double( frame.getMinX() + point.getX() - maskMovePoint.getX(), frame.getMinY() + point.getY() - maskMovePoint.getY(), frame.getWidth(), frame.getHeight())); maskMovePoint = point;/* w ww . java 2 s.com*/ fireMaskUpdateEvent(getSelectedMask()); } }
From source file:ucar.unidata.idv.control.chart.TimeSeriesChartWrapper.java
/** * On left axis/* w w w .j a v a 2 s .c o m*/ * * @param mouseEvent the event * * @return on left axis */ private boolean isOnLeftRangeAxis(MouseEvent mouseEvent) { Rectangle2D dataArea = chartPanel.getScreenDataArea(); if (mouseEvent.getY() < dataArea.getY()) { return false; } if (mouseEvent.getY() > dataArea.getY() + dataArea.getHeight()) { return false; } // System.err.println("mouse:" + mouseEvent.getX() +" da:" + dataArea); double left = dataArea.getX(); if (mouseEvent.getX() < left) { return true; } if (mouseEvent.getX() > left + 20) { return false; } return true; }
From source file:ucar.unidata.idv.control.chart.TimeSeriesChart.java
/** * Draw the sunrise/sunset curves//w ww . j a va2 s .com * * @param g2 the graphics area * @param plot the plot * @param dataArea the date range */ private void drawSunriseSunset(Graphics2D g2, XYPlot plot, Rectangle2D dataArea) { if (sunriseLocation == null) { return; } DateAxis domainAxis = (DateAxis) plot.getDomainAxis(); Date startDate = ((DateAxis) domainAxis).getMinimumDate(); Date endDate = ((DateAxis) domainAxis).getMaximumDate(); if ((sunriseDates == null) || !Misc.equals(startDate, lastStartDate) || !Misc.equals(endDate, lastEndDate)) { lastStartDate = startDate; lastEndDate = endDate; sunriseDates = IdvTimeline.makeSunriseDates(sunriseLocation, startDate, endDate); } int top = (int) (dataArea.getY()); int bottom = (int) (dataArea.getY() + dataArea.getHeight()); int height = bottom - top; g2.setColor(Color.yellow); Shape originalClip = g2.getClip(); g2.clip(dataArea); for (int i = 0; i < sunriseDates.size(); i += 2) { Date d1 = (Date) sunriseDates.get(i + 1); Date d2 = (Date) sunriseDates.get(i); int x1 = (int) domainAxis.valueToJava2D(d1.getTime(), dataArea, RectangleEdge.BOTTOM); int x2 = (int) domainAxis.valueToJava2D(d2.getTime(), dataArea, RectangleEdge.BOTTOM); g2.fillRect(x1, top, (x2 - x1), height); } g2.setClip(originalClip); }
From source file:KIDLYRenderer.java
/** * Calculates the bar width and stores it in the renderer state. * * @param plot the plot.//from www. j av a2 s. c o m * @param dataArea the data area. * @param rendererIndex the renderer index. * @param state the renderer state. */ protected void calculateBarWidth(CategoryPlot plot, Rectangle2D dataArea, int rendererIndex, CategoryItemRendererState state) { CategoryAxis domainAxis = getDomainAxis(plot, rendererIndex); CategoryDataset dataset = plot.getDataset(rendererIndex); if (dataset != null) { int columns = dataset.getColumnCount(); int rows = state.getVisibleSeriesCount() >= 0 ? state.getVisibleSeriesCount() : dataset.getRowCount(); double space = 0.0; PlotOrientation orientation = plot.getOrientation(); if (orientation == PlotOrientation.HORIZONTAL) { space = dataArea.getHeight(); } else if (orientation == PlotOrientation.VERTICAL) { space = dataArea.getWidth(); } double maxWidth = space * getMaximumBarWidth(); double categoryMargin = 0.0; double currentItemMargin = 0.0; if (columns > 1) { categoryMargin = domainAxis.getCategoryMargin(); } if (rows > 1) { currentItemMargin = getItemMargin(); } double used = space * (1 - domainAxis.getLowerMargin() - domainAxis.getUpperMargin() - categoryMargin - currentItemMargin); if ((rows * columns) > 0) { state.setBarWidth(Math.min(used / (rows * columns), maxWidth)); } else { state.setBarWidth(Math.min(used, maxWidth)); } } }
From source file:org.geoserver.wps.gs.download.DownloadProcessTest.java
/** * Test download of raster data. The output is scaled to fit exactly the provided size. * /* w w w .ja v a 2 s .c o m*/ * @throws Exception the exception */ @Test public void testDownloadScaledRaster() throws Exception { // Estimator process for checking limits DownloadEstimatorProcess limits = new DownloadEstimatorProcess(new StaticDownloadServiceConfiguration(), getGeoServer()); final WPSResourceManager resourceManager = getResourceManager(); // Creates the new process for the download DownloadProcess downloadProcess = new DownloadProcess(getGeoServer(), limits, resourceManager); /////////////////////////////////////// // test full coverage // /////////////////////////////////////// // Download the coverage as tiff File rasterZip = downloadProcess.execute(getLayerId(MockData.USA_WORLDIMG), // layerName null, // filter "image/tiff", // outputFormat null, // targetCRS CRS.decode("EPSG:4326", true), // roiCRS null, // roi false, // cropToGeometry null, // interpolation 80, // targetSizeX 80, // targetSizeY null, // bandSelectIndices new NullProgressListener() // progressListener ); // Final checks on the result Assert.assertNotNull(rasterZip); GeoTiffReader reader = null; GridCoverage2D gc = null; try { final File[] tiffFiles = extractTIFFFile(rasterZip); Assert.assertNotNull(tiffFiles); Assert.assertTrue(tiffFiles.length > 0); reader = new GeoTiffReader(tiffFiles[0]); gc = reader.read(null); Assert.assertNotNull(gc); // check coverage size Rectangle2D originalGridRange = (GridEnvelope2D) reader.getOriginalGridRange(); Assert.assertEquals(80, Math.round(originalGridRange.getWidth())); Assert.assertEquals(80, Math.round(originalGridRange.getHeight())); // check envelope Assert.assertEquals(-130.8866985, gc.getEnvelope().getLowerCorner().getOrdinate(0), 1E-6); Assert.assertEquals(48.5552613, gc.getEnvelope().getLowerCorner().getOrdinate(1), 1E-6); Assert.assertEquals(-123.8830077, gc.getEnvelope().getUpperCorner().getOrdinate(0), 1E-6); Assert.assertEquals(54.1420339, gc.getEnvelope().getUpperCorner().getOrdinate(1), 1E-6); } finally { if (gc != null) { CoverageCleanerCallback.disposeCoverage(gc); } if (reader != null) { reader.dispose(); } // clean up process resourceManager.finished(resourceManager.getExecutionId(true)); } /////////////////////////////////////// // test partial input // /////////////////////////////////////// // Download the coverage as tiff File largerZip = downloadProcess.execute(getLayerId(MockData.USA_WORLDIMG), // layerName null, // filter "image/tiff", // outputFormat null, // targetCRS CRS.decode("EPSG:4326", true), // roiCRS null, // roi false, // cropToGeometry null, // interpolation 160, // targetSizeX null, // targetSizeY not specified, will be calculated based on targetSizeX and aspect ratio of the original image null, // bandSelectIndices new NullProgressListener() // progressListener ); // Final checks on the result Assert.assertNotNull(largerZip); try { final File[] tiffFiles = extractTIFFFile(largerZip); Assert.assertNotNull(tiffFiles); Assert.assertTrue(tiffFiles.length > 0); reader = new GeoTiffReader(tiffFiles[0]); gc = reader.read(null); Assert.assertNotNull(gc); // check coverage size Rectangle2D originalGridRange = (GridEnvelope2D) reader.getOriginalGridRange(); Assert.assertEquals(160, Math.round(originalGridRange.getWidth())); Assert.assertEquals(160, Math.round(originalGridRange.getHeight())); } finally { if (gc != null) { CoverageCleanerCallback.disposeCoverage(gc); } if (reader != null) { reader.dispose(); } // clean up process resourceManager.finished(resourceManager.getExecutionId(true)); } ////////////////////////////////// // test with ROI // ////////////////////////////////// Polygon roi = (Polygon) new WKTReader2().read( "POLYGON (( -127.57473954542964 54.06575021619523, -130.88669845369998 52.00807146727025, -129.50812897394974 49.85372324691927, -130.5300633861675 49.20465679591609, -129.25955033314003 48.60392508062591, -128.00975216684665 50.986137055052474, -125.8623089087404 48.63154492960477, -123.984159178178 50.68231871628503, -126.91186316993704 52.15307567440926, -125.3444367403868 53.54787804784162, -127.57473954542964 54.06575021619523 ))"); roi.setSRID(4326); // Download the coverage as tiff File resampledZip = downloadProcess.execute(getLayerId(MockData.USA_WORLDIMG), // layerName null, // filter "image/tiff", // outputFormat null, // targetCRS CRS.decode("EPSG:4326", true), // roiCRS roi, // roi true, // cropToGeometry null, // interpolation 80, // targetSizeX 80, // targetSizeY null, // bandSelectIndices new NullProgressListener() // progressListener ); // Final checks on the result Assert.assertNotNull(resampledZip); try { final File[] tiffFiles = extractTIFFFile(resampledZip); Assert.assertNotNull(tiffFiles); Assert.assertTrue(tiffFiles.length > 0); reader = new GeoTiffReader(tiffFiles[0]); gc = reader.read(null); Assert.assertNotNull(gc); // check coverage size Rectangle2D originalGridRange = (GridEnvelope2D) reader.getOriginalGridRange(); Assert.assertEquals(80, Math.round(originalGridRange.getWidth())); Assert.assertEquals(80, Math.round(originalGridRange.getHeight())); // check envelope Assert.assertEquals(-130.88669845369998, gc.getEnvelope().getLowerCorner().getOrdinate(0), 1E-6); Assert.assertEquals(48.611129008700004, gc.getEnvelope().getLowerCorner().getOrdinate(1), 1E-6); Assert.assertEquals(-123.95304462109999, gc.getEnvelope().getUpperCorner().getOrdinate(0), 1E-6); Assert.assertEquals(54.0861661371, gc.getEnvelope().getUpperCorner().getOrdinate(1), 1E-6); } finally { if (gc != null) { CoverageCleanerCallback.disposeCoverage(gc); } if (reader != null) { reader.dispose(); } // clean up process resourceManager.finished(resourceManager.getExecutionId(true)); } }