本文整理汇总了Java中org.geotools.feature.simple.SimpleFeatureTypeBuilder.init方法的典型用法代码示例。如果您正苦于以下问题:Java SimpleFeatureTypeBuilder.init方法的具体用法?Java SimpleFeatureTypeBuilder.init怎么用?Java SimpleFeatureTypeBuilder.init使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.geotools.feature.simple.SimpleFeatureTypeBuilder
的用法示例。
在下文中一共展示了SimpleFeatureTypeBuilder.init方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createFeatureType
import org.geotools.feature.simple.SimpleFeatureTypeBuilder; //导入方法依赖的package包/类
public static SimpleFeatureType createFeatureType(
final SimpleFeatureType sceneType ) {
// initialize the feature type
final SimpleFeatureTypeBuilder typeBuilder = new SimpleFeatureTypeBuilder();
typeBuilder.init(sceneType);
typeBuilder.setName(BANDS_TYPE_NAME);
typeBuilder.add(
BAND_ATTRIBUTE_NAME,
String.class);
typeBuilder.add(
SIZE_ATTRIBUTE_NAME,
Float.class);
typeBuilder.add(
BAND_DOWNLOAD_ATTRIBUTE_NAME,
String.class);
final SimpleFeatureType bandType = typeBuilder.buildFeatureType();
return bandType;
}
示例2: addDateWithFormatToFeatureType
import org.geotools.feature.simple.SimpleFeatureTypeBuilder; //导入方法依赖的package包/类
private void addDateWithFormatToFeatureType(String format) {
SimpleFeatureTypeBuilder typeBuilder = new SimpleFeatureTypeBuilder();
typeBuilder.init(featureType);
AttributeDescriptor dateAtt = null;
AttributeTypeBuilder dateAttBuilder = new AttributeTypeBuilder();
dateAttBuilder.setName("dateAttrWithFormat");
dateAttBuilder.setBinding(Date.class);
dateAtt = dateAttBuilder.buildDescriptor("dateAttrWithFormat", dateAttBuilder.buildType());
dateAtt.getUserData().put(DATE_FORMAT, format);
typeBuilder.add(dateAtt);
featureType = typeBuilder.buildFeatureType();
setFilterBuilder();
}
示例3: alter
import org.geotools.feature.simple.SimpleFeatureTypeBuilder; //导入方法依赖的package包/类
SimpleFeatureSource alter(SimpleFeatureCollection collection, String typename,
SimpleFeatureType featureType, final List<AttributeDescriptor> newTypes) {
try {
// Create target schema
SimpleFeatureTypeBuilder buildType = new SimpleFeatureTypeBuilder();
buildType.init(featureType);
buildType.setName(typename);
buildType.addAll(newTypes);
final SimpleFeatureType schema = buildType.buildFeatureType();
// Configure memory datastore
final MemoryDataStore memory = new MemoryDataStore();
memory.createSchema(schema);
collection.accepts(new FeatureVisitor() {
public void visit(Feature feature) {
SimpleFeatureBuilder builder = new SimpleFeatureBuilder(schema);
builder.init((SimpleFeature) feature);
for (AttributeDescriptor descriptor : newTypes) {
builder.add(DataUtilities.defaultValue(descriptor));
}
SimpleFeature newFeature = builder.buildFeature(feature.getIdentifier().getID());
memory.addFeature(newFeature);
}
}, null);
return memory.getFeatureSource(typename);
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
示例4: setNamespace
import org.geotools.feature.simple.SimpleFeatureTypeBuilder; //导入方法依赖的package包/类
/**
* Sets the namespace of the reprojected feature type associated with this
* data adapter
*
* @param namespaceURI
* - new namespace URI
*/
public void setNamespace(
final String namespaceURI ) {
final SimpleFeatureTypeBuilder builder = new SimpleFeatureTypeBuilder();
builder.init(reprojectedFeatureType);
builder.setNamespaceURI(namespaceURI);
reprojectedFeatureType = builder.buildFeatureType();
}
示例5: addNewColumn
import org.geotools.feature.simple.SimpleFeatureTypeBuilder; //导入方法依赖的package包/类
/**
* Adds the new column.
*/
public void addNewColumn() {
if (featureCollection != null) {
String attributeName = getUniqueAttributeName();
columnList.add(attributeName);
// Populate field names
SimpleFeatureTypeBuilder featureTypeBuilder = new SimpleFeatureTypeBuilder();
featureTypeBuilder.init(featureCollection.getSchema());
featureTypeBuilder.add(attributeName, String.class);
SimpleFeatureType newFeatureType = featureTypeBuilder.buildFeatureType();
String typeName = userLayer.getInlineFeatureType().getTypeName();
try {
SimpleFeatureSource featureSource = userLayer.getInlineFeatureDatastore()
.getFeatureSource(typeName);
SimpleFeatureBuilder sfb = new SimpleFeatureBuilder(newFeatureType);
ArrayList<SimpleFeature> featureList = new ArrayList<SimpleFeature>();
SimpleFeatureIterator it = featureSource.getFeatures().features();
try {
while (it.hasNext()) {
SimpleFeature sf = it.next();
sfb.addAll(sf.getAttributes());
sfb.add(new String(""));
featureList.add(sfb.buildFeature(null));
}
} finally {
it.close();
}
SimpleFeatureCollection collection = new ListFeatureCollection(newFeatureType,
featureList);
featureCollection = collection;
cachedFeature = null;
lastRow = -1;
DataStore dataStore = DataUtilities.dataStore(collection);
userLayer.setInlineFeatureDatastore(dataStore);
userLayer.setInlineFeatureType(newFeatureType);
} catch (IOException e) {
ConsoleManager.getInstance().exception(this, e);
}
this.fireTableStructureChanged();
this.fireTableDataChanged();
if (parentObj != null) {
parentObj.inlineFeatureUpdated();
}
}
}
示例6: removeColumn
import org.geotools.feature.simple.SimpleFeatureTypeBuilder; //导入方法依赖的package包/类
/**
* Removes the column.
*
* @param columnName the column name
*/
public void removeColumn(String columnName) {
if (featureCollection != null) {
if (columnList.contains(columnName)) {
columnList.remove(columnName);
// Find field name to remote
SimpleFeatureTypeBuilder featureTypeBuilder = new SimpleFeatureTypeBuilder();
featureTypeBuilder.init(featureCollection.getSchema());
featureTypeBuilder.remove(columnName);
SimpleFeatureType newFeatureType = featureTypeBuilder.buildFeatureType();
int attributeToRemoveIndex = 0;
for (AttributeDescriptor descriptor : newFeatureType.getAttributeDescriptors()) {
if (descriptor.getLocalName().compareTo(columnName) == 0) {
break;
}
attributeToRemoveIndex++;
}
String typeName = userLayer.getInlineFeatureType().getTypeName();
try {
SimpleFeatureSource featureSource = userLayer.getInlineFeatureDatastore()
.getFeatureSource(typeName);
SimpleFeatureBuilder sfb = new SimpleFeatureBuilder(newFeatureType);
ArrayList<SimpleFeature> featureList = new ArrayList<SimpleFeature>();
SimpleFeatureIterator it = featureSource.getFeatures().features();
try {
while (it.hasNext()) {
SimpleFeature sf = it.next();
List<Object> attributes = sf.getAttributes();
attributes.remove(attributeToRemoveIndex);
sfb.addAll(attributes);
featureList.add(sfb.buildFeature(null));
}
} finally {
it.close();
}
SimpleFeatureCollection collection = new ListFeatureCollection(newFeatureType,
featureList);
featureCollection = collection;
cachedFeature = null;
lastRow = -1;
DataStore dataStore = DataUtilities.dataStore(collection);
userLayer.setInlineFeatureDatastore(dataStore);
userLayer.setInlineFeatureType(newFeatureType);
} catch (IOException e) {
ConsoleManager.getInstance().exception(this, e);
}
this.fireTableStructureChanged();
this.fireTableDataChanged();
if (parentObj != null) {
parentObj.inlineFeatureUpdated();
}
}
}
}
示例7: importDataIntoStore
import org.geotools.feature.simple.SimpleFeatureTypeBuilder; //导入方法依赖的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;
}
示例8: createStyledFeatureType
import org.geotools.feature.simple.SimpleFeatureTypeBuilder; //导入方法依赖的package包/类
public static SimpleFeatureType createStyledFeatureType(SimpleFeatureType type) {
SimpleFeatureTypeBuilder sftb = new SimpleFeatureTypeBuilder();
sftb.init(type);
sftb.add(PlainFeatureFactory.ATTRIB_NAME_STYLE_CSS, String.class);
return sftb.buildFeatureType();
}
示例9: decodeType
import org.geotools.feature.simple.SimpleFeatureTypeBuilder; //导入方法依赖的package包/类
public static SimpleFeatureType decodeType(
final String nameSpace,
final String typeName,
final String typeDescriptor,
final String axis )
throws SchemaException {
SimpleFeatureType featureType = (nameSpace != null) && (nameSpace.length() > 0) ? DataUtilities.createType(
nameSpace,
typeName,
typeDescriptor) : DataUtilities.createType(
typeName,
typeDescriptor);
final String lCaseAxis = axis.toLowerCase(Locale.ENGLISH);
final CoordinateReferenceSystem crs = featureType.getCoordinateReferenceSystem();
final String typeAxis = getAxis(crs);
// Default for EPSG:4326 is lat/long, If the provided type was
// long/lat, then re-establish the order
if ((crs != null) && crs.getIdentifiers().toString().contains(
"EPSG:4326") && !lCaseAxis.equalsIgnoreCase(typeAxis)) {
final SimpleFeatureTypeBuilder builder = new SimpleFeatureTypeBuilder();
builder.init(featureType);
try {
// truely no way to force lat first
// but it is the default in later versions of GeoTools.
// this all depends on the authority at the time of creation
featureType = SimpleFeatureTypeBuilder.retype(
featureType,
CRS.decode(
"EPSG:4326",
lCaseAxis.equals("east")));
}
catch (final FactoryException e) {
throw new SchemaException(
"Cannot decode EPSG:4326",
e);
}
}
return featureType;
}