本文整理匯總了Java中org.geotools.data.DataStore.createSchema方法的典型用法代碼示例。如果您正苦於以下問題:Java DataStore.createSchema方法的具體用法?Java DataStore.createSchema怎麽用?Java DataStore.createSchema使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.geotools.data.DataStore
的用法示例。
在下文中一共展示了DataStore.createSchema方法的13個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: exportFeaturesToShapeFile
import org.geotools.data.DataStore; //導入方法依賴的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();
}
}
示例2: run
import org.geotools.data.DataStore; //導入方法依賴的package包/類
public static int run(String[] args) throws Exception {
CommandLineParser parser = new BasicParser();
Options options = getCommonRequiredOptions();
CommandLine cmd = parser.parse( options, args);
Map<String, String> dsConf = getAccumuloDataStoreConf(cmd);
String featureName = cmd.getOptionValue(FEATURE_NAME);
SimpleFeatureType featureType = DataUtilities.createType(featureName, "geom:Point:srid=4326");
DataStore ds = DataStoreFinder.getDataStore(dsConf);
ds.createSchema(featureType);
TopologyBuilder topologyBuilder = new TopologyBuilder();
String topic = cmd.getOptionValue(TOPIC);
String groupId = topic;
dsConf.put(OSMIngest.FEATURE_NAME, featureName);
OSMKafkaSpout OSMKafkaSpout = new OSMKafkaSpout(dsConf, groupId, topic);
topologyBuilder.setSpout("Spout", OSMKafkaSpout, 10).setNumTasks(10);
OSMKafkaBolt OSMKafkaBolt = new OSMKafkaBolt(dsConf, groupId, topic);
topologyBuilder.setBolt("Bolt", OSMKafkaBolt, 20).shuffleGrouping("Spout");
Config stormConf = new Config();
stormConf.setNumWorkers(10);
stormConf.setDebug(true);
StormSubmitter.submitTopology(topic, stormConf, topologyBuilder.createTopology());
return 0;
}
示例3: main
import org.geotools.data.DataStore; //導入方法依賴的package包/類
public static void main(String [ ] args) throws Exception {
CommandLineParser parser = new BasicParser();
Options options = getCommonRequiredOptions();
Option ingestFileOpt = OptionBuilder.withArgName(INGEST_FILE)
.hasArg()
.isRequired()
.withDescription("ingest tsv file on hdfs")
.create(INGEST_FILE);
options.addOption(ingestFileOpt);
CommandLine cmd = parser.parse( options, args);
Map<String, String> dsConf = getAccumuloDataStoreConf(cmd);
String featureName = cmd.getOptionValue(FEATURE_NAME);
SimpleFeatureType featureType = buildGDELTFeatureType(featureName);
DataStore ds = DataStoreFinder.getDataStore(dsConf);
ds.createSchema(featureType);
runMapReduceJob(featureName,
dsConf,
new Path(cmd.getOptionValue(INGEST_FILE)));
}
示例4: getStatementFeatureType
import org.geotools.data.DataStore; //導入方法依賴的package包/類
private static SimpleFeatureType getStatementFeatureType(final DataStore dataStore) throws IOException, SchemaException {
SimpleFeatureType featureType;
final String[] datastoreFeatures = dataStore.getTypeNames();
if (Arrays.asList(datastoreFeatures).contains(FEATURE_NAME)) {
featureType = dataStore.getSchema(FEATURE_NAME);
} else {
featureType = DataUtilities.createType(FEATURE_NAME,
SUBJECT_ATTRIBUTE + ":String," +
PREDICATE_ATTRIBUTE + ":String," +
OBJECT_ATTRIBUTE + ":String," +
CONTEXT_ATTRIBUTE + ":String," +
GEOMETRY_ATTRIBUTE + ":Geometry:srid=4326," +
GEO_ID_ATTRIBUTE + ":String");
dataStore.createSchema(featureType);
}
return featureType;
}
示例5: getStatementFeatureType
import org.geotools.data.DataStore; //導入方法依賴的package包/類
private static SimpleFeatureType getStatementFeatureType(final DataStore dataStore) throws IOException, SchemaException {
SimpleFeatureType featureType;
final String[] datastoreFeatures = dataStore.getTypeNames();
if (Arrays.asList(datastoreFeatures).contains(FEATURE_NAME)) {
featureType = dataStore.getSchema(FEATURE_NAME);
} else {
final String featureSchema = SUBJECT_ATTRIBUTE + ":String," //
+ PREDICATE_ATTRIBUTE + ":String," //
+ OBJECT_ATTRIBUTE + ":String," //
+ CONTEXT_ATTRIBUTE + ":String," //
+ GEOMETRY_ATTRIBUTE + ":Geometry:srid=4326;geomesa.mixed.geometries='true'";
featureType = SimpleFeatureTypes.createType(FEATURE_NAME, featureSchema);
dataStore.createSchema(featureType);
}
return featureType;
}
示例6: testEmpty
import org.geotools.data.DataStore; //導入方法依賴的package包/類
public void testEmpty()
throws Exception {
final SimpleFeatureType type = DataUtilities.createType(
"GeoWaveFeatureSourceTest_e",
"geometry:Geometry:srid=4326,pop:java.lang.Long,pid:String,when:Date");
final DataStore dataStore = createDataStore();
dataStore.createSchema(type);
final SimpleFeatureSource source = dataStore.getFeatureSource("GeoWaveFeatureSourceTest_e");
final ReferencedEnvelope env = source.getBounds();
assertEquals(
90.0,
env.getMaxX(),
0.0001);
assertEquals(
-180.0,
env.getMinY(),
0.0001);
final Query query = new Query(
"GeoWaveFeatureSourceTest_e",
Filter.INCLUDE);
assertEquals(
0,
source.getCount(query));
}
示例7: addSchemaToStore
import org.geotools.data.DataStore; //導入方法依賴的package包/類
public static void addSchemaToStore(DataStore store, String typeName, Map<String, Class> attributes) throws IOException {
SimpleFeatureTypeBuilder typeBuilder = new SimpleFeatureTypeBuilder();
typeBuilder.setName(typeName);
for(String propName : attributes.keySet()) {
typeBuilder.add(propName, attributes.get(propName));
}
store.createSchema(typeBuilder.buildFeatureType());
}
示例8: exportGeometriesToShapeFile
import org.geotools.data.DataStore; //導入方法依賴的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();
}
}
示例9: exportToShapefileForceWGS84
import org.geotools.data.DataStore; //導入方法依賴的package包/類
public static void exportToShapefileForceWGS84(DataStore newDataStore, FeatureCollection<SimpleFeatureType,SimpleFeature> featureCollection)/*,SimpleFeatureType ftype)*/ throws Exception {
// carefully open an iterator and writer to process the results
Transaction transaction = new DefaultTransaction();
//CoordinateReferenceSystem crsOrig=featureCollection.getSchema().getCoordinateReferenceSystem();
//set wgs84 coordinates ref sys
SimpleFeatureType featureType = SimpleFeatureTypeBuilder.retype(featureCollection.getSchema(), DefaultGeographicCRS.WGS84);
newDataStore.createSchema(featureType);
FeatureWriter<SimpleFeatureType, SimpleFeature> writer = newDataStore.getFeatureWriter(newDataStore.getTypeNames()[0], transaction);
//create the transformation
MathTransform trans=CRS.findMathTransform(CRS.parseWKT(WKTString.WKT3995_ESRI),DefaultGeographicCRS.WGS84);
FeatureIterator<SimpleFeature> iterator = featureCollection.features();
try {
while( iterator.hasNext() ){
SimpleFeature feature = iterator.next();
SimpleFeature copy = writer.next();
Geometry geometry = (Geometry) feature.getDefaultGeometry();
geometry=JTS.transform(geometry,trans);
if(geometry!=null){
copy.setDefaultGeometry( geometry.buffer(0));
writer.write();
}else{
logger.warn("Warning:geometry null");
}
}
transaction.commit();
logger.info("Export to shapefile complete" );
} catch (Exception problem) {
problem.printStackTrace();
transaction.rollback();
logger.error("Export to shapefile failed",problem );
} finally {
writer.close();
iterator.close();
transaction.close();
}
}
示例10: importDataIntoStore
import org.geotools.data.DataStore; //導入方法依賴的package包/類
/**
*
* @param features
* @param name
* @param storeInfo
* @return
* @throws IOException
* @throws ProcessException
*/
private SimpleFeatureType importDataIntoStore(SimpleFeatureCollection features, String name,
DataStoreInfo storeInfo) throws IOException, ProcessException {
SimpleFeatureType targetType;
// grab the data store
DataStore ds = (DataStore) storeInfo.getDataStore(null);
// decide on the target ft name
SimpleFeatureType sourceType = features.getSchema();
if (name != null) {
SimpleFeatureTypeBuilder tb = new SimpleFeatureTypeBuilder();
tb.init(sourceType);
tb.setName(name);
sourceType = tb.buildFeatureType();
}
// create the schema
ds.createSchema(sourceType);
// try to get the target feature type (might have slightly different
// name and structure)
targetType = ds.getSchema(sourceType.getTypeName());
if (targetType == null) {
// ouch, the name was changed... we can only guess now...
// try with the typical Oracle mangling
targetType = ds.getSchema(sourceType.getTypeName().toUpperCase());
}
if (targetType == null) {
throw new WPSException(
"The target schema was created, but with a name "
+ "that we cannot relate to the one we provided the data store. Cannot proceeed further");
} else {
// check the layer is not already there
String newLayerName = storeInfo.getWorkspace().getName() + ":"
+ targetType.getTypeName();
LayerInfo layer = this.catalog.getLayerByName(newLayerName);
// todo: we should not really reach here and know beforehand what the targetType
// name is, but if we do we should at least get a way to drop it
if (layer != null) {
throw new ProcessException("Target layer " + newLayerName
+ " already exists in the catalog");
}
}
// try to establish a mapping with old and new attributes. This is again
// just guesswork until we have a geotools api that will give us the
// exact mapping to be performed
Map<String, String> mapping = buildAttributeMapping(sourceType, targetType);
// start a transaction and fill the target with the input features
Transaction t = new DefaultTransaction();
SimpleFeatureStore fstore = (SimpleFeatureStore) ds.getFeatureSource(targetType.getTypeName());
fstore.setTransaction(t);
SimpleFeatureIterator fi = features.features();
SimpleFeatureBuilder fb = new SimpleFeatureBuilder(targetType);
while (fi.hasNext()) {
SimpleFeature source = fi.next();
fb.reset();
for (String sname : mapping.keySet()) {
fb.set(mapping.get(sname), source.getAttribute(sname));
}
SimpleFeature target = fb.buildFeature(null);
fstore.addFeatures(DataUtilities.collection(target));
}
t.commit();
t.close();
return targetType;
}
示例11: writeFeatureCollection
import org.geotools.data.DataStore; //導入方法依賴的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;
}
示例12: exportToShapefile
import org.geotools.data.DataStore; //導入方法依賴的package包/類
/**
* Export features to a new shapefile using the map projection in which they are currently
* displayed
*/
// docs start export
private void exportToShapefile() throws Exception {
SimpleFeatureType schema = featureSource.getSchema();
JFileDataStoreChooser chooser = new JFileDataStoreChooser("shp");
chooser.setDialogTitle("Save reprojected shapefile");
chooser.setSaveFile(sourceFile);
int returnVal = chooser.showSaveDialog(null);
if (returnVal != JFileDataStoreChooser.APPROVE_OPTION) {
return;
}
File file = chooser.getSelectedFile();
if (file.equals(sourceFile)) {
JOptionPane.showMessageDialog(null, "Cannot replace " + file);
return;
}
// set up the math transform used to process the data
CoordinateReferenceSystem dataCRS = schema.getCoordinateReferenceSystem();
CoordinateReferenceSystem worldCRS = map.getCoordinateReferenceSystem();
boolean lenient = true; // allow for some error due to different datums
MathTransform transform = CRS.findMathTransform(dataCRS, worldCRS, lenient);
// grab all features
SimpleFeatureCollection featureCollection = featureSource.getFeatures();
// And create a new Shapefile with a slight modified schema
DataStoreFactorySpi factory = new ShapefileDataStoreFactory();
Map<String, Serializable> create = new HashMap<String, Serializable>();
create.put("url", file.toURI().toURL());
create.put("create spatial index", Boolean.TRUE);
DataStore dataStore = factory.createNewDataStore(create);
SimpleFeatureType featureType = SimpleFeatureTypeBuilder.retype(schema, worldCRS);
dataStore.createSchema(featureType);
// carefully open an iterator and writer to process the results
Transaction transaction = new DefaultTransaction("Reproject");
FeatureWriter<SimpleFeatureType, SimpleFeature> writer =
dataStore.getFeatureWriterAppend(featureType.getTypeName(), transaction);
SimpleFeatureIterator iterator = featureCollection.features();
try {
while (iterator.hasNext()) {
// copy the contents of each feature and transform the geometry
SimpleFeature feature = iterator.next();
SimpleFeature copy = writer.next();
copy.setAttributes(feature.getAttributes());
Geometry geometry = (Geometry) feature.getDefaultGeometry();
Geometry geometry2 = JTS.transform(geometry, transform);
copy.setDefaultGeometry(geometry2);
writer.write();
}
transaction.commit();
JOptionPane.showMessageDialog(null, "Export to shapefile complete");
} catch (Exception problem) {
problem.printStackTrace();
transaction.rollback();
JOptionPane.showMessageDialog(null, "Export to shapefile failed");
} finally {
writer.close();
iterator.close();
transaction.close();
}
}
示例13: populate
import org.geotools.data.DataStore; //導入方法依賴的package包/類
public void populate(
final SimpleFeatureType type,
final DataStore dataStore )
throws IOException,
CQLException,
ParseException {
dataStore.createSchema(type);
final Transaction transaction1 = new DefaultTransaction();
final FeatureWriter<SimpleFeatureType, SimpleFeature> writer = dataStore.getFeatureWriter(
type.getTypeName(),
transaction1);
assertFalse(writer.hasNext());
SimpleFeature newFeature = writer.next();
newFeature.setAttribute(
"pop",
Long.valueOf(77));
newFeature.setAttribute(
"pid",
UUID.randomUUID().toString());
newFeature.setAttribute(
"when",
DateUtilities.parseISO("2005-05-19T20:32:56Z"));
newFeature.setAttribute(
"geometry",
factory.createPoint(new Coordinate(
43.454,
28.232)));
writer.write();
newFeature = writer.next();
newFeature.setAttribute(
"pop",
Long.valueOf(66));
newFeature.setAttribute(
"pid",
UUID.randomUUID().toString());
newFeature.setAttribute(
"when",
DateUtilities.parseISO("2005-05-18T20:32:56Z"));
newFeature.setAttribute(
"geometry",
factory.createPoint(new Coordinate(
43.454,
27.232)));
writer.write();
newFeature = writer.next();
newFeature.setAttribute(
"pop",
Long.valueOf(100));
newFeature.setAttribute(
"pid",
UUID.randomUUID().toString());
newFeature.setAttribute(
"when",
DateUtilities.parseISO("2005-05-17T20:32:56Z"));
newFeature.setAttribute(
"geometry",
factory.createPoint(new Coordinate(
43.454,
28.242)));
writer.write();
writer.close();
transaction1.commit();
transaction1.close();
}