Package org.geotools.data.collection

Examples of org.geotools.data.collection.ListFeatureCollection


  }

  private FeatureCollection<SimpleFeatureType, SimpleFeature> createCollection(List<InternalFeature> features,
      VectorLayer layer, CoordinateReferenceSystem mapCrs, Style style) {
    SimpleFeatureType type = createFeatureType(layer, mapCrs);
    ListFeatureCollection result = new ListFeatureCollection(type);
    SimpleFeatureBuilder builder = new SimpleFeatureBuilder(type);
    StyleAttributeExtractor extractor = new StyleAttributeExtractor();
    style.accept(extractor);
    Set<String> styleAttributeNames = extractor.getAttributeNameSet();
    FeatureInfo featureInfo = layer.getLayerInfo().getFeatureInfo();
    for (InternalFeature internalFeature : features) {
      // 2 more attributes : geometry + style attribute
      Object[] values = new Object[internalFeature.getAttributes().size() + 2];
      int i = 0;
      for (AttributeInfo attrInfo : featureInfo.getAttributes()) {
        String name = attrInfo.getName();
        if (styleAttributeNames.contains(name)) {
          values[i++] = internalFeature.getAttributes().get(name).getValue();
        } else {
          values[i++] = null;
        }
      }
      values[i++] = internalFeature.getStyleInfo().getIndex();
      values[i++] = internalFeature.getGeometry();
      result.add(builder.buildFeature(internalFeature.getId(), values));
    }
    return result;
  }
View Full Code Here


        /*
         * SimpleFeatureStore has a method to add features from a
         * SimpleFeatureCollection object, so we use the
         * ListFeatureCollection class to wrap our list of features.
         */
        SimpleFeatureCollection collection = new ListFeatureCollection(
            features.get(0).getFeatureType(), features);
        featureStore.setTransaction(transaction);
        try {
          featureStore.addFeatures(collection);
          transaction.commit();
View Full Code Here

                }
                if (!exitForIntermediateSaving) {
                    hasFinished = true;
                }
                SimpleFeatureCollection featureCollection = new ListFeatureCollection(srcSchema, sfcData);
                featureStoreData.addFeatures(featureCollection);
            }
           
            tx.commit();
            LOGGER.info("Copied " + i + " features for "+ layer+"/"+year+"/"+month+"/"+day+ " to " + dstPg);
View Full Code Here

        try {
         
          // open iterator
            iterator = sourceFC.features();
          // prepare feature holder
          final ListFeatureCollection lfc= new ListFeatureCollection(sourceFC.getSchema());
          int count=0;
          int numPag = sourceFC.size() / ITEM_X_PAGE;
          int currentPage = 0;
          LOGGER.info("Page size: " + ITEM_X_PAGE + ", Page amount: " + numPag);
          while (iterator.hasNext()) {

              // copy over
               final SimpleFeature sf = iterator.next();
               lfc.add(sf);
//               LOGGER.debug("Feature " + count + " - page: " + currentPage);
               // paging check
               if(count++>=ITEM_X_PAGE){
                 // commit to relief load from destination DB
                   featureStoreData.addFeatures(lfc);                      
                   tx.commit();
                   lfc.clear();
                   count=0;
//                   System.gc();
                   LOGGER.debug("Page" + currentPage++ + "/" + numPag + " committed... ");

               }
            }
          LOGGER.info("Commit latest features...");
            if(!lfc.isEmpty()){
            // commit to relief load from destination DB
              featureStoreData.addFeatures(lfc);
            
              // final commit
              tx.commit();   
View Full Code Here

     * @throws SeException
     */
    public SimpleFeatureCollection createTestFeatures(Class<? extends Geometry> jtsGeomType,
            int numFeatures) throws IOException, SeException {
        SimpleFeatureType type = getDataStore().getSchema(getTempTableName());
        ListFeatureCollection col = new ListFeatureCollection( type );
        Object[] values = new Object[type.getAttributeCount()];

        for (int i = 0; i < numFeatures; i++) {
            values[0] = Integer.valueOf(i);

            // put some nulls
            values[1] = ((i % 2) == 0) ? null : Integer.valueOf(2 * i);
            values[2] = new Float(0.1 * i);
            values[3] = new Double(1000 * i);
            values[4] = "String value #" + i;
            values[5] = "NString value #" + i;

            Calendar cal = Calendar.getInstance();
            cal.set(Calendar.DAY_OF_MONTH, i);
            values[6] = cal.getTime();
            values[7] = createTestGeometry(jtsGeomType, i);

            SimpleFeature f = SimpleFeatureBuilder.build(type, values, null);
            col.add(f);
        }
        return col;
    }
View Full Code Here

        SimpleFeatureCollection fcLine = fsLine.getFeatures();
        SimpleFeatureIterator fLine = fcLine.features();
       
        SimpleFeatureSource fsPoly = (SimpleFeatureSource) layers.get(getRestrictedPolygonTypeRef());
        
        ListFeatureCollection fcPoly = new ListFeatureCollection( fsPoly.getFeatures() );
               
        while(fLine.hasNext()){
          SimpleFeature line = fLine.next();
            SimpleFeatureIterator fPoly = fcPoly.features();
            Geometry lineGeom = (Geometry) line.getDefaultGeometry();
            if(envelope.contains(lineGeom.getEnvelopeInternal())){
              //   check for valid comparison
              if(LineString.class.isAssignableFrom(lineGeom.getClass())){
                while(fPoly.hasNext()){
                  SimpleFeature poly = fPoly.next();
                  Geometry polyGeom = (Geometry) poly.getDefaultGeometry();
                        if(envelope.contains(polyGeom.getEnvelopeInternal())){
                          if(Polygon.class.isAssignableFrom(polyGeom.getClass())){
                            Geometry polyGeomBoundary = polyGeom.getBoundary();
                            if(!polyGeomBoundary.contains(lineGeom)){
                              results.error(poly,"Boundary does not contain the specified Line.");
                              r = false;
                            }
                            // do next.
                          }else{
                            fcPoly.remove(poly);
                            results.warning(poly,"Invalid type: this feature is not a derivative of a Polygon");
                          }
                        }else{
                        fcPoly.remove(poly);
                        }
                }
              }else{
                results.warning(line,"Invalid type: this feature is not a derivative of a LineString");
              }
View Full Code Here

        SimpleFeatureIterator fLine = fcLine.features();
       
        SimpleFeatureSource fsPoly = (SimpleFeatureSource) layers.get(getRestrictedPolygonTypeRef());
        if(fsPoly == null)
          return true;
        ListFeatureCollection fcPoly = new ListFeatureCollection( fsPoly.getFeatures() );
               
        while(fLine.hasNext()){
          SimpleFeature line = fLine.next();
          SimpleFeatureIterator fPoly = fcPoly.features();
          Geometry lineGeom = (Geometry) line.getDefaultGeometry();
          if(envelope.contains(lineGeom.getEnvelopeInternal())){
            //   check for valid comparison
            if(LineString.class.isAssignableFrom(lineGeom.getClass())){
              while(fPoly.hasNext()){
                SimpleFeature poly = fPoly.next();
                Geometry polyGeom = (Geometry) poly.getDefaultGeometry();
                if(envelope.contains(polyGeom.getEnvelopeInternal())){
                  if(Polygon.class.isAssignableFrom(polyGeom.getClass())){
                    Polygon p = (Polygon)polyGeom;
                    for(int i=0;i<p.getNumInteriorRing();i++){
                      if(!p.getInteriorRingN(i).touches(lineGeom)){
                        results.error(poly,"Polygon interior touches the specified Line.");
                      }
                    }
                        // do next.
                  }else{
                    fcPoly.remove(poly);
                    results.warning(poly,"Invalid type: this feature is not a derivative of a Polygon");
                  }
                }else{
                  fcPoly.remove(poly);
                }
              }
            }else{
              results.warning(line,"Invalid type: this feature is not a derivative of a LineString");
            }
View Full Code Here

                        final int numberOfSlices = vaAdapter.getNumberOfSlices();
                        numImages += numberOfSlices;

                        int startPagingIndex = 0;
                        final int limit = INTERNAL_INDEX_CREATION_PAGE_SIZE;
                        final ListFeatureCollection collection = new ListFeatureCollection(indexSchema);

                        int writtenFeatures = 0;
                        while (writtenFeatures < numberOfSlices) {
                            // Get a bunch of features
                            vaAdapter.getFeatures(startPagingIndex, limit, collection);
                            if (variableImageStartIndex != 0) {
                                // Need to updated the imageIndex of the features since all indexes
                                // are zero based inside each variable but we need to index them inside
                                // the whole NetCDF dataset.
                                updateFeaturesIndex(collection, variableImageStartIndex);
                            }
                            final int features = collection.size();
                            if (features > 0) {
                                // adding granules to the catalog and updating the number of written features
                                getCatalog().addGranules(indexSchema.getTypeName(), collection, transaction);
                                collection.clear();
                                startPagingIndex += features;
                            }
                            writtenFeatures += features;
                        }
                    }
View Full Code Here

        }
        final SimpleFeatureType indexSchema = store.getSchema();
        final SimpleFeature feature = new ShapefileCompatibleFeature(DataUtilities.template(indexSchema));
        store.setTransaction(transaction);
       
        final ListFeatureCollection collection = new ListFeatureCollection(indexSchema);
        final String fileLocation = prepareLocation(configuration, fileBeingProcessed);
        final String locationAttribute = configuration.getParameter(Prop.LOCATION_ATTRIBUTE);

        // getting input granules
        if (inputReader instanceof StructuredGridCoverage2DReader) {
           
            //
            // Case A: input reader is a StructuredGridCoverage2DReader. We can get granules from a source
            //
            // Getting granule source and its input granules
            final GranuleSource source = ((StructuredGridCoverage2DReader) inputReader).getGranules(coverageName, true);
            final SimpleFeatureCollection originCollection = source.getGranules(null);
            final DefaultProgressListener listener = new DefaultProgressListener();
           
            // Getting attributes structure to be filled
            final Collection<Property> destProps = feature.getProperties();
            final Set<Name> destAttributes = new HashSet<Name>();
            for (Property prop: destProps) {
                destAttributes.add(prop.getName());
            }
           
            // Collecting granules
            originCollection.accepts( new AbstractFeatureVisitor(){
                public void visit( Feature feature ) {
                    if(feature instanceof SimpleFeature)
                    {
                            // get the feature
                            final SimpleFeature sourceFeature = (SimpleFeature) feature;
                            final SimpleFeature destFeature = DataUtilities.template(indexSchema);
                            Collection<Property> props = sourceFeature.getProperties();
                            Name propName = null;
                            Object propValue = null;
                           
                            // Assigning value to dest feature for matching attributes
                            for (Property prop: props) {
                                propName = prop.getName();
                                propValue = prop.getValue();
                               
                                // Matching attributes are set
                                if (destAttributes.contains(propName)) {
                                    destFeature.setAttribute(propName, propValue);
                                }
                            }
                           
                            // Set location
                            destFeature.setAttribute(locationAttribute, fileLocation);
                           
                            // delegate remaining attributes set to properties collector
                            updateAttributesFromCollectors(destFeature, fileBeingProcessed, inputReader, propertiesCollectors);
                            collection.add(destFeature);
                           
                            // check if something bad occurred
                            if(listener.isCanceled()||listener.hasExceptions()){
                                if(listener.hasExceptions())
                                    throw new RuntimeException(listener.getExceptions().peek());
                                else
                                    throw new IllegalStateException("Feature visitor has been canceled");
                            }
                    }
                }
            }, listener);
        } else {
            //
            // Case B: old style reader, proceed with classic way, using properties collectors
            //
            feature.setAttribute(indexSchema.getGeometryDescriptor().getLocalName(),
                    GEOM_FACTORY.toGeometry(new ReferencedEnvelope((Envelope) envelope)));
            feature.setAttribute(locationAttribute, fileLocation);
           
            updateAttributesFromCollectors(feature, fileBeingProcessed, inputReader, propertiesCollectors);
            collection.add(feature);
        }

        // drop all the granules associated to the same        
        Filter filter = Utils.FF.equal(Utils.FF.property(locationAttribute), Utils.FF.literal(fileLocation),
                !isCaseSensitiveFileSystem(fileBeingProcessed));
View Full Code Here

        if (boundsCRS != null && builderCRS != null &&
                !CRS.equalsIgnoreMetadata(boundsCRS, builderCRS)) {
            throw new IllegalArgumentException("Different CRS set for bounds and the feature builder");
        }

        final ListFeatureCollection fc = new ListFeatureCollection(gridFeatureBuilder.getType());
        HexagonBuilder gridBuilder = new HexagonBuilder(bounds, sideLen, orientation);
        gridBuilder.buildGrid(gridFeatureBuilder, vertexSpacing, fc);
        return DataUtilities.source(fc);
    }
View Full Code Here

TOP

Related Classes of org.geotools.data.collection.ListFeatureCollection

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.