⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 wmscapstransformer.java

📁 电子地图服务器,搭建自己的地图服务
💻 JAVA
📖 第 1 页 / 共 4 页
字号:
                        }
                    }
                } catch (Exception e) {
                    if (LOGGER.isLoggable(Level.WARNING)) {
                        LOGGER.log(Level.WARNING, e.getLocalizedMessage(), e);
                    }
                }

                if (LOGGER.isLoggable(Level.FINE)) {
                    LOGGER.fine("Summarized LatLonBBox is " + latlonBbox);
                }

                handleLatLonBBox(latlonBbox);
            }
        }

        /**
         * @param featuresLayerTree
         */
        private void handleFeaturesTree(LayerTree featuresLayerTree) {
            final List data = new ArrayList(featuresLayerTree.getData());
            final Collection childrens = featuresLayerTree.getChildrens();
            FeatureTypeInfo fLayer;

            Collections.sort(data, new FeatureTypeInfoTitleComparator());
            for (Iterator it = data.iterator(); it.hasNext();) {
                fLayer = (FeatureTypeInfo) it.next();

                try {
                    if (fLayer.isEnabled() && !fLayer.isGeometryless()) {
                        handleFeatureType(fLayer);
                    }
                } catch (Exception e) {
                    if (LOGGER.isLoggable(Level.WARNING)) {
                        LOGGER.log(Level.WARNING, e.getLocalizedMessage(), e);
                    }
                }
            }

            LayerTree layerTree;

            for (Iterator it = childrens.iterator(); it.hasNext();) {
                layerTree = (LayerTree) it.next();
                start("Layer");
                element("Name", layerTree.getName());
                element("Title", layerTree.getName());
                handleFeaturesTree(layerTree);
                end("Layer");
            }
        }

        /**
         * Calls super.handleFeatureType to add common FeatureType content such
         * as Name, Title and LatLonBoundingBox, and then writes WMS specific
         * layer properties as Styles, Scale Hint, etc.
         *
         * @param ftype
         *            The featureType to write out.
         *
         * @throws RuntimeException
         *             DOCUMENT ME!
         *
         * @task TODO: write wms specific elements.
         */
        protected void handleFeatureType(FeatureTypeInfo ftype) {
            // HACK: by now all our layers are queryable, since they reference
            // only featuretypes managed by this server
            AttributesImpl qatts = new AttributesImpl();
            qatts.addAttribute("", "queryable", "queryable", "", "1");
            start("Layer", qatts);
            element("Name", ftype.getName());
            element("Title", ftype.getTitle());
            element("Abstract", ftype.getAbstract());

            handleKeywordList(ftype.getKeywords());

            /**
             * @task REVISIT: should getSRS() return the full URL? no - the spec
             *       says it should be a set of <SRS>EPSG:#</SRS>...
             */
            element("SRS", EPSG + ftype.getSRS());

            // DJB: I want to be nice to the people reading the capabilities
            // file - I'm going to get the
            // human readable name and stick it in the capabilities file
            // NOTE: this isnt well done because "comment()" isnt in the
            // ContentHandler interface...
            try {
                CoordinateReferenceSystem crs = CRS.decode(EPSG + ftype.getSRS());
                String desc = new StringBuffer("WKT definition of this CRS:\n").append(crs.toWKT())
                                                                               .toString();
                comment(desc);
            } catch (Exception e) {
                if (LOGGER.isLoggable(Level.WARNING)) {
                    LOGGER.log(Level.WARNING, e.getLocalizedMessage(), e);
                }
            }

            Envelope bbox = null;
            Envelope llbbox = null;

            try {
                bbox = ftype.getBoundingBox();
                llbbox = ftype.getLatLongBoundingBox();
            } catch (IOException ex) {
                throw new RuntimeException("Can't obtain latLongBBox of " + ftype.getName() + ": "
                    + ex.getMessage(), ex);
            }

            handleLatLonBBox(llbbox);
            handleBBox(bbox, EPSG + ftype.getSRS());
            // handle metadata URLs
            handleMetadataList(ftype.getMetadataLinks());

            // add the layer style
            start("Style");

            Style ftStyle = ftype.getDefaultStyle();
            element("Name", ftStyle.getName());
            element("Title", ftStyle.getTitle());
            element("Abstract", ftStyle.getAbstract());
            handleLegendURL(ftype);
            end("Style");

            final ArrayList styles = ftype.getStyles();
            Iterator s_IT = styles.iterator();

            while (s_IT.hasNext()) {
                ftStyle = (Style) s_IT.next();
                start("Style");
                element("Name", ftStyle.getName());
                element("Title", ftStyle.getTitle());
                element("Abstract", ftStyle.getAbstract());
                handleLegendURL(ftype);
                end("Style");
            }

            end("Layer");
        }

        /**
         * @param coveragesLayerTree
         */
        private void handleCoveragesTree(LayerTree coveragesLayerTree) {
            final List data = new ArrayList(coveragesLayerTree.getData());
            final Collection childrens = coveragesLayerTree.getChildrens();
            CoverageInfo cLayer;

            Collections.sort(data, new CoverageInfoLabelComparator());
            for (Iterator it = data.iterator(); it.hasNext();) {
                cLayer = (CoverageInfo) it.next();

                if (cLayer.isEnabled()) {
                    handleCoverage(cLayer);
                }
            }

            LayerTree layerTree;

            for (Iterator it = childrens.iterator(); it.hasNext();) {
                layerTree = (LayerTree) it.next();
                start("Layer");
                element("Name", layerTree.getName());
                element("Title", layerTree.getName());
                handleCoveragesTree(layerTree);
                end("Layer");
            }
        }

        protected void handleCoverage(CoverageInfo coverage) {
            // HACK: by now all our layers are queryable, since they reference
            // only featuretypes managed by this server
            AttributesImpl qatts = new AttributesImpl();
            qatts.addAttribute("", "queryable", "queryable", "", "0");
            // qatts.addAttribute("", "opaque", "opaque", "", "1");
            // qatts.addAttribute("", "cascaded", "cascaded", "", "1");
            start("Layer", qatts);
            element("Name", coverage.getName());
            element("Title", coverage.getLabel());
            element("Abstract", coverage.getDescription());

            handleKeywordList(coverage.getKeywords());

            String desc = "WKT definition of this CRS:\n" + coverage.getSrsWKT();
            comment(desc);

            String authority = coverage.getSrsName();

            /*CoordinateReferenceSystem crs = coverage.getCrs();
            if (crs != null && !crs.getIdentifiers().isEmpty()) {
                    Identifier[] idents = (Identifier[]) crs.getIdentifiers()
                                    .toArray(new Identifier[crs.getIdentifiers().size()]);
                    authority = idents[0].toString();
            } else if (crs != null && crs instanceof DerivedCRS) {
                    final CoordinateReferenceSystem baseCRS = ((DerivedCRS) crs)
                                    .getBaseCRS();
                    if (baseCRS != null && !baseCRS.getIdentifiers().isEmpty())
                            authority = ((Identifier[]) baseCRS.getIdentifiers()
                                            .toArray(
                                                            new Identifier[baseCRS.getIdentifiers()
                                                                            .size()]))[0].toString();
                    else
                            authority = coverage.getNativeCRS();
            } else if (crs != null && crs instanceof ProjectedCRS) {
                    final CoordinateReferenceSystem baseCRS = ((ProjectedCRS) crs)
                                    .getBaseCRS();
                    if (baseCRS != null && !baseCRS.getIdentifiers().isEmpty())
                            authority = ((Identifier[]) baseCRS.getIdentifiers()
                                            .toArray(
                                                            new Identifier[baseCRS.getIdentifiers()
                                                                            .size()]))[0].toString();
                    else
                            authority = coverage.getNativeCRS();
            } else
                    authority = coverage.getNativeCRS();*/
            element("SRS", authority);

            GeneralEnvelope bounds = null;
            GeneralEnvelope llBounds = null;

            // try {
            // We need LON/LAT Envelopes
            // TODO check for BBOX, maybe it should be expressed in original
            // CRS coords!!
            final GeneralEnvelope latLonEnvelope = coverage.getWGS84LonLatEnvelope();
            // final CoordinateReferenceSystem llCRS = latLonEnvelope
            // .getCoordinateReferenceSystem();
            bounds = coverage.getEnvelope();
            llBounds = latLonEnvelope;

            // bounds =
            // CoverageStoreUtils.adjustEnvelopeLongitudeFirst(llCRS,
            // coverage.getEnvelope());
            // llBounds =
            // CoverageStoreUtils.adjustEnvelopeLongitudeFirst(llCRS,
            // // latLonEnvelope);
            // } catch (MismatchedDimensionException e) {
            //	
            // } catch (IndexOutOfBoundsException e) {
            //			
            // }
            final Envelope bbox = new Envelope(bounds.getLowerCorner().getOrdinate(0),
                    bounds.getUpperCorner().getOrdinate(0), bounds.getLowerCorner().getOrdinate(1),
                    bounds.getUpperCorner().getOrdinate(1));

            final Envelope llBbox = new Envelope(llBounds.getLowerCorner().getOrdinate(0),
                    llBounds.getUpperCorner().getOrdinate(0),
                    llBounds.getLowerCorner().getOrdinate(1),
                    llBounds.getUpperCorner().getOrdinate(1));

            handleLatLonBBox(llBbox);
            handleBBox(bbox, authority);

            // add the layer style
            start("Style");

            Style cvStyle = coverage.getDefaultStyle();
            element("Name", cvStyle.getName());
            element("Title", cvStyle.getTitle());
            element("Abstract", cvStyle.getAbstract());
            handleLegendURL(coverage);
            end("Style");

            final ArrayList styles = coverage.getStyles();
            Iterator s_IT = styles.iterator();

            while (s_IT.hasNext()) {
                cvStyle = (Style) s_IT.next();
                start("Style");
                element("Name", cvStyle.getName());
                element("Title", cvStyle.getTitle());
                element("Abstract", cvStyle.getAbstract());
                handleLegendURL(coverage);
                end("Style");
            }

            end("Layer");
        }

        protected void handleLayerGroups(Map baseMapLayers, Map baseMapStyles, Map baseMapEnvelopes)
            throws FactoryException, TransformException {
            if (baseMapLayers == null) {
                return;
            }

            List names = new ArrayList(baseMapLayers.keySet());
            Collections.sort(names);

            CoordinateReferenceSystem wgs84 = CRS.decode("EPSG:4326");

            for (Iterator it = names.iterator(); it.hasNext();) {
                String layerName = (String) it.next();

                AttributesImpl qatts = new AttributesImpl();
                qatts.addAttribute("", "queryable", "queryable", "", "0");
                // qatts.addAttribute("", "opaque", "opaque", "", "1");
                // qatts.addAttribute("", "cascaded", "cascaded", "", "1");
                start("Layer", qatts);
                element("Name", layerName);
                element("Title", layerName);
                element("Abstract", "Layer-Group type layer: " + layerName);

                //handleKeywordList(...getKeywords());

                /*String desc = "WKT definition of this CRS:\n" + coverage.getSrsWKT();
                comment(desc);*/
                GeneralEnvelope bounds = (GeneralEnvelope) baseMapEnvelopes.get(layerName);
                GeneralEnvelope llBounds = null;

                String authority = bounds.getCoordinateReferenceSystem().getIdentifiers().toArray()[0]
                    .toString();

                element("SRS", authority);

                if (CRSUtilities.equalsIgnoreMetadata(wgs84, bounds.getCoordinateReferenceSystem())) {
                    llBounds = bounds;
                } else {
                    final MathTransform srcCRStoWGS84 = CRS.findMathTransform(bounds
                            .getCoordinateReferenceSystem(), wgs84);
                    final GeneralEnvelope latLonEnvelope = CRSUtilities.transform(srcCRStoWGS84,
                            bounds);
                    latLonEnvelope.setCoordinateReferenceSystem(wgs84);
                    llBounds = latLonEnvelope;
                }

                final Envelope bbox = new Envelope(bounds.getLowerCorner().getOrdinate(0),
                        bounds.getUpperCorner().getOrdinate(0),
                        bounds.getLowerCorner().getOrdinate(1),
                        bounds.getUpperCorner().getOrdinate(1));

                final Envelope llBbox = new Envelope(llBounds.getLowerCorner().getOrdinate(0),
                        llBounds.getUpperCorner().getOrdinate(0),
                        llBounds.getLowerCorner().getOrdinate(1),
                        llBounds.getUpperCorner().getOrdinate(1));

                handleLatLonBBox(llBbox);
                handleBBox(bbox, authority);

                // add the layer style
                start("Style");

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -