• 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏吧

Java FileDataStoreFactorySpi类的典型用法和代码示例

java 2次浏览

本文整理汇总了Java中org.geotools.data.FileDataStoreFactorySpi的典型用法代码示例。如果您正苦于以下问题:Java FileDataStoreFactorySpi类的具体用法?Java FileDataStoreFactorySpi怎么用?Java FileDataStoreFactorySpi使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。

FileDataStoreFactorySpi类属于org.geotools.data包,在下文中一共展示了FileDataStoreFactorySpi类的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: exportFeaturesToShapeFile

点赞 3

import org.geotools.data.FileDataStoreFactorySpi; //导入依赖的package包/类
public static void exportFeaturesToShapeFile(File fileOutput,FeatureCollection<SimpleFeatureType,SimpleFeature> featureCollection){
  	 DataStore data =null;
  	 try {

  		 if (!fileOutput.exists()){
  			 fileOutput.createNewFile();
  			 fileOutput.setWritable(true);
  		 }
   	 FileDataStoreFactorySpi factory = new ShapefileDataStoreFactory();
   	 data = factory.createDataStore( fileOutput.toURI().toURL() );

   	 data.createSchema(featureCollection.getSchema());
   	 exportToShapefile(data,featureCollection);
} catch (Exception e) {
	logger.error("Export to shapefile failed",e );
}finally{
	if(data!=null)
		data.dispose();
}
   }
 

开发者ID:ec-europa,
项目名称:sumo,
代码行数:21,
代码来源:SimpleShapefile.java

示例2: showOpenFile

点赞 3

import org.geotools.data.FileDataStoreFactorySpi; //导入依赖的package包/类
/**
 * Show a file open dialog that filters for files that match a given file
 * data store format
 *
 * @param format the file data store format
 * @param initialDir initial directory to display; if {@code null} the initial directory
 *        will be the user's default directory
 * @param parent parent GUI component (may be null)
 *
 * @return the selected file or null if the user cancelled the selection
 * @throws java.awt.HeadlessException if run in an unsupported environment
 */
public static File showOpenFile( FileDataStoreFactorySpi format, File initialDir, Shell parent ) {

    JFileDataStoreChooser dialog = new JFileDataStoreChooser(parent, SWT.OPEN, format);
    FileDialog fileDialogInternal = dialog.getFileDialog();
    if (initialDir != null) {
        if (initialDir.isDirectory()) {
            fileDialogInternal.setFilterPath(initialDir.getAbsolutePath());
        } else {
            fileDialogInternal.setFilterPath(initialDir.getParentFile().getAbsolutePath());
        }
    }

    fileDialogInternal.open();
    String filePath = fileDialogInternal.getFileName();
    File file = new File(filePath);
    return file;
}
 

开发者ID:gama-platform,
项目名称:gama,
代码行数:30,
代码来源:JFileDataStoreChooser.java

示例3: mergeShapeFile2

点赞 2

import org.geotools.data.FileDataStoreFactorySpi; //导入依赖的package包/类
/**
 *
 * @param collectionsLayer
 * @param shpInput
 * @param transform
 * @param bbox
 * @return
 * @throws Exception
 */
public static GeometryImage mergeShapeFile2(SimpleFeatureCollection collectionsLayer, File shpInput,GeoTransform transform,Polygon bbox)throws Exception {
	Map<String, Serializable> params = new HashMap<String, Serializable>();
    params.put("url", shpInput.toURI().toURL());

    //create a DataStore object to connect to the physical source
    DataStore dataStore = DataStoreFinder.getDataStore(params);
    //retrieve a FeatureSource to work with the feature data
    SimpleFeatureSource shape2 = (SimpleFeatureSource) dataStore.getFeatureSource(dataStore.getTypeNames()[0]);

    ClipProcess clip=new ClipProcess();
    SimpleFeatureCollection collectionsShape2=shape2.getFeatures();
    SimpleFeatureCollection fc=clip.execute(collectionsShape2, bbox,true);
    SimpleFeatureSource source = new CollectionFeatureSource(fc);

    SimpleFeatureCollection result=joinFeaures(source, shape2);

    //create new datastore to save the new shapefile
    FileDataStoreFactorySpi factory = new ShapefileDataStoreFactory();
    File tmp=new File(SumoPlatform.getApplication().getCachePath()+"\\tmpshape_"+System.currentTimeMillis()+".shp");
    Map<String, Serializable> params2 = new HashMap<String, Serializable>();
    params2.put("url", tmp.toURI().toURL());
    ShapefileDataStore newds=(ShapefileDataStore)factory.createNewDataStore(params2);

    String geoName = collectionsLayer.getSchema().getGeometryDescriptor().getType().getName().toString();
    //String nameOutput="merge_"+shpInput.getName()+"_"+LayerManager.getIstanceManager().getCurrentImageLayer().getName();

  //from here create the new GeometricLayer
    Collection<PropertyDescriptor>descriptorsMerge=new ArrayList<>();
    descriptorsMerge.addAll(shape2.getSchema().getDescriptors());
    descriptorsMerge.addAll(collectionsLayer.getSchema().getDescriptors());

    String[] schema = createSchema(descriptorsMerge);
    String[] types = createTypes(descriptorsMerge);

    GeometryImage out=GeometryImage.createLayerFromFeatures(geoName, newds, result, schema, types,true,transform);

    return out;
}
 

开发者ID:ec-europa,
项目名称:sumo,
代码行数:48,
代码来源:SimpleShapefile.java

示例4: associations

点赞 2

import org.geotools.data.FileDataStoreFactorySpi; //导入依赖的package包/类
static Map<String, String> associations( List<String> extensions ) {
    Map<String, String> fileAssociations = new TreeMap<String, String>();

    for( String extension : extensions ) {
        String ext = extension.toLowerCase().trim();
        if (!ext.startsWith("*.")) {
            if (ext.startsWith(".")) {
                ext = "*" + ext;
            } else {
                ext = "*." + ext;
            }
        }

        FileDataStoreFactorySpi factory = FileDataStoreFinder.getDataStoreFactory(ext);
        if (factory != null) {
            fileAssociations.put(ext, factory.getDescription());

        } else {
            // guess some common ones
            if (".csv".equals(ext)) {
                fileAssociations.put(ext, "Comma-delimited files (*.csv)");

            } else if (ext.startsWith(".tif")) {
                fileAssociations.put(ext, "GeoTIFF files (*.tif; *.tiff)");

            } else {
                // fallback
                fileAssociations.put(ext, ext.toUpperCase().substring(1) + "files (*" + ext + ")");
            }
        }
    }
    return fileAssociations;
}
 

开发者ID:gama-platform,
项目名称:gama,
代码行数:34,
代码来源:JFileDataStoreChooser.java

示例5: mergeShapeFile

点赞 2

import org.geotools.data.FileDataStoreFactorySpi; //导入依赖的package包/类
/**
 *
 * @param layer
 * @param shpInput
 * @param transform
 * @return
 * @throws Exception
 */
public static GeometryImage mergeShapeFile(SimpleFeatureCollection collectionsLayer, File shpInput,GeoTransform transform,Polygon bbox)throws Exception {
	Map<String, Serializable> params = new HashMap<String, Serializable>();
    params.put("url", shpInput.toURI().toURL());

    //create a DataStore object to connect to the physical source
    DataStore dataStore = DataStoreFinder.getDataStore(params);

    SimpleFeatureSource shape2 = (SimpleFeatureSource) dataStore.getFeatureSource(dataStore.getTypeNames()[0]);

    SimpleFeatureCollection collectionsShape2=shape2.getFeatures();
    SimpleFeatureType schemaShape2=shape2.getSchema();

    ClipProcess clip=new ClipProcess();
    SimpleFeatureCollection fc=clip.execute(collectionsShape2, bbox,true);

    SimpleFeatureType schemaLayer=collectionsLayer.getSchema();

    //merge the schema and the types
    SimpleFeatureTypeBuilder stb = new SimpleFeatureTypeBuilder();
    stb.setName("merged_geom");
    stb.setCRS(schemaLayer.getCoordinateReferenceSystem());
    stb.addAll(schemaShape2.getAttributeDescriptors());
    stb.addAll(schemaLayer.getAttributeDescriptors());
    SimpleFeatureType newFeatureType = stb.buildFeatureType();

    //create new datastore to save the new shapefile
    FileDataStoreFactorySpi factory = new ShapefileDataStoreFactory();
    File tmp=new File(SumoPlatform.getApplication().getCachePath()+"\\tmpshape_"+System.currentTimeMillis()+".shp");
    Map<String, Serializable> params2 = new HashMap<String, Serializable>();
    params2.put("url", tmp.toURI().toURL());
    ShapefileDataStore newds=(ShapefileDataStore)factory.createNewDataStore(params2);
    GeometryImage out=null;
    try{
     newds.createSchema(newFeatureType);

     //merge the feaures
     SimpleFeatureStore mergeFeat=(SimpleFeatureStore)newds.getFeatureSource();
     mergeFeat.addFeatures(collectionsLayer);
     mergeFeat.addFeatures(fc);
     //save the new shape file
     exportToShapefile(newds, mergeFeat.getFeatures());//,newds.getSchema());

     //from here create the new GeometricLayer
     Collection<PropertyDescriptor>descriptorsMerge=new ArrayList<>();
     descriptorsMerge.addAll(schemaShape2.getDescriptors());
     descriptorsMerge.addAll(schemaLayer.getDescriptors());

     String[] schema = createSchema(descriptorsMerge);
     String[] types = createTypes(descriptorsMerge);


     String geoName = schemaLayer.getGeometryDescriptor().getType().getName().toString();
     out=GeometryImage.createLayerFromFeatures(geoName, newds, mergeFeat.getFeatures(), schema, types,true,transform);
     //out = GeometricLayer.createImageProjectedLayer(out, transform,null);
     out.setName("merge_"+shpInput.getName()+"_"+LayerManager.getIstanceManager().getCurrentImageLayer().getName());
    }finally{
    	if(newds!=null)
    		newds.dispose();
    }
    return out;
}
 

开发者ID:ec-europa,
项目名称:sumo,
代码行数:70,
代码来源:SimpleShapefile.java

示例6: exportGeometriesToShapeFile

点赞 2

import org.geotools.data.FileDataStoreFactorySpi; //导入依赖的package包/类
/**
 *
 * @param geoms
 * @param fileOutput
 * @param geomType
 * @param transform
 * @throws IOException
 * @throws SchemaException
 */
public static void exportGeometriesToShapeFile(final List<Geometry> geoms,
	 File fileOutput,String geomType,GeoTransform transform,
	 SimpleFeatureType featureType) throws IOException, SchemaException{

 FileDataStoreFactorySpi factory = new ShapefileDataStoreFactory();
 //Map map = Collections.singletonMap( "url", fileOutput.toURI().toURL() );
 DataStore data = factory.createDataStore( fileOutput.toURI().toURL() );
 boolean addAttr=true;
 if(featureType==null){
	 featureType=DataUtilities.createType( "the_geom", "geom:"+geomType+",name:String,age:Integer,description:String" );
	 addAttr=false;
 }
 data.createSchema( featureType );

 Transaction transaction = new DefaultTransaction();
    FeatureWriter<SimpleFeatureType, SimpleFeature> writer = data.getFeatureWriterAppend(data.getTypeNames()[0], transaction);

    SimpleFeatureBuilder featureBuilder=new SimpleFeatureBuilder(featureType);
    GeometryFactory gb=new GeometryFactory();
    try {
     int fid=0;
     for(final Geometry g:geoms){
    	 Geometry clone=gb.createGeometry(g);
    	 if(transform!=null)
    		 clone=transform.transformGeometryGeoFromPixel(clone);

    	 featureBuilder.add("the_geom");
    	 featureBuilder.add(clone);
    	 SimpleFeature sf=featureBuilder.buildFeature(""+fid++);
    	 SimpleFeature sfout=writer.next();
    	 sfout.setAttributes( sf.getAttributes() );
         //setting attributes geometry
       	 AttributesGeometry att=(AttributesGeometry) g.getUserData();
       	 try{
        	 if(att!=null&&addAttr){
         	 String sch[]=att.getSchema();
         	 for(int i=0;i<sch.length;i++){
         		 Object val=att.get(sch[i]);
         		 if(val.getClass().isArray()){
         			 Object o=ArrayUtils.toString(val);
         			 sfout.setAttribute(sch[i], o);
         		 }else{
         			 sfout.setAttribute(sch[i], val);
         		 }
         	 }
        	 }
       	 }catch(Exception e ){
       		 logger.warn("Error adding attributes to geometry:"+e.getMessage());
       	 }

         sfout.setDefaultGeometry( clone);
    	 writer.write();
	 }
     transaction.commit();
     logger.info("Export to shapefile complete:"+ fileOutput.getAbsolutePath());
    } catch (Exception problem) {
        problem.printStackTrace();
        transaction.rollback();
        logger.error("Export to shapefile failed",problem );
    } finally {
        writer.close();
        transaction.close();
        data.dispose();
    }

}
 

开发者ID:ec-europa,
项目名称:sumo,
代码行数:76,
代码来源:SimpleShapefile.java

示例7: writeFeatureCollection

点赞 2

import org.geotools.data.FileDataStoreFactorySpi; //导入依赖的package包/类
@Execute
public void writeFeatureCollection() throws IOException {
    if (!concatOr(!hasWritten, doReset)) {
        return;
    }

    pm.beginTask("Writing features to shapefile...", -1);

    if (!file.endsWith(".shp")) {
        file = file + ".shp";
    }
    if (geodata != null && geodata.size() != 0) {
        pType = geodata.getSchema();
    }
    File shapeFile = new File(file);
    FileDataStoreFactorySpi factory = FileDataStoreFinder.getDataStoreFactory("shp");
    Map map = Collections.singletonMap("url", shapeFile.toURI().toURL());
    DataStore newDataStore = factory.createNewDataStore(map);
    newDataStore.createSchema(pType);

    Transaction transaction = new DefaultTransaction("create");
    String typeName = newDataStore.getTypeNames()[0];
    SimpleFeatureStore featureStore = (SimpleFeatureStore) newDataStore.getFeatureSource(typeName);

    featureStore.setTransaction(transaction);
    try {
        if (geodata == null) {
            featureStore.addFeatures(new DefaultFeatureCollection());
        } else {
            featureStore.addFeatures(geodata);
        }
        transaction.commit();
    } catch (Exception problem) {
        transaction.rollback();
        throw new IOException(problem.getLocalizedMessage());
    } finally {
        transaction.close();
        pm.done();
    }

    hasWritten = true;
}
 

开发者ID:TheHortonMachine,
项目名称:hortonmachine,
代码行数:43,
代码来源:OmsShapefileFeatureWriter.java

示例8: JFileDataStoreChooser

点赞 1

import org.geotools.data.FileDataStoreFactorySpi; //导入依赖的package包/类
/**
 * Creates a dialog that filters for files matching the specified
 * data format. 
 *
 * @param format data file format
 */
public JFileDataStoreChooser( Shell parent, int style, final FileDataStoreFactorySpi format ) {
    fileDialog = new FileDialog(parent, style);
    fileDialog.setFilterExtensions(format.getFileExtensions());
}
 

开发者ID:gama-platform,
项目名称:gama,
代码行数:11,
代码来源:JFileDataStoreChooser.java


版权声明:本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系管理员进行删除。
喜欢 (0)