本文整理汇总了Java中org.geotools.data.shapefile.ShapefileDataStore类的典型用法代码示例。如果您正苦于以下问题:Java ShapefileDataStore类的具体用法?Java ShapefileDataStore怎么用?Java ShapefileDataStore使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ShapefileDataStore类属于org.geotools.data.shapefile包,在下文中一共展示了ShapefileDataStore类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: configure
import org.geotools.data.shapefile.ShapefileDataStore; //导入依赖的package包/类
@Override
protected DataTableSpec[] configure(DataTableSpec[] inSpecs) throws InvalidSettingsException {
if (shpFile.getStringValue() == null) {
throw new InvalidSettingsException("No file name specified");
}
DataTableSpec[] result = null;
try {
ShapefileDataStore dataStore = GisUtils.getDataStore(shpFile.getStringValue());
result = new DataTableSpec[] { createSpec(dataStore.getFeatureSource().getSchema()) };
dataStore.dispose();
} catch (IOException e) {
throw new InvalidSettingsException(e.getMessage());
}
return result;
}
示例2: CommunityAreas
import org.geotools.data.shapefile.ShapefileDataStore; //导入依赖的package包/类
public CommunityAreas() {
communities = new HashMap<>();
try {
File f = new File(shapeFilePath);
ShapefileDataStore shapefile = new ShapefileDataStore(f.toURI().toURL());
SimpleFeatureIterator features = shapefile.getFeatureSource().getFeatures().features();
SimpleFeature shp;
while (features.hasNext()) {
shp = features.next();
int id = Integer.parseInt((String) shp.getAttribute("AREA_NUMBE"));
String name = (String) shp.getAttribute("COMMUNITY");
MultiPolygon boundary = (MultiPolygon) shp.getDefaultGeometry();
CommunityArea ca = new CommunityArea(id, name, boundary);
communities.put(id, ca);
}
features.close();
shapefile.dispose();
} catch (IOException e) {
e.printStackTrace();
}
}
示例3: computeEnvelope
import org.geotools.data.shapefile.ShapefileDataStore; //导入依赖的package包/类
@Override
public Envelope3D computeEnvelope(final IScope scope) {
if (gis == null) {
ShapefileDataStore store = null;
try {
store = getDataStore(getFile(scope).toURI().toURL());
final Envelope3D env = Envelope3D.of(store.getFeatureSource().getBounds());
computeProjection(scope, env);
} catch (final IOException e) {
return new Envelope3D();
} finally {
if (store != null) {
store.dispose();
}
}
}
return gis.getProjectedEnvelope();
}
示例4: makeLineLayer
import org.geotools.data.shapefile.ShapefileDataStore; //导入依赖的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();
}
}
示例5: writeShapefile
import org.geotools.data.shapefile.ShapefileDataStore; //导入依赖的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();
}
}
示例6: open
import org.geotools.data.shapefile.ShapefileDataStore; //导入依赖的package包/类
public void open() throws KettleException{
try {
// try closing first
close();
// TODO: Don't use a memory-mapped file reader (3rd arg) because this
// causes out of memory errors with large files (~500mb).
gtDataStore = new ShapefileDataStore(gisURL, null, false, Charset.forName(Const.isEmpty(this.charset)?"ISO-8859-1":this.charset));
featSrc = gtDataStore.getFeatureSource(gtDataStore.getTypeNames()[0]);
featColl = featSrc.getFeatures();
featIter = featColl.features();
}catch(Exception e) {
throw new KettleException("Error opening GIS file at URL: "+gisURL, e);
}
}
示例7: init
import org.geotools.data.shapefile.ShapefileDataStore; //导入依赖的package包/类
@Before
public void init() throws Exception {
ClassLoader classloader = Thread.currentThread().getContextClassLoader();
URL url = classloader.getResource(SHAPE_FILE);
DataStore dataStore = new ShapefileDataStore(url);
featureModel = new GeoToolsFeatureModel(dataStore, LAYER_NAME, 4326, converterService);
featureModel.setLayerInfo(layerInfo);
FeatureSource<SimpleFeatureType, SimpleFeature> fs = featureModel.getFeatureSource();
FeatureIterator<SimpleFeature> fi = fs.getFeatures().features();
feature = fi.next();
feature = fi.next();
feature = fi.next();
feature = fi.next();
feature = fi.next();
}
示例8: setUp
import org.geotools.data.shapefile.ShapefileDataStore; //导入依赖的package包/类
@Before
public void setUp() throws Exception {
ClassLoader classloader = Thread.currentThread().getContextClassLoader();
URL url = classloader.getResource(SHAPE_FILE);
DataStore dataStore = new ShapefileDataStore(url);
featureModel = new ShapeInMemFeatureModel(dataStore, LAYER_NAME, 4326, converterService);
featureModel.setLayerInfo(layerInfo);
FeatureSource<SimpleFeatureType, SimpleFeature> fs = featureModel.getFeatureSource();
FeatureIterator<SimpleFeature> fi = fs.getFeatures().features();
feature = fi.next();
feature = fi.next();
feature = fi.next();
feature = fi.next();
feature = fi.next();
fi.close();
}
示例9: createDataStore
import org.geotools.data.shapefile.ShapefileDataStore; //导入依赖的package包/类
@SuppressWarnings("unused")
private static FileDataStore createDataStore(String filename, SimpleFeatureType ft, String projection) throws Exception {
File file = new File(filename);
FileDataStore dataStore = FileDataStoreFinder.getDataStore(file);
// Tell the DataStore what type of Coordinate Reference System (CRS) to use
if (projection != null) {
((ShapefileDataStore)dataStore).forceSchemaCRS(CRS.decode(projection));
}
return dataStore;
}
示例10: mergeShapeFile2
import org.geotools.data.shapefile.ShapefileDataStore; //导入依赖的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;
}
示例11: ShapefileIterator
import org.geotools.data.shapefile.ShapefileDataStore; //导入依赖的package包/类
public ShapefileIterator(File file, boolean forceUTF8) {
try {
this.forceUTF8 = forceUTF8;
datastore = new ShapefileDataStore(file.toURI().toURL());
FeatureSource<SimpleFeatureType, SimpleFeature> source = datastore
.getFeatureSource(datastore.getTypeNames()[0]);
FeatureCollection<SimpleFeatureType, SimpleFeature> collection = source.getFeatures(INCLUDE);
features = collection.features();
}
catch (IOException e) {
throw propagate(e);
}
}
示例12: write
import org.geotools.data.shapefile.ShapefileDataStore; //导入依赖的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);
}
}
示例13: testAllShapesArePolygon
import org.geotools.data.shapefile.ShapefileDataStore; //导入依赖的package包/类
public void testAllShapesArePolygon() {
try {
File fin = new File(CommunityAreas.shapeFilePath);
ShapefileDataStore r = new ShapefileDataStore(fin.toURI().toURL());
SimpleFeatureType sft = r.getSchema();
assertEquals(sft.getTypes().size(), 10);
assertEquals(sft.getType(0).getName().getLocalPart(), "MultiPolygon");
assertEquals(sft.getType(5).getName().getLocalPart(), "AREA_NUMBE");
assertEquals(sft.getType(6).getName().getLocalPart(), "COMMUNITY");
FeatureReader<SimpleFeatureType, SimpleFeature> fr = r.getFeatureReader();
SimpleFeature shp;
int total = 0;
while (fr.hasNext()) {
total ++;
shp = fr.next();
MultiPolygon g = (MultiPolygon) shp.getDefaultGeometry();
}
fr.close();
r.dispose();
assertEquals(total, 77);
} catch (Exception e) {
e.printStackTrace();
}
}
示例14: openInputShapefile
import org.geotools.data.shapefile.ShapefileDataStore; //导入依赖的package包/类
/**
* Open the input shape file and load it into memory.
*/
public void openInputShapefile(String inputShapefile) throws IOException {
File file = new File(inputShapefile);
ShapefileDataStoreFactory dataStoreFactory = new ShapefileDataStoreFactory();
Map<String, Serializable> params = new HashMap<>();
params.put(ShapefileDataStoreFactory.URLP.key, file.toURI().toURL());
params.put(ShapefileDataStoreFactory.CREATE_SPATIAL_INDEX.key, Boolean.TRUE);
params.put(ShapefileDataStoreFactory.ENABLE_SPATIAL_INDEX.key, Boolean.TRUE);
params.put(ShapefileDataStoreFactory.MEMORY_MAPPED.key, Boolean.TRUE);
params.put(ShapefileDataStoreFactory.CACHE_MEMORY_MAPS.key, Boolean.TRUE);
ShapefileDataStore store = (ShapefileDataStore) dataStoreFactory.createNewDataStore(params);
featureSource = store.getFeatureSource();
// determine the correct case of the tz attribute because its case has been
// changed from efele to evansiroky
SimpleFeatureType schema = featureSource.getSchema();
List<AttributeDescriptor> attributeDescriptorList = schema.getAttributeDescriptors();
for (AttributeDescriptor attributeDescriptor : attributeDescriptorList) {
if ("tzid".equalsIgnoreCase(attributeDescriptor.getLocalName())) {
tzidAttr = attributeDescriptor.getLocalName();
}
}
filterFactory = CommonFactoryFinder.getFilterFactory2(GeoTools.getDefaultHints());
geometryFactory = JTSFactoryFinder.getGeometryFactory();
}
示例15: main
import org.geotools.data.shapefile.ShapefileDataStore; //导入依赖的package包/类
public static void main(String[] args) throws IOException {
JLegendPanel legend = new JLegendPanel();
File file = new File("../../data/states.shp");
ShapefileDataStore ds = new ShapefileDataStore(
DataUtilities.fileToURL(file));
ContentFeatureCollection collection = ds.getFeatureSource()
.getFeatures();
String[] pals = legend.getPalletes();
for (String p : pals)
System.out.println(p);
for (String n : legend.getClassifiers()) {
System.out.println(n);
legend.setFunction(n);
Style style = legend.getStyle(collection, "P_FEMALE");
SLDTransformer tx = new SLDTransformer();
tx.setIndentation(2);
try {
tx.transform(style, System.out);
} catch (TransformerException e) {
throw (IOException) new IOException("Error writing style")
.initCause(e);
}
}
}