Class StyleUtilities


  • public class StyleUtilities
    extends Object
    Style related utilities.
    Author:
    Andrea Antonello (www.hydrologis.com)
    • Constructor Detail

      • StyleUtilities

        public StyleUtilities()
    • Method Detail

      • getAllMarksArray

        public static String[] getAllMarksArray()
        Getter for an array of all available marks.
        Returns:
        all mark names (for gui use).
      • readStyle

        public static org.geotools.styling.StyledLayerDescriptor readStyle​(File file)
                                                                    throws IOException
        Parse a file and extract the StyledLayerDescriptor.
        Parameters:
        file - the sld file to parse.
        Returns:
        the styled layer descriptor.
        Throws:
        IOException
      • externalGraphicsFromRule

        public static List<org.geotools.styling.ExternalGraphic> externalGraphicsFromRule​(org.geotools.styling.Rule rule)
        Collect all ExternalGraphics from the given Rule.
        Parameters:
        rule - the rule to check.
        Returns:
        the extracted ExternalGraphics.
      • externalGraphicsFromGraphic

        public static List<org.geotools.styling.ExternalGraphic> externalGraphicsFromGraphic​(org.geotools.styling.Graphic graphic)
        Collect all ExternalGraphics from the given Graphic.
        Parameters:
        graphic - the graphic to check.
        Returns:
        the extracted ExternalGraphics.
      • createDefaultStyle

        public static org.geotools.styling.Style createDefaultStyle​(org.geotools.data.simple.SimpleFeatureCollection featureCollection)
        Creates a default Style for a featurecollection.
        Returns:
        the default style.
      • createDefaultPointStyle

        public static org.geotools.styling.Style createDefaultPointStyle()
        Creates a default Style for a point.
        Returns:
        the default style.
      • createDefaultPointRule

        public static org.geotools.styling.Rule createDefaultPointRule()
        Creates a default Rule for a point.
        Returns:
        the default rule.
      • createDefaultPolygonStyle

        public static org.geotools.styling.Style createDefaultPolygonStyle()
        Creates a default Style for a polygon.
        Returns:
        the default style.
      • createDefaultPolygonRule

        public static org.geotools.styling.Rule createDefaultPolygonRule()
        Creates a default Rule for a polygon.
        Returns:
        the default rule.
      • createDefaultFill

        public static org.geotools.styling.Fill createDefaultFill()
      • createDefaultLineStyle

        public static org.geotools.styling.Style createDefaultLineStyle()
        Creates a default Style for a line.
        Returns:
        the default style.
      • createDefaultLineRule

        public static org.geotools.styling.Rule createDefaultLineRule()
        Creates a default Rule for a line.
        Returns:
        the default rule.
      • createDefaultStroke

        public static org.geotools.styling.Stroke createDefaultStroke()
      • pointSymbolizerFromRule

        public static org.geotools.styling.PointSymbolizer pointSymbolizerFromRule​(org.geotools.styling.Rule rule)
        Get the PointSymbolizer from the given rule.
        Parameters:
        rule - the rule to check for symbolizers.
        Returns:
        the first symbolizer found.
      • polygonSymbolizerFromRule

        public static org.geotools.styling.PolygonSymbolizer polygonSymbolizerFromRule​(org.geotools.styling.Rule rule)
        Get the PolygonSymbolizer from the given rule.
        Parameters:
        rule - the rule to check for symbolizers.
        Returns:
        the first symbolizer found.
      • lineSymbolizerFromRule

        public static org.geotools.styling.LineSymbolizer lineSymbolizerFromRule​(org.geotools.styling.Rule rule)
        Get the LineSymbolizer from the given rule.
        Parameters:
        rule - the rule to check for symbolizers.
        Returns:
        the first symbolizer found.
      • substituteMark

        public static void substituteMark​(org.geotools.styling.Rule rule,
                                          String wellKnownMarkName)
        Change the mark shape in a rule.
        Parameters:
        rule - the rule of which the mark has to be changed.
        wellKnownMarkName - the name of the new mark.
      • substituteExternalGraphics

        public static void substituteExternalGraphics​(org.geotools.styling.Rule rule,
                                                      URL externalGraphicsUrl)
        Change the external graphic in a rule.
        Parameters:
        rule - the rule of which the external graphic has to be changed.
        path - the path of the image.
      • getFormat

        public static String getFormat​(String path)
      • getExternalGraphicFormat

        public static String getExternalGraphicFormat​(String name)
        Get the format of an ExternalGraphic from its path or name.
        Parameters:
        name - the path or file name to test against.
        Returns:
        teh format definition.
      • changeMarkSize

        public static void changeMarkSize​(org.geotools.styling.Rule rule,
                                          int newSize)
        Changes the size of a mark inside a rule.
        Parameters:
        rule - the Rule.
        newSize - the new size.
      • changeRotation

        public static void changeRotation​(org.geotools.styling.Rule rule,
                                          int newRotation)
        Changes the rotation value inside a rule.
        Parameters:
        rule - the Rule.
        newRotation - the new rotation value in degrees.
      • getOffset

        public static Point2D getOffset​(org.geotools.styling.Symbolizer symbolizer)
        Get the offset from a Symbolizer.
        Parameters:
        symbolizer - the symbolizer.
        Returns:
        the offset.
      • setOffset

        public static void setOffset​(org.geotools.styling.Symbolizer symbolizer,
                                     String text)
        Sets the offset in a symbolizer.
        Parameters:
        symbolizer - the symbolizer.
        text - the text representing the offsets in the CSV form.
      • checkSameNameRule

        public static String checkSameNameRule​(List<RuleWrapper> rulesWrapper,
                                               String ruleName)
        Checks if the list of Rules supplied contains one with the supplied name.

        If the rule is contained it adds an index to the name.

        Parameters:
        rulesWrapper - the list of rules to check.
        ruleName - the name of the rule to find.
        Returns:
        the new name of the rule.
      • checkSameNameFeatureTypeStyle

        public static String checkSameNameFeatureTypeStyle​(List<FeatureTypeStyleWrapper> ftsWrapperList,
                                                           String ftsName)
        Checks if the list of FeatureTypeStyleWrappers supplied contains one with the supplied name.

        If the rule is contained it adds an index to the name.

        Parameters:
        ftsWrapperList - the list of featureTypeStyles to check.
        ftsName - the name of the featureTypeStyle to find.
        Returns:
        the new name of the featureTypeStyle.
      • checkSameNameStyle

        public static String checkSameNameStyle​(List<StyleWrapper> styles,
                                                String styleName)
        Checks if the list of StyleWrappers supplied contains one with the supplied name.

        If the style is contained it adds an index to the name.

        Parameters:
        styles - the list of style wrappers to check.
        styleName - the name of the style to find.
        Returns:
        the new name of the style.
      • rulesToStyle

        public static org.geotools.styling.Style rulesToStyle​(List<org.geotools.styling.Rule> rules,
                                                              String name,
                                                              boolean oneFeaturetypestylePerRule)
        Converts a list of Rules to a Style with the given name.
        Parameters:
        rules - the list of rules.
        name - the name of the new style.
        oneFeaturetypestylePerRule - switch to create a FeatureTypeStyle per Rule.
        Returns:
        the new style created.
      • styleToString

        public static String styleToString​(org.geotools.styling.Style style)
                                    throws Exception
        Converts a style to its string representation to be written to file.
        Parameters:
        style - the style to convert.
        Returns:
        the style string.
        Throws:
        Exception
      • createStyleFromGraphic

        public static StyleWrapper createStyleFromGraphic​(File graphicsPath)
                                                   throws IOException
        Generates a style based on a graphic.
        Parameters:
        graphicsPath - the graphic.
        Returns:
        the generated style.
        Throws:
        IOException
      • getDash

        public static float[] getDash​(String dashStr)
        Returns a dash array from a dash string.
        Parameters:
        dashStr - the dash string definition.
        Returns:
        the dash array or null if the definition can't be parsed.
      • getDashString

        public static String getDashString​(float[] dashArray)
        Converts teh array to string.
        Parameters:
        dashArray - the dash array.
        Returns:
        the converted string.
      • isNumber

        public static <T extends Number> T isNumber​(String value,
                                                    Class<T> adaptee)
        Checks if a string is a number (currently Double, Float, Integer).
        Parameters:
        value - the string to check.
        adaptee - the class to check against. If null, the more permissive Double will be used.
        Returns:
        the number or null, if the parsing fails.
      • sld2awtJoin

        public static int sld2awtJoin​(String sldJoin)
        Convert a sld line join definition to the java awt value.
        Parameters:
        sldJoin - the sld join string.
        Returns:
        the awt value.
      • sld2awtCap

        public static int sld2awtCap​(String sldCap)
        Convert a sld line cap definition to the java awt value.
        Parameters:
        sldCap - the sld cap string.
        Returns:
        the awt value.