use of org.opengis.filter.Literal in project geotoolkit by Geomatys.
the class CategoryStyleBuilder method analyze.
public void analyze(final MapLayer layer) {
Resource resource = layer.getData();
if (!(resource instanceof FeatureSet)) {
throw new IllegalArgumentException("Layer resource must be a FeatureSet");
}
this.layer = layer;
fts.rules().clear();
properties.clear();
if (layer != null) {
FeatureType schema;
try {
schema = ((FeatureSet) resource).getType();
} catch (DataStoreException ex) {
throw new FeatureStoreRuntimeException(ex.getMessage(), ex);
}
for (PropertyType desc : schema.getProperties(true)) {
if (desc instanceof AttributeType) {
Class<?> type = ((AttributeType) desc).getValueClass();
if (!Geometry.class.isAssignableFrom(type)) {
properties.add(ff.property(desc.getName().tip().toString()));
}
}
}
// find the geometry class for template
Class<?> geoClass = null;
try {
PropertyType geo = FeatureExt.getDefaultGeometry(schema);
geoClass = Features.toAttribute(geo).map(AttributeType::getValueClass).orElse(null);
} catch (PropertyNotFoundException ex) {
LOGGER.log(Level.FINE, "No sis:geometry property found", ex);
}
if (geoClass == null) {
return;
}
if (Polygon.class.isAssignableFrom(geoClass) || MultiPolygon.class.isAssignableFrom(geoClass)) {
Stroke stroke = sf.stroke(Color.BLACK, 1);
Fill fill = sf.fill(Color.BLUE);
template = sf.polygonSymbolizer(stroke, fill, null);
expectedType = PolygonSymbolizer.class;
} else if (LineString.class.isAssignableFrom(geoClass) || MultiLineString.class.isAssignableFrom(geoClass)) {
Stroke stroke = sf.stroke(Color.BLUE, 2);
template = sf.lineSymbolizer(stroke, null);
expectedType = LineSymbolizer.class;
} else {
Stroke stroke = sf.stroke(Color.BLACK, 1);
Fill fill = sf.fill(Color.BLUE);
List<GraphicalSymbol> symbols = new ArrayList<>();
symbols.add(sf.mark(StyleConstants.MARK_CIRCLE, fill, stroke));
Graphic gra = sf.graphic(symbols, ff.literal(1), ff.literal(12), ff.literal(0), sf.anchorPoint(), sf.displacement());
template = sf.pointSymbolizer(gra, null);
expectedType = PointSymbolizer.class;
}
// try to rebuild the previous analyze if it was one
List<? extends FeatureTypeStyle> ftss = layer.getStyle().featureTypeStyles();
if (ftss.size() == 1) {
FeatureTypeStyle fts = ftss.get(0);
// defensive copy avoid synchronization
List<? extends Rule> candidateRules = new ArrayList<>(fts.rules());
for (Rule r : candidateRules) {
// defensive copy avoid synchronization
List<? extends Symbolizer> candidateSymbols = new ArrayList<>(r.symbolizers());
if (candidateSymbols.size() != 1)
break;
Symbolizer symbol = candidateSymbols.get(0);
if (expectedType.isInstance(symbol)) {
if (r.isElseFilter()) {
// it looks like it's a valid classification "other" rule
this.fts.rules().add((MutableRule) r);
template = symbol;
other = true;
} else {
Filter f = r.getFilter();
if (f != null && f.getOperatorType() == ComparisonOperatorName.PROPERTY_IS_EQUAL_TO) {
BinaryComparisonOperator equal = (BinaryComparisonOperator) f;
Expression exp1 = equal.getOperand1();
Expression exp2 = equal.getOperand2();
if (exp1 instanceof ValueReference && exp2 instanceof Literal) {
if (properties.contains(exp1)) {
// it looks like it's a valid classification property rule
this.fts.rules().add((MutableRule) r);
template = symbol;
currentProperty = (ValueReference) exp1;
} else {
// property is not in the schema
break;
}
} else if (exp2 instanceof ValueReference && exp1 instanceof Literal) {
if (properties.contains(exp2)) {
// it looks like it's a valid classification property rule
this.fts.rules().add((MutableRule) r);
template = symbol;
currentProperty = (ValueReference) exp2;
} else {
// property is not in the schema
break;
}
} else {
// mismatch analyze structure
break;
}
}
}
} else {
break;
}
}
}
}
}
use of org.opengis.filter.Literal in project geotoolkit by Geomatys.
the class IntervalStyleBuilder method isIntervalStyle.
public boolean isIntervalStyle(final FeatureTypeStyle fts) {
if (fts.rules().isEmpty())
return false;
for (Rule r : fts.rules()) {
Filter f = r.getFilter();
if (f == null || r.isElseFilter())
return false;
if (r.symbolizers().size() != 1)
return false;
if (f.getOperatorType() == LogicalOperatorName.AND) {
LogicalOperator<Object> and = (LogicalOperator) f;
if (and.getOperands().size() != 2)
return false;
Filter<Object> op1 = and.getOperands().get(0);
Filter<Object> op2 = and.getOperands().get(1);
if (op2.getOperatorType() == ComparisonOperatorName.PROPERTY_IS_GREATER_THAN_OR_EQUAL_TO) {
// flip order
op1 = op2;
op2 = and.getOperands().get(0);
}
if (op1.getOperatorType() == ComparisonOperatorName.PROPERTY_IS_GREATER_THAN_OR_EQUAL_TO) {
BinaryComparisonOperator under = (BinaryComparisonOperator) op1;
Expression exp1 = under.getOperand1();
Expression exp2 = under.getOperand2();
if (exp1.getFunctionName().tip().toString().equals("Divide")) {
List parameters = exp1.getParameters();
if (!properties.contains(parameters.get(0)))
return false;
if (!properties.contains(parameters.get(1)))
return false;
} else if (exp1 instanceof ValueReference) {
ValueReference name = (ValueReference) exp1;
if (!properties.contains(name))
return false;
} else {
return false;
}
if (!(exp2 instanceof Literal)) {
return false;
}
if (op2.getOperatorType() == ComparisonOperatorName.PROPERTY_IS_LESS_THAN || op2.getOperatorType() == ComparisonOperatorName.PROPERTY_IS_LESS_THAN_OR_EQUAL_TO) {
BinaryComparisonOperator bc = (BinaryComparisonOperator) op2;
Expression ex1 = under.getOperand1();
Expression ex2 = under.getOperand2();
if (exp1.getFunctionName().tip().toString().equals("Divide")) {
List parameters = exp1.getParameters();
if (!properties.contains(parameters.get(0)))
return false;
if (!properties.contains(parameters.get(1)))
return false;
} else if (exp1 instanceof ValueReference) {
ValueReference name = (ValueReference) ex1;
if (!properties.contains(name))
return false;
} else {
return false;
}
if (!(ex2 instanceof Literal)) {
return false;
}
} else {
return false;
}
} else {
return false;
}
}
template = r.symbolizers().get(0);
}
method = METHOD.MANUAL;
nbClasses = fts.rules().size() + 1;
return true;
}
use of org.opengis.filter.Literal in project geotoolkit by Geomatys.
the class FilterFactory2 method intersects.
public BinarySpatialOperator<Object> intersects(final String propertyName, final Geometry geometry) {
final ValueReference name = property(propertyName);
final Literal geom = super.literal(geometry);
return intersects(name, geom);
}
use of org.opengis.filter.Literal in project geotoolkit by Geomatys.
the class FilterFactory2 method within.
public BinarySpatialOperator<Object> within(final String propertyName, final Geometry geometry) {
final ValueReference name = property(propertyName);
final Literal geom = super.literal(geometry);
return within(name, geom);
}
use of org.opengis.filter.Literal in project geotoolkit by Geomatys.
the class FilterFactory2 method disjoint.
public BinarySpatialOperator<Object> disjoint(final String propertyName, final Geometry geometry) {
final ValueReference name = property(propertyName);
final Literal geom = super.literal(geometry);
return disjoint(name, geom);
}
Aggregations