Package org.geotools.map

Examples of org.geotools.map.Layer


    @Test
    public void testKmltitleFormatOption() throws Exception {
        SimpleFeatureCollection features = FeatureCollections
                .newCollection();
        Style style = mockData.getDefaultStyle().getStyle();
        Layer layer = new FeatureLayer(features, style);

        WMSMapContent mapContent = new WMSMapContent();
        GetMapRequest request = mockData.createRequest();
        mapContent.setRequest(request);
View Full Code Here


            zip.putNextEntry(images);
           
            // write the images
            List<Layer> layers = mapContent.layers();
            for (int i = 0; i < layers.size(); i++) {
                Layer mapLayer = layers.get(i);

                // create a context for this single layer
                WMSMapContent subContext = new WMSMapContent();
                subContext.addLayer(mapLayer);
                subContext.setRequest(mapContent.getRequest());
View Full Code Here

       
        //
        // extract the raster symbolizers and the eventual rendering transformation
        //
        double scaleDenominator = mapContent.getScaleDenominator(true);
        Layer layer = mapContent.layers().get(layerIndex);
        FeatureType featureType = layer.getFeatureSource().getSchema();
        Style style = layer.getStyle();

        RasterSymbolizerVisitor visitor = new RasterSymbolizerVisitor(scaleDenominator, featureType);
        style.accept(visitor);

        List<RasterSymbolizer> symbolizers = visitor.getRasterSymbolizers();
        if (symbolizers.size() != 1) {
            return null;
        }
        RasterSymbolizer symbolizer = symbolizers.get(0);
        Expression transformation = visitor.getRasterRenderingTransformation();

        //
        // Dimensions
        //
        final int mapWidth = mapContent.getMapWidth();
        final int mapHeight= mapContent.getMapHeight();
        // force east/north, otherwise the reading code might think we are reprojecting
        // and start adding padding around the requests
        final ReferencedEnvelope mapEnvelope = getEastNorthEnvelope(mapContent.getRenderingArea());
        final CoordinateReferenceSystem mapCRS = mapEnvelope.getCoordinateReferenceSystem();
        final Rectangle mapRasterArea = new Rectangle(0, 0, mapWidth,mapHeight);
        final AffineTransform worldToScreen = RendererUtilities.worldToScreenTransform(mapEnvelope, mapRasterArea);       
        

        //
        // Check transparency and bg color
        //
        final boolean transparent = mapContent.isTransparent() && isTransparencySupported();
        Color bgColor = mapContent.getBgColor();
        // set transparency
        if (transparent) {
            bgColor = new Color(bgColor.getRed(), bgColor.getGreen(), bgColor.getBlue(), 0);
        } else {
            bgColor = new Color(bgColor.getRed(), bgColor.getGreen(), bgColor.getBlue(), 255);
        }
 
        //
        // Grab the interpolation
        //
        final Interpolation interpolation;
        if (wms != null) {
            if (WMSInterpolation.Nearest.equals(wms.getInterpolation())) {
                interpolation = Interpolation.getInstance(Interpolation.INTERP_NEAREST);
            } else if (WMSInterpolation.Bilinear.equals(wms.getInterpolation())) {
                interpolation = Interpolation.getInstance(Interpolation.INTERP_BILINEAR);
            } else if (WMSInterpolation.Bicubic.equals(wms.getInterpolation())) {
                interpolation = Interpolation.getInstance(Interpolation.INTERP_BICUBIC);
            } else {
                interpolation = Interpolation.getInstance(Interpolation.INTERP_NEAREST);
            }
        } else {
            interpolation = Interpolation.getInstance(Interpolation.INTERP_NEAREST);
        }
     
        //
        // Tiling
        //
        // if there is a output tile size hint, use it, otherwise use the output size itself
        final int tileSizeX;
        final int tileSizeY;
        if (mapContent.getTileSize() != -1) {
            tileSizeX = tileSizeY = mapContent.getTileSize();
        } else {
            tileSizeX = mapContent.getMapWidth();
            tileSizeY = mapContent.getMapHeight();
        }
       
        // actual read
        RenderedImage image = null;
        GridCoverage2D coverage;
        RenderingHints interpolationHints = new RenderingHints(JAI.KEY_INTERPOLATION, interpolation);
        try {
            final Color readerBgColor = transparent ? null : bgColor;
            if (transformation == null) {
                //
                // Get the reader
                //
                final Feature feature = mapContent.layers().get(0).getFeatureSource().getFeatures()
                        .features().next();
                final GridCoverage2DReader reader = (GridCoverage2DReader) feature.getProperty(
                        "grid").getValue();
                // render via grid coverage renderer, that will apply the advanced projection
                // handling
                final Object params = feature.getProperty("params").getValue();
                GeneralParameterValue[] readParameters = getReadParameters(params, null, null,
                        interpolation, readerBgColor);
                final GridCoverageRenderer gcr = new GridCoverageRenderer(mapEnvelope.getCoordinateReferenceSystem(), mapEnvelope,
                        mapRasterArea, worldToScreen, interpolationHints);
                gcr.setAdvancedProjectionHandlingEnabled(true);
                gcr.setWrapEnabled(DefaultWebMapService.isContinuousMapWrappingEnabled());
                image = gcr.renderImage(reader, readParameters, symbolizer, interpolation,
                        mapContent.getBgColor(), tileSizeX, tileSizeY);
                if (image == null) {
                    // we're outside of the coverage definition area, return an empty space
                    image = createBkgImage(mapWidth, mapHeight, bgColor, null);
                }
            } else {
                //
                // Prepare the reading parameters (for the RT case)
                //
                final CoordinateReferenceSystem coverageCRS = layer.getFeatureSource().getSchema()
                        .getCoordinateReferenceSystem();
                final GridGeometry2D readGG;
                final boolean equalsMetadata = CRS.equalsIgnoreMetadata(mapCRS, coverageCRS);
                boolean sameCRS;
                try {
                    sameCRS = equalsMetadata ? true : CRS.findMathTransform(mapCRS, coverageCRS,
                            true).isIdentity();
                } catch (FactoryException e1) {
                    final IOException ioe = new IOException();
                    ioe.initCause(e1);
                    throw ioe;
                }
                final boolean needsGutter = !sameCRS
                        || !(interpolation instanceof InterpolationNearest);
                if (!needsGutter) {
                    readGG = new GridGeometry2D(new GridEnvelope2D(mapRasterArea), mapEnvelope);

                } else {
                    //
                    // SG added gutter to the drawing. We need to investigate much more and also we
                    // need to do this only when needed
                    //
                    // enlarge raster area
                    Rectangle bufferedTargetArea = (Rectangle) mapRasterArea.clone();
                    bufferedTargetArea.add(mapRasterArea.x + mapRasterArea.width + 10,
                            mapRasterArea.y + mapRasterArea.height + 10);
                    bufferedTargetArea.add(mapRasterArea.x - 10, mapRasterArea.y - 10);

                    // now create the final envelope accordingly
                    try {
                        readGG = new GridGeometry2D(new GridEnvelope2D(bufferedTargetArea),
                                PixelInCell.CELL_CORNER, new AffineTransform2D(
                                        worldToScreen.createInverse()), mapCRS, null);
                    } catch (Exception e) {
                        final IOException ioe = new IOException();
                        ioe.initCause(e);
                        throw ioe;
                    }
                }

                RenderingTransformationHelper helper = new RenderingTransformationHelper() {
                   
                    protected GridCoverage2D readCoverage(GridCoverage2DReader reader, Object params, GridGeometry2D readGG)
                            throws IOException {
                        return readBestCoverage(
                                reader,
                                params,
                                ReferencedEnvelope.reference(readGG.getEnvelope()),
                                readGG.getGridRange2D(),
                                interpolation,
                                readerBgColor);
                    }
                   
                };
               
                Object result = helper.applyRenderingTransformation(transformation, layer.getFeatureSource(),
                        layer.getQuery(), Query.ALL, readGG, coverageCRS, interpolationHints);
                if(result == null) {
                    coverage = null;
                } else if(result instanceof GridCoverage2D) {
                    coverage = (GridCoverage2D) result;
                } else {
View Full Code Here

        zip.putNextEntry(images);
        // write the images
        WMSMapContent mapContent = context.getMapContent();
        for (Entry<String, Layer> goEntry : context.getKmzGroundOverlays().entrySet()) {
            String path = goEntry.getKey();
            Layer mapLayer = goEntry.getValue();

            // create a context for this single layer
            WMSMapContent subContext = new WMSMapContent();
            subContext.addLayer(mapLayer);
            subContext.setRequest(mapContent.getRequest());
View Full Code Here

        shpfile = getClass().getResource("cities.shp");
        source = getFeatureSource(shpfile);
        style = getStyle("cities.sld");
        mapContent.addLayer(new DefaultMapLayer(source, style));

        Layer layer = createCrsLayer(geographicBoundingBox, crs);
        mapContent.addLayer(layer);

        return mapContent;
    }
View Full Code Here

        link.setViewRefreshMode(ViewRefreshMode.NEVER);
    }

    private void encodeLayerSuperOverlay(Document container, int layerIndex, Envelope bounds,
            int zoomLevel) {
        Layer layer = mapContent.layers().get(layerIndex);
        Folder folder = container.createAndAddFolder();
        folder.setName(layer.getTitle());

        LookAtOptions lookAtOptions = new LookAtOptions(request.getFormatOptions());
        if (bounds != null) {
            LookAtDecoratorFactory lookAtFactory = new LookAtDecoratorFactory();
            ReferencedEnvelope layerBounds = layer.getBounds();
            CoordinateReferenceSystem layerCRS = layerBounds.getCoordinateReferenceSystem();
            if(layerCRS != null && !CRS.equalsIgnoreMetadata(layerCRS, DefaultGeographicCRS.WGS84)) {
                try {
                    layerBounds = layerBounds.transform(DefaultGeographicCRS.WGS84, true);
                } catch(Exception e) {
                    throw new ServiceException("Failed to transform the layer bounds for "
                            + layer.getTitle() + " to WGS84", e);
                }
            }
            LookAt la = lookAtFactory.buildLookAt(layerBounds, lookAtOptions, false);
            folder.setAbstractView(la);
        }
View Full Code Here

        @Override
        public Feature next() {
            while (i < size) {
                List<Layer> layers = context.getMapContent().layers();
                Layer layer = layers.get(i++);
                context.setCurrentLayer(layer);
               
                // setup the folder and let it be decorated
                Folder folder = new Folder();
                folder.setName(layer.getTitle());

                // if it's a feature layer, setup the feature collection for it (some decorators use it)
                if (layer instanceof FeatureLayer) {
                    try {
                        WMSMapContent mapContent = context.getMapContent();
View Full Code Here

        aggregatedBounds.setToNull();

        final List<Layer> mapLayers = context.layers();
        final List<MapLayerInfo> layerInfos = context.getRequest().getLayers();
        for (int i = 0; i < mapLayers.size(); i++) {
            final Layer Layer = mapLayers.get(i);
            final MapLayerInfo layerInfo = layerInfos.get(i);

            ReferencedEnvelope layerLatLongBbox;
            layerLatLongBbox = computeLayerBounds(Layer, layerInfo, computeQueryBounds);
            try {
View Full Code Here

        }

        informationLabel.setText("Please, set Start point first.");

        Style style = SLD.createSimpleStyle(simpleFeatureSource.getSchema(), Color.GRAY);
        Layer layer = new FeatureLayer(simpleFeatureSource, style);
        map.addLayer(layer);

        JMapPane mapPane = new JMapPane(map);
        mapPane.setBackground(Color.WHITE);
        mapPane.setBorder(BorderFactory.createLineBorder(Color.BLACK));
View Full Code Here

        FeatureSource<SimpleFeatureType, SimpleFeature> routeSource;
        try {
            routeSource = routeCalculator.getRouteFeatureSource();
            Style style = SLD.createLineStyle(Color.RED, 3);

            Layer layer = new FeatureLayer(routeSource, style);
            map.addLayer(layer);

            Logger.i("Draw route");
            informationLabel.setText("Route has been drawn");
            JOptionPane.showMessageDialog(MainView.this, "Route has been drawn");
View Full Code Here

TOP

Related Classes of org.geotools.map.Layer

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.