Package org.geotools.data.simple

Examples of org.geotools.data.simple.SimpleFeatureIterator


        Query query = new Query(InProcessViewSupportTestData.typeName, Filter.INCLUDE, Query.ALL_PROPERTIES);
        SimpleFeatureCollection fc = fs.getFeatures(query);
        int fcCount = fc.size();
        int itCount = 0;
        final int expectedCount = 7;
        SimpleFeatureIterator it = fc.features();
        try {
            while (it.hasNext()) {
                SimpleFeature f = (SimpleFeature) it.next();
                assertNotNull(f);
                itCount++;
            }
        } finally {
            it.close();
        }
        assertEquals(expectedCount, fcCount);
        assertEquals(expectedCount, itCount);
    }
View Full Code Here


        SimpleFeatureSource fs = store.getFeatureSource(InProcessViewSupportTestData.typeName);
        SimpleFeatureCollection fc = fs.getFeatures(query);
        int fcCount = fc.size();
        int itCount = 0;
        final int expectedCount = 3;
        SimpleFeatureIterator it = fc.features();
        try {
            while (it.hasNext()) {
                SimpleFeature f = it.next();
                assertNotNull(f);
                itCount++;
            }
        } finally {
            it.close();
        }
        assertEquals(expectedCount, fcCount);
        assertEquals(expectedCount, itCount);
    }
View Full Code Here

        testFeatures = testData.createTestFeatures(LineString.class, featureCount);

        final DataStore ds = testData.getDataStore();

        final SimpleFeatureType ftype = testFeatures.getSchema();
        final SimpleFeatureIterator iterator = testFeatures.features();

        final Transaction transaction = new DefaultTransaction();
        final FeatureWriter<SimpleFeatureType, SimpleFeature> writer;
        writer = ds.getFeatureWriter(typeName, transaction);

        FeatureReader<SimpleFeatureType, SimpleFeature> reader;
        final Query query = new Query(typeName);
        try {
            try {
                while (iterator.hasNext()) {
                    SimpleFeature addFeature = iterator.next();
                    SimpleFeature newFeature = writer.next();
                    for (int i = 0; i < ftype.getAttributeCount(); i++) {
                        String localName = ftype.getDescriptor(i).getLocalName();
                        newFeature.setAttribute(localName, addFeature.getAttribute(localName));
                    }
View Full Code Here

        SimpleFeatureCollection features = store.getFeatures(oldValueFilter);
        final int initialSize = features.size();
        assertEquals(1, initialSize);// just to not go forward with bad data
        final SimpleFeature originalFeature;
        SimpleFeatureIterator iterator = features.features();
        try {
            originalFeature = iterator.next();
        } finally {
            iterator.close();
        }

        {
            final Transaction transaction = new DefaultTransaction("testModifyFeaturesTransaction");
            store.setTransaction(transaction);

            try {
                final AttributeDescriptor propDescriptor = schema.getDescriptor("INT32_COL");
                store.modifyFeatures(propDescriptor.getName(), Integer.valueOf(-1000),
                        oldValueFilter);
                transaction.commit();
            } catch (Exception e) {
                transaction.rollback();
            } finally {
                transaction.close();
            }
        }
        store.setTransaction(Transaction.AUTO_COMMIT);

        final Query oldValueQuery = new Query(typeName, oldValueFilter);
        final Query newValueQuery = new Query(typeName, newValueFilter);

        assertEquals(0, store.getCount(oldValueQuery));
        assertEquals(1, store.getCount(newValueQuery));

        final SimpleFeatureIterator newFeatures = store.getFeatures(newValueQuery).features();
        final SimpleFeature modifiedFeature;
        try {
            modifiedFeature = newFeatures.next();
        } finally {
            newFeatures.close();
        }

        // verify the non modified properties stay the same
        final List<Attribute> originalValues = (List<Attribute>) originalFeature.getValue();
        final List<Attribute> actualValues = (List<Attribute>) modifiedFeature.getValue();
View Full Code Here

        }
        store.setTransaction(Transaction.AUTO_COMMIT);

        try {
            SimpleFeatureCollection features;
            SimpleFeatureIterator iterator;

            features = store.getFeatures(fid1Filter);
            iterator = features.features();
            final SimpleFeature feature1 = iterator.next();
            iterator.close();

            features = store.getFeatures(fid2Filter);
            iterator = features.features();
            final SimpleFeature feature2 = iterator.next();
            iterator.close();

            // Note that for tables that are ambiguous about what types of geometries
            // they store (as this table is), ArcSDE will "compress" a stored geometry
            // to it's simplest representation. So in case the defaultGeometry.getBinding()
            // returns "Geometry", do instanceof checks to verify what kind of geometry
View Full Code Here

            public void run() {
                try {
                    System.err.println("worker2 calling getFeartures()");
                    SimpleFeatureCollection collection = fStore.getFeatures();
                    System.err.println("worker2 opening iterator...");
                    SimpleFeatureIterator features = collection.features();
                    try {
                        System.err.println("worker2 iterating...");
                        while (features.hasNext()) {
                            SimpleFeature next = features.next();
                            System.out.println("**Got feature " + next.getID());
                        }
                        System.err.println("worker2 closing FeatureCollection");
                    } finally {
                        features.close();
                    }
                    System.err.println("worker2 done.");
                } catch (Throwable e) {
                    errors[1] = e;
                } finally {
View Full Code Here

            count = store.getCount(Query.ALL);
            assertEquals(1, count);
            assertEquals(0, source.getCount(Query.ALL));

            {
                SimpleFeatureIterator features = store.getFeatures().features();
                SimpleFeature f = features.next();
                features.close();
                Object obj = f.getDefaultGeometry();
                assertTrue(obj instanceof Point);
                Point p = (Point) obj;
                double x = p.getX();
                double y = p.getY();
                assertEquals(10D, x, 1E-5);
                assertEquals(10D, y, 1E-5);
            }

            transaction.commit();
            assertEquals(1, source.getCount(Query.ALL));

            content[0] = "Feature name 2";
            content[1] = reader.read("POINT (2 2)");
            feature = SimpleFeatureBuilder.build(schema, content, (String) null);
            collection = DataUtilities.collection(feature);

            store.addFeatures(collection);

            count = store.getCount(Query.ALL);
            assertEquals(2, count);

            assertEquals(1, source.getCount(Query.ALL));
            transaction.rollback();
            assertEquals(1, store.getCount(Query.ALL));

            transaction.close();

            {
                SimpleFeatureIterator features = source.getFeatures().features();
                SimpleFeature f = features.next();
                features.close();
                Object obj = f.getDefaultGeometry();
                assertTrue(obj instanceof Point);
                Point p = (Point) obj;
                double x = p.getX();
                double y = p.getY();
View Full Code Here

    //filter = (Filter) ff.createBBoxExpression(bBox);

    SimpleFeatureCollection collectionA = featureSourceA.getFeatures(filter);
    SimpleFeatureCollection collectionB = featureSourceB.getFeatures(filter);
   
    SimpleFeatureIterator fr1 = null;
    SimpleFeatureIterator fr2 = null;
    try
    {
      fr1 = collectionA.features();
      if (fr1 == null)
        return false;
           
      while (fr1.hasNext())
      {
        SimpleFeature f1 = fr1.next();
        Geometry g1 = (Geometry) f1.getDefaultGeometry();
        fr2 = collectionB.features();
        try {
            while (fr2 != null && fr2.hasNext())
            {
              SimpleFeature f2 = fr2.next();
              Geometry g2 = (Geometry) f2.getDefaultGeometry();
              if(g1.touches(g2) != expected )
              {
                results.error( f1, ((Geometry) f1.getDefaultGeometry()).getGeometryType()+" "+getGeomTypeRefA()+" touches "+getGeomTypeRefB()+"("+f2.getID()+"), Result was not "+expected );
                success = false;
              }
            }
                }
                finally {
                    fr2.close();
                }
      }
    }finally
    {
        fr1.close();
View Full Code Here

      boolean r = true;
     
        SimpleFeatureSource fsLine = (SimpleFeatureSource) layers.get(getLineTypeRef());
       
        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())){
                    if(!polyGeom.contains(lineGeom)){
                      results.error(poly,"Polygon does not contain the specified Line.");
View Full Code Here

        PropertyIsEqualTo filter = ff.equals(ff.property(aname("stringProperty")), ff.literal("one"));

        SimpleFeatureCollection features = featureSource.getFeatures(filter);
        assertEquals(1, features.size());

        SimpleFeatureIterator iterator = features.features();
        try {
            assertTrue(iterator.hasNext());
   
            SimpleFeature feature = (SimpleFeature) iterator.next();
            assertEquals("one", feature.getAttribute(aname("stringProperty")));
            assertEquals( new Double(1.1), feature.getAttribute( aname("doubleProperty")) );
        } finally {
            iterator.close();
        }
    }
View Full Code Here

TOP

Related Classes of org.geotools.data.simple.SimpleFeatureIterator

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.