use of org.geotools.map.FeatureLayer in project polymap4-core by Polymap4.
the class FeatureRenderProcessor2 method getMapRequest.
@Override
public void getMapRequest(GetMapRequest request, ProcessorContext context) throws Exception {
long start = System.currentTimeMillis();
// result
BufferedImage result = new BufferedImage(request.getWidth(), request.getHeight(), TYPE_4BYTE_ABGR);
result.setAccelerationPriority(1);
final Graphics2D g = result.createGraphics();
// log.info( "IMAGE: accelerated=" + result.getCapabilities( g.getDeviceConfiguration() ).isAccelerated() );
MapContent mapContent = new MapContent();
try {
// MapContent
mapContent.getViewport().setCoordinateReferenceSystem(request.getBoundingBox().getCoordinateReferenceSystem());
mapContent.addLayer(new FeatureLayer(fs.get(), style.get()));
StreamingRenderer renderer = new NoThreadStreamingRenderer();
// error handler
renderer.addRenderListener(new RenderListener() {
@Override
public void featureRenderer(SimpleFeature feature) {
}
@Override
public void errorOccurred(Exception e) {
if (e.getMessage() == null || e.getMessage().contains("Error transforming bbox") || e.getMessage().contains("too close to a pole")) {
log.warn("Renderer: " + e.getMessage());
} else {
log.error("Renderer error: ", e);
drawErrorMsg(g, "Unable to render.", e);
}
}
});
// rendering hints
RenderingHints hints = new RenderingHints(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);
hints.add(new RenderingHints(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON));
hints.add(new RenderingHints(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON));
hints.add(new RenderingHints(RenderingHints.KEY_FRACTIONALMETRICS, RenderingHints.VALUE_FRACTIONALMETRICS_ON));
// hints.add( new RenderingHints(
// RenderingHints.KEY_TEXT_ANTIALIASING,
// RenderingHints.VALUE_TEXT_ANTIALIAS_LCD_HRGB ) );
// geoserver compatibility to support *env* in SLD functions
double scale = RendererUtilities.calculateOGCScale(request.getBoundingBox(), request.getWidth(), Collections.EMPTY_MAP);
EnvFunction.setLocalValue("wms_scale_denominator", scale);
renderer.setJava2DHints(hints);
g.setRenderingHints(hints);
// render params
Map rendererParams = new HashMap();
rendererParams.put("optimizedDataLoadingEnabled", Boolean.TRUE);
renderer.setRendererHints(rendererParams);
renderer.setMapContent(mapContent);
Rectangle paintArea = new Rectangle(request.getWidth(), request.getHeight());
renderer.paint(g, paintArea, request.getBoundingBox());
} catch (Throwable e) {
log.error("Renderer error: ", e);
drawErrorMsg(g, "Unable to render.", e);
} finally {
mapContent.dispose();
EnvFunction.clearLocalValues();
if (g != null) {
g.dispose();
}
}
log.debug(" ...done: (" + (System.currentTimeMillis() - start) + "ms).");
context.sendResponse(new ImageResponse(result));
}
use of org.geotools.map.FeatureLayer in project spatial-portal by AtlasOfLivingAustralia.
the class AreaUploadShapefileWizardController method executeShapeImageRenderer.
private void executeShapeImageRenderer(Filter filter) {
try {
LOGGER.debug("Generating image");
SimpleFeatureCollection features1;
if (filter == null) {
features1 = source.getFeatures();
} else {
features1 = source.getFeatures(filter);
}
// Create a map content and add our shapefile to it
MapContent map = new MapContent();
org.geotools.styling.Style style = SLD.createSimpleStyle(source.getSchema());
Layer layer = new FeatureLayer(features1, style);
map.addLayer(layer);
GTRenderer renderer = new StreamingRenderer();
renderer.setMapContent(map);
int imageWidth = 800;
int imageHeight = 300;
Rectangle imageBounds;
ReferencedEnvelope mapBounds;
mapBounds = map.getMaxBounds();
double heightToWidth = mapBounds.getSpan(1) / mapBounds.getSpan(0);
if (heightToWidth * imageWidth > imageHeight) {
imageBounds = new Rectangle(0, 0, (int) Math.round(imageHeight / heightToWidth), imageHeight);
} else {
imageBounds = new Rectangle(0, 0, imageWidth, (int) Math.round(imageWidth * heightToWidth));
}
BufferedImage image = new BufferedImage(imageBounds.width, imageBounds.height, BufferedImage.TYPE_INT_RGB);
Graphics2D gr = image.createGraphics();
gr.setPaint(Color.WHITE);
gr.fill(imageBounds);
renderer.paint(gr, imageBounds, mapBounds);
img.setContent(image);
} catch (Exception e) {
LOGGER.debug("Unable to generate image for selected shapefile", e);
}
}
use of org.geotools.map.FeatureLayer in project sldeditor by robward-scisys.
the class RenderPanelImpl method renderVectorMap.
/**
* Render vector map.
*
* @param features the results
* @param imageSize the image size
* @param style the style
* @param dpi the dpi
*/
private void renderVectorMap(FeatureSource<SimpleFeatureType, SimpleFeature> features, Rectangle imageSize, Style style, int dpi) {
List<Layer> layerList = new ArrayList<Layer>();
if (style != null) {
FeatureLayer featureLayer = new FeatureLayer(features, style);
layerList.add(featureLayer);
}
boolean hasGeometry = false;
ReferencedEnvelope bounds = null;
if (features != null) {
bounds = calculateBounds();
wmsEnvVarValues.setMapBounds(bounds);
EnvironmentVariableManager.getInstance().setWMSEnvVarValues(wmsEnvVarValues);
if (features.getSchema() != null) {
hasGeometry = (features.getSchema().getGeometryDescriptor() != null);
}
}
internal_renderMap(layerList, bounds, imageSize, hasGeometry, dpi);
}
use of org.geotools.map.FeatureLayer in project sldeditor by robward-scisys.
the class MapRender method renderSymbol.
/**
* Render symbol.
*
* @param mapContent the map content
* @param styledLayer the styled layer
* @param style the style
*/
private void renderSymbol(MapContent mapContent, StyledLayer styledLayer, Style style) {
for (Layer layer : mapContent.layers()) {
mapContent.removeLayer(layer);
}
switch(geometryType) {
case RASTER:
{
GridReaderLayer gridLayer = new GridReaderLayer(gridCoverage, (org.geotools.styling.Style) style);
mapContent.addLayer(gridLayer);
mapContent.getViewport().setBounds(gridLayer.getBounds());
if (gridCoverage != null) {
mapPane.setDisplayArea(gridCoverage.getOriginalEnvelope());
}
}
break;
case POINT:
case LINE:
case POLYGON:
{
FeatureSource<SimpleFeatureType, SimpleFeature> tmpFeatureList = null;
if (styledLayer instanceof UserLayer) {
if (userLayerFeatureListMap != null) {
tmpFeatureList = userLayerFeatureListMap.get(styledLayer);
}
} else {
tmpFeatureList = featureList;
}
if (tmpFeatureList != null) {
mapContent.addLayer(new FeatureLayer(tmpFeatureList, (org.geotools.styling.Style) style));
try {
mapPane.setDisplayArea(tmpFeatureList.getBounds());
} catch (IOException e) {
ConsoleManager.getInstance().exception(this, e);
}
}
}
break;
default:
break;
}
wmsEnvVarValues.setMapBounds(mapBounds);
EnvironmentVariableManager.getInstance().setWMSEnvVarValues(wmsEnvVarValues);
}
use of org.geotools.map.FeatureLayer in project dhis2-core by dhis2.
the class MapUtils method createFeatureLayerFromMapObject.
/**
* Creates a feature layer based on a map object.
*/
public static Layer createFeatureLayerFromMapObject(InternalMapObject mapObject) {
Style style = mapObject.getStyle();
SimpleFeatureType featureType = mapObject.getFeatureType();
SimpleFeatureBuilder featureBuilder = new SimpleFeatureBuilder(featureType);
DefaultFeatureCollection featureCollection = new DefaultFeatureCollection();
featureBuilder.add(mapObject.getGeometry());
SimpleFeature feature = featureBuilder.buildFeature(null);
featureCollection.add(feature);
return new FeatureLayer(featureCollection, style);
}
Aggregations