Class StyleUtilities
- java.lang.Object
-
- org.hortonmachine.gears.utils.style.StyleUtilities
-
public class StyleUtilities extends Object
Style related utilities.- Author:
- Andrea Antonello (www.hydrologis.com)
-
-
Field Summary
Fields Modifier and Type Field Description static StringDEFAULT_COLORstatic StringDEFAULT_GROUPNAMEstatic StringDEFAULT_MAXSCALEstatic StringDEFAULT_MINSCALEstatic StringDEFAULT_OFFSETstatic StringDEFAULT_OPACITYstatic StringDEFAULT_ROTATIONstatic StringDEFAULT_SIZEstatic StringDEFAULT_STYLENAMEstatic StringDEFAULT_WIDTHstatic intDISPLACEMENT_MAXstatic intDISPLACEMENT_MINstatic intDISPLACEMENT_STEPstatic org.opengis.filter.FilterFactoryffThe defaultFilterFactoryto use.static String[]lineCapNamesThe SLD names of the line cap definitions.static HashMap<String,String>lineEndStylesA map of user friendly names to the SLD names of line end styles.static String[]lineJoinNamesThe SLD names of the line join definitions.static HashMap<String,String>markNamesToDefA map of names for all the marks.static StringNONEstatic intOFFSET_MAXstatic intOFFSET_MINstatic intOFFSET_STEPstatic org.geotools.styling.StyleBuildersbThe defaultStyleBuilderto use.static org.geotools.styling.StyleFactorysfThe defaultStyleFactoryto use.static StringSHAPE_PREFIXstatic String[]shapeMarkDefsThe custom shape mark names as needed by geotools.static String[]shapeMarkNamesThe custom shape mark names for gui.static StringSLD_EXTENTIONstatic String[]verticalPlacementNamesThe SLD names of the line join definitions.static String[]wkMarkDefsThe SLD defined well known mark codes.static String[]wkMarkNamesThe SLD defined well known mark names for gui use.
-
Constructor Summary
Constructors Constructor Description StyleUtilities()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static voidchangeMarkSize(org.geotools.styling.Rule rule, int newSize)Changes the size of a mark inside a rule.static voidchangeRotation(org.geotools.styling.Rule rule, int newRotation)Changes the rotation value inside a rule.static StringcheckSameNameFeatureTypeStyle(List<FeatureTypeStyleWrapper> ftsWrapperList, String ftsName)Checks if the list ofFeatureTypeStyleWrappers supplied contains one with the supplied name.static StringcheckSameNameRule(List<RuleWrapper> rulesWrapper, String ruleName)Checks if the list ofRules supplied contains one with the supplied name.static StringcheckSameNameStyle(List<StyleWrapper> styles, String styleName)Checks if the list ofStyleWrappers supplied contains one with the supplied name.static org.geotools.styling.FillcreateDefaultFill()static org.geotools.styling.RulecreateDefaultLineRule()Creates a defaultRulefor a line.static org.geotools.styling.StylecreateDefaultLineStyle()Creates a defaultStylefor a line.static org.geotools.styling.RulecreateDefaultPointRule()Creates a defaultRulefor a point.static org.geotools.styling.StylecreateDefaultPointStyle()Creates a defaultStylefor a point.static org.geotools.styling.RulecreateDefaultPolygonRule()Creates a defaultRulefor a polygon.static org.geotools.styling.StylecreateDefaultPolygonStyle()Creates a defaultStylefor a polygon.static org.geotools.styling.StrokecreateDefaultStroke()static org.geotools.styling.StylecreateDefaultStyle(org.geotools.data.simple.SimpleFeatureCollection featureCollection)Creates a defaultStylefor a featurecollection.static StyleWrappercreateStyleFromGraphic(File graphicsPath)Generates a style based on a graphic.static List<org.geotools.styling.ExternalGraphic>externalGraphicsFromGraphic(org.geotools.styling.Graphic graphic)Collect allExternalGraphics from the givenGraphic.static List<org.geotools.styling.ExternalGraphic>externalGraphicsFromRule(org.geotools.styling.Rule rule)Collect allExternalGraphics from the givenRule.static String[]getAllMarksArray()Getter for an array of all available marks.static BasicStylegetBasicStyle(org.geotools.styling.Style style)static float[]getDash(String dashStr)Returns a dash array from a dash string.static StringgetDashString(float[] dashArray)Converts teh array to string.static StringgetExternalGraphicFormat(String name)Get the format of anExternalGraphicfrom its path or name.static StringgetFormat(String path)static Point2DgetOffset(org.geotools.styling.Symbolizer symbolizer)Get the offset from aSymbolizer.static <T extends Number>
TisNumber(String value, Class<T> adaptee)Checks if a string is a number (currently Double, Float, Integer).static org.geotools.styling.LineSymbolizerlineSymbolizerFromRule(org.geotools.styling.Rule rule)Get theLineSymbolizerfrom the given rule.static org.geotools.styling.PointSymbolizerpointSymbolizerFromRule(org.geotools.styling.Rule rule)Get thePointSymbolizerfrom the given rule.static org.geotools.styling.PolygonSymbolizerpolygonSymbolizerFromRule(org.geotools.styling.Rule rule)Get thePolygonSymbolizerfrom the given rule.static org.geotools.styling.StyledLayerDescriptorreadStyle(File file)Parse a file and extract theStyledLayerDescriptor.static org.geotools.styling.StylerulesToStyle(List<org.geotools.styling.Rule> rules, String name, boolean oneFeaturetypestylePerRule)Converts a list ofRules to aStylewith the given name.static voidsetOffset(org.geotools.styling.Symbolizer symbolizer, String text)Sets the offset in a symbolizer.static intsld2awtCap(String sldCap)Convert a sld line cap definition to the java awt value.static intsld2awtJoin(String sldJoin)Convert a sld line join definition to the java awt value.static StringstyleToString(org.geotools.styling.Style style)Converts a style to its string representation to be written to file.static voidsubstituteExternalGraphics(org.geotools.styling.Rule rule, URL externalGraphicsUrl)Change the external graphic in a rule.static voidsubstituteMark(org.geotools.styling.Rule rule, String wellKnownMarkName)Change the mark shape in a rule.
-
-
-
Field Detail
-
NONE
public static final String NONE
- See Also:
- Constant Field Values
-
DEFAULT_SIZE
public static final String DEFAULT_SIZE
- See Also:
- Constant Field Values
-
DEFAULT_WIDTH
public static final String DEFAULT_WIDTH
- See Also:
- Constant Field Values
-
DEFAULT_ROTATION
public static final String DEFAULT_ROTATION
- See Also:
- Constant Field Values
-
DEFAULT_OFFSET
public static final String DEFAULT_OFFSET
- See Also:
- Constant Field Values
-
DEFAULT_OPACITY
public static final String DEFAULT_OPACITY
- See Also:
- Constant Field Values
-
DEFAULT_COLOR
public static final String DEFAULT_COLOR
- See Also:
- Constant Field Values
-
DEFAULT_MINSCALE
public static final String DEFAULT_MINSCALE
- See Also:
- Constant Field Values
-
DEFAULT_MAXSCALE
public static final String DEFAULT_MAXSCALE
- See Also:
- Constant Field Values
-
OFFSET_MAX
public static final int OFFSET_MAX
- See Also:
- Constant Field Values
-
OFFSET_MIN
public static final int OFFSET_MIN
- See Also:
- Constant Field Values
-
OFFSET_STEP
public static final int OFFSET_STEP
- See Also:
- Constant Field Values
-
DISPLACEMENT_MAX
public static final int DISPLACEMENT_MAX
- See Also:
- Constant Field Values
-
DISPLACEMENT_MIN
public static final int DISPLACEMENT_MIN
- See Also:
- Constant Field Values
-
DISPLACEMENT_STEP
public static final int DISPLACEMENT_STEP
- See Also:
- Constant Field Values
-
DEFAULT_GROUPNAME
public static final String DEFAULT_GROUPNAME
- See Also:
- Constant Field Values
-
DEFAULT_STYLENAME
public static final String DEFAULT_STYLENAME
- See Also:
- Constant Field Values
-
SLD_EXTENTION
public static final String SLD_EXTENTION
- See Also:
- Constant Field Values
-
wkMarkDefs
public static final String[] wkMarkDefs
The SLD defined well known mark codes.
-
wkMarkNames
public static final String[] wkMarkNames
The SLD defined well known mark names for gui use.
-
SHAPE_PREFIX
public static final String SHAPE_PREFIX
- See Also:
- Constant Field Values
-
shapeMarkDefs
public static final String[] shapeMarkDefs
The custom shape mark names as needed by geotools.
-
shapeMarkNames
public static final String[] shapeMarkNames
The custom shape mark names for gui.
-
markNamesToDef
public static final HashMap<String,String> markNamesToDef
A map of names for all the marks.
-
lineCapNames
public static final String[] lineCapNames
The SLD names of the line cap definitions.
-
verticalPlacementNames
public static final String[] verticalPlacementNames
The SLD names of the line join definitions.
-
lineJoinNames
public static final String[] lineJoinNames
The SLD names of the line join definitions.
-
lineEndStyles
public static final HashMap<String,String> lineEndStyles
A map of user friendly names to the SLD names of line end styles.
-
sf
public static org.geotools.styling.StyleFactory sf
The defaultStyleFactoryto use.
-
ff
public static org.opengis.filter.FilterFactory ff
The defaultFilterFactoryto use.
-
sb
public static org.geotools.styling.StyleBuilder sb
The defaultStyleBuilderto use.
-
-
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 theStyledLayerDescriptor.- 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 allExternalGraphics from the givenRule.- 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 allExternalGraphics from the givenGraphic.- 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 defaultStylefor a featurecollection.- Returns:
- the default style.
-
createDefaultPointStyle
public static org.geotools.styling.Style createDefaultPointStyle()
Creates a defaultStylefor a point.- Returns:
- the default style.
-
createDefaultPointRule
public static org.geotools.styling.Rule createDefaultPointRule()
Creates a defaultRulefor a point.- Returns:
- the default rule.
-
createDefaultPolygonStyle
public static org.geotools.styling.Style createDefaultPolygonStyle()
Creates a defaultStylefor a polygon.- Returns:
- the default style.
-
createDefaultPolygonRule
public static org.geotools.styling.Rule createDefaultPolygonRule()
Creates a defaultRulefor a polygon.- Returns:
- the default rule.
-
createDefaultFill
public static org.geotools.styling.Fill createDefaultFill()
-
createDefaultLineStyle
public static org.geotools.styling.Style createDefaultLineStyle()
Creates a defaultStylefor a line.- Returns:
- the default style.
-
createDefaultLineRule
public static org.geotools.styling.Rule createDefaultLineRule()
Creates a defaultRulefor 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 thePointSymbolizerfrom 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 thePolygonSymbolizerfrom 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 theLineSymbolizerfrom 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.
-
getExternalGraphicFormat
public static String getExternalGraphicFormat(String name)
Get the format of anExternalGraphicfrom 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- theRule.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- theRule.newRotation- the new rotation value in degrees.
-
getOffset
public static Point2D getOffset(org.geotools.styling.Symbolizer symbolizer)
Get the offset from aSymbolizer.- 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 ofRules 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 ofFeatureTypeStyleWrappers 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 ofStyleWrappers 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 ofRules to aStylewith the given name.- Parameters:
rules- the list of rules.name- the name of the new style.oneFeaturetypestylePerRule- switch to create aFeatureTypeStyleperRule.- 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 permissiveDoublewill 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.
-
getBasicStyle
public static BasicStyle getBasicStyle(org.geotools.styling.Style style) throws Exception
- Throws:
Exception
-
-