Package org.geotools.data

Examples of org.geotools.data.FeatureSource


    private MapContext createContextFromShapefile( final URL shape, final URL sld )
            throws IOException
    {
        ShapefileDataStore ds = new ShapefileDataStore( shape );

        FeatureSource fs = ds.getFeatureSource();
        com.vividsolutions.jts.geom.Envelope env = fs.getBounds();
        myMapPane.setMapArea( env );
        StyleFactory factory = CommonFactoryFinder.getStyleFactory( null );

        SLDParser stylereader = new SLDParser( factory, sld );
        org.geotools.styling.Style[] style = stylereader.readXML();

        CoordinateReferenceSystem crs = fs.getSchema().getDefaultGeometry().getCoordinateSystem();
        if ( crs == null )
        {
            crs = DefaultGeographicCRS.WGS84;
        }
        MapContext context = new DefaultMapContext( crs );
View Full Code Here


//    }
//   

    public void testAttributeFilters() throws Exception {
        OGRDataStore s = new OGRDataStore(getAbsolutePath(STATE_POP), null, null);
        FeatureSource fs = s.getFeatureSource(s.getTypeNames()[0]);
       
        // equality filter
        FilterFactory ff = CommonFactoryFinder.getFilterFactory(null);
        Filter f = ff.equal(ff.property("STATE_NAME"), ff.literal("New York"), true);
        assertEquals(1, fs.getFeatures(f).size());
       
        // greater than
        f = ff.greater(ff.property("PERSONS"), ff.literal(10000000));
        assertEquals(6, fs.getFeatures(f).size());
       
        // mix in a filter that cannot be encoded
        f = ff.and(f, ff.like(ff.property("STATE_NAME"), "C*"));
        assertEquals(1, fs.getFeatures(f).size());
    }
View Full Code Here

        assertEquals(1, fs.getFeatures(f).size());
    }
   
    public void testGeometryFilters() throws Exception {
        OGRDataStore s = new OGRDataStore(getAbsolutePath(STATE_POP), null, null);
        FeatureSource fs = s.getFeatureSource(s.getTypeNames()[0]);
       
        // from one of the GeoServer demo requests
        FilterFactory ff = CommonFactoryFinder.getFilterFactory(null);
        Filter f = ff.bbox("the_geom", -75.102613, 40.212597, -72.361859,41.512517, null);
        assertEquals(4, fs.getFeatures(f).size());
       
        // mix in an attribute filter
        f = ff.and(f, ff.greater(ff.property("PERSONS"), ff.literal("10000000")));
        assertEquals(6, fs.getFeatures(f).size());  
    }
View Full Code Here

        if (file == null) {
            return;
        }

        FileDataStore store = FileDataStoreFinder.getDataStore(file);
        FeatureSource source = store.getFeatureSource();
       
        // Check that we have line features
        Class<?> geomBinding = source.getSchema().getGeometryDescriptor().getType().getBinding();
        boolean isLine = geomBinding != null
                && (LineString.class.isAssignableFrom(geomBinding) ||
                    MultiLineString.class.isAssignableFrom(geomBinding));
       
        if (!isLine) {
            System.out.println("This example needs a shapefile with line features");
            return;
        }

        // load shapefile end (docs marker)

        final SpatialIndex index = new STRtree();
        FeatureCollection features = source.getFeatures();
        System.out.println("Slurping in features ...");
        features.accepts(new FeatureVisitor() {

            @Override
            public void visit(Feature feature) {
View Full Code Here

        assertEquals( Timestamp.class, ft.getDescriptor( aname("dt") ).getType().getBinding() );
        assertEquals( Time.class, ft.getDescriptor( aname("t") ).getType().getBinding() );
    }
   
    public void testFiltersByDate() throws Exception {
        FeatureSource fs = dataStore.getFeatureSource( tname("dates") );
       
        FilterFactory ff = dataStore.getFilterFactory();
       
        DateFormat df = new SimpleDateFormat("yyyy-dd-MM");
        df.setTimeZone( TimeZone.getTimeZone("PST"));
       
        //less than
        Filter f = ff.lessOrEqual( ff.property( aname("d") ), ff.literal( df.parse("2009-28-06")
         ) );
        assertEquals( 2, fs.getCount( new DefaultQuery(tname("dates"),f ) ) );
       
        f = ff.lessOrEqual( ff.property( aname("d") ),ff.literal( df.parse("2009-28-06") ) );
        assertEquals( 2, fs.getCount( new DefaultQuery(tname("dates"),f ) ) );
    }
View Full Code Here

        f = ff.lessOrEqual( ff.property( aname("d") ),ff.literal( df.parse("2009-28-06") ) );
        assertEquals( 2, fs.getCount( new DefaultQuery(tname("dates"),f ) ) );
    }
   
    public void testFilterByTimeStamp() throws Exception {
        FeatureSource fs = dataStore.getFeatureSource( tname("dates") );
       
        FilterFactory ff = dataStore.getFilterFactory();
       
        //equal to
        Filter f = ff.equals( ff.property( aname("dt") ), ff.literal( "2009-06-28 15:12:41" ) );
        assertEquals( 1, fs.getCount( new DefaultQuery(tname("dates"),f ) ) );
       
        f = ff.equals( ff.property( aname("dt") ),
                ff.literal( new SimpleDateFormat("HH:mm:ss,dd-yyyy-MM").parse("15:12:41,28-2009-06") ) );
        assertEquals( 1, fs.getCount( new DefaultQuery(tname("dates"),f ) ) );
    }
View Full Code Here

                ff.literal( new SimpleDateFormat("HH:mm:ss,dd-yyyy-MM").parse("15:12:41,28-2009-06") ) );
        assertEquals( 1, fs.getCount( new DefaultQuery(tname("dates"),f ) ) );
    }
   
    public void testFilterByTime() throws Exception {
        FeatureSource fs = dataStore.getFeatureSource( tname("dates") );
       
        FilterFactory ff = dataStore.getFilterFactory();
       
        // greather than or equal to
        Filter f = ff.greaterOrEqual( ff.property( aname("t") ), ff.literal( "13:10:12" ) );
        assertEquals( 3, fs.getCount( new DefaultQuery(tname("dates"),f ) ) );
       
        f = ff.greaterOrEqual( ff.property( aname("t") ),
                ff.literal( new SimpleDateFormat("ss:HH:mm").parse("12:13:10") ) );
        assertEquals( 3, fs.getCount( new DefaultQuery(tname("dates"),f ) ) );
    }
View Full Code Here

        assertEquals(4326, type.getGeometryDescriptor().getUserData().get(JDBCDataStore.JDBC_NATIVE_SRID));
        assertEquals(2, type.getGeometryDescriptor().getUserData().get(Hints.COORDINATE_DIMENSION));
    }
   
    public void testListAll() throws Exception {
        FeatureSource fsView = dataStore.getFeatureSource("riverReduced");
        assertFalse(fsView instanceof FeatureStore);

        assertEquals(1, fsView.getCount(Query.ALL));
       
        FeatureIterator<SimpleFeature> it = null;
        try {
            it = fsView.getFeatures().features();
           
            assertTrue(it.hasNext());
            SimpleFeature sf = it.next();
            assertEquals("rv1", sf.getAttribute(aname("river")));
            assertEquals(9.0, ((Number) sf.getAttribute(aname("doubleFlow"))).doubleValue(), 0.1);
View Full Code Here

            it.close();
        }
    }
   
    public void testBounds() throws Exception {
        FeatureSource fsView = dataStore.getFeatureSource("riverReduced");
        ReferencedEnvelope env = fsView.getBounds();
        assertNotNull(env);
    }
View Full Code Here

            // ok, that's what we expected
        }
    }
   
    public void testGetFeatureId() throws Exception {
        FeatureSource fsView = dataStore.getFeatureSource("riverReducedPk");
        assertFalse(fsView instanceof FeatureStore);

        assertEquals(1, fsView.getCount(Query.ALL));
       
        FeatureIterator<SimpleFeature> it = null;
        try {
            it = fsView.getFeatures().features();
           
            assertTrue(it.hasNext());
            SimpleFeature sf = it.next();
            // check the primary key is build out of the fid attribute
            assertEquals("riverReducedPk.0", sf.getID());
View Full Code Here

TOP

Related Classes of org.geotools.data.FeatureSource

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.