本文整理匯總了Java中org.geotools.data.simple.SimpleFeatureCollection.getSchema方法的典型用法代碼示例。如果您正苦於以下問題:Java SimpleFeatureCollection.getSchema方法的具體用法?Java SimpleFeatureCollection.getSchema怎麽用?Java SimpleFeatureCollection.getSchema使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.geotools.data.simple.SimpleFeatureCollection
的用法示例。
在下文中一共展示了SimpleFeatureCollection.getSchema方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: mergeShapeFile
import org.geotools.data.simple.SimpleFeatureCollection; //導入方法依賴的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;
}