hasGroup = true; if (checkValid) { if (fts.getTransformation() != null) { throw new IllegalArgumentException( "Invalid "
if (fts.getTransformation() != null) { copy.setTransformation(copy(fts.getTransformation()));
public FeatureTypeStyleBuilder reset(FeatureTypeStyle fts) { if (fts == null) { return unset(); } this.name = fts.getName(); this.description.reset(fts.getDescription()); this.definedFor.reset(fts.getFeatureInstanceIDs()); this.featureTypeNames.clear(); if (fts.featureTypeNames() != null) { this.featureTypeNames.addAll(fts.featureTypeNames()); } this.rules.clear(); if (fts.rules() != null) { for (Rule rule : fts.rules()) { this.rules.add(new RuleBuilder(this).reset(rule)); } } this.options.clear(); this.options.putAll(fts.getOptions()); this.transformation = fts.getTransformation(); this.unset = false; return this; }
@Override protected void encode(FeatureTypeStyle featureStyle) { put("name", featureStyle.getName()); put("title", featureStyle.getTitle()); put("abstract", featureStyle.getAbstract()); if (featureStyle.getTransformation() != null) { push("transform").inline(new TransformEncoder(featureStyle.getTransformation())); pop(); } put("rules", new RuleEncoder(featureStyle)); vendorOptions(featureStyle.getOptions()); } }
ruleList, elseRuleList, fts.getTransformation()); } else { lfts = ruleList, elseRuleList, fts.getTransformation());
private double getStrokeWidth( List<FeatureTypeStyle> featureTypeStyles, Rule[] rules, double dpi) { ArrayList<LiteFeatureTypeStyle> lfts = new ArrayList<LiteFeatureTypeStyle>(); for (FeatureTypeStyle fts : featureTypeStyles) { List<Rule> ruleList = new ArrayList<Rule>(Arrays.asList(rules)); List<Rule> elseRuleList = new ArrayList<Rule>(); LiteFeatureTypeStyle s = new LiteFeatureTypeStyle( null, null, ruleList, elseRuleList, fts.getTransformation()); lfts.add(s); } Map hints = new HashMap(); hints.put("dpi", new Double(dpi)); StreamingRenderer renderer = new StreamingRenderer(); renderer.scaleDenominator = 1; renderer.setRendererHints(hints); renderer.applyUnitRescale(lfts); for (LiteFeatureTypeStyle s : lfts) { Rule r = s.ruleList[0]; LineSymbolizer rescaledLineSymbolizer = (LineSymbolizer) r.getSymbolizers()[0]; return rescaledLineSymbolizer.getStroke().getWidth().evaluate(null, Double.class); } // this should not happen return -1; } }
public void visit(FeatureTypeStyle fts) { start("FeatureTypeStyle"); if ((fts.getName() != null) && (fts.getName().length() > 0)) { element("Name", fts.getName()); } if (fts.getDescription() != null && fts.getDescription().getTitle() != null) element("Title", fts.getDescription().getTitle()); if (fts.getDescription() != null && fts.getDescription().getAbstract() != null) element("Abstract", fts.getDescription().getAbstract()); if ((fts.featureTypeNames() != null) && (fts.featureTypeNames().size() > 0)) { element("FeatureTypeName", fts.featureTypeNames().iterator().next().toString()); } if (fts.getTransformation() != null) { element("Transformation", fts.getTransformation()); } String[] sti = fts.getSemanticTypeIdentifiers(); if (sti.length != 1 || !sti[0].equals(SemanticType.ANY.toString())) { for (int i = 0; i < sti.length; i++) { element("SemanticTypeIdentifier", sti[i]); } } Rule[] rules = fts.getRules(); for (int i = 0; i < rules.length; i++) { rules[i].accept(this); } encodeVendorOptions(fts.getOptions()); end("FeatureTypeStyle"); }
FeatureTypeStyle fs = SLD.defaultStyle(sld).featureTypeStyles().get(0); Expression tx = fs.getTransformation(); assertNotNull(tx);
@Test public void testRenderingTransformationAlternateInputParam() throws IOException { String yaml = "feature-styles: \n" + "- transform:\n" + " input: foo\n" + " name: ras:Contour\n" + " params:\n" + " levels:\n" + " - 1000\n" + " - 1100\n" + " - 1200\n"; StyledLayerDescriptor sld = Ysld.parse(yaml); FeatureTypeStyle fs = SLD.defaultStyle(sld).featureTypeStyles().get(0); Expression tx = fs.getTransformation(); assertNotNull(tx); ProcessFunction pf = (ProcessFunction) tx; assertThat( pf, hasProperty( "parameters", containsInAnyOrder( rtParam("foo"), rtParam("levels", literal(1000), literal(1100), literal(1200))))); }
public void testFeatureStyleImplCopy() throws Exception { // create FeatureTypeStyleImpl FeatureTypeStyle fts = new FeatureTypeStyleImpl(); assertNull(fts.getTransformation()); assertNull(fts.getOnlineResource()); // Create OnlineResource and transformation OnLineResource impl = new OnLineResourceImpl(); Expression style = filterFactory.literal("square"); // set OnlineResource and transformation fts.setTransformation(style); fts.setOnlineResource(impl); // test if set assertEquals(fts.getTransformation(), filterFactory.literal("square")); assertEquals(fts.getOnlineResource(), new OnLineResourceImpl()); // create copy fts2 from fts FeatureTypeStyleImpl fts2 = new FeatureTypeStyleImpl(fts); // test if values are equal and thus copied assertEquals(fts.getTransformation(), fts2.getTransformation()); assertEquals(fts.getOnlineResource(), fts2.getOnlineResource()); } }
/** * Tests whether a style contains a Rendering Transformation. * * @param style the style to check * @return true if the style contains a rendering transformation */ private static boolean hasTransformation(Style style) { for (FeatureTypeStyle fs : style.featureTypeStyles()) { if (fs.getTransformation() != null) return true; } return false; }
@Test public void testRenderingTransformation() throws IOException { String yaml = "feature-styles: \n" + "- transform:\n" + " name: ras:Contour\n" + " params:\n" + " levels:\n" + " - 1000\n" + " - 1100\n" + " - 1200\n"; StyledLayerDescriptor sld = Ysld.parse(yaml); FeatureTypeStyle fs = SLD.defaultStyle(sld).featureTypeStyles().get(0); Expression tx = fs.getTransformation(); assertNotNull(tx); ProcessFunction pf = (ProcessFunction) tx; assertThat( pf, hasProperty( "parameters", containsInAnyOrder( rtParam("data"), rtParam("levels", literal(1000), literal(1100), literal(1200))))); }
@Test public void testRenderingTransformationWMSAuto() throws IOException { String yaml = "feature-styles: \n" + "- transform:\n" + " name: vec:Heatmap\n" + " params:\n" + " weightAttr: pop2000\n" + " radius: 100\n" + " pixelsPerCell: 10\n"; StyledLayerDescriptor sld = Ysld.parse(yaml); FeatureTypeStyle fs = SLD.defaultStyle(sld).featureTypeStyles().get(0); Expression tx = fs.getTransformation(); assertNotNull(tx); ProcessFunction pf = (ProcessFunction) tx; assertThat( pf, hasProperty( "parameters", containsInAnyOrder( rtParam("data"), rtParam("weightAttr", literal("pop2000")), rtParam("radius", literal(100)), rtParam("pixelsPerCell", literal(10)), rtParam("outputBBOX", function("env", literal("wms_bbox"))), rtParam("outputWidth", function("env", literal("wms_width"))), rtParam("outputHeight", function("env", literal("wms_height")))))); }
@Test public void testRenderingTransformationWMSAutoMixed() throws IOException { String yaml = "feature-styles: \n" + "- transform:\n" + " name: vec:Heatmap\n" + " params:\n" + " weightAttr: pop2000\n" + " radius: 100\n" + " pixelsPerCell: 10\n" + " outputBBOX: ${env('test')}\n"; StyledLayerDescriptor sld = Ysld.parse(yaml); FeatureTypeStyle fs = SLD.defaultStyle(sld).featureTypeStyles().get(0); Expression tx = fs.getTransformation(); assertNotNull(tx); ProcessFunction pf = (ProcessFunction) tx; assertThat( pf, hasProperty( "parameters", containsInAnyOrder( rtParam("data"), rtParam("weightAttr", literal("pop2000")), rtParam("radius", literal(100)), rtParam("pixelsPerCell", literal(10)), rtParam("outputBBOX", function("env", literal("test"))), rtParam("outputWidth", function("env", literal("wms_width"))), rtParam("outputHeight", function("env", literal("wms_height")))))); }
FeatureTypeStyle fs = SLD.defaultStyle(sld).featureTypeStyles().get(0); Expression tx = fs.getTransformation(); assertNotNull(tx);
@Override public void visit(Style style) { super.visit(style); Style copy = (Style) pages.peek(); // merge the feature type styles sharing the same transformation List<FeatureTypeStyle> featureTypeStyles = copy.featureTypeStyles(); List<FeatureTypeStyle> reduced = new ArrayList<FeatureTypeStyle>(); FeatureTypeStyle current = null; for (FeatureTypeStyle fts : featureTypeStyles) { if (current == null || !sameTranformation(current.getTransformation(), fts.getTransformation())) { current = fts; reduced.add(current); } else { // flatten, we don't need to draw a pretty picture and having multiple FTS // would result in the feature being returned twice, since we cannot // assume feature ids to be stable either current.rules().addAll(fts.rules()); } } // replace copy.featureTypeStyles().clear(); copy.featureTypeStyles().addAll(reduced); }
@Override protected void encode(FeatureTypeStyle featureStyle) { put("name", featureStyle.getName()); put("title", featureStyle.getTitle()); put("abstract", featureStyle.getAbstract()); if (featureStyle.getTransformation() != null) { push("transform").inline(new TransformEncoder(featureStyle.getTransformation())); pop(); } put("rules", new RuleEncoder(featureStyle)); vendorOptions(featureStyle.getOptions()); } }
if (fts.getTransformation() != null) { element("Transformation", fts.getTransformation());
@Test public void testRasterToVectorTransform() { FeatureTypeStyle fts = sb.createFeatureTypeStyle(sb.createLineSymbolizer()); Function data = ff.function("parameter", ff.literal("data")); Function levels = ff.function( "parameter", ff.literal("levels"), ff.literal("1100"), ff.literal("1200")); Function tx = ff.function("ras:Contour", data, levels); fts.setTransformation(tx); fts.getOptions().put(FeatureTypeStyle.COMPOSITE_BASE, "true"); Style style = sb.createStyle(); style.featureTypeStyles().add(fts); style.accept(visitor); Style copy = (Style) visitor.getCopy(); assertTrue(visitor.hasTransformations()); assertTrue(visitor.hasVectorTransformations()); assertThat(copy.featureTypeStyles().get(0).getTransformation(), instanceOf(Function.class)); Function txCopy = (Function) copy.featureTypeStyles().get(0).getTransformation(); assertEquals("ras:Contour", txCopy.getName()); }
static Function assertDynamicColorColormap(StyledLayerDescriptor sld) throws TransformerException { // logStyle(sld); NamedLayer layer = (NamedLayer) sld.getStyledLayers()[0]; Style style = layer.getStyles()[0]; assertEquals(1, style.featureTypeStyles().size()); FeatureTypeStyle fts = style.featureTypeStyles().get(0); Function dcm = (Function) fts.getTransformation(); assertNotNull(dcm); assertEquals("ras:DynamicColorMap", dcm.getName()); assertEquals(3, dcm.getParameters().size()); // first param, the full data set assetIsParameterFunction(dcm.getParameters().get(0), "data"); // second param, the opacity EnvFunction.clearLocalValues(); Expression opacity = assetIsParameterFunction(dcm.getParameters().get(1), "opacity"); assertEquals(1f, opacity.evaluate(null, Float.class), 0f); EnvFunction.setLocalValue(PaletteParser.OPACITY, "0.5"); assertEquals(0.5f, opacity.evaluate(null, Float.class), 0f); // second one, the colormap Expression crValue = assetIsParameterFunction(dcm.getParameters().get(2), "colorRamp"); Function cm = (Function) crValue; assertEquals("colormap", cm.getName()); return cm; }