org.geotools.renderer.GTRenderer Java Examples
The following examples show how to use
org.geotools.renderer.GTRenderer.
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: GridCoverageNwwLayer.java From hortonmachine with GNU General Public License v3.0 | 6 votes |
private static GTRenderer getRenderer( File rasterFile ) { AbstractGridFormat format = GridFormatFinder.findFormat(rasterFile); AbstractGridCoverage2DReader coverageReader = format.getReader(rasterFile); MapContent mapContent = new MapContent(); try { Style rasterStyle = SldUtilities.getStyleFromFile(rasterFile); if (rasterStyle == null) { RasterSymbolizer sym = SldUtilities.sf.getDefaultRasterSymbolizer(); rasterStyle = SLD.wrapSymbolizers(sym); } GridReaderLayer layer = new GridReaderLayer(coverageReader, rasterStyle); mapContent.addLayer(layer); mapContent.getViewport().setCoordinateReferenceSystem(CrsUtilities.WGS84); } catch (Exception e) { e.printStackTrace(); } GTRenderer renderer = new StreamingRenderer(); renderer.setMapContent(mapContent); return renderer; }
Example #2
Source File: SLDMapPane.java From sldeditor with GNU General Public License v3.0 | 5 votes |
/** * Gets the renderer, creating a default one if required. * * @return the renderer */ public GTRenderer getRenderer() { if (renderer == null) { doSetRenderer(new StreamingRenderer()); } return renderer; }
Example #3
Source File: SwtMapPane.java From gama with GNU General Public License v3.0 | 5 votes |
/** * Constructor - creates an instance of JMapPane with the given renderer and map context. * * @param renderer * a renderer object * */ public SwtMapPane(final Composite parent, final int style, final GTRenderer renderer, final MapContent content) { super(parent, style); white = getDisplay().getSystemColor(SWT.COLOR_WHITE); yellow = getDisplay().getSystemColor(SWT.COLOR_YELLOW); addListener(SWT.Paint, this); addListener(SWT.MouseDown, this); addListener(SWT.MouseUp, this); imageOrigin = new Point(0, 0); redrawBaseImage = true; setRenderer(renderer); setMapContent(content); this.addMouseListener(this); this.addMouseMoveListener(this); addControlListener(new ControlAdapter() { @Override public void controlResized(final ControlEvent e) { curPaintArea = getVisibleRect(); doSetDisplayArea(SwtMapPane.this.content.getViewport().getBounds()); } }); }
Example #4
Source File: SwtMapPane.java From gama with GNU General Public License v3.0 | 5 votes |
/** * Set the renderer for this map pane. * * @param renderer * the renderer to use */ public void setRenderer(final GTRenderer renderer) { if (renderer != null) { if (renderer instanceof StreamingRenderer) { if (this.content != null) { renderer.setMapContent(this.content); } } } this.renderer = renderer; }
Example #5
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 #6
Source File: RasterizedFeatureCollectionLayer.java From hortonmachine with GNU General Public License v3.0 | 5 votes |
private static GTRenderer getRenderer( SimpleFeatureCollection featureCollectionLL, Style style ) { MapContent mapContent = new MapContent(); try { FeatureLayer layer = new FeatureLayer(featureCollectionLL, style); mapContent.addLayer(layer); } catch (Exception e) { e.printStackTrace(); } GTRenderer renderer = new StreamingRenderer(); renderer.setMapContent(mapContent); return renderer; }
Example #7
Source File: RasterizedSpatialiteLayer.java From hortonmachine with GNU General Public License v3.0 | 5 votes |
private static GTRenderer getRenderer( ASpatialDb db, String tableName, int featureLimit, Style style ) { MapContent mapContent = new MapContent(); // read data and convert it to featurecollection try { long t1 = System.currentTimeMillis(); System.out.println("STARTED READING: " + tableName); String databasePath = db.getDatabasePath(); File dbFile = new File(databasePath); File parentFolder = dbFile.getParentFile(); if (style == null) { File sldFile = new File(parentFolder, tableName + ".sld"); if (sldFile.exists()) { style = SldUtilities.getStyleFromFile(sldFile); } } DefaultFeatureCollection fc = SpatialDbsImportUtils.tableToFeatureFCollection(db, tableName, featureLimit, NwwUtilities.GPS_CRS_SRID, null); long t2 = System.currentTimeMillis(); System.out.println("FINISHED READING: " + tableName + " -> " + ((t2 - t1) / 1000) + "sec"); if (style == null) { style = SLD.createSimpleStyle(fc.getSchema()); } FeatureLayer layer = new FeatureLayer(fc, style); long t3 = System.currentTimeMillis(); System.out.println("FINISHED BUILDING: " + tableName + " -> " + ((t3 - t2) / 1000) + "sec"); mapContent.addLayer(layer); } catch (Exception e) { e.printStackTrace(); } GTRenderer renderer = new StreamingRenderer(); renderer.setMapContent(mapContent); return renderer; }
Example #8
Source File: GridCoverageNwwLayer.java From hortonmachine with GNU General Public License v3.0 | 4 votes |
private static LevelSet makeLevels( File imsf, GTRenderer renderer, Integer tileSize, Color colorToMakeTransparent ) throws MalformedURLException { AVList params = new AVListImpl(); if (tileSize == null || tileSize < 256) { tileSize = TILESIZE; } int finalTileSize = tileSize; String tilesPart = "-tiles"; String cacheRelativePath = "imagemosaics/" + imsf.getName() + tilesPart; String urlString = imsf.toURI().toURL().toExternalForm(); params.setValue(AVKey.URL, urlString); params.setValue(AVKey.TILE_WIDTH, finalTileSize); params.setValue(AVKey.TILE_HEIGHT, finalTileSize); params.setValue(AVKey.DATA_CACHE_NAME, cacheRelativePath); params.setValue(AVKey.SERVICE, "*"); params.setValue(AVKey.DATASET_NAME, "*"); final String imageFormat = "png"; params.setValue(AVKey.FORMAT_SUFFIX, "." + imageFormat); params.setValue(AVKey.NUM_LEVELS, 22); params.setValue(AVKey.NUM_EMPTY_LEVELS, 0); params.setValue(AVKey.LEVEL_ZERO_TILE_DELTA, new LatLon(Angle.fromDegrees(22.5d), Angle.fromDegrees(45d))); params.setValue(AVKey.SECTOR, new MercatorSector(-1.0, 1.0, Angle.NEG180, Angle.POS180)); File cacheRoot = CacheUtils.getCacheRoot(); final File cacheFolder = new File(cacheRoot, cacheRelativePath); if (!cacheFolder.exists()) { cacheFolder.mkdirs(); } params.setValue(AVKey.TILE_URL_BUILDER, new TileUrlBuilder(){ public URL getURL( Tile tile, String altImageFormat ) throws MalformedURLException { int zoom = tile.getLevelNumber() + 3; Sector sector = tile.getSector(); double north = sector.getMaxLatitude().degrees; double south = sector.getMinLatitude().degrees; double east = sector.getMaxLongitude().degrees; double west = sector.getMinLongitude().degrees; double centerX = west + (east - west) / 2.0; double centerY = south + (north - south) / 2.0; int[] tileNumber = NwwUtilities.getTileNumber(centerY, centerX, zoom); int x = tileNumber[0]; int y = tileNumber[1]; Rectangle imageBounds = new Rectangle(0, 0, finalTileSize, finalTileSize); BufferedImage image = new BufferedImage(imageBounds.width, imageBounds.height, BufferedImage.TYPE_INT_RGB); Graphics2D gr = image.createGraphics(); gr.setPaint(Color.WHITE); gr.fill(imageBounds); gr.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); try { synchronized (renderer) { renderer.paint(gr, imageBounds, new ReferencedEnvelope(west, east, south, north, DefaultGeographicCRS.WGS84)); File tileImageFolderFile = new File(cacheFolder, zoom + File.separator + x); if (!tileImageFolderFile.exists()) { tileImageFolderFile.mkdirs(); } File imgFile = new File(tileImageFolderFile, y + ".png"); if (!imgFile.exists()) { if (colorToMakeTransparent != null) { image = ImageUtilities.makeColorTransparent(image, colorToMakeTransparent); } ImageIO.write(image, "png", imgFile); } return imgFile.toURI().toURL(); } } catch (IOException e) { e.printStackTrace(); return null; } } }); return new LevelSet(params); }
Example #9
Source File: SLDMapPane.java From sldeditor with GNU General Public License v3.0 | 2 votes |
/** * Creates a new map pane. Any or all arguments may be {@code null} * * @param content the map content containing the layers to display * @param executor the rendering executor to manage drawing * @param renderer the renderer to use for drawing layers */ public SLDMapPane(MapContent content, RenderingExecutor executor, GTRenderer renderer) { super(content, executor); doSetRenderer(renderer); }
Example #10
Source File: SLDMapPane.java From sldeditor with GNU General Public License v3.0 | 2 votes |
/** * Sets the renderer to be used by this map pane. * * @param renderer the renderer to use */ public void setRenderer(GTRenderer renderer) { doSetRenderer(renderer); }
Example #11
Source File: MapUtils.java From dhis2-core with BSD 3-Clause "New" or "Revised" License | 2 votes |
public static BufferedImage render( InternalMap map, Integer maxWidth, Integer maxHeight ) { MapContent mapContent = new MapContent(); // Convert map objects to features, and add them to the map for ( InternalMapLayer mapLayer : map.getLayers() ) { for ( InternalMapObject mapObject : mapLayer.getMapObjects() ) { mapContent.addLayer( createFeatureLayerFromMapObject( mapObject ) ); } } // Create a renderer for this map GTRenderer renderer = new StreamingRenderer(); renderer.setMapContent( mapContent ); // Calculate image height ReferencedEnvelope mapBounds = mapContent.getMaxBounds(); double widthToHeightFactor = mapBounds.getSpan( 0 ) / mapBounds.getSpan( 1 ); int[] widthHeight = getWidthHeight( maxWidth, maxHeight, LegendSet.LEGEND_TOTAL_WIDTH, TITLE_HEIGHT, widthToHeightFactor ); //LegendSet.LEGEND_TOTAL_WIDTH; Rectangle imageBounds = new Rectangle( 0, 0, widthHeight[0], widthHeight[1] ); // Create an image and get the graphics context from it BufferedImage image = new BufferedImage( imageBounds.width, imageBounds.height, BufferedImage.TYPE_INT_ARGB ); Graphics2D graphics = (Graphics2D) image.getGraphics(); graphics.setRenderingHint( RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON ); renderer.paint( graphics, imageBounds, mapBounds ); mapContent.dispose(); return image; }
Example #12
Source File: SwtMapPane.java From gama with GNU General Public License v3.0 | 2 votes |
/** * Get the renderer being used by this map pane * * @return live reference to the renderer being used */ public GTRenderer getRenderer() { return renderer; }