Package org.geotools.data

Examples of org.geotools.data.FileDataStore


                GisStop.delete("gisUpload = ?", gisUpload);
             
              // remove existing updload field mappings
              GisUploadField.delete("gisUpload = ?", gisUpload);
             
              FileDataStore store = FileDataStoreFinder.getDataStore(shapeFile);
              SimpleFeatureSource featureSource = store.getFeatureSource();
             
              SimpleFeatureCollection featureCollection = featureSource.getFeatures();
              SimpleFeatureIterator featureIterator = featureCollection.features();
             
              List<AttributeDescriptor> attributeDescriptors = featureSource.getSchema().getAttributeDescriptors();
View Full Code Here


     * @throws IOException
     */
    public void testDefaultShapefileImplemenation()  throws IOException {
        File file = new File("data/point.shp");
       
        FileDataStore raw = FileDataStoreFinder.getDataStore( file );
        assertNotNull( raw );
        assertTrue( "shapefile implementation", raw instanceof org.geotools.data.shapefile.ShapefileDataStore );
    }
View Full Code Here

        return ret;
    }

    public static FileDataStore createDatastore(File shapeFile) throws PostGisException {

        FileDataStore ret = null;
        try {
            ret = FileDataStoreFinder.getDataStore(shapeFile);
        } catch (IOException ex) {
            throw new PostGisException("Can't create shapeFile datastore ["+shapeFile+"]", ex);
        }
View Full Code Here

     *
     * @return the count of features copied
     * TODO this must become generic and NOT create a store per se for the postgis layer!!!
     */
    public static int shapeToPostGis(File srcShapeFile, PostGisConfig dstPg, String layer, String year, String month, String day) throws PostGisException {
        FileDataStore srcStore = null;
        try {
            // read the shape file and put it into a SimpeFeatureCollection
            srcStore = createDatastore(srcShapeFile);
           
            SimpleFeatureSource featureSource = srcStore.getFeatureSource();
            SimpleFeatureCollection sfc = (SimpleFeatureCollection) featureSource.getFeatures();
            return enrichAndAddFeatures(sfc, dstPg, layer, year, month, day, true);
        } catch (IOException ex) {
            throw new PostGisException("Error copying features: " + ex.getMessage(), ex);
        } finally {
View Full Code Here

          if (layername==null) throw new ActionException(this, "the layer name cannot be empty");
          if (rasterpixelheight==0.0d || rasterpixelwidth==0.0d) throw new ActionException(this, "the raster pixel size is wrong");
         
          FileSystemEvent fileEvent=(FileSystemEvent)ev;
          File file = fileEvent.getSource();
          FileDataStore store = null;
          // this action can be used also getting a simpleFeatureCollection from another resource than a file
          // in this case the features field is not null but it is filled externally
                    if (features==null) {
                       
              store = FileDataStoreFinder.getDataStore(file);
              if (store==null) throw new ActionException(this, "the layer "+file.getCanonicalPath()+" cannot be found. Skip execution.");
                        FeatureSource featureSource = store.getFeatureSource();
                        SimpleFeatureType schema = (SimpleFeatureType) featureSource.getSchema();
                        Query query = new Query( schema.getTypeName(), Filter.INCLUDE );
                        query.setCoordinateSystem(CRS.decode("EPSG:4326", true));
                        features = (SimpleFeatureCollection) featureSource.getFeatures( query );
                       
          //    features = (SimpleFeatureCollection) featureSource.getFeatures();
                    }
                   
          //CoordinateReferenceSystem crs = DefaultGeographicCRS.WGS84;
          CoordinateReferenceSystem crs = features.getSchema().getCoordinateReferenceSystem();
          ReferencedEnvelope bounds = new ReferencedEnvelope(rasterx0, rasterx1, rastery0, rastery1,crs);

              Dimension gridDim = new Dimension(rasterpixelwidth, rasterpixelheight);

              String covName = layername;
              ProgressListener monitor = null;

              GridCoverage2D cov = VectorToRasterProcess.process(features, rasterAttribName, gridDim, bounds, covName, monitor);
              LOGGER.debug("CRS :"+cov.getCoordinateReferenceSystem().toWKT());
//              System.out.println(cov.toString());

//          Map<String, Object> attribute = new HashMap<String, Object>();
//          attribute.put("rasterAttribName", rasterAttribName);
//          if (rasterCqlFilter!=null) attribute.put("rasterCqlFilter", rasterCqlFilter);
          File tmpTiff = null;
          if (conf.getFilename()!=null)
              tmpTiff = new File(conf.getWorkingDirectory(),conf.getFilename());
          else 
              tmpTiff =   new File(conf.getWorkingDirectory(),"testcov.tif");
          GeoTiffWriter writer = null;
          try {
                        writer = new GeoTiffWriter(tmpTiff);
                       
            if (height>0 && width>0) {
              GeoTiffWriteParams params = new GeoTiffWriteParams();
             
                            params.setTilingMode(TIFFImageWriteParam.MODE_EXPLICIT);
                            params.setTiling(conf.getRetileH(), conf.getRetileW());
                            ParameterValue<GeoToolsWriteParams> value = GeoTiffFormat.GEOTOOLS_WRITE_PARAMS.createValue();
                            value.setValue(params);
                            writer.write(cov, new GeneralParameterValue[]{value});
                        }
                        else
                          writer.write(cov, null );
          } catch (IOException e) {
            // TODO Auto-generated catch block
            LOGGER.error("An exception was raised executing the RasterizeAction",e);
            throw new ActionException(this,"An exception was raised executing the RasterizeAction");
                    }
                    finally {
                    //  if (writer!=null) writer.dispose();
                  FileSystemEvent fileSystemInsertEvent = new FileSystemEvent(tmpTiff, FileSystemEventType.FILE_ADDED);
              ret.add(fileSystemInsertEvent);
              if (store!=null) store.dispose();
                    }
         
          // add the event to the return

View Full Code Here

          if (layername==null) throw new ActionException(this, "the layer name cannot be empty");
          if (rasterpixelheight==0.0d || rasterpixelwidth==0.0d) throw new ActionException(this, "the raster pixel size is wrong");
         
          FileSystemEvent fileEvent=(FileSystemEvent)ev;
          File file = fileEvent.getSource();
          FileDataStore store = null;
          // this action can be used also getting a simpleFeatureCollection from another resource than a file
          // in this case the features field is not null but it is filled externally
                    if (features==null) {
                       
              store = FileDataStoreFinder.getDataStore(file);
              if (store==null) throw new ActionException(this, "the layer "+file.getCanonicalPath()+" cannot be found. Skip execution.");
                        FeatureSource featureSource = store.getFeatureSource();
                        SimpleFeatureType schema = (SimpleFeatureType) featureSource.getSchema();
                        Query query = new Query( schema.getTypeName(), Filter.INCLUDE );
                        query.setCoordinateSystem(CRS.decode("EPSG:4326", true));
                        features = (SimpleFeatureCollection) featureSource.getFeatures( query );
                       
          //    features = (SimpleFeatureCollection) featureSource.getFeatures();
                    }
                   
          //CoordinateReferenceSystem crs = DefaultGeographicCRS.WGS84;
          CoordinateReferenceSystem crs = features.getSchema().getCoordinateReferenceSystem();
          ReferencedEnvelope bounds = new ReferencedEnvelope(rasterx0, rasterx1, rastery0, rastery1,crs);

              Dimension gridDim = new Dimension(rasterpixelwidth, rasterpixelheight);

              String covName = layername;
              ProgressListener monitor = null;

              GridCoverage2D cov = VectorToRasterProcess.process(features, rasterAttribName, gridDim, bounds, covName, monitor);
              LOGGER.debug("CRS :"+cov.getCoordinateReferenceSystem().toWKT());
//              System.out.println(cov.toString());

//          Map<String, Object> attribute = new HashMap<String, Object>();
//          attribute.put("rasterAttribName", rasterAttribName);
//          if (rasterCqlFilter!=null) attribute.put("rasterCqlFilter", rasterCqlFilter);
          File tmpTiff = null;
          if (conf.getFilename()!=null)
              tmpTiff = new File(conf.getWorkingDirectory(),conf.getFilename());
          else 
              tmpTiff =   new File(conf.getWorkingDirectory(),"testcov.tif");
          GeoTiffWriter writer = null;
          try {
                        writer = new GeoTiffWriter(tmpTiff);
                       
            if (height>0 && width>0) {
              GeoTiffWriteParams params = new GeoTiffWriteParams();
             
                            params.setTilingMode(TIFFImageWriteParam.MODE_EXPLICIT);
                            params.setTiling(conf.getRetileH(), conf.getRetileW());
                            ParameterValue<GeoToolsWriteParams> value = GeoTiffFormat.GEOTOOLS_WRITE_PARAMS.createValue();
                            value.setValue(params);
                            writer.write(cov, new GeneralParameterValue[]{value});
                        }
                        else
                          writer.write(cov, null );
          } catch (IOException e) {
            // TODO Auto-generated catch block
            LOGGER.error("An exception was raised executing the RasterizeAction",e);
            throw new ActionException(this,"An exception was raised executing the RasterizeAction");
                    }
                    finally {
                    //  if (writer!=null) writer.dispose();
                  FileSystemEvent fileSystemInsertEvent = new FileSystemEvent(tmpTiff, FileSystemEventType.FILE_ADDED);
              ret.add(fileSystemInsertEvent);
              if (store!=null) store.dispose();
                    }
         
          // add the event to the return

View Full Code Here

 
  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();
View Full Code Here

        LOG.debug("Feature attributes: input data in {}, labeled with {}", inputAttribute, labelAttribute);
        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();
View Full Code Here

        File file = JFileDataStoreChooser.showOpenFile("shp", null);
        if (file == null) {
            return;
        }

        FileDataStore store = FileDataStoreFinder.getDataStore(file);
        SimpleFeatureSource featureSource = store.getFeatureSource();
       
        // CachingFeatureSource is deprecated as experimental (not yet production ready)
        CachingFeatureSource cache = new CachingFeatureSource(featureSource);

        // Create a map content and add our shapefile to it
View Full Code Here

     * This method connects to the shapefile; retrieves information about
     * its features; creates a map frame to display the shapefile and adds
     * a custom feature selection tool to the toolbar of the map frame.
     */
    public void displayShapefile(File file) throws Exception {
        FileDataStore store = FileDataStoreFinder.getDataStore(file);
        featureSource = store.getFeatureSource();
        setGeometry();

        /*
         * Create the JMapFrame and set it to display the shapefile's features
         * with a default line and colour style
View Full Code Here

TOP

Related Classes of org.geotools.data.FileDataStore

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.