Package net.opengis.wfs

Examples of net.opengis.wfs.QueryType


            List queries = (List) EMFUtils.get(eObject, "query");
            List filters = new ArrayList();

            for (Iterator q = queries.iterator(); q.hasNext();) {
                QueryType query = (QueryType) q.next();
                List typeName = query.getTypeName();
                Filter filter = null;

                if (typeName.size() > 1) {
                    //TODO: not sure what to do here, just going to and them up
                    List and = new ArrayList(typeName.size());
View Full Code Here


        for (Iterator i = results.iterator(); i.hasNext();) {
            FeatureCollection<SimpleFeatureType, SimpleFeature> fc = (FeatureCollection)i.next();
            features.getFeature().add(fc);
           
            QueryType qt = WfsFactory.eINSTANCE.createQueryType();
            String crs = GML2EncodingUtils.epsgCode(fc.getSchema().getCoordinateReferenceSystem());
            if (crs != null) {
                final String srsName = "EPSG:" + crs;
                try {
                    qt.setSrsName(new URI(srsName));
                } catch (URISyntaxException e) {
                    throw new ServiceException("Unable to determite coordinate system for featureType " + fc.getSchema().getTypeName() + ".  Schema told us '" + srsName + "'", e);
                }
            }
            gfreq.getQuery().add(qt);
View Full Code Here

            return request.getHandle();
        }
       
        StringBuffer sb = new StringBuffer();
        for (Iterator f = request.getQuery().iterator(); f.hasNext();) {
            QueryType query = (QueryType) f.next();
            sb.append(getLayerName(query) + "_");
        }       
        sb.setLength(sb.length() - 1);
        LOGGER.log(Level.FINE,"Using layer names for file name: "+sb.toString());
        if (sb.length() > 20) {
View Full Code Here

     * @return
     */
    private String[] getLayerNames(Iterator it) {
        List<String> names = new ArrayList<String>();
        while (it.hasNext()) {
            QueryType query = (QueryType) it.next();
            names.add(getLayerName(query).toUpperCase());
        }

        return names.toArray(new String[] {});
    }
View Full Code Here

     *
     * @generated modifiable
     */
    public Object parse(ElementInstance instance, Node node, Object value)
        throws Exception {
        QueryType query = wfsfactory.createQueryType();

        //&lt;xsd:choice maxOccurs="unbounded" minOccurs="0"&gt;
        //&lt;xsd:element ref="wfs:PropertyName"&gt;
        if (node.hasChild("PropertyName")) {
            //HACK, stripping of namespace prefix
            for (Iterator p = node.getChildValues("PropertyName").iterator(); p.hasNext();) {
                Object property = p.next();
                String propertyName;
                if(property instanceof String)
                    propertyName = (String) property;
                else
                    propertyName = (String) ((PropertyName) property).getPropertyName();

                if (propertyName.indexOf(':') != -1) {
                    propertyName = propertyName.substring(propertyName.indexOf(':') + 1);
                }

                query.getPropertyName().add(propertyName);
            }
        }

        //&lt;xsd:element ref="ogc:Function"&gt;
        if (node.hasChild("Function")) {
            query.getFunction().add(node.getChildValues("Function"));
        }

        //&lt;/xsd:choice&gt;

        //&lt;xsd:element maxOccurs="1" minOccurs="0" ref="ogc:Filter"&gt;
        if (node.hasChild(Filter.class)) {
            query.setFilter((Filter) node.getChildValue(Filter.class));
        }

        //&lt;xsd:element maxOccurs="1" minOccurs="0" ref="ogc:SortBy"&gt;
        if (node.hasChild(SortBy[].class)) {
            SortBy[] sortBy = (SortBy[]) node.getChildValue(SortBy[].class);

            for (int i = 0; i < sortBy.length; i++)
                query.getSortBy().add(sortBy[i]);
        }

        //&lt;xsd:attribute name="handle" type="xsd:string" use="optional"&gt;
        if (node.hasAttribute("handle")) {
            query.setHandle((String) node.getAttributeValue("handle"));
        }

        //&lt;xsd:attribute name="typeName" type="wfs:TypeNameListType" use="required"&gt;
        query.setTypeName((List) node.getAttributeValue("typeName"));

        //&lt;xsd:attribute name="featureVersion" type="xsd:string" use="optional"&gt;
        if (node.hasAttribute("featureVersion")) {
            query.setFeatureVersion((String) node.getAttributeValue("featureVersion"));
        }

        //&lt;xsd:attribute name="srsName" type="xsd:anyURI" use="optional"&gt;
        if (node.hasAttribute("srsName")) {
            query.setSrsName((URI) node.getAttributeValue("srsName"));
        }
       
        if ( node.hasChild( "XlinkPropertyName" ) ) {
            query.getXlinkPropertyName().addAll( node.getChildValues( "XlinkPropertyName" ));   
        }
       
        return query;
    }
View Full Code Here

            }

            //JD: wfs reprojection: should not set srs form metadata but from
            // the request
            //srs = Integer.parseInt(meta.getSRS());
            QueryType query = (QueryType) request.getQuery().get(i);
            try {
                String srsName = query.getSrsName() != null ? query.getSrsName().toString() : null;
                if ( srsName == null ) {
                    //no SRS in query...asking for the default?
                    srsName = meta.getSRS();
                }
                if ( srsName != null ) {
                    CoordinateReferenceSystem crs = CRS.decode(srsName);
                    String epsgCode = GML2EncodingUtils.epsgCode(crs);
                    srs = Integer.parseInt(epsgCode);
                }
            }
            catch( Exception e ) {
                LOGGER.log(Level.WARNING, "Problem encoding:" + query.getSrsName(), e);
               
            }
           
            //track num decimals, in cases where the query has multiple types we choose the max
            // of all the values
View Full Code Here

        int count = 0; //should probably be long

        List results = new ArrayList();
        try {
            for (int i = 0; (i < request.getQuery().size()) && (count < maxFeatures); i++) {
                QueryType query = (QueryType) request.getQuery().get(i);

                FeatureTypeInfo meta = null;

                if (query.getTypeName().size() == 1) {
                    meta = featureTypeInfo((QName) query.getTypeName().get(0));
                } else {
                    //TODO: a join is taking place
                }

                FeatureSource<? extends FeatureType, ? extends Feature> source = meta.getFeatureSource(null,null);

                List<AttributeTypeInfo> atts = meta.attributes();
                List attNames = new ArrayList( atts.size() );
                for ( AttributeTypeInfo att : atts ) {
                    attNames.add( att.getName() );
                }

                //make sure property names are cool
                List propNames = query.getPropertyName();

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

                    //HACK: strip off namespace
                    if (propName.indexOf(':') != -1) {
                        propName = propName.substring(propName.indexOf(':') + 1);
                    }

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

                        throw new WFSException(mesg);
                    }
                }

                //we must also include any properties that are mandatory ( even if not requested ),
                // ie. those with minOccurs > 0
                List extraGeometries = new ArrayList();
                List properties = new ArrayList();
                if (propNames.size() != 0) {
                    Iterator ii = atts.iterator();

                    while (ii.hasNext()) {
                        AttributeTypeInfo ati = (AttributeTypeInfo) ii.next();
                        LOGGER.finer("checking to see if " + propNames + " contains" + ati);

                        if (((ati.getMinOccurs() > 0) && (ati.getMaxOccurs() != 0))) {
                            //mandatory, add it
                            properties.add(ati.getName());

                            continue;
                        }

                        //check if it was requested
                        for (Iterator p = propNames.iterator(); p.hasNext();) {
                            String propName = (String) p.next();

                            if (propName.matches("(\\w+:)?" + ati.getName())) {
                                properties.add(ati.getName());
                                break;
                            }
                        }
                       
                        // if we need to force feature bounds computation, we have to load
                        // all of the geometries, but we'll have to remove them in the
                        // returned feature type
                        if(wfs.isFeatureBounding() && meta.getFeatureType().getDescriptor(ati.getName()) instanceof GeometryDescriptor
                                && !properties.contains(ati.getName())) {
                            properties.add(ati.getName());
                            extraGeometries.add(ati.getName());
                        }
                    }

                    //replace property names
                    query.getPropertyName().clear();
                    query.getPropertyName().addAll(properties);
                }

                //make sure filters are sane
                //
                // Validation of filters on non-simple feature types is not yet supported.
                // FIXME: Support validation of filters on non-simple feature types:
                // need to consider xpath properties and how to configure namespace prefixes in
                // GeoTools app-schema FeaturePropertyAccessorFactory.
                if (query.getFilter() != null && source.getSchema() instanceof SimpleFeatureType) {
                   
                    //1. ensure any property name refers to a property that
                    // actually exists
                    final FeatureType featureType = source.getSchema();
                    ExpressionVisitor visitor = new AbstractExpressionVisitor() {
                            public Object visit(PropertyName name, Object data) {
                                // case of multiple geometries being returned
                                if (name.evaluate(featureType) == null) {
                                    throw new WFSException("Illegal property name: "
                                        + name.getPropertyName(), "InvalidParameterValue");
                                }

                                return name;
                            }
                            ;
                        };
                    query.getFilter().accept(new AbstractFilterVisitor(visitor), null);
                   
                    //2. ensure any spatial predicate is made against a property
                    // that is actually special
                    AbstractFilterVisitor fvisitor = new AbstractFilterVisitor() {
                     
                        protected Object visit( BinarySpatialOperator filter, Object data ) {
                            PropertyName name = null;
                            if ( filter.getExpression1() instanceof PropertyName ) {
                                name = (PropertyName) filter.getExpression1();
                            }
                            else if ( filter.getExpression2() instanceof PropertyName ) {
                                name = (PropertyName) filter.getExpression2();
                            }
                           
                            if ( name != null ) {
                                //check against fetaure type to make sure its
                                // a geometric type
                                AttributeDescriptor att = (AttributeDescriptor) name.evaluate(featureType);
                                if ( !( att instanceof GeometryDescriptor ) ) {
                                    throw new WFSException("Property " + name + " is not geometric", "InvalidParameterValue");
                                }
                            }
                           
                            return filter;
                        }
                    };
                    query.getFilter().accept(fvisitor, null);
                   
                    //3. ensure that any bounds specified as part of the query
                    // are valid with respect to the srs defined on the query
                    if ( wfs.isCiteCompliant() ) {
                       
                        if ( query.getSrsName() != null ) {
                            final QueryType fquery = query;
                            fvisitor = new AbstractFilterVisitor() {
                                public Object visit(BBOX filter, Object data) {
                                    if ( filter.getSRS() != null &&
                                            !fquery.getSrsName().toString().equals( filter.getSRS() ) ) {
                                       
                                        //back project bounding box into geographic coordinates
                                        CoordinateReferenceSystem geo = DefaultGeographicCRS.WGS84;
                                       
                                        GeneralEnvelope e = new GeneralEnvelope(
                                            new double[] { filter.getMinX(), filter.getMinY()},
                                            new double[] { filter.getMaxX(), filter.getMaxY()}
                                        );
                                        CoordinateReferenceSystem crs = null;
                                        try {
                                            crs = CRS.decode( filter.getSRS() );
                                            e = CRS.transform(CRS.findMathTransform(crs, geo, true), e);
                                        }
                                        catch( Exception ex ) {
                                            throw new WFSException( ex );
                                        }
                                       
                                        //ensure within bounds defined by srs specified on
                                        // query
                                        try {
                                            crs = CRS.decode( fquery.getSrsName().toString() );
                                        }
                                        catch( Exception ex ) {
                                            throw new WFSException( ex );
                                        }
                                       
                                        GeographicBoundingBox valid =
                                            (GeographicBoundingBox) crs.getDomainOfValidity()
                                            .getGeographicElements().iterator().next();
                                       
                                        if ( e.getMinimum(0) < valid.getWestBoundLongitude() ||
                                            e.getMinimum(0) > valid.getEastBoundLongitude() ||
                                            e.getMaximum(0) < valid.getWestBoundLongitude() ||
                                            e.getMaximum(0) > valid.getEastBoundLongitude() ||
                                            e.getMinimum(1) < valid.getSouthBoundLatitude() ||
                                            e.getMinimum(1) > valid.getNorthBoundLatitude() ||
                                            e.getMaximum(1) < valid.getSouthBoundLatitude() ||
                                            e.getMaximum(1) > valid.getNorthBoundLatitude() ) {
                                               
                                            throw new WFSException( "bounding box out of valid range of crs", "InvalidParameterValue");
                                        }
                                    }
                                   
                                    return data;
                                }
                            };
                           
                            query.getFilter().accept(fvisitor, null);
                        }
                    }  
                }

                // handle local maximum
                int queryMaxFeatures = maxFeatures - count;
                if(meta.getMaxFeatures() > 0 && meta.getMaxFeatures() < queryMaxFeatures)
                    queryMaxFeatures = meta.getMaxFeatures();
                org.geotools.data.Query gtQuery = toDataQuery(query, queryMaxFeatures, source, request);
               
                LOGGER.fine("Query is " + query + "\n To gt2: " + gtQuery);

                FeatureCollection<? extends FeatureType, ? extends Feature> features = getFeatures(request, source, gtQuery);
               
                // optimization: WFS 1.0 does not require count unless we have multiple query elements
                // and we are asked to perform a global limit on the results returned
                if(("1.0".equals(request.getVersion()) || "1.0.0".equals(request.getVersion())) &&
                        (request.getQuery().size() == 1 || maxFeatures == Integer.MAX_VALUE)) {
                    // skip the count update, in this case we don't need it
                } else {
                  count += features.size();
                }
               
                // we may need to shave off geometries we did load only to make bounds
                // computation happy
                // TODO: support non-SimpleFeature geometry shaving
                if(features.getSchema() instanceof SimpleFeatureType && extraGeometries.size() > 0) {
                    List residualProperties = new ArrayList(properties);
                    residualProperties.removeAll(extraGeometries);
                    String[] residualNames = (String[]) residualProperties.toArray(new String[residualProperties.size()]);
                    SimpleFeatureType targetType = DataUtilities.createSubType((SimpleFeatureType) features.getSchema(), residualNames);
                    features = new FeatureBoundsFeatureCollection((FeatureCollection<SimpleFeatureType, SimpleFeature>) features, targetType);
                }

                //JD: TODO reoptimize
                //                if ( i == request.getQuery().size() - 1 ) {
                //                  //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
                //encoding if it was a lock request. may be after ensuring the lock
                //succeed?
                results.add(features);
            }
        } catch (IOException e) {
            throw new WFSException("Error occurred getting features", e, request.getHandle());
        } catch (SchemaException e) {
            throw new WFSException("Error occurred getting features", e, request.getHandle());
        }

        //locking
        String lockId = null;
        if (request instanceof GetFeatureWithLockType) {
            GetFeatureWithLockType withLockRequest = (GetFeatureWithLockType) request;

            LockFeatureType lockRequest = WfsFactory.eINSTANCE.createLockFeatureType();
            lockRequest.setExpiry(withLockRequest.getExpiry());
            lockRequest.setHandle(withLockRequest.getHandle());
            lockRequest.setLockAction(AllSomeType.ALL_LITERAL);

            for (int i = 0; i < request.getQuery().size(); i++) {
                QueryType query = (QueryType) request.getQuery().get(i);

                LockType lock = WfsFactory.eINSTANCE.createLockType();
                lock.setFilter(query.getFilter());
                lock.setHandle(query.getHandle());

                //TODO: joins?
                lock.setTypeName((QName) query.getTypeName().get(0));
                lockRequest.getLock().add(lock);
            }

            LockFeature lockFeature = new LockFeature(wfs, catalog);
            lockFeature.setFilterFactory(filterFactory);
View Full Code Here

        for (int fcIndex = 0; fcIndex < featureCollections.size(); fcIndex++) {
            if(getFeature.getParameters()[0] instanceof GetFeatureType) {
                // get the query for this featureCollection
                GetFeatureType request = (GetFeatureType) OwsUtils.parameter(getFeature.getParameters(),
                        GetFeatureType.class);
                QueryType queryType = (QueryType) request.getQuery().get(fcIndex);
               
                // may have multiple type names in each query, so add them all
                for (QName name : (List<QName>) queryType.getTypeName()) {
                    // get a feature type name from the query
                    Name featureTypeName = new NameImpl(name.getNamespaceURI(), name.getLocalPart());
                    FeatureTypeInfo meta = catalog.getFeatureTypeByName(featureTypeName);
                   
                    if (meta == null) {
View Full Code Here

    private GetFeatureType toGetFeatureType(FeatureCollectionType featureCollection,
            GetLogType request) {
        FeatureCollection<SimpleFeatureType, SimpleFeature> features = (FeatureCollection) featureCollection.getFeature().get(0);
        SimpleFeatureType featureType = features.getSchema();
        GetFeatureType ftRequest = WfsFactory.eINSTANCE.createGetFeatureType();
        QueryType query = WfsFactory.eINSTANCE.createQueryType();
        query.setTypeName(Collections.singletonList(featureType.getTypeName()));
        ftRequest.getQuery().add(query);
        ftRequest.setBaseUrl(request.getBaseUrl());
        ftRequest.setHandle(request.getHandle());
        ftRequest.setMaxFeatures(request.getMaxFeatures());
        ftRequest.setOutputFormat(request.getOutputFormat());
View Full Code Here

     *
     * @generated modifiable
     */
    public Object parse(ElementInstance instance, Node node, Object value)
        throws Exception {
        QueryType queryType = wfsfactory.createQueryType();

        //<xsd:element maxOccurs="unbounded" minOccurs="0" ref="ogc:PropertyName">
        //JD:difference in spec here, moved from ogc:PropertyName to string
        List propertyNames = node.getChildValues(PropertyName.class);

        for (Iterator p = propertyNames.iterator(); p.hasNext();) {
            PropertyName propertyName = (PropertyName) p.next();
            queryType.getPropertyName().add(propertyName.getPropertyName());
        }

        //<xsd:element maxOccurs="1" minOccurs="0" ref="ogc:Filter">
        Filter filter = (Filter) node.getChildValue(Filter.class);

        if (filter == null) {
            filter = (Filter) Filter.INCLUDE;
        }

        queryType.setFilter(filter);

        //<xsd:attribute name="handle" type="xsd:string" use="optional"/>
        queryType.setHandle((String) node.getAttributeValue("handle"));

        //<xsd:attribute name="typeName" type="xsd:QName" use="required"/>
        List typeNameList = new ArrayList();
        typeNameList.add(node.getAttributeValue("typeName"));
        queryType.setTypeName(typeNameList);

        //<xsd:attribute name="featureVersion" type="xsd:string" use="optional"> 
        queryType.setFeatureVersion((String) node.getAttributeValue("featureVersion"));

        //JD: even though reprojection is not supported in 1.0 we handle it
        // anyways
        //&lt;xsd:attribute name="srsName" type="xsd:anyURI" use="optional"&gt;
        if (node.hasAttribute("srsName")) {
            queryType.setSrsName(new URI((String)node.getAttributeValue("srsName")));
        }

        return queryType;
    }
View Full Code Here

TOP

Related Classes of net.opengis.wfs.QueryType

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.