org.geotools.styling.Rule Java Examples

The following examples show how to use org.geotools.styling.Rule. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ExtractValidFieldTypes.java    From sldeditor with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Process styles.
 *
 * @param fieldsUpdated the fields updated
 * @param styleList the style list
 * @param featureList the feature list
 * @return true, if successful
 */
private static boolean processStyles(
        boolean fieldsUpdated,
        List<org.geotools.styling.Style> styleList,
        FeatureSource<SimpleFeatureType, SimpleFeature> featureList) {
    for (Style style : styleList) {
        for (FeatureTypeStyle fts : style.featureTypeStyles()) {
            for (Rule rule : fts.rules()) {
                Object drawMe = null;
                try {
                    drawMe = featureList.getFeatures().features().next();
                } catch (IOException | NoSuchElementException e) {
                    ConsoleManager.getInstance().exception(ExtractValidFieldTypes.class, e);
                }

                fieldsUpdated = processRule(fieldsUpdated, rule, drawMe);
            }
        }
    }
    return fieldsUpdated;
}
 
Example #2
Source File: StyleGenerator.java    From constellation with Apache License 2.0 6 votes vote down vote up
private static Rule makeFillRule() {
    final FilterFactory filterFactory = CommonFactoryFinder.getFilterFactory();
    final StyleFactory styleFactory = CommonFactoryFinder.getStyleFactory();

    // create a partially opaque outline stroke
    final Stroke stroke = styleFactory.createStroke(
            filterFactory.literal(Color.BLACK),
            filterFactory.literal(1),
            filterFactory.literal(.5)
    );

    // create a partially opaque fill
    Fill fill = styleFactory.createFill(
            filterFactory.literal(COLORS.next()),
            filterFactory.literal(.5)
    );

    // setting the geometryPropertyName arg to null signals that we want to draw the default geometry of features
    final PolygonSymbolizer sym = styleFactory.createPolygonSymbolizer(stroke, fill, null);

    final Rule rule = styleFactory.createRule();
    rule.symbolizers().add(sym);

    return rule;
}
 
Example #3
Source File: FeatureLayerConfigurationPersistencyTest.java    From snap-desktop with GNU General Public License v3.0 6 votes vote down vote up
@SuppressWarnings({"deprecation"})
private static Style createStyle() {
    StyleFactory styleFactory = CommonFactoryFinder.getStyleFactory(null);
    FilterFactory filterFactory = CommonFactoryFinder.getFilterFactory(null);
    PolygonSymbolizer symbolizer = styleFactory.createPolygonSymbolizer();
    Fill fill = styleFactory.createFill(
            filterFactory.literal("#FFAA00"),
            filterFactory.literal(0.5)
    );
    symbolizer.setFill(fill);
    Rule rule = styleFactory.createRule();
    rule.setSymbolizers(new Symbolizer[]{symbolizer});
    FeatureTypeStyle fts = styleFactory.createFeatureTypeStyle();
    fts.setRules(new Rule[]{rule});

    Style style = styleFactory.createStyle();
    style.addFeatureTypeStyle(fts);
    return style;
}
 
Example #4
Source File: RuleWrapper.java    From hortonmachine with GNU General Public License v3.0 6 votes vote down vote up
public RuleWrapper( Rule rule, FeatureTypeStyleWrapper parent ) {
    this.rule = rule;
    this.parent = parent;

    name = rule.getName();
    try {
        maxScale = String.valueOf(rule.getMaxScaleDenominator());
        minScale = String.valueOf(rule.getMinScaleDenominator());
    } catch (Exception e) {
        maxScale = DEFAULT_MAXSCALE;
        minScale = DEFAULT_MINSCALE;
    }

    List<Symbolizer> symbolizers = rule.symbolizers();
    for( Symbolizer symbolizer : symbolizers ) {
        SymbolizerWrapper wrapper = getWrapper(symbolizer);
        symbolizersWrapperList.add(wrapper);
    }
}
 
Example #5
Source File: ExtractAttributesTest.java    From sldeditor with GNU General Public License v3.0 6 votes vote down vote up
@Test
public void testFunctionExpression() {
    DummyInternalSLDFile2 dummy = new DummyInternalSLDFile2();

    StyledLayerDescriptor sld = createTestSLD(dummy);
    List<Rule> ruleList = getRuleList(sld);

    ExtractAttributes extract = new ExtractAttributes();
    Rule rule = DefaultSymbols.createNewRule();

    String expectedEnvVar = "testenvvar";
    Function function = ff.function("env", ff.property(expectedEnvVar));

    Filter filter = ff.equal(ff.literal("not equal"), function, true);
    rule.setFilter(filter);
    ruleList.clear();
    ruleList.add(rule);
    extract.extractDefaultFields(sld);

    // Check fields extracted ok
    List<DataSourceAttributeData> actualFieldnameList = extract.getFields();
    assertEquals(1, actualFieldnameList.size());
    DataSourceAttributeData dataSourceField = actualFieldnameList.get(0);
    assertEquals(String.class, dataSourceField.getType());
}
 
Example #6
Source File: SymbolizerFilterVisitorTest.java    From geomajas-project-server with GNU Affero General Public License v3.0 6 votes vote down vote up
@Test
public void testGeometries() throws IOException{
	SymbolizerFilterVisitor visitor = new SymbolizerFilterVisitor();
	visitor.setIncludeGeometry(true);
	visitor.setIncludeText(false);
	SLDParser parser = new SLDParser(styleFactory);
	parser.setInput(getClass().getResource("point_pointwithdefaultlabel.sld"));
	Style[] styles = parser.readXML();
	Assert.assertEquals(1, styles.length);
	visitor.visit(styles[0]);
	Style copy = (Style) visitor.getCopy();
	FeatureTypeStyle featureTypeStyle = copy.featureTypeStyles().iterator().next();
	Rule rule = featureTypeStyle.rules().iterator().next();
	Iterator<Symbolizer> it = rule.symbolizers().iterator();
	Assert.assertTrue(it.next() instanceof PointSymbolizer);
	Assert.assertFalse(it.hasNext());
}
 
Example #7
Source File: SymbolManager.java    From sldeditor with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Convert symbols.
 *
 * @param rule the rule
 * @param layerName the layer name
 * @param transparency the transparency
 * @param element the element
 */
public void convertSymbols(Rule rule, String layerName, int transparency, JsonElement element) {

    if (element == null) return;

    JsonObject jsonSymbol = element.getAsJsonObject();
    boolean found = false;
    for(String symbolType : symbolMap.keySet())
    {
        JsonElement obj = jsonSymbol.get(symbolType);

        if(obj != null)
        {
            EsriSymbolInterface esriSymbol = symbolMap.get(symbolType);
            esriSymbol.convert(rule, obj, layerName, transparency);
            found = true;
            break;
        }
    }

    if(!found)
    {
        ConsoleManager.getInstance().error(this, "Unsupported symbol : " + SymbolUtils.extractName(element));
    }
}
 
Example #8
Source File: SimpleLineSymbol.java    From sldeditor with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void convert(Rule rule, JsonElement element, String layerName, int transparency) {
    if(element == null) return;
    if(rule == null) return;

    JsonObject obj = element.getAsJsonObject();
    @SuppressWarnings("unused")
    int style = getInt(obj, CommonSymbolKeys.STYLE);

    List<Symbolizer> symbolizerList = rule.symbolizers();

    List<Stroke> strokeList = convert(obj);

    Stroke stroke = null;

    if(!strokeList.isEmpty())
    {
        stroke = strokeList.get(0);
    }

    LineSymbolizer lineSymbolizer = styleFactory.createLineSymbolizer(stroke, null);

    symbolizerList.add(lineSymbolizer);
}
 
Example #9
Source File: RenderSymbol.java    From sldeditor with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Should render symbol.
 *
 * @param style the style
 * @param ruleToRender the rule to render
 * @return true, if successful
 */
private boolean shouldRenderSymbol(
        Style style, FeatureTypeStyle ftsToRender, Rule ruleToRender) {

    if (ruleToRender == null) {
        return true;
    }

    for (FeatureTypeStyle fts : style.featureTypeStyles()) {
        if (fts == ftsToRender) {
            for (Rule rule : fts.rules()) {
                if (rule == ruleToRender) {
                    return true;
                }
            }
        }
    }

    return false;
}
 
Example #10
Source File: SymbolizerFilterVisitorTest.java    From geomajas-project-server with GNU Affero General Public License v3.0 6 votes vote down vote up
@Test
public void testLabels() throws IOException {
	SymbolizerFilterVisitor visitor = new SymbolizerFilterVisitor();
	visitor.setIncludeGeometry(false);
	visitor.setIncludeText(true);
	SLDParser parser = new SLDParser(styleFactory);
	parser.setInput(getClass().getResource("point_pointwithdefaultlabel.sld"));
	Style[] styles = parser.readXML();
	Assert.assertEquals(1, styles.length);
	visitor.visit(styles[0]);
	Style copy = (Style) visitor.getCopy();
	FeatureTypeStyle featureTypeStyle = copy.featureTypeStyles().iterator().next();
	Rule rule = featureTypeStyle.rules().iterator().next();
	Iterator<Symbolizer> it = rule.symbolizers().iterator();
	Assert.assertTrue(it.next() instanceof TextSymbolizer);
	Assert.assertFalse(it.hasNext());
}
 
Example #11
Source File: SymbolizerFilterVisitorTest.java    From geomajas-project-server with GNU Affero General Public License v3.0 6 votes vote down vote up
@Test
public void testLabelsAndGeometries() throws IOException{
	SymbolizerFilterVisitor visitor = new SymbolizerFilterVisitor();
	visitor.setIncludeGeometry(true);
	visitor.setIncludeText(true);
	SLDParser parser = new SLDParser(styleFactory);
	parser.setInput(getClass().getResource("point_pointwithdefaultlabel.sld"));
	Style[] styles = parser.readXML();
	Assert.assertEquals(1, styles.length);
	visitor.visit(styles[0]);
	Style copy = (Style) visitor.getCopy();
	FeatureTypeStyle featureTypeStyle = copy.featureTypeStyles().iterator().next();
	Rule rule = featureTypeStyle.rules().iterator().next();
	Iterator<Symbolizer> it = rule.symbolizers().iterator();
	Assert.assertTrue(it.next() instanceof PointSymbolizer);
	Assert.assertTrue(it.next() instanceof TextSymbolizer);
	Assert.assertFalse(it.hasNext());
}
 
Example #12
Source File: DistributedRenderCallback.java    From geowave with Apache License 2.0 6 votes vote down vote up
private static FeatureTypeStyle getDirectRasterStyle(
    final String geometryPropertyName,
    final Expression transformation) {
  final StyleFactory styleFactory = CommonFactoryFinder.getStyleFactory();
  final FeatureTypeStyle style = styleFactory.createFeatureTypeStyle();
  final Rule rule = styleFactory.createRule();
  rule.setName("distributed render - direct raster");
  rule.setTitle("Distributed Render - Direct Raster");

  final RasterSymbolizer symbolizer = styleFactory.createRasterSymbolizer();
  symbolizer.setGeometryPropertyName(geometryPropertyName);
  rule.symbolizers().add(symbolizer);
  style.rules().add(rule);
  style.setTransformation(transformation);
  return style;
}
 
Example #13
Source File: ExtractAttributesTest.java    From sldeditor with GNU General Public License v3.0 6 votes vote down vote up
@Test
public void testIsLike() {
    DummyInternalSLDFile2 dummy = new DummyInternalSLDFile2();

    StyledLayerDescriptor sld = createTestSLD(dummy);
    List<Rule> ruleList = getRuleList(sld);

    Rule rule = DefaultSymbols.createNewRule();

    // Try isLike
    Filter filter = ff.like(ff.property("test"), "abcd1");
    rule.setFilter(filter);
    ruleList.clear();
    ruleList.add(rule);
    ExtractAttributes extract = new ExtractAttributes();
    extract.extractDefaultFields(sld);

    // Check fields extracted ok
    List<DataSourceAttributeData> actualFieldnameList = extract.getFields();
    assertEquals(1, actualFieldnameList.size());
    DataSourceAttributeData dataSourceField = actualFieldnameList.get(0);
    assertEquals(String.class, dataSourceField.getType());
}
 
Example #14
Source File: StyleConverterServiceTest.java    From geomajas-project-server with GNU Affero General Public License v3.0 6 votes vote down vote up
@Test
public void testFilters() throws LayerException {
	Style style = styleConverterService.convert(layerBeansMixedGeometryStyleInfoSld.getUserStyle());
	List<Rule> rules = style.featureTypeStyles().get(0).rules();
	assertThat(rules.get(0).getFilter()).isInstanceOf(BBOX.class);
	assertThat(rules.get(1).getFilter()).isInstanceOf(Contains.class);
	assertThat(rules.get(2).getFilter()).isInstanceOf(Crosses.class);
	assertThat(rules.get(3).getFilter()).isInstanceOf(Disjoint.class);
	assertThat(rules.get(4).getFilter()).isInstanceOf(Equals.class);
	assertThat(rules.get(5).getFilter()).isInstanceOf(Intersects.class);
	assertThat(rules.get(6).getFilter()).isInstanceOf(Overlaps.class);
	assertThat(rules.get(7).getFilter()).isInstanceOf(Touches.class);
	assertThat(rules.get(8).getFilter()).isInstanceOf(Within.class);
	NamedStyleInfo namedStyleInfo = styleConverterService.convert(
			layerBeansMixedGeometryStyleInfoSld.getUserStyle(), featureInfo);
	Assert.assertEquals(9, namedStyleInfo.getFeatureStyles().size());
}
 
Example #15
Source File: Utils.java    From gama with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Create a default polygon style.
 *
 * @return the created style.
 */
public static Style createPolygonStyle() {

	// create a partially opaque outline stroke
	final Stroke stroke = styleFactory.createStroke(filterFactory.literal(Color.BLUE), filterFactory.literal(1),
			filterFactory.literal(0.5));

	// create a partial opaque fill
	final Fill fill = styleFactory.createFill(filterFactory.literal(Color.CYAN), filterFactory.literal(0.5));

	/*
	 * Setting the geometryPropertyName arg to null signals that we want to draw the default geomettry of features
	 */
	final PolygonSymbolizer sym = styleFactory.createPolygonSymbolizer(stroke, fill, null);

	final Rule rule = styleFactory.createRule();
	rule.symbolizers().add(sym);
	final FeatureTypeStyle fts = styleFactory.createFeatureTypeStyle(new Rule[] { rule });
	final Style style = styleFactory.createStyle();
	style.featureTypeStyles().add(fts);

	return style;
}
 
Example #16
Source File: SLDTreeTools.java    From sldeditor with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Gets the rule tree node.
 *
 * @return the rule tree node
 */
private DefaultMutableTreeNode getRuleTreeNode() {
    if (symbolTree != null) {
        TreePath path = symbolTree.getSelectionPath();

        DefaultMutableTreeNode lastNode = (DefaultMutableTreeNode) path.getLastPathComponent();
        Object obj = lastNode.getUserObject();

        if (obj instanceof Symbolizer) {
            return (DefaultMutableTreeNode) lastNode.getParent();
        } else if (obj instanceof Rule) {
            return lastNode;
        }
    }
    return rootNode;
}
 
Example #17
Source File: ExtractAttributesTest.java    From sldeditor with GNU General Public License v3.0 6 votes vote down vote up
@Test
public void testBinaryTemporalFilter() {
    DummyInternalSLDFile2 dummy = new DummyInternalSLDFile2();

    StyledLayerDescriptor sld = createTestSLD(dummy);
    List<Rule> ruleList = getRuleList(sld);

    Rule rule = DefaultSymbols.createNewRule();

    // Try begins
    Filter filter = ff.begins(ff.property("test"), ff.literal("1234"));
    rule.setFilter(filter);
    ruleList.clear();
    ruleList.add(rule);
    ExtractAttributes extract = new ExtractAttributes();
    extract.extractDefaultFields(sld);

    // Check fields extracted ok
    List<DataSourceAttributeData> actualFieldnameList = extract.getFields();
    assertEquals(1, actualFieldnameList.size());
    DataSourceAttributeData dataSourceField = actualFieldnameList.get(0);
    assertEquals(Integer.class, dataSourceField.getType());
}
 
Example #18
Source File: SLDUtils.java    From sldeditor with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Find equivalent rule.
 *
 * @param otherSLD the other SLD
 * @param styledLayerIndex the styled layer index
 * @param styleIndex the style index
 * @param ftsIndex the fts index
 * @param ruleIndex the rule index
 * @return the rule
 */
private static Rule findEquivalentRule(
        StyledLayerDescriptor otherSLD,
        int styledLayerIndex,
        int styleIndex,
        int ftsIndex,
        int ruleIndex) {
    if (otherSLD != null) {
        List<StyledLayer> styledLayerList = otherSLD.layers();

        try {
            StyledLayer styledLayer = styledLayerList.get(styledLayerIndex);

            List<Style> styleList = getStylesList(styledLayer);

            Style style = styleList.get(styleIndex);
            FeatureTypeStyle fts = style.featureTypeStyles().get(ftsIndex);
            return fts.rules().get(ruleIndex);
        } catch (IndexOutOfBoundsException exception) {
            // Do nothing
        }
    }
    return null;
}
 
Example #19
Source File: SLDUtils.java    From sldeditor with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Traverse symbolizers.
 *
 * @param sld the sld
 * @param traverseSymbolizersInterface the traverse symbolizers interface
 */
public static void traverseSymbolizers(
        StyledLayerDescriptor sld, TraverseSymbolizersInterface traverseSymbolizersInterface) {
    List<StyledLayer> styledLayerList = sld.layers();

    for (StyledLayer styledLayer : styledLayerList) {
        List<Style> styleList = SLDUtils.getStylesList(styledLayer);

        for (Style style : styleList) {
            for (FeatureTypeStyle fts : style.featureTypeStyles()) {
                for (Rule rule : fts.rules()) {
                    for (org.opengis.style.Symbolizer symbolizer : rule.symbolizers()) {
                        processSymbolizer(symbolizer, traverseSymbolizersInterface);
                    }
                }
            }
        }
    }
}
 
Example #20
Source File: Utils.java    From gama with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Create a default line style.
 *
 * @return the created style.
 */
public static Style createLineStyle() {
	final Stroke stroke = styleFactory.createStroke(filterFactory.literal(Color.BLUE), filterFactory.literal(1));

	/*
	 * Setting the geometryPropertyName arg to null signals that we want to draw the default geomettry of features
	 */
	final LineSymbolizer sym = styleFactory.createLineSymbolizer(stroke, null);

	final Rule rule = styleFactory.createRule();
	rule.symbolizers().add(sym);
	final FeatureTypeStyle fts = styleFactory.createFeatureTypeStyle(new Rule[] { rule });
	final Style style = styleFactory.createStyle();
	style.featureTypeStyles().add(fts);

	return style;
}
 
Example #21
Source File: ExtractAttributesTest.java    From sldeditor with GNU General Public License v3.0 6 votes vote down vote up
@Test
public void testNotFilter() {
    DummyInternalSLDFile2 dummy = new DummyInternalSLDFile2();

    StyledLayerDescriptor sld = createTestSLD(dummy);
    List<Rule> ruleList = getRuleList(sld);

    ExtractAttributes extract = new ExtractAttributes();
    Rule rule = DefaultSymbols.createNewRule();
    // Try with NOT
    extract = new ExtractAttributes();
    Filter filter = ff.not(ff.greater(ff.literal(42.1), ff.property("dble")));
    rule.setFilter(filter);
    ruleList.clear();
    ruleList.add(rule);
    extract.extractDefaultFields(sld);

    // Check fields extracted ok
    List<DataSourceAttributeData> actualFieldnameList = extract.getFields();
    assertEquals(1, actualFieldnameList.size());
    DataSourceAttributeData dataSourceField = actualFieldnameList.get(0);
    assertEquals(Double.class, dataSourceField.getType());
}
 
Example #22
Source File: ExtractAttributesTest.java    From sldeditor with GNU General Public License v3.0 6 votes vote down vote up
@Test
public void testMultiComparatorFilter() {
    DummyInternalSLDFile2 dummy = new DummyInternalSLDFile2();

    StyledLayerDescriptor sld = createTestSLD(dummy);
    List<Rule> ruleList = getRuleList(sld);

    Rule rule = DefaultSymbols.createNewRule();

    // Try with something complex
    Filter filter =
            ff.and(
                    ff.greater(ff.literal(42), ff.property("int")),
                    ff.less(ff.literal(12), ff.property("abc")));
    rule.setFilter(filter);
    ruleList.clear();
    ruleList.add(rule);
    ExtractAttributes extract = new ExtractAttributes();
    extract.extractDefaultFields(sld);

    // Check fields extracted ok
    List<DataSourceAttributeData> actualFieldnameList = extract.getFields();
    assertEquals(2, actualFieldnameList.size());
    DataSourceAttributeData dataSourceField = actualFieldnameList.get(0);
    assertEquals(Integer.class, dataSourceField.getType());
}
 
Example #23
Source File: SLDTreeSymbolizerButtonStateTest.java    From sldeditor with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Test method for {@link
 * com.sldeditor.ui.tree.SLDTreeSymbolizerButtonState#setGeometryType(com.sldeditor.datasource.impl.GeometryTypeEnum)}.
 * Test method for {@link
 * com.sldeditor.ui.tree.SLDTreeSymbolizerButtonState#isMarkerVisible(java.lang.Object,
 * java.lang.Object)}. Test method for {@link
 * com.sldeditor.ui.tree.SLDTreeSymbolizerButtonState#isLineVisible(java.lang.Object,
 * java.lang.Object)}. Test method for {@link
 * com.sldeditor.ui.tree.SLDTreeSymbolizerButtonState#isPolygonVisible(java.lang.Object,
 * java.lang.Object)}. Test method for {@link
 * com.sldeditor.ui.tree.SLDTreeSymbolizerButtonState#isRasterVisible(java.lang.Object,
 * java.lang.Object)}. Test method for {@link
 * com.sldeditor.ui.tree.SLDTreeSymbolizerButtonState#isTextVisible(java.lang.Object,
 * java.lang.Object)}. Test method for {@link
 * com.sldeditor.ui.tree.SLDTreeSymbolizerButtonState#isImageOutlineLineVisible(java.lang.Object,
 * java.lang.Object)}. Test method for {@link
 * com.sldeditor.ui.tree.SLDTreeSymbolizerButtonState#isImageOutlinePolygonVisible(java.lang.Object,
 * java.lang.Object)}.
 */
@Test
public void testRaster() {
    SLDTreeSymbolizerButtonState obj = new SLDTreeSymbolizerButtonState();

    obj.setGeometryType(GeometryTypeEnum.RASTER);
    obj.showSymbolizerButtons();
    assertFalse(obj.isLineVisible(null, null));
    assertFalse(obj.isMarkerVisible(null, null));
    assertFalse(obj.isPolygonVisible(null, null));
    assertFalse(obj.isRasterVisible(null, null));
    assertFalse(obj.isTextVisible(null, null));
    assertFalse(obj.isImageOutlineLineVisible(null, null));
    assertFalse(obj.isImageOutlinePolygonVisible(null, null));

    Rule rule = DefaultSymbols.createNewRule();
    assertTrue(obj.isRasterVisible(null, rule));
    assertTrue(obj.isTextVisible(null, rule));

    RasterSymbolizer raster = DefaultSymbols.createDefaultRasterSymbolizer();
    assertTrue(obj.isImageOutlineLineVisible(null, raster));
    assertTrue(obj.isImageOutlinePolygonVisible(null, raster));

    raster.setImageOutline(DefaultSymbols.createDefaultLineSymbolizer());
    assertFalse(obj.isImageOutlineLineVisible(null, raster));
    assertFalse(obj.isImageOutlinePolygonVisible(null, raster));

    raster.setImageOutline(DefaultSymbols.createDefaultPolygonSymbolizer());
    assertFalse(obj.isImageOutlineLineVisible(null, raster));
    assertFalse(obj.isImageOutlinePolygonVisible(null, raster));
}
 
Example #24
Source File: SLDTreeSymbolizerButtonState.java    From sldeditor with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Checks if marker button is visible.
 *
 * @param parentObj the parent obj
 * @param obj the obj
 * @return true, if is marker visible
 */
public boolean isMarkerVisible(Object parentObj, Object obj) {
    boolean enabled = false;
    if (overallEnableSymbolizersOverride) {
        enabled = (obj instanceof Rule) && (geometryType == GeometryTypeEnum.POINT);
    }
    return enabled;
}
 
Example #25
Source File: StyleUtilities.java    From hortonmachine with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Creates a default {@link Rule} for a line.
 * 
 * @return the default rule.
 */
public static Rule createDefaultLineRule() {
    LineSymbolizer lineSymbolizer = sf.createLineSymbolizer();
    lineSymbolizer.setStroke(createDefaultStroke());

    Rule rule = sf.createRule();
    rule.setName("New rule");
    rule.symbolizers().add(lineSymbolizer);

    return rule;
}
 
Example #26
Source File: SimpleStyleUtilities.java    From hortonmachine with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Creates a simple {@link Rule} for a line.
 * 
 * @param color
 *            the color.
 * @param width
 *            the line width.
 * @return the rule.
 */
public static Rule createSimpleLineRule( Color color, float width ) {
    LineSymbolizer lineSymbolizer = StyleUtilities.sf.createLineSymbolizer();
    lineSymbolizer.setStroke(
            StyleUtilities.sf.createStroke(StyleUtilities.ff.literal("#" + Integer.toHexString(color.getRGB() & 0xffffff)),
                    StyleUtilities.ff.literal(width)));

    Rule rule = StyleUtilities.sf.createRule();
    rule.setName("New rule");
    rule.symbolizers().add(lineSymbolizer);

    return rule;
}
 
Example #27
Source File: StyleConverterServiceImpl.java    From geomajas-project-server with GNU Affero General Public License v3.0 5 votes vote down vote up
private Rule createRule(Filter filter, FeatureStyleInfo featureStyle) throws LayerException {
	Rule rule = styleBuilder.createRule(createGeometrySymbolizer(featureStyle));
	if (filter.equals(Filter.INCLUDE)) {
		rule.setElseFilter(true);
	} else {
		rule.setFilter(filter);
	}
	rule.setName(featureStyle.getName());
	rule.setTitle(featureStyle.getName());
	return rule;
}
 
Example #28
Source File: ScaleSLDData.java    From sldeditor with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Update scales.
 *
 * @param sldWriter the sld writer
 */
public boolean updateScales(SLDWriterInterface sldWriter) {
    boolean refreshUI = false;
    if ((rule != null) && (sldWriter != null)) {
        if (isMinimumScaleUpdated()) {
            rule.setMinScaleDenominator(minScale);
            minimumScaleUpdated = false;
        }

        if (isMaximumScaleUpdated()) {
            rule.setMaxScaleDenominator(maxScale);
            maximumScaleUpdated = false;
        }

        String sldContents = sldWriter.encodeSLD(null, this.sld);

        SLDDataInterface current = SLDEditorFile.getInstance().getSLDData();

        if (current.getSLDFile().equals(sldData.getSLDFile())
                || current.getSLDURL().equals(sldData.getSLDURL())) {
            Rule currentFule =
                    SLDUtils.findRule(sld, rule, SelectedSymbol.getInstance().getSld());
            if (currentFule != null) {
                currentFule.setMinScaleDenominator(minScale);
                currentFule.setMaxScaleDenominator(maxScale);
                refreshUI = true;
            }
        }

        sldData.updateSLDContents(sldContents);
    }

    return refreshUI;
}
 
Example #29
Source File: StyleUtilities.java    From hortonmachine with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Changes the rotation value inside a rule.
 * 
 * @param rule the {@link Rule}.
 * @param newRotation the new rotation value in degrees.
 */
public static void changeRotation( Rule rule, int newRotation ) {
    PointSymbolizer pointSymbolizer = StyleUtilities.pointSymbolizerFromRule(rule);
    Graphic graphic = SLD.graphic(pointSymbolizer);
    graphic.setRotation(ff.literal(newRotation));
    // Mark oldMark = SLDs.mark(pointSymbolizer);
    // oldMark.setSize(ff.literal(newRotation));
}
 
Example #30
Source File: ShapefileLoader.java    From snap-desktop with GNU General Public License v3.0 5 votes vote down vote up
private static Style createPointStyle() {
    PointSymbolizer symbolizer = styleFactory.createPointSymbolizer();
    symbolizer.getGraphic().setSize(filterFactory.literal(1));

    Rule rule = styleFactory.createRule();
    rule.symbolizers().add(symbolizer);
    FeatureTypeStyle fts = styleFactory.createFeatureTypeStyle();
    fts.rules().add(rule);

    Style style = styleFactory.createStyle();
    style.featureTypeStyles().add(fts);
    return style;
}