本文整理汇总了Java中org.geotools.data.DataUtilities类的典型用法代码示例。如果您正苦于以下问题:Java DataUtilities类的具体用法?Java DataUtilities怎么用?Java DataUtilities使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
DataUtilities类属于org.geotools.data包,在下文中一共展示了DataUtilities类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createSampleFeature
import org.geotools.data.DataUtilities; //导入依赖的package包/类
/**
* Creates a sample Feature instance in the hope that it can be used in the rendering of the
* legend graphic.
*
* @param schema the schema for which to create a sample Feature instance
*
*
*
* @throws ServiceException
*/
private Feature createSampleFeature(FeatureType schema) throws ServiceException {
Feature sampleFeature;
try {
if (schema instanceof SimpleFeatureType) {
if (hasMixedGeometry((SimpleFeatureType) schema)) {
// we can't create a sample for a generic Geometry type
sampleFeature = null;
} else {
sampleFeature = SimpleFeatureBuilder.template((SimpleFeatureType) schema, null);
}
} else {
sampleFeature = DataUtilities.templateFeature(schema);
}
} catch (IllegalAttributeException e) {
throw new ServiceException(e);
}
return sampleFeature;
}
示例2: run
import org.geotools.data.DataUtilities; //导入依赖的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: buildGdeltFeatureType
import org.geotools.data.DataUtilities; //导入依赖的package包/类
/**
* Builds the feature type for the GDELT data set
*
* @param featureName
* @return
* @throws SchemaException
*/
public static SimpleFeatureType buildGdeltFeatureType(String featureName) throws SchemaException {
List<String> attributes = new ArrayList<String>();
for (Attributes attribute : Attributes.values()) {
if (attribute == Attributes.geom) {
// set geom to be the default geometry for geomesa by adding a *
attributes.add("*geom:Point:srid=4326");
} else {
attributes.add(attribute.name() + ":" + attribute.getType());
}
}
String spec = Joiner.on(",").join(attributes);
SimpleFeatureType featureType = DataUtilities.createType(featureName, spec);
//This tells GeoMesa to use this Attribute as the Start Time index
featureType.getUserData().put(SimpleFeatureTypes.DEFAULT_DATE_KEY, Attributes.SQLDATE.name());
return featureType;
}
示例4: getStatementFeatureType
import org.geotools.data.DataUtilities; //导入依赖的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: OSMInfo
import org.geotools.data.DataUtilities; //导入依赖的package包/类
public OSMInfo(final URL url, final long modificationStamp) {
super(modificationStamp);
CoordinateReferenceSystem crs = null;
ReferencedEnvelope env2 = new ReferencedEnvelope();
int number = 0;
try {
final File f = new File(url.toURI());
final GamaOsmFile osmfile = new GamaOsmFile(null, f.getAbsolutePath());
attributes.putAll(osmfile.getOSMAttributes(GAMA.getRuntimeScope()));
final SimpleFeatureType TYPE = DataUtilities.createType("geometries", "geom:LineString");
final ArrayList<SimpleFeature> list = new ArrayList<SimpleFeature>();
for (final IShape shape : osmfile.iterable(null)) {
list.add(SimpleFeatureBuilder.build(TYPE, new Object[] { shape.getInnerGeometry() }, null));
}
final SimpleFeatureCollection collection = new ListFeatureCollection(TYPE, list);
final SimpleFeatureSource featureSource = DataUtilities.source(collection);
env2 = featureSource.getBounds();
number = osmfile.nbObjects;
crs = osmfile.getOwnCRS(null);
} catch (final Exception e) {
System.out.println("Error in reading metadata of " + url);
hasFailed = true;
} finally {
// approximation of the width and height in meters.
width = env2 != null ? env2.getWidth() * (FastMath.PI / 180) * 6378137 : 0;
height = env2 != null ? env2.getHeight() * (FastMath.PI / 180) * 6378137 : 0;
itemNumber = number;
this.crs = crs;
}
}
示例6: initType
import org.geotools.data.DataUtilities; //导入依赖的package包/类
private synchronized void initType() {
if (featureType == null
|| !featureType.getName().getLocalPart()
.equals(dataStoreTypeName)) {
try {
featureType = DataUtilities
.createType(
dataStoreTypeName,
"envelope:com.vividsolutions.jts.geom.Polygon,id:java.lang.Long,queryString:String,path:String,startTime:Date,"
+ "endTime:Date,totalTime:java.lang.Long,BodyAsString:String,BodyContentLength:java.lang.Long,"
+ "Host:String,ErrorMessage:String,HttpMethod:String,HttpReferer:String,InternalHost:String,"
+ "Operation:String,OwsVersion:String,QueryString:String,RemoteAddr:String,RemoteCity:String,"
+ "RemoteCountry:String,RemoteHost:String,RemoteLat:double,"
+ "RemoteLon:double,RemoteUser:String,RemoteUserAgent:String,Resources:String,"
+ "ResponseContentType:String,ResponseLength:java.lang.Long,ResponseStatus:int,"
+ "Service:String,SubOperation:String,Status:String,Category:String");
} catch (SchemaException e) {
LOGGER.log(Level.SEVERE, "Failed to initialized feature type",
e);
}
}
}
示例7: createCollection
import org.geotools.data.DataUtilities; //导入依赖的package包/类
/**
* Create a SimpleFeatureCollection with a Geometry
*
* @param all
* @return
* @throws SchemaException
*/
public static SimpleFeatureCollection createCollection(Geometry g) throws SchemaException {
SimpleFeatureCollection collection = FeatureCollections.newCollection();
SimpleFeatureType TYPE = DataUtilities.createType("MBB", "location:Polygon:srid=4326"); // 4326
// =
// srid
// of
// wgs84
SimpleFeatureBuilder featureBuilder = new SimpleFeatureBuilder(TYPE);
featureBuilder.add(g);
SimpleFeature feature = featureBuilder.buildFeature(null);
collection.add(feature);
return collection;
}
示例8: createFeatureType
import org.geotools.data.DataUtilities; //导入依赖的package包/类
private SimpleFeatureType createFeatureType(GeometryType geometryType) throws Exception {
String schema = null;
switch(geometryType) {
case POINT:
schema = "the_geom:Point:srid=4326," + dataSchema;
break;
case MULTIPOLYGON:
schema = "the_geom:MultiPolygon:srid=4326," + dataSchema;
break;
}
try {
return DataUtilities.createType(geometryType.name().toLowerCase(), schema);
} catch (SchemaException e) {
throw new Exception("Failed to create feature types for shapefile export", e);
}
}
示例9: writeShapefile
import org.geotools.data.DataUtilities; //导入依赖的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();
}
}
示例10: getInstanceOfCountry
import org.geotools.data.DataUtilities; //导入依赖的package包/类
public static SimpleFeature getInstanceOfCountry() throws Exception {
if (COUNTRY != null) {
return COUNTRY;
}
final SimpleFeatureType type = DataUtilities.createType("Location",
"geometry:Polygon:srid=4326," + "countryName:String," + "population:Integer,"
+ "principalMineralResource:String");
SimpleFeatureBuilder featureBuilder = new SimpleFeatureBuilder(type);
WKTReader reader = new WKTReader();
MultiPolygon geometry = (MultiPolygon) reader.read(usaGeometry());
featureBuilder.add(geometry);
featureBuilder.add("USA");
featureBuilder.add(307006550);
featureBuilder.add("oil");
COUNTRY = featureBuilder.buildFeature(null);
return COUNTRY;
}
示例11: rawSchemaExample
import org.geotools.data.DataUtilities; //导入依赖的package包/类
private void rawSchemaExample() throws Exception {
Name typeName = null;
URL schemaLocation = null;
CoordinateReferenceSystem crs = null;
// rawSchemaExample start
// assume we are working from WFS 1.1 / GML3 / etc...
final QName featureName = new QName(typeName.getNamespaceURI(), typeName.getLocalPart());
String namespaceURI = featureName.getNamespaceURI();
String uri = schemaLocation.toExternalForm();
Configuration wfsConfiguration = new org.geotools.gml3.ApplicationSchemaConfiguration(
namespaceURI, uri);
FeatureType parsed = GTXML.parseFeatureType(wfsConfiguration, featureName, crs);
// safely cast down to SimpleFeatureType
SimpleFeatureType schema = DataUtilities.simple(parsed);
// rawSchemaExample end
}
示例12: write
import org.geotools.data.DataUtilities; //导入依赖的package包/类
@Override
public void write(
final DataOutput output )
throws IOException {
output
.writeUTF(featureType.getName().getNamespaceURI() == null ? "-" : featureType
.getName()
.getNamespaceURI());
output.writeUTF(featureType.getTypeName());
output.writeUTF(DataUtilities.encodeType(featureType));
output.writeUTF(FeatureDataUtils.getAxis(featureType.getCoordinateReferenceSystem()));
// write feature id
output.writeUTF(feature.getID());
// write the attributes
for (final AttributeDescriptor ad : featureType.getAttributeDescriptors()) {
final Object value = feature.getAttribute(ad.getLocalName());
writeAttribute(
output,
ad,
value);
}
}
示例13: setup
import org.geotools.data.DataUtilities; //导入依赖的package包/类
@Before
public void setup()
throws SchemaException,
CQLException,
IOException,
GeoWavePluginException {
dataStore = createDataStore();
type = DataUtilities.createType(
"geostuff",
"geometry:Geometry:srid=4326,pop:java.lang.Long,pid:String,when:Date");
type.getDescriptor(
"when").getUserData().put(
"time",
false);
dataStore.createSchema(type);
}
示例14: setup
import org.geotools.data.DataUtilities; //导入依赖的package包/类
@Before
public void setup()
throws SchemaException,
CQLException,
IOException,
GeoWavePluginException {
dataStore = createDataStore();
type = DataUtilities.createType(
"geostuff",
"geometry:Geometry:srid=4326,pop:java.lang.Long,when:Date,pid:String");
dataStore.createSchema(type);
query = new Query(
"geostuff",
CQL
.toFilter("BBOX(geometry,27.20,41.30,27.30,41.20) and when during 2005-05-19T20:32:56Z/2005-05-19T21:32:56Z"),
new String[] {
"geometry",
"pid"
});
}
示例15: testEmpty
import org.geotools.data.DataUtilities; //导入依赖的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));
}