>If you can modify your data, it might make sense to just add a column of >random values to it and reference those from the SLD - that would allow you a >bit more control if you find that the colors need tweaking (two similar colors >in adjacent polygons, etc.)
That would be a simple solution, in the SLD template how do I simply set the color equal to database field value? -Håvard 2011/8/29 David Winslow <dwins...@opengeo.org>: > If I wanted to achieve such a thing in Java, I would try something along the > lines of: > > int hash = feature.getFeatureId().hashCode(); > String colorCode = String.format("#%06x", hash & 0xFFFFFF); > > I believe there is a format function exposed in GeoServer's SLD > implementation - but I am not sure about a good SLD substitute for > .hashCode. If you have to, it's not hard for a Java developer to add a > filter function. > > If you can modify your data, it might make sense to just add a column of > random values to it and reference those from the SLD - that would allow you > a bit more control if you find that the colors need tweaking (two similar > colors in adjacent polygons, etc.) > > -- > David Winslow > OpenGeo - http://opengeo.org/ > > 2011/8/28 Håvard Wahl Kongsgård <haavard.kongsga...@gmail.com> >> >> Hi, I have a layer with multiple bordering polygons which needs to be >> visually separated. >> >> One possibility is to create a massive SLD template, defining random >> colors for specific polygons. >> >> However, I noticed this post >> >> http://osgeo-org.1803224.n2.nabble.com/Random-function-in-SLD-td6125434.html >> >> The problem with that approach is that polygons change colors when >> zooming, and when map tiles are enabled, polygons crossing different >> tiles have multiple colors. With SLD templates is there another way to >> do this? >> >> >> <?xml version="1.0" encoding="ISO-8859-1"?> >> <StyledLayerDescriptor version="1.0.0" >> xsi:schemaLocation="http://www.opengis.net/sld StyledLayerDescriptor.xsd" >> xmlns="http://www.opengis.net/sld" >> xmlns:ogc="http://www.opengis.net/ogc" >> xmlns:xlink="http://www.w3.org/1999/xlink" >> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> >> <!-- a Named Layer is the basic building block of an SLD document --> >> <NamedLayer> >> <Name>default_polygon</Name> >> <UserStyle> >> <!-- Styles can have names, titles and abstracts --> >> <Title>Default Polygon</Title> >> <Abstract>A sample style that draws a polygon</Abstract> >> <!-- FeatureTypeStyles describe how to render different features --> >> <!-- A FeatureTypeStyle for rendering polygons --> >> <FeatureTypeStyle> >> <Rule> >> <Name>rule1</Name> >> <PolygonSymbolizer> >> <Fill> >> <CssParameter name="fill"> >> <ogc:Function name="numberFormat"> >> <ogc:Literal>'#'000000</ogc:Literal> >> <ogc:Mul> >> <ogc:Function name="random"></ogc:Function> >> <ogc:Literal>1000000</ogc:Literal> >> </ogc:Mul> >> </ogc:Function> >> </CssParameter> >> <CssParameter name="fill-opacity">0.7</CssParameter> >> </Fill> >> <Stroke> >> <CssParameter name="stroke">#000000</CssParameter> >> <CssParameter name="stroke-width">1</CssParameter> >> </Stroke> >> </PolygonSymbolizer> >> </Rule> >> </FeatureTypeStyle> >> </UserStyle> >> </NamedLayer> >> </StyledLayerDescriptor> >> >> -- >> Håvard Wahl Kongsgård >> >> >> ------------------------------------------------------------------------------ >> EMC VNX: the world's simplest storage, starting under $10K >> The only unified storage solution that offers unified management >> Up to 160% more powerful than alternatives and 25% more efficient. >> Guaranteed. http://p.sf.net/sfu/emc-vnx-dev2dev >> _______________________________________________ >> Geoserver-users mailing list >> Geoserver-users@lists.sourceforge.net >> https://lists.sourceforge.net/lists/listinfo/geoserver-users > > ------------------------------------------------------------------------------ EMC VNX: the world's simplest storage, starting under $10K The only unified storage solution that offers unified management Up to 160% more powerful than alternatives and 25% more efficient. Guaranteed. http://p.sf.net/sfu/emc-vnx-dev2dev _______________________________________________ Geoserver-users mailing list Geoserver-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/geoserver-users