Package org.geotools.data.simple

Examples of org.geotools.data.simple.SimpleFeatureSource


  public static PointSet fromShapefile( File file ) throws IOException, NoSuchAuthorityCodeException, FactoryException, EmptyPolygonException, UnsupportedGeometryException {
        if ( ! file.exists())
            throw new RuntimeException("Shapefile does not exist.");
       
        FileDataStore store = FileDataStoreFinder.getDataStore(file);
        SimpleFeatureSource featureSource = store.getFeatureSource();

        CoordinateReferenceSystem sourceCRS = featureSource.getInfo().getCRS();
        CoordinateReferenceSystem WGS84 = CRS.decode("EPSG:4326", true);
       
        Query query = new Query();
        query.setCoordinateSystem(sourceCRS);
        query.setCoordinateSystemReproject(WGS84);
        SimpleFeatureCollection featureCollection = featureSource.getFeatures(query);
       
        SimpleFeatureIterator it = featureCollection.features();
       
        PointSet ret = new PointSet(featureCollection.size());
        int i=0;
View Full Code Here


        try {
            File file = new File(filename);
            if ( ! file.exists())
                throw new RuntimeException("Shapefile does not exist.");
            FileDataStore store = FileDataStoreFinder.getDataStore(file);
            SimpleFeatureSource featureSource = store.getFeatureSource();

            CoordinateReferenceSystem sourceCRS = featureSource.getInfo().getCRS();
            CoordinateReferenceSystem WGS84 = CRS.decode("EPSG:4326", true);

            Query query = new Query();
            query.setCoordinateSystem(sourceCRS);
            query.setCoordinateSystemReproject(WGS84);
            SimpleFeatureCollection featureCollection = featureSource.getFeatures(query);

            SimpleFeatureIterator it = featureCollection.features();
            int i = 0;
            while (it.hasNext()) {
                SimpleFeature feature = it.next();
View Full Code Here

    @Test
    public void testRespectsQueryAttributes() throws IOException, IllegalAttributeException,
            SeException, CQLException {
        final String typeName = testData.getTempTableName();
        final DataStore ds = testData.getDataStore();
        final SimpleFeatureSource fs = ds.getFeatureSource(typeName);

        final String[] queryAtts = { "SHAPE" };
        final Filter filter = CQL.toFilter("INT32_COL = 1");

        // build the query asking for a subset of attributes
        final Query query = new Query(typeName, filter, queryAtts);

        SimpleFeatureCollection features = fs.getFeatures(query);
        SimpleFeatureType resultSchema = features.getSchema();

        assertEquals(1, resultSchema.getAttributeCount());
        assertEquals("SHAPE", resultSchema.getDescriptor(0).getLocalName());
View Full Code Here

     * @throws Exception
     */
    @Test
    public void testMixedQueries() throws Exception {
        final int EXPECTED_RESULT_COUNT = 1;
        SimpleFeatureSource fs = store.getFeatureSource(testData.getTempTableName());
        SimpleFeatureType schema = fs.getSchema();
        Filter bboxFilter = ff.bbox(schema.getGeometryDescriptor().getLocalName(), -60, -55, -40,
                -20, schema.getCoordinateReferenceSystem().getName().getCode());
        Filter sqlFilter = CQL.toFilter("INT32_COL < 5");
        LOGGER.fine("Geometry filter: " + bboxFilter);
        LOGGER.fine("SQL filter: " + sqlFilter);

        And mixedFilter = ff.and(sqlFilter, bboxFilter);

        Not not = ff.not(ff.id(Collections.singleton(ff.featureId(testData.getTempTableName()
                + ".90000"))));

        mixedFilter = ff.and(mixedFilter, not);

        LOGGER.fine("Mixed filter: " + mixedFilter);

        // verify both filter constraints are met
        try {
            testFilter(mixedFilter, fs, EXPECTED_RESULT_COUNT);
        } catch (Exception e) {
            e.printStackTrace();
            throw e;
        }
        // check that getBounds and size do function
        SimpleFeatureIterator reader = null;
        SimpleFeatureCollection results = fs.getFeatures(mixedFilter);
        Envelope bounds = results.getBounds();
        assertNotNull(bounds);
        LOGGER.fine("results bounds: " + bounds);

        reader = results.features();
View Full Code Here

     * @throws Exception
     */
    @Test
    public void testAttributeOnlyQuery() throws Exception {
        DataStore ds = testData.getDataStore();
        SimpleFeatureSource fSource = ds.getFeatureSource(testData.getTempTableName());
        SimpleFeatureType type = fSource.getSchema();
        Query attOnlyQuery = new Query(type.getTypeName());
        List<String> propNames = new ArrayList<String>(type.getAttributeCount() - 1);

        for (int i = 0; i < type.getAttributeCount(); i++) {
            if (type.getDescriptor(i) instanceof GeometryDescriptor) {
                continue;
            }

            propNames.add(type.getDescriptor(i).getLocalName());
        }

        attOnlyQuery.setPropertyNames(propNames);

        SimpleFeatureCollection results = fSource.getFeatures(attOnlyQuery);
        SimpleFeatureType resultSchema = results.getSchema();
        assertEquals(propNames.size(), resultSchema.getAttributeCount());

        for (int i = 0; i < propNames.size(); i++) {
            assertEquals(propNames.get(i), resultSchema.getDescriptor(i).getLocalName());
View Full Code Here

        reader.close();

        Id filter = ff.id(new HashSet<FeatureId>(fids));

        SimpleFeatureSource source = ds.getFeatureSource(typeName);
        Query query = new Query(typeName, filter);
        SimpleFeatureCollection results = source.getFeatures(query);

        assertEquals(fids.size(), results.size());
        SimpleFeatureIterator iterator = results.features();
        try {
            while (iterator.hasNext()) {
View Full Code Here

            fids.add(ff.featureId(idTemplate + x++));
        }

        Id filter = ff.id(fids);

        SimpleFeatureSource source = ds.getFeatureSource(typeName);
        Query query = new Query(typeName, filter);
        SimpleFeatureCollection results = source.getFeatures(query);

        assertEquals(1, results.size());
        SimpleFeatureIterator iterator = results.features();
        try {
            while (iterator.hasNext()) {
View Full Code Here

    @Test
    public void testGetFeatures() throws Exception {
        final String table = testData.getTempTableName();
        LOGGER.fine("getting all features from " + table);

        SimpleFeatureSource source = store.getFeatureSource(table);
        int expectedCount = 8;
        int fCount = source.getCount(Query.ALL);
        String failMsg = "Expected and returned result count does not match";
        assertEquals(failMsg, expectedCount, fCount);

        SimpleFeatureCollection fresults = source.getFeatures();
        SimpleFeatureCollection features = fresults;
        failMsg = "FeatureResults.size and .collection().size thoes not match";
        assertEquals(failMsg, fCount, features.size());
        LOGGER.fine("fetched " + fCount + " features for " + table + " layer, OK");
    }
View Full Code Here

    @Test
    public void testSQLFilter() throws Exception {
        int expected = 4;
        Filter filter = CQL.toFilter("INT32_COL < 5");
        SimpleFeatureSource fsource = store.getFeatureSource(testData.getTempTableName());
        testFilter(filter, fsource, expected);
    }
View Full Code Here

    }

    @Test
    public void testBBoxFilter() throws Exception {
        String typeName = testData.getTempTableName();
        SimpleFeatureSource fs = store.getFeatureSource(typeName);
        SimpleFeatureType schema = fs.getSchema();
        BBOX bboxFilter = ff.bbox(schema.getGeometryDescriptor().getLocalName(), -180, -90, 180,
                90, schema.getCoordinateReferenceSystem().getName().getCode());

        int expected = 0;
        SimpleFeatureIterator features = fs.getFeatures().features();
        try {
            while (features.hasNext()) {
                SimpleFeature next = features.next();
                if (bboxFilter.evaluate(next)) {
                    expected++;
View Full Code Here

TOP

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

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.