Package org.geotools.data.shapefile

Examples of org.geotools.data.shapefile.ShapefileDataStore


        SimpleFeatureStore fstore = null;
        DataStore dstore = null;
        File file = null;
        try {
            file = new File(tempDir, schema.getTypeName() + ".shp");
            dstore = new ShapefileDataStore(file.toURL());
            dstore.createSchema(schema);
           
            fstore = (SimpleFeatureStore) dstore.getFeatureSource(schema.getTypeName());
            fstore.addFeatures(collection);
        } catch (IOException ioe) {
View Full Code Here


          SimpleFeatureType renamed = tb.buildFeatureType();
          c = new RetypingFeatureCollection(c, renamed);
        }

        SimpleFeatureStore fstore = null;
        ShapefileDataStore dstore = null;
        try {
            // create attribute name mappings, to be compatible
            // with shapefile constraints:
            //  - geometry field is always named the_geom
            //  - field names have a max length of 10
            Map<String,String> attributeMappings=createAttributeMappings(c.getSchema());
            // wraps the original collection in a remapping wrapper
            SimpleFeatureCollection remapped = new RemappingFeatureCollection(c,attributeMappings);
            SimpleFeatureType remappedSchema=(SimpleFeatureType)remapped.getSchema();
            dstore = buildStore(tempDir, charset,  remappedSchema);
            fstore = (SimpleFeatureStore) dstore.getFeatureSource();
            // we need retyping too, because the shapefile datastore
            // could have sorted fields in a different order
            SimpleFeatureCollection retyped = new RetypingFeatureCollection(remapped, fstore.getSchema());
            fstore.addFeatures(retyped);
           
            changeWKTFormatIfFileFormatIsESRI(tempDir, request, fileName,
          remappedSchema);
         
        } catch (FactoryException fe) {
          LOGGER.log(Level.WARNING,
              "Error while getting EPSG code from FeatureType", fe);
          throw new ServiceException(fe);
        } catch (IOException ioe) {
            LOGGER.log(Level.WARNING,
                "Error while writing featuretype '" + schema.getTypeName() + "' to shapefile.", ioe);
            throw new ServiceException(ioe);
        } finally {
            if(dstore != null) {
                dstore.dispose();
            }
        }
    }
View Full Code Here

     */
    private ShapefileDataStore buildStore(File tempDir,
            Charset charset, SimpleFeatureType schema) throws MalformedURLException,
            FileNotFoundException, IOException {
        File file = new File(tempDir, schema.getTypeName() + ".shp");
        ShapefileDataStore sfds = new ShapefileDataStore(file.toURL());
       
        // handle shapefile encoding
        // and dump the charset into a .cst file, for debugging and control purposes
        // (.cst is not a standard extension)
        sfds.setCharset(charset);
        File charsetFile = new File(tempDir, schema.getTypeName()+ ".cst");
        PrintWriter pw = null;
        try {
            pw  = new PrintWriter(charsetFile);
            pw.write(charset.name());
        } finally {
            if(pw != null) pw.close();
        }

        try {
            sfds.createSchema(schema);
        } catch (NullPointerException e) {
            LOGGER.warning(
                "Error in shapefile schema. It is possible you don't have a geometry set in the output. \n"
                + "Please specify a <wfs:PropertyName>geom_column_name</wfs:PropertyName> in the request");
            throw new ServiceException(
                "Error in shapefile schema. It is possible you don't have a geometry set in the output.");
        }
       
        try {
            if(schema.getCoordinateReferenceSystem() != null)
                sfds.forceSchemaCRS(schema.getCoordinateReferenceSystem());
        } catch(Exception e) {
            LOGGER.log(Level.WARNING, "Could not properly create the .prj file", e);
        }

        return sfds;
View Full Code Here

        if (shapeFile == null) {
            FileUtils.deleteDirectory(tempDir);
            throw new IOException("Could not find any file with .shp extension in the zip file");
        } else {
            ShapefileDataStore store = new ShapefileDataStore(DataUtilities.fileToURL(shapeFile));
            resources.addResource(new ShapefileResource(store, tempDir));
            return store.getFeatureSource().getFeatures();
        }

    }
View Full Code Here

            else {
                FileUtils.deleteDirectory(tempDir);
                throw new IOException("Could not find any file with .shp extension in the zip file");
            }
        } else {
            ShapefileDataStore store = new ShapefileDataStore(DataUtilities.fileToURL(shapeFile));
            return store.getFeatureSource().getFeatures();
        }
    }
View Full Code Here

     
    File directory = IOUtils.createTempDirectory("sxttmp");
        File file = new File(directory, m_sFilename);

        try {
            ShapefileDataStore dataStore = new ShapefileDataStore(DataUtilities.fileToURL(file));
            dataStore.createSchema(m_FeatureType);
            manager.addResource(new ShapefileResource(dataStore, directory));
           
            return dataStore;
        } catch(Throwable t) {
            LOGGER.log(Level.SEVERE, "Could not create shapefile output ", t);
View Full Code Here

    final DataStoreFactorySpi dataStoreFactory = new ShapefileDataStoreFactory();
    Map<String, Serializable> params = new HashMap<String, Serializable>();
    params.put("url", destination.toURI().toURL());
    params.put("create spatial index", Boolean.TRUE);
 
    ShapefileDataStore store=null;
    Transaction transaction=null;
    try{
      store = (ShapefileDataStore) dataStoreFactory.createNewDataStore(params);
      store.createSchema(fc.getSchema());
     
      final SimpleFeatureStore featureStore =(SimpleFeatureStore) store.getFeatureSource(fc.getSchema().getName());
      transaction=featureStore.getTransaction();
     
      featureStore.addFeatures(fc);   
    }catch (IOException e) {
      e.printStackTrace();
    }finally{
     
      if(transaction!=null){
 
        transaction.commit();
        transaction.close()
      }
     
      if(store!=null){
        store.dispose();
      }
    }
  }
View Full Code Here

    }

    @Test
    public void testStates() throws Exception {
        File shapeFile = TestData.file(this, "featureTypes/states.shp");
        ShapefileDataStore ds = new ShapefileDataStore(shapeFile.toURL());

        final FeatureSource<SimpleFeatureType, SimpleFeature> fs = ds.getFeatureSource("states");
        final ReferencedEnvelope env = new ReferencedEnvelope(fs.getBounds(), WGS84);

        final WMSMapContent map = new WMSMapContent();
        map.getViewport().setBounds(env);
        map.setMapWidth(mapWidth);
View Full Code Here

    throws IOException
    {
      //File file = new File(System.getProperty("java.io.tmpdir"), name+".zip");
      File file = new File(tempDir, name/*+".zip"*/);
     
      ShapefileDataStore sfds = new ShapefileDataStore(file.toURL());
      sfds.createSchema(featureResults[0].getSchema());
     
      FeatureStore store = (FeatureStore) sfds.getFeatureSource(name);
      store.addFeatures(reader);
    }
View Full Code Here

        SimpleFeatureStore fstore = null;
        DataStore dstore = null;
        File file = null;
        try {
            file = new File(tempDir, schema.getTypeName() + ".shp");
            dstore = new ShapefileDataStore(file.toURL());
            dstore.createSchema(schema);
           
            fstore = (SimpleFeatureStore) dstore.getFeatureSource(schema.getTypeName());
            fstore.addFeatures(collection);
        } catch (IOException ioe) {
View Full Code Here

TOP

Related Classes of org.geotools.data.shapefile.ShapefileDataStore

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.