use of org.opengis.filter.Expression in project geotoolkit by Geomatys.
the class CachedTextSymbolizer method evaluate.
@Override
protected void evaluate() {
if (!isNotEvaluated)
return;
final Expression expLabel = styleElement.getLabel();
// we can not know so always visible
isStaticVisible = VisibilityState.VISIBLE;
if (GO2Utilities.isStatic(expLabel)) {
label = GO2Utilities.evaluate(expLabel, null, String.class, "No Label");
} else {
label = null;
GO2Utilities.getRequieredAttributsName(expLabel, requieredAttributs);
isStatic = false;
}
cachedFont.getRequieredAttributsName(requieredAttributs);
cachedFill.getRequieredAttributsName(requieredAttributs);
cachedHalo.getRequieredAttributsName(requieredAttributs);
cachedPlacement.getRequieredAttributsName(requieredAttributs);
// no attributs needed replace with static empty list.
if (requieredAttributs.isEmpty()) {
requieredAttributs = EMPTY_ATTRIBUTS;
}
isNotEvaluated = false;
}
use of org.opengis.filter.Expression in project geotoolkit by Geomatys.
the class JAXPStreamValueCollectionWriter method writeFeature.
/**
* Write the feature into the stream.
*
* @param feature The feature
* @throws XMLStreamException
*/
private void writeFeature(final Feature feature) throws XMLStreamException {
final FeatureType type = feature.getType();
// write properties in the type order
Expression exp = FilterUtilities.FF.property(valueReference);
Object valueA = exp.apply(feature);
if (valueA instanceof Collection) {
for (Object value : (Collection) valueA) {
writer.writeStartElement("wfs", "member", WFS_NAMESPACE);
writeValue(value);
writer.writeEndElement();
}
} else if (valueA instanceof Map) {
final Map<?, ?> map = (Map) valueA;
for (Map.Entry<?, ?> entry : map.entrySet()) {
writer.writeStartElement("wfs", "member", WFS_NAMESPACE);
final Object key = entry.getKey();
if (key != null) {
writer.writeAttribute("name", (String) key);
}
writeValue(entry.getValue());
writer.writeEndElement();
}
} else if (valueA != null && valueA.getClass().isArray()) {
final int length = Array.getLength(valueA);
for (int i = 0; i < length; i++) {
writer.writeStartElement("wfs", "member", WFS_NAMESPACE);
final Object value = Array.get(valueA, i);
final String textValue;
if (value != null && value.getClass().isArray()) {
// matrix
final StringBuilder sb = new StringBuilder();
final int length2 = Array.getLength(value);
for (int j = 0; j < length2; j++) {
final Object subValue = Array.get(value, j);
sb.append(Utils.getStringValue(subValue)).append(" ");
}
textValue = sb.toString();
} else {
textValue = Utils.getStringValue(value);
}
writer.writeCharacters(textValue);
writer.writeEndElement();
}
} else if (valueA instanceof org.locationtech.jts.geom.Geometry) {
writer.writeStartElement("wfs", "member", WFS_NAMESPACE);
AbstractGeometry gmlGeometry = null;
try {
gmlGeometry = JTStoGeometry.toGML("3.2.1", (org.locationtech.jts.geom.Geometry) valueA, FeatureExt.getCRS(type));
} catch (FactoryException ex) {
LOGGER.log(Level.WARNING, "Factory exception when transforming JTS geometry to GML binding", ex);
}
final JAXBElement element = GML32_FACTORY.buildAnyGeometry(gmlGeometry);
try {
final Marshaller marshaller;
marshaller = GML_32_POOL.acquireMarshaller();
marshaller.setProperty(Marshaller.JAXB_FRAGMENT, true);
marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, false);
marshal(marshaller, element);
GML_32_POOL.recycle(marshaller);
} catch (JAXBException ex) {
LOGGER.log(Level.WARNING, "JAXB Exception while marshalling the iso geometry: " + ex.getMessage(), ex);
}
writer.writeEndElement();
} else {
String value = Utils.getStringValue(valueA);
if (value != null) {
writer.writeStartElement("wfs", "member", WFS_NAMESPACE);
writeValue(value);
writer.writeEndElement();
}
}
}
use of org.opengis.filter.Expression in project geotoolkit by Geomatys.
the class XmlFeatureTest method testWriteSimpleFeaturePrimitiveWithAtts.
@Test
public void testWriteSimpleFeaturePrimitiveWithAtts() throws JAXBException, IOException, XMLStreamException, DataStoreException, ParserConfigurationException, SAXException {
final File temp = File.createTempFile("gml", ".xml");
temp.deleteOnExit();
final XmlFeatureWriter writer = new JAXPStreamFeatureWriter("3.2.1", "1.1.0", null);
writer.write(featureEmpty, temp);
writer.dispose();
String result = IOUtilities.toString(new FileInputStream(temp));
String expResult = IOUtilities.toString(XmlFeatureTest.class.getResourceAsStream("/org/geotoolkit/feature/xml/SimpleFeatureEmpty.xml"));
expResult = expResult.replace("EPSG_VERSION", EPSG_VERSION);
expResult = expResult.replaceAll("(?i)epsg\\:\\d+\\.\\d+\\.?\\d*\\:", "epsg::");
result = result.replaceAll("(?i)epsg\\:\\d+\\.\\d+\\.?\\d*\\:", "epsg::");
final Expression exp = new DefaultPropertyName("/identifier/_value");
Object v = exp.apply(featureEmpty);
DomCompare.compare(expResult, result);
}
use of org.opengis.filter.Expression in project geotoolkit by Geomatys.
the class PojoDemo method main.
public static void main(String[] args) {
Demos.init();
final Pojo myPojo = new Pojo("squid", 1200, new Date());
Expression exp = FF.property("family");
System.out.println(exp.apply(myPojo));
exp = FF.property("depth");
System.out.println(exp.apply(myPojo));
exp = FF.property("birth");
System.out.println(exp.apply(myPojo));
}
use of org.opengis.filter.Expression in project geotoolkit by Geomatys.
the class ExpressionDemo method functionExpression.
private static Expression functionExpression() {
// display all available functions
System.out.println("\n==============================================================\n");
final Collection<FunctionRegister> factories = Functions.getFactories();
for (FunctionRegister ff : factories) {
System.out.println(Classes.getShortClassName(ff));
System.out.println(StringUtilities.toStringTree(ff.getNames()));
}
final Expression function = Functions.function(MathFunctionFactory.COS, null, FF.property("age"));
return function;
}
Aggregations