当前位置: 首页>>代码示例>>Java>>正文


Java FeatureStore.setTransaction方法代码示例

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


在下文中一共展示了FeatureStore.setTransaction方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: main

import org.geotools.data.FeatureStore; //导入方法依赖的package包/类
public static void main(String[] args) throws MalformedURLException,
		IOException, NoSuchAuthorityCodeException, FactoryException {
	if (args.length < 3) {
		System.err.println("Usage: ReprojectShapeFile in.shp out.shp epsg:code");
		System.exit(3);
	}
	File in = new File(args[0]);
	File out = new File(args[1]);
	CoordinateReferenceSystem crs = CRS.decode(args[2]);

	ShapefileDataStoreFactory fac = new ShapefileDataStoreFactory();
	FileDataStore inStore = fac.createDataStore(in.toURI().toURL());
	FileDataStore outStore = fac.createDataStore(out.toURI().toURL());

	SimpleFeatureCollection inFeatures = inStore.getFeatureSource()
			.getFeatures();

	ReprojectShapeFile reprojector = new ReprojectShapeFile();

	SimpleFeatureCollection outFeatures = reprojector
			.reproject(inFeatures, crs);
	outStore.createSchema(outFeatures.getSchema());
	Transaction transaction = new DefaultTransaction("create");
	String outName = outStore.getNames().get(0).getLocalPart();
	SimpleFeatureSource featureSource = outStore.getFeatureSource(outName);
	FeatureStore featureStore = (FeatureStore) featureSource;
	featureStore.setTransaction(transaction);
	featureStore.addFeatures(outFeatures);
	transaction.commit();
	outStore.dispose();
}
 
开发者ID:ianturton,项目名称:geotools-cookbook,代码行数:32,代码来源:ReprojectShapeFile.java

示例2: createShapeFile

import org.geotools.data.FeatureStore; //导入方法依赖的package包/类
private File createShapeFile(FeatureCollection<SimpleFeatureType, SimpleFeature> collection) throws IOException {

		String shapeFileSuffix = ".shp";

		File tempBaseFile = File.createTempFile("resolveDir", ".tmp");
		tempBaseFile.deleteOnExit();
		File parent = tempBaseFile.getParentFile();

		File shpBaseDirectory = new File(parent, UUID.randomUUID().toString());

		if (!shpBaseDirectory.mkdir()) {
			throw new IllegalStateException("Could not create temporary shp directory.");
		}

		File tempSHPfile = File.createTempFile("shp", shapeFileSuffix, shpBaseDirectory);
		tempSHPfile.deleteOnExit();
		DataStoreFactorySpi dataStoreFactory = new ShapefileDataStoreFactory();
		Map<String, Serializable> params = new HashMap<String, Serializable>();
		params.put("url", tempSHPfile.toURI().toURL());
		params.put("create spatial index", Boolean.TRUE);

		ShapefileDataStore newDataStore = (ShapefileDataStore) dataStoreFactory
				.createNewDataStore(params);

		newDataStore.createSchema(collection.getSchema());
		if(collection.getSchema().getCoordinateReferenceSystem()==null){
			newDataStore.forceSchemaCRS(getCRS_WGS84());
		}else{
			newDataStore.forceSchemaCRS(collection.getSchema()
				.getCoordinateReferenceSystem());
		}

		Transaction transaction = new DefaultTransaction("create");

		String typeName = newDataStore.getTypeNames()[0];
		@SuppressWarnings("unchecked")
		FeatureStore<SimpleFeatureType, SimpleFeature> featureStore = (FeatureStore<SimpleFeatureType, SimpleFeature>) newDataStore
				.getFeatureSource(typeName);
		featureStore.setTransaction(transaction);
		try {
			featureStore.addFeatures(collection);
			transaction.commit();
		} catch (Exception problem) {
			transaction.rollback();
		} finally {
			transaction.close();
		}

		// Get names of additional files
		String path = tempSHPfile.getAbsolutePath();
		String baseName = path.substring(0, path.length() - shapeFileSuffix.length());
		File shx = new File(baseName + ".shx");
		File dbf = new File(baseName + ".dbf");
		File prj = new File(baseName + ".prj");

		// mark created files for delete
		tempSHPfile.deleteOnExit();
		shx.deleteOnExit();
		dbf.deleteOnExit();
		prj.deleteOnExit();
		shpBaseDirectory.deleteOnExit();

		return shpBaseDirectory;
	}
 
开发者ID:enviroCar,项目名称:enviroCar-server,代码行数:65,代码来源:TrackShapefileEncoder.java


注:本文中的org.geotools.data.FeatureStore.setTransaction方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。