本文整理了Java中org.geotools.util.Converters
类的一些代码示例,展示了Converters
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Converters
类的具体详情如下:
包路径:org.geotools.util.Converters
类名称:Converters
[英]Convenience class for converting an object from one type to an object of another.
[中]用于将对象从一种类型转换为另一种类型的对象的便利类。
代码示例来源:origin: geoserver/geoserver
@Override
public <T> T evaluate(Object object, Class<T> context) {
// Selection of the first expression
Expression clazzExpression = parameters.get(0);
// Getting the defined class
Class clazz = clazzExpression.evaluate(object, Class.class);
// Checking the result
boolean result = false;
// If the input class is Object, the function always returns true
if (clazz != null) {
if (clazz == Object.class) {
result = true;
} else {
// Otherwise the function checks if the class is an instance of the
// input class
result = clazz.isAssignableFrom(object.getClass());
}
}
// Finally the result is converted to the defined context class
return Converters.convert(result, context);
}
代码示例来源:origin: geotools/geotools
/**
* Uses {@link Converters} to parse the provided text into the correct values to create a
* feature.
*
* @param type FeatureType
* @param fid Feature ID for new feature
* @param text Text representation of values
* @return newly created feature
* @throws IllegalAttributeException
*/
public static SimpleFeature parse(SimpleFeatureType type, String fid, String[] text)
throws IllegalAttributeException {
Object[] attributes = new Object[text.length];
for (int i = 0; i < text.length; i++) {
AttributeType attType = type.getDescriptor(i).getType();
attributes[i] = Converters.convert(text[i], attType.getBinding());
}
return SimpleFeatureBuilder.build(type, attributes, fid);
}
代码示例来源:origin: geotools/geotools
@Test
public void testContrastDarkLigthReference() {
Function function =
FF.function(
"contrast",
FF.literal("#222222"),
FF.literal("#101010"),
FF.literal("#dddddd"));
Color result = (Color) function.evaluate(null);
assertEquals("#DDDDDD", Converters.convert(result, String.class));
}
代码示例来源:origin: geotools/geotools
private void doSetAttribute(AttributeDescriptor d, Object o) {
if (d instanceof GeometryDescriptor) {
MongoUtil.setDBOValue(
featureDBO, mapper.getGeometryPath(), mapper.toObject((Geometry) o));
} else {
MongoUtil.setDBOValue(
featureDBO,
mapper.getPropertyPath(d.getLocalName()),
Converters.convert(o, d.getType().getBinding()));
}
}
代码示例来源:origin: geotools/geotools
throws IllegalArgumentException {
if (value == null) {
if (descriptor.isNillable()) {
return descriptor.getDefaultValue();
Class target = descriptor.getType().getBinding();
if (!target.isAssignableFrom(value.getClass())) {
Object converted = Converters.convert(value, target);
if (converted != null) {
return converted;
代码示例来源:origin: geoserver/geoserver
public void modifyFeatures(AttributeDescriptor[] type, Object[] values, Filter filter)
throws IOException {
SimpleFeatureType original = typeMap.getOriginalFeatureType();
// map back attribute types and values to the original values
AttributeDescriptor[] originalTypes = new AttributeDescriptor[type.length];
Object[] originalValues = new Object[values.length];
for (int i = 0; i < values.length; i++) {
originalTypes[i] = original.getDescriptor(type[i].getName());
if (values[i] != null) {
Class<?> target = originalTypes[i].getType().getBinding();
originalValues[i] = Converters.convert(values[i], target);
if (originalValues[i] == null)
throw new IOException("Could not map back " + values[i] + " to type " + target);
}
}
featureStore()
.modifyFeatures(originalTypes, originalValues, store.retypeFilter(filter, typeMap));
}
代码示例来源:origin: geotools/geotools
double data0 = workingPoints.get(0).data.evaluate(object, Double.class);
double data1 = workingPoints.get(1).data.evaluate(object, Double.class);
workingPoints.add(
0, new InterpPoint(ff2.literal(2 * data0 - data1), workingPoints.get(0).value));
segment++;
double data0 = workingPoints.get(segment).data.evaluate(object, Double.class);
double data1 = workingPoints.get(segment - 1).data.evaluate(object, Double.class);
workingPoints.add(
new InterpPoint(
ff2.literal(2 * data0 - data1), workingPoints.get(segment).value));
return Converters.convert(interpolated, context);
代码示例来源:origin: geoserver/geoserver
/**
* returns the value asociated with <code>key</code> on the set of key/value pairs of this
* request reader
*
* @param key DOCUMENT ME!
* @return DOCUMENT ME!
*/
protected String getValue(String key) {
return Converters.convert(kvpPairs.get(key), String.class);
}
代码示例来源:origin: geotools/geotools
Double value = lookupExp.evaluate(object, Double.class);
if (value == null) {
value = Converters.convert(object, Double.class);
convertedValues = new Object[values.length];
for (int i = 0; i < convertedValues.length; i++) {
convertedValues[i] = values[i].evaluate(object, context);
return (T) convertedValues[valIdx];
} else {
return values[valIdx].evaluate(object, context);
isIncludedInThreshold = ff.greater(lookupExp, threshholdExp);
} else {
isIncludedInThreshold = ff.greaterOrEqual(lookupExp, threshholdExp);
代码示例来源:origin: geotools/geotools
/**
* Allows this Attribute to convert an argument to its prefered storage type. If no parsing is
* possible, returns the original value. If a parse is attempted, yet fails (i.e. a poor decimal
* format) throw the Exception. This is mostly for use internally in Features, but implementors
* should simply follow the rules to be safe.
*
* @param value the object to attempt parsing of.
* @return <code>value</code> converted to the preferred storage of this <code>AttributeType
* </code>. If no parsing was possible then the same object is returned.
* @throws IllegalArgumentException if parsing is attempted and is unsuccessful.
*/
protected Object parse(Object value) throws IllegalArgumentException {
if (value != null) {
Class target = getType().getBinding();
if (!target.isAssignableFrom(value.getClass())) {
// attempt to convert
Object converted = Converters.convert(value, target);
if (converted != null) {
value = converted;
}
}
}
return value;
}
}
代码示例来源:origin: geotools/geotools
public void testAfterInstant() throws Exception {
Date date = convert("2002-12-03 10:00:00AM", Date.class);
DefaultInstant instant = new DefaultInstant(new DefaultPosition(date));
Expression literal = filterFac.literal(instant);
Expression prop =
filterFac.property(timestampFType.getAttributeDescriptors().get(0).getLocalName());
PropertyIsEqualTo filter = filterFac.equals(prop, literal);
encoder.setFeatureType(timestampFType);
encoder.encode(filter);
LOGGER.fine("testAttr is a Timestamp " + filter + " -> " + output.getBuffer().toString());
assertEquals(output.getBuffer().toString(), "WHERE testAttr = '2002-12-03 10:00:00.0'");
}
代码示例来源:origin: geotools/geotools
@Override
public Object visit(PropertyIsBetween filter, Object extraData) {
BasicDBObject output = asDBObject(extraData);
String propName = convert(filter.getExpression().accept(this, null), String.class);
Object lower = filter.getLowerBoundary().accept(this, getValueType(filter.getExpression()));
Object upper = filter.getUpperBoundary().accept(this, getValueType(filter.getExpression()));
BasicDBObject dbo = new BasicDBObject();
dbo.put("$gte", lower);
dbo.put("$lte", upper);
output.put(propName, dbo);
return output;
}
代码示例来源:origin: org.geoserver/gs-wms
@Override
public Object getDefaultValue(
ResourceInfo resource, String dimensionName, DimensionInfo dimension, Class clz) {
String attrName = dimension.getAttribute();
Class<?> attrType = String.class;
if (resource instanceof FeatureTypeInfo) {
List<AttributeTypeInfo> attrTypes;
try {
attrTypes = ((FeatureTypeInfo) resource).attributes();
for (AttributeTypeInfo attr : attrTypes) {
if (attr.getName().equals(attrName)) {
attrType = attr.getBinding();
break;
}
}
} catch (IOException e) {
}
}
final FeatureCalc nearest =
new NearestVisitor(ff.property(dimension.getAttribute()), this.toMatch);
CalcResult res = getCalculatedResult((FeatureTypeInfo) resource, dimension, nearest);
if (res.equals(CalcResult.NULL_RESULT)) {
return null;
} else {
return Converters.convert(res.getValue(), clz);
}
}
代码示例来源:origin: geotools/geotools
/**
* Processed the {@link ConverterFactory} extension point.
*
* @return A collection of converter factories.
* @since 2.4
*/
static ConverterFactory[] factories() {
if (factories == null) {
Collection<ConverterFactory> factoryCollection =
getConverterFactories(GeoTools.getDefaultHints());
factories =
(ConverterFactory[])
factoryCollection.toArray(
new ConverterFactory[factoryCollection.size()]);
}
return factories;
}
}
代码示例来源:origin: geotools/geotools
/**
* Returns a set of all available {@link ConverterFactory}'s which can handle convert from the
* source to destination class.
*
* <p>This method essentially returns all factories in which the following returns non null.
*
* <pre>
* factory.createConverter( source, target );
* </pre>
*
* @since 2.5
*/
public static Set<ConverterFactory> getConverterFactories(Class<?> source, Class<?> target) {
HashSet<ConverterFactory> factories = new HashSet<ConverterFactory>();
for (ConverterFactory factory : factories()) {
if (factory.createConverter(source, target, null) != null) {
factories.add(factory);
}
}
return factories;
}
代码示例来源:origin: geotools/geotools
public void setAttribute(int index, Object value) throws IndexOutOfBoundsException {
// first do conversion
Object converted =
Converters.convert(
value, getFeatureType().getDescriptor(index).getType().getBinding());
// if necessary, validation too
if (validating) Types.validate(featureType.getDescriptor(index), converted);
// finally set the value into the feature
values[index] = converted;
}
代码示例来源:origin: geotools/geotools
@Test
public void testMix() {
Function function =
FF.function("mix", FF.literal("#ff0000"), FF.literal("#0000ff"), FF.literal("50%"));
Color result = (Color) function.evaluate(null);
assertEquals("#800080", Converters.convert(result, String.class));
}
代码示例来源:origin: geotools/geotools
public static SimpleFeature feature(SimpleFeatureType fType, String fid, Node node)
throws Exception {
SimpleFeatureBuilder b = new SimpleFeatureBuilder(fType);
int attributeCount = fType.getAttributeCount();
for (int i = 0; i < attributeCount; i++) {
AttributeDescriptor att = fType.getDescriptor(i);
AttributeType attType = att.getType();
Object attValue = node.getChildValue(att.getLocalName());
if ((attValue != null) && !attType.getBinding().isAssignableFrom(attValue.getClass())) {
// type mismatch, to try convert
Object converted = Converters.convert(attValue, attType.getBinding());
if (converted != null) {
attValue = converted;
}
}
b.add(attValue);
}
// create the feature
return b.buildFeature(fid);
}
代码示例来源:origin: geotools/geotools
if (attType.isNillable()) {
return null; // it was an explicit "<null>"
try {
Geometry geometry = wktReader.read(stringValue);
value = Converters.convert(geometry, attType.getType().getBinding());
} catch (ParseException e) {
value = Converters.convert(stringValue, attType.getType().getBinding());
代码示例来源:origin: geotools/geotools
polySymb.getStroke().setWidth(filterFactory.literal(size));
polySymb.getOptions().put(PolygonSymbolizer.GRAPHIC_MARGIN_KEY, "15");
PolygonSymbolizer rescaledPolySymb = (PolygonSymbolizer) visitor.getCopy();
double rescaledSize =
rescaledPolySymb.getStroke().getWidth().evaluate(null, Double.class);
.get(TextSymbolizer.GRAPHIC_MARGIN_KEY)
.split("\\s+");
int rescaledGraphicMargin = Converters.convert(splitted[0], Integer.class).intValue();
assertEquals(expectedGraphicMargin, rescaledGraphicMargin);
} catch (Exception e2) {
内容来源于网络,如有侵权,请联系作者删除!