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


Java SimpleFeatureStore类代码示例

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


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

示例1: getFeatureStorefromDB

import org.geotools.data.simple.SimpleFeatureStore; //导入依赖的package包/类
/**
 * Gets the feature storefrom db.
 *
 * @param uazTbl
 *          the uaz tbl
 * @return the feature storefrom db
 * @throws WifInvalidInputException
 *           the wif invalid input exception
 */
public SimpleFeatureStore getFeatureStorefromDB(final String uazTbl)
    throws WifInvalidInputException {

  LOGGER.info("getFeatureStorefromDB for table : {}", uazTbl);

  SimpleFeatureSource featureSourceUD;

  featureSourceUD = getFeatureSourcefromDB(uazTbl);

  if (featureSourceUD instanceof SimpleFeatureStore) {

    LOGGER.info("UAZ featureSource Name: {} ", featureSourceUD.getName());
    return (SimpleFeatureStore) featureSourceUD;
  } else {
    throw new WifInvalidInputException(
        "table doesn't have write priviledges " + uazTbl);
  }
}
 
开发者ID:AURIN,项目名称:online-whatif,代码行数:28,代码来源:GeodataFinder.java

示例2: addFeature

import org.geotools.data.simple.SimpleFeatureStore; //导入依赖的package包/类
/**
 * Add a feature to the store.
 * 
 * @param feature the feature to add.
 */
default public void addFeature( SimpleFeature feature) {
    FeatureStoreInfo featureStoreInfo = getFeatureStoreInfo();
    SimpleFeatureStore featureStore = featureStoreInfo.getFeatureStore();
    if (featureStore != null) {
        Transaction transaction = new DefaultTransaction("add");
        featureStore.setTransaction(transaction);
        
        try {
            DefaultFeatureCollection fc = new DefaultFeatureCollection();
            fc.add(feature);
            featureStore.addFeatures(fc);
            transaction.commit();
        } catch (Exception eek) {
            try {
                transaction.rollback();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
}
 
开发者ID:TheHortonMachine,项目名称:hortonmachine,代码行数:27,代码来源:IFeatureShape.java

示例3: FeatureCollectionLinesLayer

import org.geotools.data.simple.SimpleFeatureStore; //导入依赖的package包/类
/**
 * Build the layer.
 * 
 * @param title layer name.
 * @param featureCollectionLL the featurecollection in latlong.
 * @param featureStore the feature store. If not null, then the feature attributes will be editable.
 * @param field2ValuesMap an optional map of fields and possible values.
 */
public FeatureCollectionLinesLayer( String title, SimpleFeatureCollection featureCollectionLL,
        SimpleFeatureStore featureStore, HashMap<String, String[]> field2ValuesMap ) {
    this.title = title;
    this.featureStore = featureStore;
    this.featureStoreInfo = new FeatureStoreInfo(featureStore, field2ValuesMap);
    this.featureCollectionLL = featureCollectionLL;

    AirspaceAttributes attrs = new BasicAirspaceAttributes();
    attrs.setDrawInterior(true);
    attrs.setDrawOutline(true);
    attrs.setInteriorMaterial(new Material(Color.WHITE));
    attrs.setOutlineMaterial(new Material(Color.BLACK));
    attrs.setOutlineWidth(2);
    attrs.setEnableAntialiasing(true);
    highlightAttrs = new BasicAirspaceAttributes(attrs);
    highlightAttrs.setOutlineMaterial(new Material(Color.RED));

    setStyle(null);
    loadData();
}
 
开发者ID:TheHortonMachine,项目名称:hortonmachine,代码行数:29,代码来源:FeatureCollectionLinesLayer.java

示例4: makeLineLayer

import org.geotools.data.simple.SimpleFeatureStore; //导入依赖的package包/类
private void makeLineLayer( IEpanetType[] types, File baseFolder, CoordinateReferenceSystem mapCrs )
        throws MalformedURLException, IOException {
    SimpleFeatureTypeBuilder b = new SimpleFeatureTypeBuilder();
    String shapefileName = types[0].getShapefileName();
    String typeName = types[0].getName();
    b.setName(typeName);
    b.setCRS(mapCrs);
    b.add("the_geom", LineString.class);
    for( IEpanetType type : types ) {
        b.add(type.getAttributeName(), type.getClazz());
    }
    SimpleFeatureType tanksType = b.buildFeatureType();
    ShapefileDataStoreFactory factory = new ShapefileDataStoreFactory();
    File file = new File(baseFolder, shapefileName);
    Map<String, Serializable> create = new HashMap<String, Serializable>();
    create.put("url", file.toURI().toURL());
    ShapefileDataStore newDataStore = (ShapefileDataStore) factory.createNewDataStore(create);
    newDataStore.createSchema(tanksType);
    Transaction transaction = new DefaultTransaction();
    SimpleFeatureStore featureStore = (SimpleFeatureStore) newDataStore.getFeatureSource();
    featureStore.setTransaction(transaction);
    try {
        featureStore.addFeatures(new DefaultFeatureCollection());
        transaction.commit();
    } catch (Exception problem) {
        problem.printStackTrace();
        transaction.rollback();
    } finally {
        transaction.close();
    }
}
 
开发者ID:TheHortonMachine,项目名称:hortonmachine,代码行数:32,代码来源:OmsEpanetProjectFilesGenerator.java

示例5: writeShapefile

import org.geotools.data.simple.SimpleFeatureStore; //导入依赖的package包/类
private void writeShapefile(MemoryDataStore memoryDataStore, File outputFile) throws Exception {

		SimpleFeatureSource featureSource = memoryDataStore.getFeatureSource(memoryDataStore.getTypeNames()[0]);
		SimpleFeatureType featureType = featureSource.getSchema();

		Map<String, java.io.Serializable> creationParams = new HashMap<String, java.io.Serializable>();
		creationParams.put("url", DataUtilities.fileToURL(outputFile));

		ShapefileDataStoreFactory factory = (ShapefileDataStoreFactory) FileDataStoreFinder.getDataStoreFactory("shp");
		ShapefileDataStore dataStore = (ShapefileDataStore) factory.createNewDataStore(creationParams);
		dataStore.setCharset(Charset.forName("UTF-8"));
		dataStore.createSchema(featureType);

		SimpleFeatureStore featureStore = (SimpleFeatureStore) dataStore.getFeatureSource(dataStore.getTypeNames()[0]);

		Transaction transaction = new DefaultTransaction();
		try {
			SimpleFeatureCollection collection = featureSource.getFeatures();
			featureStore.addFeatures(collection);
			transaction.commit();
		} catch (IOException e) {
			try {
				transaction.rollback();
				throw new Exception("Failed to commit data to feature store", e);
			} catch (IOException e2 ) {
				logger.error("Failed to commit data to feature store", e);
				throw new Exception("Transaction rollback failed", e2);
			}
		} finally {
			transaction.close();
		}
	}
 
开发者ID:dainst,项目名称:gazetteer,代码行数:33,代码来源:ShapefileCreator.java

示例6: addFeaturesExample

import org.geotools.data.simple.SimpleFeatureStore; //导入依赖的package包/类
private void addFeaturesExample() throws Exception {
    // addExample start
    SimpleFeatureStore store = (SimpleFeatureStore) dataStore.getFeatureSource( typeName );
    
    SimpleFeatureType featureType = store.getSchema();
    
    SimpleFeatureBuilder build = new SimpleFeatureBuilder(featureType);
    GeometryBuilder geom = new GeometryBuilder();
    
    List<SimpleFeature> list = new ArrayList<SimpleFeature>();
    list.add( build.buildFeature("fid1", new Object[]{ geom.point(1,1), "hello" } ) );
    list.add( build.buildFeature("fid2", new Object[]{ geom.point(2,3), "martin" } ) );
    SimpleFeatureCollection collection = new ListFeatureCollection(featureType, list);

    Transaction transaction = new DefaultTransaction("Add Example");
    store.setTransaction( transaction );
    try {
        store.addFeatures( collection );
        transaction.commit(); // actually writes out the features in one go
    }
    catch( Exception eek){
        transaction.rollback();
    }
    // addExample end
}
 
开发者ID:ianturton,项目名称:geotools-cookbook,代码行数:26,代码来源:SimpleFeatureStoreExamples.java

示例7: addFeatureIdExample

import org.geotools.data.simple.SimpleFeatureStore; //导入依赖的package包/类
private void addFeatureIdExample(SimpleFeatureCollection collection ) throws Exception {
    // addFeatureIdExample start
    Transaction transaction = new DefaultTransaction("Add Example");
    SimpleFeatureStore store = (SimpleFeatureStore) dataStore.getFeatureSource(typeName);
    store.setTransaction(transaction);
    try {
        List<FeatureId> added = store.addFeatures( collection );
        System.out.println( added ); // prints out the temporary feature ids
        
        transaction.commit();
        System.out.println( added ); // prints out the final feature ids
        
        Set<FeatureId> selection = new HashSet<FeatureId>( added );
        FilterFactory ff = CommonFactoryFinder.getFilterFactory();
        Filter selected = ff.id( selection ); // filter selecting all the features just added
    }
    catch( Exception problem){
        transaction.rollback();
        throw problem;
    }
    // addFeatureIdExample end
}
 
开发者ID:ianturton,项目名称:geotools-cookbook,代码行数:23,代码来源:SimpleFeatureStoreExamples.java

示例8: removeExample

import org.geotools.data.simple.SimpleFeatureStore; //导入依赖的package包/类
private void removeExample() throws Exception {
    // removeExample start
    Transaction transaction = new DefaultTransaction("removeExample");
    SimpleFeatureStore store = (SimpleFeatureStore) dataStore.getFeatureSource(typeName);
    store.setTransaction(transaction);
    
    FilterFactory ff = CommonFactoryFinder.getFilterFactory(GeoTools.getDefaultHints());
    Filter filter = ff.id(Collections.singleton(ff.featureId("fred")));
    try {
        store.removeFeatures(filter);
        transaction.commit();
    } catch (Exception eek) {
        transaction.rollback();
    }
    // removeExample end
}
 
开发者ID:ianturton,项目名称:geotools-cookbook,代码行数:17,代码来源:SimpleFeatureStoreExamples.java

示例9: removeExample2

import org.geotools.data.simple.SimpleFeatureStore; //导入依赖的package包/类
private void removeExample2() throws Exception {
    // removeExample2 start
    Transaction transaction = new DefaultTransaction("removeExample");
    SimpleFeatureStore store = (SimpleFeatureStore) dataStore.getFeatureSource(typeName);
    store.setTransaction(transaction);
    
    FilterFactory ff = CommonFactoryFinder.getFilterFactory(GeoTools.getDefaultHints());
    Filter filter = ff.id(Collections.singleton(ff.featureId("fred")));
    try {
        final Set<FeatureId> removed = new HashSet<FeatureId>();
        SimpleFeatureCollection collection = store.getFeatures( new Query( typeName, filter, Query.NO_NAMES ));
        collection.accepts( new FeatureVisitor(){
            public void visit(Feature feature) {
                removed.add( feature.getIdentifier() );
            }
        }, null );
        store.removeFeatures(filter);
        transaction.commit();
    } catch (Exception eek) {
        transaction.rollback();
    }
    // removeExample2 end
}
 
开发者ID:ianturton,项目名称:geotools-cookbook,代码行数:24,代码来源:SimpleFeatureStoreExamples.java

示例10: delete

import org.geotools.data.simple.SimpleFeatureStore; //导入依赖的package包/类
@Override
@Transactional(rollbackFor = { Throwable.class })
public void delete(String featureId) throws LayerException {
	SimpleFeatureSource source = getFeatureSource();
	if (source instanceof SimpleFeatureStore) {
		SimpleFeatureStore store = (SimpleFeatureStore) source;
		Filter filter = filterService.createFidFilter(new String[] { featureId });
		transactionSynchronization.synchTransaction(store);
		try {
			store.removeFeatures(filter);
			if (log.isDebugEnabled()) {
				log.debug("Deleted feature {} in {}", featureId, getFeatureSourceName());
			}
		} catch (IOException ioe) {
			featureModelUsable = false;
			throw new LayerException(ioe, ExceptionCode.LAYER_MODEL_IO_EXCEPTION);
		}
	} else {
		log.error("Don't know how to delete from " + getFeatureSourceName() + ", class "
				+ source.getClass().getName() + " does not implement SimpleFeatureStore");
		throw new LayerException(ExceptionCode.DELETE_NOT_IMPLEMENTED, getFeatureSourceName(), source.getClass()
				.getName());
	}
}
 
开发者ID:geomajas,项目名称:geomajas-project-server,代码行数:25,代码来源:GeoToolsLayer.java

示例11: getBounds

import org.geotools.data.simple.SimpleFeatureStore; //导入依赖的package包/类
@Override
public Envelope getBounds(Filter filter) throws LayerException {
	FeatureSource<SimpleFeatureType, SimpleFeature> source = getFeatureSource();
	if (source instanceof FeatureStore<?, ?>) {
		SimpleFeatureStore store = (SimpleFeatureStore) source;
		transactionSynchronization.synchTransaction(store);
	}
	try {
		FeatureCollection<SimpleFeatureType, SimpleFeature> fc;
		if (null == filter) {
			fc = source.getFeatures();
		} else {
			fc = source.getFeatures(filter);
		}
		FeatureIterator<SimpleFeature> it = fc.features();
		transactionSynchronization.addIterator(it);
		return fc.getBounds();
	} catch (Throwable t) { // NOSONAR avoid errors (like NPE) as well
		throw new LayerException(t, ExceptionCode.UNEXPECTED_PROBLEM);
	}
}
 
开发者ID:geomajas,项目名称:geomajas-project-server,代码行数:22,代码来源:GeoToolsLayer.java

示例12: getElements

import org.geotools.data.simple.SimpleFeatureStore; //导入依赖的package包/类
/**
 * {@inheritDoc}
 *
 */
@Transactional(readOnly = true)
public Iterator<?> getElements(Filter filter, int offset, int maxResultSize) throws LayerException {
	FeatureSource<SimpleFeatureType, SimpleFeature> source = getFeatureSource();
	try {
		if (source instanceof FeatureStore<?, ?>) {
			SimpleFeatureStore store = (SimpleFeatureStore) source;
			transactionSynchronization.synchTransaction(store);
		}
		Query query = new Query();
		query.setFilter(filter);
		query.setMaxFeatures(maxResultSize > 0 ? maxResultSize : Integer.MAX_VALUE);
		query.setStartIndex(offset);
		FeatureCollection<SimpleFeatureType, SimpleFeature> fc = source.getFeatures(query);
		FeatureIterator<SimpleFeature> it = fc.features();
		transactionSynchronization.addIterator(it);
		return new JavaIterator(it);
	} catch (Throwable t) { // NOSONAR avoid errors (like NPE) as well
		throw new LayerException(t, ExceptionCode.UNEXPECTED_PROBLEM);
	}
}
 
开发者ID:geomajas,项目名称:geomajas-project-server,代码行数:25,代码来源:GeoToolsLayer.java

示例13: write

import org.geotools.data.simple.SimpleFeatureStore; //导入依赖的package包/类
public static <T> void write(File file,
        Consumer<SimpleFeatureTypeBuilder> fun1,
        BiConsumer<SimpleFeatureBuilder, T> fun2,
        List<T> geometries) {
    try {
        SimpleFeatureTypeBuilder typeBuilder = new SimpleFeatureTypeBuilder();
        typeBuilder.setName("MyFeatureType");
        typeBuilder.setCRS(DefaultGeographicCRS.WGS84);
        fun1.accept(typeBuilder);
        SimpleFeatureType type = typeBuilder.buildFeatureType();
        SimpleFeatureBuilder featureBuilder = new SimpleFeatureBuilder(type);
        AtomicInteger id = new AtomicInteger(0);
        List<SimpleFeature> geoms = geometries.stream().map(g -> {
            fun2.accept(featureBuilder, g);
            return featureBuilder.buildFeature(String.valueOf(id.getAndIncrement()));
        }).collect(toList());
        ShapefileDataStoreFactory datastoreFactory = new ShapefileDataStoreFactory();
        Map<String, Serializable> params = newHashMap();
        params.put("url", file.toURI().toURL());
        params.put("create spatial index", Boolean.TRUE);
        ShapefileDataStore datastore = (ShapefileDataStore) datastoreFactory.createNewDataStore(params);
        datastore.createSchema(type);
        Transaction transaction = new DefaultTransaction("create");
        String typeName = datastore.getTypeNames()[0];
        SimpleFeatureSource featureSource = datastore.getFeatureSource(typeName);
        SimpleFeatureStore featureStore = (SimpleFeatureStore) featureSource;
        SimpleFeatureCollection collection = new ListFeatureCollection(type, geoms);
        featureStore.setTransaction(transaction);
        featureStore.addFeatures(collection);
        transaction.commit();
        transaction.close();
        datastore.dispose();
    }
    catch (IOException e) {
        throw propagate(e);
    }
}
 
开发者ID:Mappy,项目名称:fpm,代码行数:38,代码来源:ShapefileWriter.java

示例14: insertFeatures

import org.geotools.data.simple.SimpleFeatureStore; //导入依赖的package包/类
static void insertFeatures(String simpleFeatureTypeName,
                           DataStore dataStore,
                           FeatureCollection featureCollection)
        throws IOException {

    FeatureStore featureStore = (SimpleFeatureStore) dataStore.getFeatureSource(simpleFeatureTypeName);
    featureStore.addFeatures(featureCollection);
}
 
开发者ID:geomesa,项目名称:geomesa-tutorials,代码行数:9,代码来源:FeatureLevelVisibility.java

示例15: init

import org.geotools.data.simple.SimpleFeatureStore; //导入依赖的package包/类
@Override
public void init() {
	LOGGER.info("Output as shapefile: " + outFile);
	file = new File(outFile);

	try {
		// Define Schema
		final SimpleFeatureType TYPE = createFeatureType();
		featureBuilder = new SimpleFeatureBuilder(TYPE);

		geomF = new GeometryFactory();
		ShapefileDataStoreFactory dataStoreFactory = new ShapefileDataStoreFactory();

		// define parameter for ShapeFileDataStore object
		Map<String, Serializable> params = new HashMap<String, Serializable>();
		params.put("url", file.toURI().toURL());
		params.put("create spatial index", Boolean.TRUE);

		dataStore = (ShapefileDataStore) dataStoreFactory.createNewDataStore(params);
		dataStore.createSchema(TYPE);

		// define transaction
		transaction = new DefaultTransaction("create");
		String typeName = dataStore.getTypeNames()[0];
		SimpleFeatureSource featureSource = dataStore.getFeatureSource(typeName);
		if (featureSource instanceof SimpleFeatureStore) {
			featureStore = (SimpleFeatureStore) featureSource;

			featureStore.setTransaction(transaction);
		}
	} catch (IOException e1) {
		e1.printStackTrace();
	}
}
 
开发者ID:GIScience,项目名称:osmgpxfilter,代码行数:35,代码来源:ShapeFileWriter.java


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