Package org.vfny.geoserver.wfs

Examples of org.vfny.geoserver.wfs.Query


        WFS wfs = request.getWFS();
        GeoServer config = wfs.getGeoServer();
        Data catalog = wfs.getData();
        FeatureTypeInfo meta = null;
        NameSpaceInfo namespace;
        Query query;

        FeatureSource source;
        Feature feature;
        String fid;
        FilterFactory filterFactory = FilterFactoryFinder.createFilterFactory();
        FidFilter fidFilter;

        try {
            for (Iterator it = request.getQueries().iterator(); it.hasNext();) {
                query = (Query) it.next();

                // the feature type name used in the content disposition response will match
                // the first feature type
                if (featureTypeName == null) {
                    featureTypeName = query.getTypeName();
                }

                meta = catalog.getFeatureTypeInfo(query.getTypeName());
                namespace = meta.getDataStoreInfo().getNameSpace();
                source = meta.getFeatureSource();

                List attrs = meta.getAttributes();

                List propNames = query.getPropertyNames(); // REAL LIST: be careful here :)
                List attributeNames = meta.getAttributeNames();

                for (Iterator iter = propNames.iterator(); iter.hasNext();) {
                    String propName = (String) iter.next();

                    if (!attributeNames.contains(propName)) {
                        String mesg = "Requested property: " + propName + " is "
                            + "not available for " + query.getTypeName() + ".  "
                            + "The possible propertyName values are: " + attributeNames;
                        throw new WfsException(mesg);
                    }
                   
                   
                }

                List extraGeometries = new ArrayList();
                List properties = new ArrayList();
                if (propNames.size() != 0) {
                    Iterator ii = attrs.iterator();
                   

                    while (ii.hasNext()) {
                        AttributeTypeInfo ati = (AttributeTypeInfo) ii.next();

                        //String attName = (String) ii.next();
                        LOGGER.finer("checking to see if " + propNames + " contains" + ati);

                        if (((ati.getMinOccurs() > 0) && (ati.getMaxOccurs() != 0))
                                || propNames.contains(ati.getName())) {
                            properties.add(ati.getName());
                        }
                       
                        //if(wfs.isFeatureBounding() && meta.getFeatureType().getAttributeType(ati.getName()) instanceof GeometryAttributeType
                        //        && !properties.contains(ati.getName())) {
                        //    properties.add(ati.getName());
                        //    extraGeometries.add(ati.getName());
                        //}
                        if(meta.getFeatureType().getAttributeType(ati.getName()) instanceof GeometryAttributeType
                                && !properties.contains(ati.getName())) {
                            properties.add(ati.getName());
                            extraGeometries.add(ati.getName());
                        }
                    }

                    query.setPropertyNames(properties);
                }
               
                // Add range to filter
                AttributeExpression geomAttb = filterFactory.createAttributeExpression(meta.getFeatureType(), meta.getFeatureType().getDefaultGeometry().getName());
                LiteralExpression pointExpr = filterFactory.createLiteralExpression(request.getPoint());
                DWithin dWithin = filterFactory.dwithin(geomAttb, pointExpr, request.getMaxRange(), request.getUnits());
                if (query.getFilter() == null) {
                    query.addFilter((Filter)dWithin);
                   
                } else {
                    And andFilter = filterFactory.and(Arrays.asList(new Filter[] { (Filter)dWithin, query.getFilter() }));
                    query.addFilter((Filter)andFilter);
                }
               
                LOGGER.fine("Query is " + query + "\n To gt2: " + query.toDataQuery(Integer.MAX_VALUE));

                //DJB: note if maxFeatures gets to 0 the while loop above takes care of this! (this is a subtle situation)
                FeatureCollection featuresCheck = source.getFeatures(query.toDataQuery(Integer.MAX_VALUE));
               
                // find nearest feature
                Unit fromUnit = SI.METER;
                Unit toUnit = UnitFormat.getInstance().parseUnit(request.getUnits());
                Converter unitConvert = fromUnit.getConverterTo(toUnit);
View Full Code Here


     * @param filter What to filter features on.
     *
     * @return List of requested queries
     */
    private static Query makeQuery(String featureType, List propertyNames, Filter filter) {
        Query currentQuery = new Query();

        currentQuery.setTypeName(featureType);

        if (propertyNames != null) {
            for (int i = 0; i < propertyNames.size(); i++) {
                currentQuery.addPropertyName((String) propertyNames.get(i));
            }
        }

        if (filter != null) {
            currentQuery.addFilter(filter);
        }

        return currentQuery;
    }
View Full Code Here

        insideTag = localName;

        // if at a query element, empty the current query, set insideQuery
        //  flag, and get query typeNames
        if (insideTag.equals("Query")) {
            currentQuery = new Query();
            insideQuery = true;

            for (int i = 0, n = atts.getLength(); i < n; i++) {
                String name = atts.getLocalName(i);
                String value = atts.getValue(i);
View Full Code Here

            currentQuery.addFilter(filter);
        } else {
            LOGGER.finest("adding filter to all queries: " + filter);

            for (int i = 0, n = request.queries.size(); i < n; i++) {
                Query query = (Query) request.queries.get(i);
                Filter queryFilter = query.getFilter();

                if (queryFilter != null) {
                    query.addFilter(queryFilter.and(filter));
                } else {
                    query.addFilter(filter);
                }
            }
        }
    }
View Full Code Here

        //
        GeoServer config = request.getWFS().getGeoServer();
        Data catalog = request.getWFS().getData();
        FeatureTypeInfo meta = null;
        NameSpaceInfo namespace;
        Query query;
        int maxFeatures = request.getMaxFeatures();
        int serverMaxFeatures = config.getMaxFeatures();

        if (maxFeatures > serverMaxFeatures) {
            maxFeatures = serverMaxFeatures;
        }

        Set lockedFids = new HashSet();
        Set lockFailedFids = new HashSet();

        FeatureSource source;
        Feature feature;
        String fid;
        FilterFactory filterFactory = FilterFactory.createFilterFactory();
        FidFilter fidFilter;
        int numberLocked;

        try {
            for (Iterator it = request.getQueries().iterator();
                    it.hasNext() && (maxFeatures > 0);) {
                query = (Query) it.next();
                meta = catalog.getFeatureTypeInfo(query.getTypeName());
                namespace = meta.getDataStoreInfo().getNameSpace();
                source = meta.getFeatureSource();

                List attrs = meta.getAttributes();

                List propNames = query.getPropertyNames(); // REAL LIST: be careful here :)
                List attributeNames = meta.getAttributeNames();

                for (Iterator iter = propNames.iterator(); iter.hasNext();) {
                    String propName = (String) iter.next();

                    if (!attributeNames.contains(propName)) {
                        String mesg = "Requested property: " + propName
                            + " is " + "not available for "
                            + query.getTypeName() + ".  "
                            + "The possible propertyName values are: "
                            + attributeNames;
                        throw new WfsException(mesg);
                    }
                }

                if (propNames.size() != 0) {
                    Iterator ii = attrs.iterator();
                    List tmp = new LinkedList();

                    while (ii.hasNext()) {
                        AttributeTypeInfo ati = (AttributeTypeInfo) ii.next();

                        //String attName = (String) ii.next();
                        LOGGER.finer("checking to see if " + propNames
                            + " contains" + ati);

                        if (((ati.getMinOccurs() > 0)
                                && (ati.getMaxOccurs() != 0))
                                || propNames.contains(ati.getName())) {
                            tmp.add(ati.getName());
                        }
                    }

                    query.setPropertyNames(tmp);
                }

                // This doesn't seem to be working?
                // Run through features and record FeatureIDs
                // Lock FeatureIDs as required
                //}
                LOGGER.fine("Query is " + query + "\n To gt2: "
                    + query.toDataQuery(maxFeatures));

                //DJB: note if maxFeatures gets to 0 the while loop above takes care of this! (this is a subtle situation)
               
                FeatureResults features = source.getFeatures(query.toDataQuery(
                            maxFeatures));
                if (it.hasNext()) //DJB: dont calculate feature count if you dont have to. The MaxFeatureReader will take care of the last iteration
                  maxFeatures -= features.getCount();

                //GR: I don't know if the featuresults should be added here for later
View Full Code Here

        insideTag = localName;

        // if at a query element, empty the current query, set insideQuery
        //  flag, and get query typeNames
        if (insideTag.equals("Query")) {
            currentQuery = new Query();
            insideQuery = true;

            for (int i = 0, n = atts.getLength(); i < n; i++) {
                String name = atts.getLocalName(i);
                String value = atts.getValue(i);
View Full Code Here

            currentQuery.addFilter(filter);
        } else {
            LOGGER.finest("adding filter to all queries: " + filter);

            for (int i = 0, n = request.queries.size(); i < n; i++) {
                Query query = (Query) request.queries.get(i);
                Filter queryFilter = query.getFilter();

                if (queryFilter != null) {
                    query.addFilter(queryFilter.and(filter));
                } else {
                    query.addFilter(filter);
                }
            }
        }
    }
View Full Code Here

     *
     * @return List of requested queries
     */
    private static Query makeQuery(String featureType, List propertyNames,
        Filter filter) {
        Query currentQuery = new Query();

        currentQuery.setTypeName(featureType);

        if (propertyNames != null) {
            for (int i = 0; i < propertyNames.size(); i++) {
                currentQuery.addPropertyName((String) propertyNames.get(i));
            }
        }

        if (filter != null) {
            currentQuery.addFilter(filter);
        }

        return currentQuery;
    }
View Full Code Here

    public LockRequest asLockRequest() {
        LockRequest lockRequest = new LockRequest();
        lockRequest.setExpiry(expiry);

        for (Iterator i = queries.iterator(); i.hasNext();) {
            Query curQuery = (Query) i.next();
            lockRequest.addLock(curQuery.getTypeName(), curQuery.getFilter(),
                curQuery.getHandle());
        }

        LOGGER.finest("returning: " + super.toString() + " as " + lockRequest);

        return lockRequest;
View Full Code Here

    }

    public void test3() throws Exception {
        // make base comparison objects               
        FeatureRequest baseRequest = new FeatureRequest();
        Query query = new Query();
        query.setTypeName("rail");
        query.addFilter(factory.createFidFilter("123"));
        query.addPropertyName("name");
        query.addPropertyName("tracks");
        query.addPropertyName("id");
        baseRequest.addQuery(query);

        // run test
        assertTrue(runXmlTest(baseRequest, "7", true));
    }
View Full Code Here

TOP

Related Classes of org.vfny.geoserver.wfs.Query

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.