Java Code Examples for org.geotools.geometry.jts.ReferencedEnvelope#getCoordinateReferenceSystem()
The following examples show how to use
org.geotools.geometry.jts.ReferencedEnvelope#getCoordinateReferenceSystem() .
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: RenderPanelImpl.java From sldeditor with GNU General Public License v3.0 | 6 votes |
/** * Calculate bounds. * * @return the referenced envelope */ private ReferencedEnvelope calculateBounds() { ReferencedEnvelope bounds = null; try { bounds = featureList.getBounds(); if (bounds == null) { // It could be that the above call was too costly! bounds = featureList.getFeatures().getBounds(); } if (bounds.getCoordinateReferenceSystem() == null) { // We need a coordinate reference system set otherwise // transformations fail to render bounds = ReferencedEnvelope.create(bounds, DefaultGeographicCRS.WGS84); } if (bounds != null) { expandEnvelope(bounds); } } catch (IOException e) { ConsoleManager.getInstance().exception(this, e); } return bounds; }
Example 2
Source File: SwtMapPane.java From gama with GNU General Public License v3.0 | 6 votes |
public void setCrs(final CoordinateReferenceSystem crs) { try { final ReferencedEnvelope rEnv = getDisplayArea(); final CoordinateReferenceSystem sourceCRS = rEnv.getCoordinateReferenceSystem(); final CoordinateReferenceSystem targetCRS = crs; final MathTransform transform = CRS.findMathTransform(sourceCRS, targetCRS); final com.vividsolutions.jts.geom.Envelope newJtsEnv = JTS.transform(rEnv, transform); final ReferencedEnvelope newEnvelope = new ReferencedEnvelope(newJtsEnv, targetCRS); content.getViewport().setBounds(newEnvelope); fullExtent = null; doSetDisplayArea(newEnvelope); } catch (final Exception e) { e.printStackTrace(); } }
Example 3
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 4
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 5
Source File: NwwUtilities.java From hortonmachine with GNU General Public License v3.0 | 5 votes |
private static SimpleFeatureCollection reprojectToWGS84( SimpleFeatureCollection fc ) { // BOUNDS ReferencedEnvelope bounds = fc.getBounds(); CoordinateReferenceSystem crs = bounds.getCoordinateReferenceSystem(); if (!CRS.equalsIgnoreMetadata(crs, GPS_CRS)) { try { fc = new ReprojectingFeatureCollection(fc, GPS_CRS); } catch (Exception e) { throw new IllegalArgumentException("The data need to be of WGS84 lat/lon projection.", e); } } return fc; }
Example 6
Source File: NwwUtilities.java From hortonmachine with GNU General Public License v3.0 | 5 votes |
public static Sector envelope2Sector( ReferencedEnvelope env ) throws Exception { CoordinateReferenceSystem sourceCRS = env.getCoordinateReferenceSystem(); CoordinateReferenceSystem targetCRS = GPS_CRS; MathTransform transform = CRS.findMathTransform(sourceCRS, targetCRS); Envelope envLL = JTS.transform(env, transform); ReferencedEnvelope llEnv = new ReferencedEnvelope(envLL, targetCRS); Sector sector = Sector.fromDegrees(llEnv.getMinY(), llEnv.getMaxY(), llEnv.getMinX(), llEnv.getMaxX()); return sector; }
Example 7
Source File: GeoHashGrid.java From elasticgeo with GNU General Public License v3.0 | 4 votes |
public void initalize(ReferencedEnvelope srcEnvelope, SimpleFeatureCollection features) throws TransformException, FactoryException { final List<Map<String, Object>> buckets = readFeatures(features); final String firstGeohash = buckets.isEmpty() ? null : (String) buckets.get(0).get("key"); final int precision; if (!isValid(firstGeohash)) { LOGGER.fine("No aggregations found or missing/invalid geohash key"); precision = DEFAULT_PRECISION; } else { precision = ((String) buckets.get(0).get("key")).length(); } cellWidth = GeoHash.widthDegrees(precision); cellHeight = GeoHash.heightDegrees(precision); if (srcEnvelope.getCoordinateReferenceSystem() != null) { srcEnvelope = srcEnvelope.transform(DefaultGeographicCRS.WGS84,false); } computeMinLonOffset(srcEnvelope); envelope = computeEnvelope(srcEnvelope, precision); boundingBox = new ReferencedEnvelope(envelope.getMinX()-cellWidth/2.0, envelope.getMaxX()+cellWidth/2.0, envelope.getMinY()-cellHeight/2.0, envelope.getMaxY()+cellHeight/2.0, DefaultGeographicCRS.WGS84); final int numCol = (int) Math.round((envelope.getMaxX()-envelope.getMinX())/cellWidth+1); final int numRow = (int) Math.round((envelope.getMaxY()-envelope.getMinY())/cellHeight+1); grid = new float[numRow][numCol]; LOGGER.fine("Created grid with size (" + numCol + ", " + numRow + ")"); if (emptyCellValue != 0) { for (float[] row: grid) Arrays.fill(row, emptyCellValue); } List<GridCell> cells = new ArrayList<>(); buckets.forEach(bucket -> { Number rasterValue = computeCellValue(bucket); cells.add(new GridCell((String) bucket.get("key"), rasterValue)); scale.prepareScale(rasterValue.floatValue()); }); cells.forEach(cell -> updateGrid(cell.getGeohash(), cell.getValue())); LOGGER.fine("Read " + cells.size() + " aggregation buckets"); }
Example 8
Source File: GeopaparazziMapsCreator.java From hortonmachine with GNU General Public License v3.0 | 4 votes |
@Execute public void process() throws Exception { checkNull(inROI, outFolder); SimpleFeatureCollection boundsVector = OmsVectorReader.readVector(inROI); ReferencedEnvelope bounds = boundsVector.getBounds(); // bounds.expandBy(50.0); OmsTmsGenerator gen = new OmsTmsGenerator(); if (inRaster1 != null || inRaster2 != null) { List<String> inRasters = new ArrayList<String>(); if (inRaster1 != null) inRasters.add(inRaster1); if (inRaster2 != null) inRasters.add(inRaster2); gen.inRasterFile = FileUtilities.stringListAsTmpFile(inRasters).getAbsolutePath(); } if (inVector1 != null || inVector2 != null || inVector3 != null || inVector4 != null || inVector5 != null) { List<String> inVectors = new ArrayList<String>(); if (inVector1 != null) inVectors.add(inVector1); if (inVector2 != null) inVectors.add(inVector2); if (inVector3 != null) inVectors.add(inVector3); if (inVector4 != null) inVectors.add(inVector4); if (inVector5 != null) inVectors.add(inVector5); gen.inVectorFile = FileUtilities.stringListAsTmpFile(inVectors).getAbsolutePath(); } gen.pMinzoom = pMinZoom; gen.pMaxzoom = pMaxZoom; gen.pName = pName; gen.inPath = outFolder; gen.pWest = bounds.getMinX(); gen.pEast = bounds.getMaxX(); gen.pNorth = bounds.getMaxY(); gen.pSouth = bounds.getMinY(); // gen.pEpsg = "EPSG:32632"; gen.dataCrs = bounds.getCoordinateReferenceSystem(); gen.doMbtiles = true; gen.inZoomLimitVector = inZoomLimitROI; gen.pZoomLimit = pZoomLimit; switch( pImageType ) { case "jpg": gen.pImagetype = 1; break; case "png": default: gen.pImagetype = 0; break; } gen.pm = pm; gen.process(); }
Example 9
Source File: OmsZonalStats.java From hortonmachine with GNU General Public License v3.0 | 4 votes |
@Execute public void process() throws Exception { checkNull(inVector, inRaster); boolean hasUserTotalMean = false; if (pTotalMean != null) { hasUserTotalMean = true; tm_usertm_tactivecells[1] = pTotalMean; } ReferencedEnvelope bounds = inVector.getBounds(); CoordinateReferenceSystem crs = bounds.getCoordinateReferenceSystem(); SimpleFeatureBuilder featureBuilder = createFeatureBuilder(crs, hasUserTotalMean); outVector = new DefaultFeatureCollection(); List<Geometry> geometriesList = FeatureUtilities.featureCollectionToGeometriesList(inVector, true, null); // pm.message("" + readEnvelope); GridGeometry2D gridGeometry = inRaster.getGridGeometry(); RandomIter readIter = CoverageUtilities.getRandomIterator(inRaster); pm.beginTask("Processing polygons...", geometriesList.size()); for( Geometry geometry : geometriesList ) { double[] polygonStats = polygonStats(geometry, gridGeometry, readIter, hasUserTotalMean, tm_usertm_tactivecells, pPercentageThres, pm); if (polygonStats == null) { continue; } Object[] values; if (!hasUserTotalMean) { values = new Object[]{geometry, // polygonStats[0], // polygonStats[1], // polygonStats[2], // polygonStats[3], // polygonStats[4], // polygonStats[5], // (int) polygonStats[6], // (int) polygonStats[7] // }; } else { values = new Object[]{geometry, // polygonStats[0], // polygonStats[1], // polygonStats[2], // polygonStats[3], // polygonStats[4], // polygonStats[5], // polygonStats[6], // (int) polygonStats[7], // (int) polygonStats[8] // }; } featureBuilder.addAll(values); SimpleFeature feature = featureBuilder.buildFeature(null); ((DefaultFeatureCollection) outVector).add(feature); pm.worked(1); } pm.done(); if (!hasUserTotalMean) { tm_usertm_tactivecells[0] = tm_usertm_tactivecells[0] / tm_usertm_tactivecells[2]; pm.message("Total mean: " + tm_usertm_tactivecells[0]); } }