Package org.geotools.geopkg.wps.GeoPackageProcessRequest

Examples of org.geotools.geopkg.wps.GeoPackageProcessRequest.FeaturesLayer


             
       for (int i=0; i < contents.getLayerCount() ; i++) {
           Layer layer = contents.getLayer(i);
          
           if (layer.getType() == LayerType.FEATURES){
               FeaturesLayer features = (FeaturesLayer) layer;
               QName ftName = features.getFeatureType();

               QueryType query = Wfs20Factory.eINSTANCE.createQueryType();
               query.getTypeNames().add(ftName);

               if (features.getSrs() == null) {
                   String ns = ftName.getNamespaceURI() != null
                       ? ftName.getNamespaceURI() : ftName.getPrefix();
                   FeatureTypeInfo ft =
                       catalog.getFeatureTypeByName(ns, ftName.getLocalPart());
                   if (ft != null) {
                       try {
                           query.setSrsName(new URI(ft.getSRS()));
                       } catch (URISyntaxException e) {
                           throw new RuntimeException(e);
                       }
                   }
               }
               else {
                   query.setSrsName(features.getSrs());
               }

               if (features.getPropertyNames() != null) {
                   query.getPropertyNames().addAll(features.getPropertyNames());
               }
               Filter filter = features.getFilter();

               //add bbox to filter if there is one
               if (features.getBbox() != null){
                   String defaultGeometry = catalog.getFeatureTypeByName(features.getFeatureType().getLocalPart())
                           .getFeatureType().getGeometryDescriptor().getLocalName();

                   Envelope e = features.getBbox();
                   // HACK: because we are going through wfs 2.0, flip the coordinates (specified in xy)
                   // which will then be later flipped back to xy
                   if (query.getSrsName() != null) {
                       try {
                           CoordinateReferenceSystem crs = CRS.decode(query.getSrsName().toString());
                           if (crs instanceof GeographicCRS) {
                               // flip the bbox
                               e = new Envelope(e.getMinY(), e.getMaxY(), e.getMinX(), e.getMaxX());
                           }
                       }
                       catch(Exception ex) {
                           throw new RuntimeException(ex);
                       }
                   }

                   Filter bboxFilter = filterFactory.bbox(filterFactory.property(defaultGeometry),
                       ReferencedEnvelope.reference(e));
                   if (filter == null) {
                       filter = bboxFilter;
                   } else {
                       filter = filterFactory.and(filter, bboxFilter);
                   }
               }
               query.setFilter(filter);
              
               GetFeatureType getFeature = Wfs20Factory.eINSTANCE.createGetFeatureType();
               getFeature.getAbstractQueryExpression().add(query);

               FeatureCollectionResponse fc = getFeatureDelegate.run(GetFeatureRequest.adapt(getFeature));
              
               for (FeatureCollection collection: fc.getFeatures()) {                  
                   if (! (collection instanceof SimpleFeatureCollection)) {
                       throw new ServiceException("GeoPackage OutputFormat does not support Complex Features.");
                   }
                  
                   FeatureEntry e = new FeatureEntry();
                   e.setTableName(layer.getName());                  
                   addLayerMetadata(e, features);
                   ReferencedEnvelope bounds = collection.getBounds();
                   if (features.getBbox() != null){
                       bounds = ReferencedEnvelope.reference(bounds.intersection(features.getBbox()));
                   }
                  
                   e.setBounds(bounds);
                 
                   gpkg.add(e, (SimpleFeatureCollectioncollection);
View Full Code Here

TOP

Related Classes of org.geotools.geopkg.wps.GeoPackageProcessRequest.FeaturesLayer

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.