use of org.geotoolkit.style.MutableFeatureTypeStyle in project geotoolkit by Geomatys.
the class SE100toGTTransformer method visitUserStyle.
// Style, FTS and Rule-------------------------------------------------------
/**
* Transform a SLD v1.0 userstyle in GT style.
*/
public MutableStyle visitUserStyle(final org.geotoolkit.sld.xml.v100.UserStyle us) {
if (us == null) {
return null;
} else {
final MutableStyle mls = styleFactory.style();
mls.setName(us.getName());
final InternationalString title = (us.getTitle() == null) ? null : new SimpleInternationalString(us.getTitle());
final InternationalString abs = (us.getAbstract() == null) ? null : new SimpleInternationalString(us.getAbstract());
mls.setDescription(styleFactory.description(title, abs));
final Boolean def = us.isIsDefault();
mls.setDefault((def != null) ? def : false);
final List<org.geotoolkit.sld.xml.v100.FeatureTypeStyle> ftss = us.getFeatureTypeStyle();
for (final org.geotoolkit.sld.xml.v100.FeatureTypeStyle obj : ftss) {
final MutableFeatureTypeStyle fts = visitFTS(obj);
mls.featureTypeStyles().add(fts);
}
return mls;
}
}
use of org.geotoolkit.style.MutableFeatureTypeStyle in project geotoolkit by Geomatys.
the class SE100toGTTransformer method visitFTS.
/**
* Transform a SLD v1.0 FeatureTypeStyle or CoverageStyle in GT FTS.
*/
public MutableFeatureTypeStyle visitFTS(final org.geotoolkit.sld.xml.v100.FeatureTypeStyle obj) {
if (obj == null)
return null;
final MutableFeatureTypeStyle fts = styleFactory.featureTypeStyle();
final org.geotoolkit.sld.xml.v100.FeatureTypeStyle ftst = (org.geotoolkit.sld.xml.v100.FeatureTypeStyle) obj;
fts.setName(ftst.getName());
final InternationalString title = (ftst.getTitle() == null) ? null : new SimpleInternationalString(ftst.getTitle());
final InternationalString abs = (ftst.getAbstract() == null) ? null : new SimpleInternationalString(ftst.getAbstract());
fts.setDescription(styleFactory.description(title, abs));
fts.semanticTypeIdentifiers().addAll(visitSemantics(ftst.getSemanticTypeIdentifier()));
if (ftst.getFeatureTypeName() != null) {
fts.featureTypeNames().add(NamesExt.create(ftst.getFeatureTypeName()));
}
if (ftst.getRule() == null || ftst.getRule().isEmpty()) {
} else {
for (org.geotoolkit.sld.xml.v100.Rule rt : ftst.getRule()) {
fts.rules().add(visitRule(rt));
}
}
return fts;
}
use of org.geotoolkit.style.MutableFeatureTypeStyle in project geotoolkit by Geomatys.
the class SE110toGTTransformer method visitUserStyle.
// Style, FTS and Rule-------------------------------------------------------
/**
* Transform a SLD v1.1 userstyle in GT style.
*/
public MutableStyle visitUserStyle(final org.geotoolkit.sld.xml.v110.UserStyle us) throws FactoryException {
if (us == null) {
return null;
} else {
final MutableStyle mls = styleFactory.style();
mls.setName(us.getName());
mls.setDescription(visitDescription(us.getDescription()));
final Boolean def = us.isIsDefault();
mls.setDefault((def != null) ? def : false);
final List<Object> ftss = us.getFeatureTypeStyleOrCoverageStyleOrOnlineResource();
for (final Object obj : ftss) {
MutableFeatureTypeStyle fts = visitFTS(obj);
mls.featureTypeStyles().add(fts);
}
return mls;
}
}
use of org.geotoolkit.style.MutableFeatureTypeStyle in project geotoolkit by Geomatys.
the class CachedPatternSymbolizer method getMasks.
public Map.Entry<FeatureSet, MutableStyle> getMasks(final GridCoverage coverage) throws IOException, TransformException {
final List<Feature> features = new ArrayList<>();
final Map<NumberRange, List<Symbolizer>> styles = new LinkedHashMap<>();
final Map<NumberRange, Integer> stylesIndexes = new LinkedHashMap<>();
final Map<Expression, List<Symbolizer>> categorizes = styleElement.getRanges();
final Expression[] steps = categorizes.keySet().toArray(new Expression[categorizes.size()]);
Arrays.sort(steps, new Comparator<Expression>() {
@Override
public int compare(Expression t1, Expression t2) {
if (t1 == null) {
return -1;
} else if (t2 == null) {
return +1;
}
double d1 = ((Number) t1.apply(null)).doubleValue();
double d2 = ((Number) t2.apply(null)).doubleValue();
double res = d1 - d2;
if (res < 0) {
return -1;
} else if (res > 0) {
return +1;
} else {
return 0;
}
}
});
// fill the numberranges ------------------------------------------------
double last = Double.NEGATIVE_INFINITY;
double end = Double.POSITIVE_INFINITY;
NumberRange interval;
int i = 0;
int index = 0;
for (; i < steps.length - 1; i++) {
end = ((Number) steps[i + 1].apply(null)).doubleValue();
interval = NumberRange.create(last, true, end, false);
styles.put(interval, categorizes.get(steps[i]));
stylesIndexes.put(interval, index++);
last = end;
}
// last element
end = Double.POSITIVE_INFINITY;
NumberRange<Double> lastRange = NumberRange.create(last, true, end, true);
styles.put(lastRange, categorizes.get(steps[i]));
stylesIndexes.put(lastRange, index++);
// calculate the polygons -----------------------------------------------
final ProcessDescriptor descriptor = CoverageToVectorDescriptor.INSTANCE;
final Integer band = ((Number) styleElement.getChannel().apply(null)).intValue();
final ParameterValueGroup input = descriptor.getInputDescriptor().createValue();
input.parameter(CoverageToVectorDescriptor.COVERAGE.getName().getCode()).setValue(coverage);
final Set<NumberRange> nrs = styles.keySet();
input.parameter(CoverageToVectorDescriptor.RANGES.getName().getCode()).setValue(nrs.toArray(new NumberRange[nrs.size()]));
input.parameter(CoverageToVectorDescriptor.BAND.getName().getCode()).setValue(band);
final Process process = descriptor.createProcess(input);
final Geometry[] polygons;
try {
polygons = (Geometry[]) process.call().parameter(CoverageToVectorDescriptor.GEOMETRIES.getName().getCode()).getValue();
} catch (ProcessException ex) {
Logger.getLogger("org.geotoolkit.display2d.ext.pattern").log(Level.WARNING, null, ex);
throw new IOException(ex.getMessage(), ex);
}
// build the global style -----------------------------------------------
final MutableStyle style = GO2Utilities.STYLE_FACTORY.style();
final MutableFeatureTypeStyle fts = GO2Utilities.STYLE_FACTORY.featureTypeStyle();
style.featureTypeStyles().add(fts);
int idx = 0;
for (List<Symbolizer> lst : styles.values()) {
MutableRule rule = GO2Utilities.STYLE_FACTORY.rule();
rule.symbolizers().addAll(lst);
rule.setFilter(GO2Utilities.FILTER_FACTORY.equal(GO2Utilities.FILTER_FACTORY.property("category"), GO2Utilities.FILTER_FACTORY.literal(idx), true, MatchAction.ANY));
fts.rules().add(rule);
idx++;
}
// build the features ---------------------------------------------------
final CoordinateReferenceSystem crs = coverage.getCoordinateReferenceSystem();
final FeatureTypeBuilder sftBuilder = new FeatureTypeBuilder();
final String geometryField = "geometry";
sftBuilder.setName("DynamicFeature");
sftBuilder.addAttribute(Integer.class).setName("id").addRole(AttributeRole.IDENTIFIER_COMPONENT);
sftBuilder.addAttribute(Geometry.class).setName(geometryField).setCRS(crs).addRole(AttributeRole.DEFAULT_GEOMETRY);
sftBuilder.addAttribute(Integer.class).setName("category");
final FeatureType sft = sftBuilder.build();
int id = 0;
for (Geometry entry : polygons) {
if (entry == null)
continue;
NumberRange numberRange = (NumberRange) entry.getUserData();
idx = stylesIndexes.get(numberRange);
entry.setUserData(crs);
final Feature feature = sft.newInstance();
feature.setPropertyValue(geometryField, entry);
feature.setPropertyValue("id", id++);
feature.setPropertyValue("category", idx);
features.add(feature);
}
return new AbstractMap.SimpleEntry<>(new InMemoryFeatureSet(sft, features), style);
}
use of org.geotoolkit.style.MutableFeatureTypeStyle in project geotoolkit by Geomatys.
the class RenderingRoutines method mergeStyles.
/**
* Merge a layer style with a selection style.
* The selection style fts elements will be placed after those of the default style.
*/
public static MutableStyle mergeStyles(MutableStyle style, Filter selectionFilter, MutableStyle selectionStyle) {
if (selectionFilter == null || Filter.exclude().equals(selectionFilter) || selectionStyle == null) {
// unmodified
return style;
}
final Filter exclusionFilter = FILTER_FACTORY.not(selectionFilter);
final MutableStyle result = GO2Utilities.STYLE_FACTORY.style();
for (FeatureTypeStyle fts : style.featureTypeStyles()) {
final MutableFeatureTypeStyle resultfts = GO2Utilities.STYLE_FACTORY.featureTypeStyle();
resultfts.setDescription(fts.getDescription());
resultfts.setFeatureInstanceIDs(fts.getFeatureInstanceIDs());
resultfts.setName(fts.getName());
resultfts.setOnlineResource(fts.getOnlineResource());
result.featureTypeStyles().add(resultfts);
for (Rule rule : fts.rules()) {
final MutableRule modifiedRule = STYLE_FACTORY.rule(rule.symbolizers().toArray(new Symbolizer[0]));
Filter f = rule.getFilter();
if (f == null) {
f = exclusionFilter;
} else {
f = FILTER_FACTORY.and(f, exclusionFilter);
}
modifiedRule.setFilter(f);
resultfts.rules().add(modifiedRule);
}
}
if (selectionStyle != null) {
for (FeatureTypeStyle fts : selectionStyle.featureTypeStyles()) {
final MutableFeatureTypeStyle resultfts = GO2Utilities.STYLE_FACTORY.featureTypeStyle();
resultfts.setDescription(fts.getDescription());
resultfts.setFeatureInstanceIDs(fts.getFeatureInstanceIDs());
resultfts.setName(fts.getName());
resultfts.setOnlineResource(fts.getOnlineResource());
result.featureTypeStyles().add(resultfts);
for (Rule rule : fts.rules()) {
final MutableRule modifiedRule = STYLE_FACTORY.rule(rule.symbolizers().toArray(new Symbolizer[0]));
Filter f = rule.getFilter();
if (f == null) {
f = selectionFilter;
} else {
f = FILTER_FACTORY.and(f, selectionFilter);
}
modifiedRule.setFilter(f);
resultfts.rules().add(modifiedRule);
}
}
}
return result;
}
Aggregations