Package org.vfny.geoserver.wms.requests

Examples of org.vfny.geoserver.wms.requests.GetFeatureInfoRequest


     *
     * @see AbstractFeatureInfoResponse#writeTo(OutputStream)
     */
    @Override
    public void writeTo(final OutputStream out) throws ServiceException, IOException {
        final GetFeatureInfoRequest fInfoReq = getRequest();
        final WMS wmsConfig = fInfoReq.getWMS();

        //the 'response' object we'll pass to our OutputFormat
        FeatureCollectionType features = WfsFactory.eINSTANCE.createFeatureCollectionType();
       
        //the 'request' object we'll pass to our OutputFormat
        GetFeatureType gfreq = WfsFactory.eINSTANCE.createGetFeatureType();
        gfreq.setBaseUrl(fInfoReq.getBaseUrl());

        for (Iterator i = results.iterator(); i.hasNext();) {
            FeatureCollection<SimpleFeatureType, SimpleFeature> fc = (FeatureCollection)i.next();
            features.getFeature().add(fc);
           
View Full Code Here


     */
    @Override
    public void writeTo(OutputStream out)
        throws ServiceException, java.io.IOException {
        // setup the writer
        final GetFeatureInfoRequest request = getRequest();
        final WMS wmsConfig = request.getWMS();
        final Charset charSet = wmsConfig.getCharSet();
        final OutputStreamWriter osw = new OutputStreamWriter(out, charSet);
       
        // if there is only one feature type loaded, we allow for header/footer customization,
        // otherwise we stick with the generic ones
View Full Code Here

    @SuppressWarnings("deprecation")
  @Override
    //@SuppressWarnings("unchecked")
    protected void execute(MapLayerInfo[] requestedLayers, Style[] styles, Filter[] filters, int x, int y, int buffer)
        throws WmsException {
        GetFeatureInfoRequest request = getRequest();
        this.format = request.getInfoFormat();

        GetMapRequest getMapReq = request.getGetMapRequest();
        CoordinateReferenceSystem requestedCRS = getMapReq.getCrs(); // optional, may be null

        // basic information about the request
        int width = getMapReq.getWidth();
        int height = getMapReq.getHeight();
        ReferencedEnvelope bbox = new ReferencedEnvelope(getMapReq.getBbox(), getMapReq.getCrs());
        double scaleDenominator = RendererUtilities.calculateOGCScale(bbox, width, new HashMap());
        FilterFactory2 ff = CommonFactoryFinder.getFilterFactory2(GeoTools.getDefaultHints());

        final int layerCount = requestedLayers.length;
        results = new ArrayList<FeatureCollection<? extends FeatureType,? extends Feature>>(layerCount);
        metas = new ArrayList<MapLayerInfo>(layerCount);
       
        try {
            for (int i = 0; i < layerCount; i++) {
                List<Rule> rules = getActiveRules(styles[i], scaleDenominator);
                if(rules.size() == 0)
                    continue;
                MapLayerInfo layerInfo = requestedLayers[i];
                if (layerInfo.getType() == MapLayerInfo.TYPE_VECTOR) {
                    CoordinateReferenceSystem dataCRS = layerInfo.getCoordinateReferenceSystem();

                    // compute the request radius
                    double radius;
                    if(buffer <= 0) {
                        // estimate the radius given the currently active rules
                        MetaBufferEstimator estimator = new MetaBufferEstimator();
                        for (Rule rule : rules) {
                            rule.accept(estimator);
                        }
                       
                        if(estimator.getBuffer() < 6.0 || !estimator.isEstimateAccurate()) {
                            radius = 3.0;
                        } else {
                            radius =  estimator.getBuffer() / 2.0;
                        }
                    } else {
                        radius = buffer;
                    }
                   
                    // make sure we don't go overboard, the admin might have set a maximum
                    int maxRadius = request.getWMS().getMaxBuffer();
                    if(maxRadius > 0 && radius > maxRadius)
                        radius = maxRadius;
                   
                    Polygon pixelRect = getEnvelopeFilter(x, y, width, height, bbox, radius);
                    if ((requestedCRS != null) && !CRS.equalsIgnoreMetadata(dataCRS, requestedCRS)) {
                        try {
                            MathTransform transform = CRS.findMathTransform(requestedCRS, dataCRS, true);
                            pixelRect = (Polygon) JTS.transform(pixelRect, transform); // reprojected
                        } catch (MismatchedDimensionException e) {
                            LOGGER.severe(e.getLocalizedMessage());
                        } catch (TransformException e) {
                            LOGGER.severe(e.getLocalizedMessage());
                        } catch (FactoryException e) {
                            LOGGER.severe(e.getLocalizedMessage());
                        }
                    }

                    final FeatureSource<? extends FeatureType, ? extends Feature> featureSource;
                    featureSource = layerInfo.getFeatureSource(false);
                    FeatureType schema = featureSource.getSchema();
                   
                    Filter getFInfoFilter = null;
                    try {
                        GeometryDescriptor geometryDescriptor = schema.getGeometryDescriptor();
                        String localName = geometryDescriptor.getLocalName();
                        getFInfoFilter = ff.intersects(ff.property(localName), ff.literal(pixelRect));
                    } catch (IllegalFilterException e) {
                        e.printStackTrace();
                        throw new WmsException(null, "Internal error : " + e.getMessage());
                    }

                    // include the eventual layer definition filter
                    if (filters[i] != null) {
                        getFInfoFilter = ff.and(getFInfoFilter, filters[i]);
                    }
                   
                    // see if we can include the rule filters as well, if too many we'll do them in memory
                    Filter postFilter = Filter.INCLUDE;
                    Filter rulesFilters = buildRulesFilter(ff, rules);
                    if(!(rulesFilters instanceof Or) ||
                        (rulesFilters instanceof Or && ((Or) rulesFilters).getChildren().size() <= 20)) {
                        getFInfoFilter = ff.and(getFInfoFilter, rulesFilters);
                    } else {
                        postFilter = rulesFilters;
                    }

                    String typeName = schema.getName().getLocalPart();
                    Query q = new DefaultQuery(typeName, null, getFInfoFilter, request.getFeatureCount(), Query.ALL_NAMES, null);
                   
                    FeatureCollection<? extends FeatureType, ? extends Feature> match;
                    match = featureSource.getFeatures(q);
                   
                    // if we could not include the rules filter into the query, post process in memory
View Full Code Here

     * @throws ServiceException DOCUMENT ME!
     */
    public void execute(Request request) throws ServiceException {
        LOGGER.entering(getClass().getName(), "execute", new Object[] { request });

        GetFeatureInfoRequest getFeatureInfoReq = (GetFeatureInfoRequest) request;
       
        EnvFunction.setLocalValues(getFeatureInfoReq.getGetMapRequest().getEnv());
        try {
            this.delegate = getDelegate(getFeatureInfoReq);
            delegate.execute(request);
        } finally {
            EnvFunction.clearLocalValues();
View Full Code Here

     *
     * @throws WmsException For any problems.
     */
    protected void execute(FeatureTypeInfo[] requestedLayers, Query[] queries,
        int x, int y) throws WmsException {
        GetFeatureInfoRequest request = getRequest();
        this.format = request.getInfoFormat();

        GetMapRequest getMapReq = request.getGetMapRequest();

        int width = getMapReq.getWidth();
        int height = getMapReq.getHeight();
        Envelope bbox = getMapReq.getBbox();

        Coordinate upperLeft = pixelToWorld(x - 2, y - 2, bbox, width, height);
        Coordinate lowerRight = pixelToWorld(x + 2, y + 2, bbox, width, height);

        Coordinate[] coords = new Coordinate[5];
        coords[0] = upperLeft;
        coords[1] = new Coordinate(lowerRight.x, upperLeft.y);
        coords[2] = lowerRight;
        coords[3] = new Coordinate(upperLeft.x, lowerRight.y);
        coords[4] = coords[0];

          //DJB:
            //TODO: this should probably put a max features restriction on the query
            //      unforunately, this queryies by filter not by query, so this is a slightly more difficult problem
            //      Its not a big deal not to do this because the writer will ensure that the correct # of items
            //      are actually printed out.
            //DJB: DONE - see "q", below
            // NOTE: you can ask for results from multiple layers at once.  So, if max features is 2 (after you add max features query to above) and you
            //       query 10 layers, you could still get 20 features being sent on.
            //       Thats why max features is handled at the query portion!
        GeometryFactory geomFac = new GeometryFactory();

        LinearRing boundary = geomFac.createLinearRing(coords);

        Polygon pixelRect = geomFac.createPolygon(boundary, null);

        FilterFactory filterFac = FilterFactory.createFilterFactory();

        GeometryFilter getFInfoFilter = null;

        try {
            getFInfoFilter = filterFac.createGeometryFilter(AbstractFilter.GEOMETRY_INTERSECTS);
            getFInfoFilter.addLeftGeometry(filterFac.createLiteralExpression(
                    pixelRect));
        } catch (IllegalFilterException e) {
            e.printStackTrace();
            throw new WmsException(null, "Internal error : " + e.getMessage());
        }

        int layerCount = requestedLayers.length;
        results = new ArrayList(layerCount);
        metas = new ArrayList(layerCount);

       
        try {
            for (int i = 0; i < layerCount; i++) {
                FeatureTypeInfo finfo = requestedLayers[i];
                Query q = new DefaultQuery( finfo.getTypeName(), null, getFInfoFilter,request.getFeatureCount(), Query.ALL_NAMES, null );
                FeatureResults match = finfo.getFeatureSource().getFeatures(q);

                //this was crashing Gml2FeatureResponseDelegate due to not setting
                //the featureresults, thus not being able of querying the SRS
                //if (match.getCount() > 0) {
View Full Code Here

     */
    private Query[] buildQueries(FeatureTypeInfo[] layers)
        throws WmsException {
        int nLayers = layers.length;
        Query[] queries = new Query[nLayers];
        GetFeatureInfoRequest infoRequest = getRequest();
        Envelope requestExtent = infoRequest.getGetMapRequest().getBbox();
        FilterFactory ffactory = FilterFactory.createFilterFactory();

        try {
            Filter finalLayerFilter;
            Query layerQuery;
View Full Code Here

     *
     * @throws ServiceException DOCUMENT ME!
     * @throws IOException DOCUMENT ME!
     */
    public void writeTo(OutputStream out) throws ServiceException, IOException {
        GetFeatureInfoRequest fInfoReq = (GetFeatureInfoRequest) getRequest();
        FeatureRequest freq = new FeatureRequest();
        freq.setHttpServletRequest(fInfoReq.getHttpServletRequest());

        freq.setRequest("GETFEATURE");
        freq.setHandle("GetFeatureInfo");
        freq.setMaxFeatures(fInfoReq.getFeatureCount());

        List queries = null;
        freq.setQueries(queries);

        GetFeatureResults getFeatureResults = new GetFeatureResults(freq);
View Full Code Here

     */
    public void execute(Request request) throws ServiceException {
        LOGGER.entering(getClass().getName(), "execute",
            new Object[] { request });

        GetFeatureInfoRequest getFeatureInfoReq = (GetFeatureInfoRequest) request;
        this.delegate = getDelegate(getFeatureInfoReq);
        delegate.execute(request);
    }
View Full Code Here

TOP

Related Classes of org.vfny.geoserver.wms.requests.GetFeatureInfoRequest

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.