Examples of ShapefileDataStore


Examples of org.geotools.data.shapefile.ShapefileDataStore

    /**
     * Test count versus old DataSource
     */
    public void testOptimizedCount() throws Exception {
        URL url = TestData.url(STATE_POP);
        ShapefileDataStore sds = new ShapefileDataStore(url);
        OGRDataStore s = new OGRDataStore(getAbsolutePath(STATE_POP), null, null);
        String typeName = s.getTypeNames()[0];

        assertEquals(sds.getCount(Query.ALL), s.getFeatureSource(typeName).getCount(Query.ALL));
    }
View Full Code Here

Examples of org.geotools.data.shapefile.ShapefileDataStore

        assertEquals(schema.getSuper(), BasicFeatureTypes.POLYGON);
    }

    public void testShapefileComparison() throws Exception {
        URL url = TestData.url(STATE_POP);
        ShapefileDataStore sds = new ShapefileDataStore(url);
        OGRDataStore ods = new OGRDataStore(getAbsolutePath(STATE_POP), null, null);

        assertFeatureTypeEquals(sds.getSchema(), ods.getSchema(sds.getSchema().getTypeName()));

        Query query = new Query(sds.getSchema().getTypeName());
        FeatureReader sfr = sds.getFeatureReader(query, Transaction.AUTO_COMMIT);
        FeatureReader ofr = ods.getFeatureReader(query, Transaction.AUTO_COMMIT);
        SimpleFeature sf = null;
        SimpleFeature of = null;
        while (true) {
            if (!sfr.hasNext()) {
                assertTrue(!ofr.hasNext());
                break;
            }
            sf = (SimpleFeature) sfr.next();
            of = (SimpleFeature) ofr.next();
            for (int i = 0; i < sds.getSchema().getAttributeCount(); i++) {
                Object shapeAtt = sf.getAttribute(i);
                Object ogrAtt = of.getAttribute(i);
                assertEquals(shapeAtt, ogrAtt);
            }
        }
        sfr.close();
        ofr.close();
        sds.dispose();
        ods.dispose();
    }
View Full Code Here

Examples of org.geotools.data.shapefile.ShapefileDataStore

    FilterFactory ff = CommonFactoryFinder.getFilterFactory(null);

    @Test
    public void testBuffer() throws Exception {
        URL url = TestData.getResource(TestData.class, "shapes/archsites.shp");
        ShapefileDataStore store = new ShapefileDataStore(url);
        SimpleFeatureCollection features = store.getFeatureSource().getFeatures();

        // first param, the context feature collection
        Function featuresParam = ff.function("parameter", ff
                .literal(BufferFeatureCollectionFactory.FEATURES.key));
        // second param, the buffer size
View Full Code Here

Examples of org.geotools.data.shapefile.ShapefileDataStore

        return name.toUpperCase().endsWith(".SHP");
      }       
        });
        for( int i=0; i<shapefiles.length;i++){
          File shapefile = new File( directory, shapefiles[i] );
          ShapefileDataStore dataStore = new ShapefileDataStore( shapefile.toURI().toURL() );
          String dataStoreId = dataStore.getTypeNames()[0].toUpperCase();
          String typeName = dataStore.getTypeNames()[0];
          SimpleFeatureIterator features = dataStore.getFeatureSource( typeName ).getFeatures().features();
          MemoryDataStore cache = new MemoryDataStore( features );
         
          repository.register( dataStoreId, cache );
        }
        File pluginDir = TestData.file(this, "plugins");
View Full Code Here

Examples of org.geotools.data.shapefile.ShapefileDataStore

        System.out.println("OGR: " + (end - start) / 1000.0);
    }
   
    public void testShapefilePerformance() throws Exception {
        URL url = TestData.url(STATE_POP);
        ShapefileDataStore sds = new ShapefileDataStore(url);
        long start = System.currentTimeMillis();
        sds.getSchema();
        long end = System.currentTimeMillis();
        System.out.println("SDS schema: " + (end - start) / 1000.0);

        DefaultQuery query = new DefaultQuery(sds.getTypeNames()[0]);
        start = System.currentTimeMillis();
        FeatureReader sfr = sds.getFeatureReader(query, Transaction.AUTO_COMMIT);
        while (sfr.hasNext())
            sfr.next();
        sfr.close();
        end = System.currentTimeMillis();
        System.out.println("SDS: " + (end - start) / 1000.0);

        System.out.println("Attribute count: " + sds.getSchema().getAttributeCount());
        System.out.println("Feature count: "
                + sds.getFeatureSource(sds.getSchema().getTypeName()).getCount(Query.ALL));
    }
View Full Code Here

Examples of org.geotools.data.shapefile.ShapefileDataStore

        @Override
        public Geometry loadFootprint(String pathNoExtension) throws Exception {
            File file = new File(pathNoExtension + ".shp");
            if (file.exists()) {
                ShapefileDataStore ds = new ShapefileDataStore(DataUtilities.fileToURL(file));
                SimpleFeatureIterator fi = null;
                try {
                    fi = ds.getFeatureSource().getFeatures().features();
                    if (!fi.hasNext()) {
                        return null;
                    } else {
                        SimpleFeature sf = fi.next();
                        Geometry result = (Geometry) sf.getDefaultGeometry();
                        if (fi.hasNext()) {
                            throw new IOException(
                                    "Found more than one footprint record in the shapefile "
                                            + file.getCanonicalPath());
                        }
                        return result;
                    }
                } finally {
                    if (fi != null) {
                        fi.close();
                    }
                    ds.dispose();
                }
            }

            return null;
        }
View Full Code Here

Examples of org.geotools.data.shapefile.ShapefileDataStore

    }

    @Test
    public void testWkbSidecars() throws Exception {
        // create wkb sidecar files
        ShapefileDataStore ds = new ShapefileDataStore(DataUtilities.fileToURL(new File(
                footprintsSource, "footprints.shp")));
        ds.getFeatureSource().getFeatures().accepts(new FeatureVisitor() {

            @Override
            public void visit(Feature feature) {
                try {
                    SimpleFeature sf = (SimpleFeature) feature;
                    String fileName = (String) sf.getAttribute("location");
                    int idx = fileName.lastIndexOf(".");
                    Geometry g = (Geometry) sf.getDefaultGeometry();
                    File wkbFile = new File(testMosaic, fileName.substring(0, idx) + ".wkb");
                    byte[] bytes = new WKBWriter().write(g);
                    FileUtils.writeByteArrayToFile(wkbFile, bytes);
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
        }, null);
        ds.dispose();
        assertItalyFootprints();
    }
View Full Code Here

Examples of org.geotools.data.shapefile.ShapefileDataStore

    }

    @Test
    public void testWktSidecars() throws Exception {
        // create wkb sidecar files
        ShapefileDataStore ds = new ShapefileDataStore(DataUtilities.fileToURL(new File(
                footprintsSource, "footprints.shp")));
        ds.getFeatureSource().getFeatures().accepts(new FeatureVisitor() {

            @Override
            public void visit(Feature feature) {
                try {
                    SimpleFeature sf = (SimpleFeature) feature;
                    String fileName = (String) sf.getAttribute("location");
                    int idx = fileName.lastIndexOf(".");
                    Geometry g = (Geometry) sf.getDefaultGeometry();
                    File wkbFile = new File(testMosaic, fileName.substring(0, idx) + ".wkt");
                    String wkt = new WKTWriter().write(g);
                    FileUtils.writeStringToFile(wkbFile, wkt);
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
        }, null);
        ds.dispose();
        assertItalyFootprints();
    }
View Full Code Here

Examples of org.geotools.data.shapefile.ShapefileDataStore

    }

    @Test
    public void testShapefileSidecars() throws Exception {
        // create wkb sidecar files
        ShapefileDataStore ds = new ShapefileDataStore(DataUtilities.fileToURL(new File(
                footprintsSource, "footprints.shp")));
        ds.getFeatureSource().getFeatures().accepts(new FeatureVisitor() {

            @Override
            public void visit(Feature feature) {
                try {
                    SimpleFeature sf = (SimpleFeature) feature;
                    String fileName = (String) sf.getAttribute("location");
                    int idx = fileName.lastIndexOf(".");
                    Geometry g = (Geometry) sf.getDefaultGeometry();
                    String filename = fileName.substring(0, idx);
                    File shpFile = new File(testMosaic, filename + ".shp");
                    ShapefileDataStore sds = new ShapefileDataStore(
                            DataUtilities.fileToURL(shpFile));
                    SimpleFeatureTypeBuilder tb = new SimpleFeatureTypeBuilder();
                    tb.setName(filename);
                    GeometryDescriptor gd = sf.getFeatureType().getGeometryDescriptor();
                    tb.add("the_geom", gd.getType().getBinding(), gd.getCoordinateReferenceSystem());
                    SimpleFeatureType sft = tb.buildFeatureType();
                    sds.createSchema(sft);

                    SimpleFeatureBuilder fb = new SimpleFeatureBuilder(sft);
                    fb.add(g);
                    SimpleFeature footprintFeature = fb.buildFeature(null);
                    SimpleFeatureStore fs = (SimpleFeatureStore) sds.getFeatureSource();
                    fs.addFeatures(DataUtilities.collection(footprintFeature));
                    sds.dispose();
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
        }, null);
View Full Code Here

Examples of org.geotools.data.shapefile.ShapefileDataStore

     *
     * @throws Exception
     */
    public void testOptimizedEnvelope() throws Exception {
        URL url = TestData.url(STATE_POP);
        ShapefileDataStore sds = new ShapefileDataStore(url);
        OGRDataStore s = new OGRDataStore(getAbsolutePath(STATE_POP), null, null, ogr);
        String typeName = s.getTypeNames()[0];

        ReferencedEnvelope expectedBounds = sds.getFeatureSource().getBounds();
        ReferencedEnvelope actualBounds = s.getFeatureSource(typeName).getBounds();
        assertEquals(expectedBounds, actualBounds);
        assertNotNull(actualBounds);
    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.