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

📄 geoserverfeaturesource.java

📁 电子地图服务器,搭建自己的地图服务
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
     *
     * @see org.geotools.data.FeatureSource#getDataStore()
     */
    public DataStore getDataStore() {
        return source.getDataStore();
    }

    /**
     * Implement addFeatureListener.
     *
     * <p>
     * Description ...
     * </p>
     *
     * @param listener
     *
     * @see org.geotools.data.FeatureSource#addFeatureListener(org.geotools.data.FeatureListener)
     */
    public void addFeatureListener(FeatureListener listener) {
        source.addFeatureListener(listener);
    }

    /**
     * Implement removeFeatureListener.
     *
     * <p>
     * Description ...
     * </p>
     *
     * @param listener
     *
     * @see org.geotools.data.FeatureSource#removeFeatureListener(org.geotools.data.FeatureListener)
     */
    public void removeFeatureListener(FeatureListener listener) {
        source.removeFeatureListener(listener);
    }

    /**
     * Implement getFeatures.
     *
     * <p>
     * Description ...
     * </p>
     *
     * @param query
     *
     * @return
     *
     * @throws IOException
     *
     * @see org.geotools.data.FeatureSource#getFeatures(org.geotools.data.Query)
     */
    public FeatureCollection getFeatures(Query query) throws IOException {
        Query newQuery = makeDefinitionQuery(query);

        // see if the CRS got xfered over
        // a. old had a CRS, new doesnt
        boolean requireXferCRS = (newQuery.getCoordinateSystem() == null)
            && (query.getCoordinateSystem() != null);

        if ((newQuery.getCoordinateSystem() != null) && (query.getCoordinateSystem() != null)) {
            //b. both have CRS, but they're different
            requireXferCRS = !(newQuery.getCoordinateSystem().equals(query.getCoordinateSystem()));
        }

        if (requireXferCRS) {
            //carry along the CRS
            if (!(newQuery instanceof DefaultQuery)) {
                newQuery = new DefaultQuery(newQuery);
            }

            ((DefaultQuery) newQuery).setCoordinateSystem(query.getCoordinateSystem());
        }

        try {
            //JD: this is a huge hack... but its the only way to ensure that we 
            // we get what we ask for ... which is not reprojection, since 
            // datastores are unreliable in this aspect we dont know if they will
            // reproject or not.
            CoordinateReferenceSystem targetCRS = newQuery.getCoordinateSystemReproject();
            if ( targetCRS != null ) {
                ((DefaultQuery)newQuery).setCoordinateSystemReproject(null);
            }
            
            //this is the raw "unprojected" feature collection
            FeatureCollection fc = source.getFeatures(newQuery);

            if ( fc.getSchema().getDefaultGeometry() == null ) {
                // reprojection and crs forcing do not make sense, bail out
                return fc;
            } 
            CoordinateReferenceSystem nativeCRS = fc.getSchema().getDefaultGeometry().getCoordinateSystem();
            
            if (srsHandling == FeatureTypeInfo.LEAVE && nativeCRS != null) {
                //do nothing
            }
            else if (srsHandling == FeatureTypeInfo.FORCE || nativeCRS == null) {
                //force the declared crs
                fc =  new ForceCoordinateSystemFeatureResults(fc, declaredCRS);
                nativeCRS = declaredCRS;
            }
            else {
                //reproject to declared crs only if no reprojection has been
                // specified in the query
                if ( targetCRS == null ) {
                    fc = new ReprojectFeatureResults(fc,declaredCRS);
                }
            }
            
            //was reproject specified as part of the query?
            if (targetCRS != null ) {
                //reprojection is occuring
                if ( nativeCRS == null ) {
                    //we do not know what the native crs which means we can 
                    // not be sure if we should reproject or not... so we go 
                    // ahead and reproject regardless
                    fc = new ReprojectFeatureResults(fc,targetCRS);
                }
                else {
                    //only reproject if native != target
                    if (!CRS.equalsIgnoreMetadata(nativeCRS, targetCRS)) {
                        fc = new ReprojectFeatureResults(fc,targetCRS);                        
                    }
                }
            }
            return fc;
        } catch (Exception e) {
            throw new DataSourceException(e);
        }
    }

    public FeatureCollection getFeatures(Filter filter)
        throws IOException {
        return getFeatures(new DefaultQuery(schema.getTypeName(), filter));
    }

    public FeatureCollection getFeatures() throws IOException {
        return getFeatures(Query.ALL);
    }

    /**
     * Implement getSchema.
     *
     * <p>
     * Description ...
     * </p>
     *
     * @return
     *
     * @see org.geotools.data.FeatureSource#getSchema()
     */
    public FeatureType getSchema() {
        return schema;
    }

    /**
     * Retrieves the total extent of this FeatureSource.
     *
     * <p>
     * Please note this extent will reflect the provided definitionQuery.
     * </p>
     *
     * @return Extent of this FeatureSource, or <code>null</code> if no
     *         optimizations exist.
     *
     * @throws IOException If bounds of definitionQuery
     */
    public Envelope getBounds() throws IOException {
        // since CRS is at most forced, we don't need to change this code
        if (definitionQuery == Filter.INCLUDE) {
            return source.getBounds();
        } else {
            Query query = new DefaultQuery(getSchema().getTypeName(), definitionQuery);

            return source.getBounds(query);
        }
    }

    /**
     * Retrive the extent of the Query.
     *
     * <p>
     * This method provides access to an optimized getBounds opperation. If no
     * optimized opperation is available <code>null</code> will be returned.
     * </p>
     *
     * <p>
     * You may still make use of getFeatures( Query ).getCount() which will
     * return the correct answer (even if it has to itterate through all the
     * results to do so.
     * </p>
     *
     * @param query User's query
     *
     * @return Extend of Query or <code>null</code> if no optimization is
     *         available
     *
     * @throws IOException If a problem is encountered with source
     */
    public Envelope getBounds(Query query) throws IOException {
        // since CRS is at most forced, we don't need to change this code
        try {
            query = makeDefinitionQuery(query);
        } catch (IOException ex) {
            return null;
        }

        return source.getBounds(query);
    }

    /**
     * Adjust query and forward to source.
     *
     * <p>
     * This method provides access to an optimized getCount opperation. If no
     * optimized opperation is available <code>-1</code> will be returned.
     * </p>
     *
     * <p>
     * You may still make use of getFeatures( Query ).getCount() which will
     * return the correct answer (even if it has to itterate through all the
     * results to do so).
     * </p>
     *
     * @param query User's query.
     *
     * @return Number of Features for Query, or -1 if no optimization is
     *         available.
     */
    public int getCount(Query query) {
        try {
            query = makeDefinitionQuery(query);
        } catch (IOException ex) {
            return -1;
        }

        try {
            return source.getCount(query);
        } catch (IOException e) {
            return 0;
        }
    }
    
    public Set getSupportedHints() {
        return source.getSupportedHints();
    }   
}

⌨️ 快捷键说明

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