Package org.geotools.map

Examples of org.geotools.map.MapLayer


  public void dispose() {
    if (mapContext != null) {
      MapLayer[] mapLayers = mapContext.getLayers();
      if (mapLayers != null) {
        for (int i = 0, count = mapLayers.length; i < count; i++) {
          MapLayer layer = mapLayers[i];
          try {
            layer.getFeatureSource().getDataStore().dispose();
          } catch (Exception e) {
            e.printStackTrace();
          }
        }
      }
View Full Code Here


                    } catch (InterruptedException e) {
                        fireErrorEvent(e);
                    }
                   
                } else {
                    MapLayer currLayer = new MapLayer(layer);
                    try {

                        // extract the feature type stylers from the style object
                        // and process them
                        processStylers(graphics, currLayer, worldToScreenTransform,
View Full Code Here

           
            if (styleLayer.getStyle().featureTypeStyles().size() < 2) continue;

            // count how many lite feature type styles are active
            int currCount = 0;
            MapLayer mapLayer = new MapLayer(layer);
            FeatureType ftype = mapLayer.getFeatureSource().getSchema();
            for (FeatureTypeStyle fts : styleLayer.getStyle().featureTypeStyles()) {
                if (isFeatureTypeStyleActive(ftype, fts)) {
                    // get applicable rules at the current scale
                    List[] splittedRules = splitRules(fts);
                    List ruleList = splittedRules[0];
View Full Code Here

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

        MapLayer layer = createCrsLayer(geographicBoundingBox, crs);
        mapContext.addLayer(layer);

        return mapContext;
    }
View Full Code Here

        public KMLSuperOverlayerTranslator(ContentHandler contentHandler) {
            super(contentHandler);
        }

        public void encode(Object o) throws IllegalArgumentException {
            MapLayer mapLayer = (MapLayer) o;

            // calculate closest resolution
            ReferencedEnvelope extent = mapContext.getAreaOfInterest();

            // zoom out until the entire bounds requested is covered by a
View Full Code Here

        b.add(wkt.read("LINESTRING(0 0, 1 1)"));
        b.add("one");
        features2.add(b.buildFeature("fid.1"));
       
        WMSMapContext context = new WMSMapContext();
        context.addLayer(new MapLayer(DataUtilities.source(features1), null));
        context.addLayer(new MapLayer(DataUtilities.source(features2), null));
        context.setMapWidth(500);
        context.setMapHeight(500);
        context.setAreaOfInterest(new ReferencedEnvelope(-180, 180, -90, 90, DefaultGeographicCRS.WGS84));
       
        ByteArrayOutputStream out = new ByteArrayOutputStream();
View Full Code Here

                throw (IOException) (new IOException("Unable to decode WGS84...").initCause(e));
            }
           
            List featureCollections = new ArrayList();
            for (int i = 0; i < map.getLayerCount(); i++) {
                MapLayer layer = map.getLayer(i);
                Query query = new Query(layer.getQuery());

                SimpleFeatureCollection features = null;
                try {
                    SimpleFeatureSource source;
                    source = (SimpleFeatureSource) layer.getFeatureSource();
                   
                    GeometryDescriptor gd = source.getSchema().getGeometryDescriptor();
                    if(gd == null) {
                        // geometryless layers...
                        features = source.getFeatures(query);
View Full Code Here

     * </p>
     */
    public void setContentDispositionHeader(final WMSMapContext mapContext, final String extension) {
        StringBuffer sb = new StringBuffer();
        for (int i = 0; i < mapContext.getLayerCount(); i++) {
            MapLayer layer = mapContext.getLayer(i);
            String title = layer.getTitle();
            if (title != null && !title.equals("")) {
                sb.append(title).append("_");
            }
        }
        String value;
View Full Code Here

            }

            final Style layerStyle = styles[i];
            final Filter layerFilter = filters[i];

            final MapLayer layer;

            int layerType = mapLayerInfo.getType();
            if (layerType == MapLayerInfo.TYPE_REMOTE_VECTOR) {

                final SimpleFeatureSource source = mapLayerInfo.getRemoteFeatureSource();
                layer = new DefaultMapLayer(source, layerStyle);
                layer.setTitle(mapLayerInfo.getRemoteFeatureSource().getSchema().getTypeName());

                final Query definitionQuery = new Query(source.getSchema().getTypeName());
                definitionQuery.setFilter(layerFilter);
                definitionQuery.setVersion(featureVersion);
                int maxFeatures = request.getMaxFeatures() != null ? request.getMaxFeatures()
                        : Integer.MAX_VALUE;
                definitionQuery.setMaxFeatures(maxFeatures);

                layer.setQuery(definitionQuery);
                mapContext.addLayer(layer);
            } else if (layerType == MapLayerInfo.TYPE_VECTOR) {
                FeatureSource<? extends FeatureType, ? extends Feature> source;
                // /////////////////////////////////////////////////////////
                //
                // Adding a feature layer
                //
                // /////////////////////////////////////////////////////////
                try {
                    source = mapLayerInfo.getFeatureSource(true);

                    // NOTE for the feature. Here there was some code that
                    // sounded like:
                    // * get the bounding box from feature source
                    // * eventually reproject it to the actual CRS used for
                    // map
                    // * if no intersection, don't bother adding the feature
                    // source to the map
                    // This is not an optimization, on the contrary,
                    // computing the bbox may be
                    // very expensive depending on the data size. Using
                    // sigma.openplans.org data
                    // and a tiled client like OpenLayers, it dragged the
                    // server to his knees
                    // and the client simply timed out
                } catch (IOException exp) {
                    if (LOGGER.isLoggable(Level.SEVERE)) {
                        LOGGER.log(Level.SEVERE, new StringBuffer("Getting feature source: ")
                                .append(exp.getMessage()).toString(), exp);
                    }

                    throw new ServiceException("Internal error", exp);
                }

                layer = new FeatureSourceMapLayer(source, layerStyle);
                layer.setTitle(mapLayerInfo.getFeature().getPrefixedName());

                final Query definitionQuery = new Query(source.getSchema().getName().getLocalPart());
                definitionQuery.setVersion(featureVersion);
                definitionQuery.setFilter(layerFilter);
              if (viewParams != null) {
                    definitionQuery.setHints(new Hints(Hints.VIRTUAL_TABLE_PARAMETERS, viewParams.get(i)));
              }

                // check for startIndex + offset
                final Integer startIndex = request.getStartIndex();
                if (startIndex != null) {
                    QueryCapabilities queryCapabilities = source.getQueryCapabilities();
                    if (queryCapabilities.isOffsetSupported()) {
                        // fsource is required to support
                        // SortBy.NATURAL_ORDER so we don't bother checking
                        definitionQuery.setStartIndex(startIndex);
                    } else {
                        // source = new PagingFeatureSource(source,
                        // request.getStartIndex(), limit);
                        throw new ServiceException("startIndex is not supported for the "
                                + mapLayerInfo.getName() + " layer");
                    }
                }

                int maxFeatures = request.getMaxFeatures() != null ? request.getMaxFeatures()
                        : Integer.MAX_VALUE;
                definitionQuery.setMaxFeatures(maxFeatures);

                layer.setQuery(definitionQuery);
                mapContext.addLayer(layer);
            } else if (layerType == MapLayerInfo.TYPE_RASTER) {

                // /////////////////////////////////////////////////////////
                //
                // Adding a coverage layer
                //
                // /////////////////////////////////////////////////////////
                final AbstractGridCoverage2DReader reader = (AbstractGridCoverage2DReader) mapLayerInfo
                        .getCoverageReader();
                if (reader != null) {

                    // get the group of parameters tha this reader supports
                    GeneralParameterValue[] readParameters = wms.getWMSReadParameters(request,
                            mapLayerInfo, layerFilter, reader, false);
                    try {

                        try {
                            layer = new DefaultMapLayer(FeatureUtilities.wrapGridCoverageReader(
                                    reader, readParameters), layerStyle);
                        } catch (Exception e) {
                            throw new RuntimeException(e);
                        }

                        layer.setTitle(mapLayerInfo.getCoverage().getPrefixedName());
                        layer.setQuery(Query.ALL);
                        mapContext.addLayer(layer);
                    } catch (IllegalArgumentException e) {
                        if (LOGGER.isLoggable(Level.SEVERE)) {
                            LOGGER.log(
                                    Level.SEVERE,
                                    new StringBuilder("Wrapping GC in feature source: ").append(
                                            e.getLocalizedMessage()).toString(), e);
                        }

                        throw new ServiceException(
                                "Internal error : unable to get reader for this coverage layer "
                                        + mapLayerInfo);
                    }
                } else {
                    throw new ServiceException(new StringBuffer(
                            "Internal error : unable to get reader for this coverage layer ")
                            .append(mapLayerInfo.toString()).toString());
                }
            } else if (layerType == MapLayerInfo.TYPE_WMS) {
                WMSLayerInfo wmsLayer = (WMSLayerInfo) mapLayerInfo.getResource();
                WebMapServer wms = wmsLayer.getStore().getWebMapServer(null);
                Layer gt2Layer = wmsLayer.getWMSLayer(null);

                // see if we can merge this layer with the previous one
                boolean merged = false;
                if (mapContext.getLayerCount() > 0) {
                    MapLayer lastLayer = mapContext.getLayer(mapContext.getLayerCount() - 1);
                    if (lastLayer instanceof WMSMapLayer) {
                        WMSMapLayer lastWMS = (WMSMapLayer) lastLayer;
                        WebMapServer otherWMS = lastWMS.getWebMapServer();
                        if (otherWMS.equals(wms)) {
                            lastWMS.addLayer(gt2Layer);
View Full Code Here

            writer.startDocument("GeoServer", null);
        }

        for (int i = 0; i < nLayers; i++) { // for every layer specified in the request

            MapLayer layer = layers[i];
            writer.startDocument(layer.getTitle(), null);

            //FeatureReader featureReader = null;
            SimpleFeatureSource fSource;
            fSource = (SimpleFeatureSource) layer.getFeatureSource();
            SimpleFeatureType schema = fSource.getSchema();

            //GeometryAttributeType geometryAttribute = schema.getDefaultGeometry();
            //CoordinateReferenceSystem sourceCrs = geometryAttribute.getCoordinateSystem();
            Rectangle paintArea = new Rectangle(imageWidth, imageHeight);
            AffineTransform worldToScreen = RendererUtilities.worldToScreenTransform(mapContext
                    .getAreaOfInterest(), paintArea);
            double scaleDenominator = 1;

            try {
                scaleDenominator = RendererUtilities.calculateScale(mapContext.getAreaOfInterest(),
                        mapContext.getCoordinateReferenceSystem(), paintArea.width,
                        paintArea.height, 90); // 90 = OGC standard DPI (see SLD spec page 37)
            } catch (Exception e) // probably either (1) no CRS (2) error xforming
             {
                scaleDenominator = 1 / worldToScreen.getScaleX(); //DJB old method - the best we can do
            }

            writer.setRequestedScale(scaleDenominator);

            String[] attributes;
            boolean isRaster = false;

            List<AttributeDescriptor> ats = schema.getAttributeDescriptors();
            final int length = ats.size();
            attributes = new String[length];

            for (int t = 0; t < length; t++) {
                attributes[t] = ats.get(i).getName().getLocalPart();

                if (attributes[t].equals("grid")) {
                    isRaster = true;
                }
            }

            try {
                CoordinateReferenceSystem sourceCrs = schema.getCoordinateReferenceSystem();
                writer.setSourceCrs(sourceCrs); // it seems to work better getting it from the schema, here

                Envelope envelope = mapContext.getAreaOfInterest();
                ReferencedEnvelope aoi = new ReferencedEnvelope(envelope,
                        mapContext.getCoordinateReferenceSystem());

                Filter filter = null;

                //ReferencedEnvelope aoi = mapContext.getAreaOfInterest();
                if (!CRS.equalsIgnoreMetadata(aoi.getCoordinateReferenceSystem(),
                            schema.getCoordinateReferenceSystem())) {
                    aoi = aoi.transform(schema.getCoordinateReferenceSystem(), true);
                }

                filter = createBBoxFilters(schema, attributes, aoi);

                // now build the query using only the attributes and the bounding
                // box needed
                Query q = new Query(schema.getTypeName());
                q.setFilter(filter);
                q.setPropertyNames(attributes);

                // now, if a definition query has been established for this layer, be
                // sure to respect it by combining it with the bounding box one.
                Query definitionQuery = layer.getQuery();

                if (definitionQuery != Query.ALL) {
                    if (q == Query.ALL) {
                        q = (Query) definitionQuery;
                    } else {
                        q = (Query) DataUtilities.mixQueries(definitionQuery, q, "KMLEncoder");
                    }
                }

                q.setCoordinateSystem(layer.getFeatureSource().getSchema().getCoordinateReferenceSystem());

                SimpleFeatureCollection fc = fSource.getFeatures(q);

                // decide wheter to render vector or raster based on kmscore
                int kmscore = wms.getKmScore();
                Object kmScoreObj = mapContext.getRequest().getFormatOptions().get("kmscore");
                if(kmScoreObj != null) {
                    kmscore = (Integer) kmScoreObj;
                }
                boolean useVector = useVectorOutput(kmscore, fc.size()); // kmscore = render vector/raster

                if (useVector || !kmz) {
                    LOGGER.info("Layer (" + layer.getTitle() + ") rendered with KML vector output.");
                    layerRenderList.add(new Integer(i)); // save layer number so it won't be rendered

                    if (!isRaster) {
                        writer.writeFeaturesAsVectors(fc, layer); // vector
                    } else {
                        writer.writeCoverages(fc, layer); // coverage
                    }
                } else {
                    // user requested KMZ and kmscore says render raster
                    LOGGER.info("Layer (" + layer.getTitle() + ") rendered with KMZ raster output.");
                    // layer order is only needed for raster results. In the <GroundOverlay> tag
                    // you need to point to a raster image, this image has the layer number as
                    // part of the name. The kml will then reference the image via the layer number
                    writer.writeFeaturesAsRaster(fc, layer, i); // raster
                }
View Full Code Here

TOP

Related Classes of org.geotools.map.MapLayer

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.