[mapserver-users] Custom Symbology using C# MapScript and SLDs
Pat B
barnhart.pat at gmail.com
Tue Mar 16 08:44:15 PDT 2010
Hi all - the following c# mapscript code is intended to change the symbol
displayed for a point layer from an existing .sym file and write the style
to an sld. Overall my goal is to let the user customize the map symbology
on the fly using predfined symbols and save those changes in a sld.
My understanding is that I should also be able to use WellKnownName symbols
(square, circle, triangle, star, cross, x) even if they don't exist in the
.sym. I've gotten it to work with the first two only (square and circle) by
setting the style.symbolname directly instead of using setSymbolByName but
it defaults back to one of those two for any of the other known names and
doesn't work for my predefined symbols. I'm pretty sure I'm missing a step
somewhere but have spent days on this with no luck, any help would be
greatly appreciated!
mapObj map = new mapObj("c:/ms4w/tmp/maps/myMapFile.map");
map.setSymbolSet("c:/ms4w/tmp/maps/symbols/symbols.sym");
layerObj layer = map.getLayerByName(layerName);
classObj cls = new classObj(layer);
styleObj style = new styleObj(cls);
style.setSymbolByName(map,"mySymbol");
cls.insertStyle(style, 0);
//remove any existing styles
for(var w=1;w<cls.numstyles;w++)
{
cls.removeStyle(w);
w = w - 1;
}
layer.insertClass(cls, 0);
//remove any existing classes
for (var w=1;w<layer.numclasses;w++)
{
layer.removeClass(w);
w = w - 1;
}
string sldString = map.generateSLD();
Here's a couple symbols from the .sym with different types (no luck with any
of them):
SYMBOL # hurricane
TYPE TRUETYPE
NAME 'hurricane'
FONT "weather"
CHARACTER "$"
ANTIALIAS true
TRANSPARENT 255
END
SYMBOL # box
TYPE vector
NAME 'box'
FILLED true
POINTS
0 4
0 0
4 0
4 4
0 4
END # Points definition
END
SYMBOL # airplane
TYPE PIXMAP
NAME 'airplane'
IMAGE "airplane.gif"
END
Here's what I get in the output .sld:
...
<NamedLayer>
<Name>Point Layer</Name>
<UserStyle>
<FeatureTypeStyle>
<Name>Point Layer</Name>
<MaxScaleDenominator>100000.000000</MaxScaleDenominator>
<PointSymbolizer></PointSymbolizer>
</FeatureTypeStyle>
</UserStyle>
</NamedLayer>
...
Here's what I want to get in the output sld:
...
<NamedLayer>
<Name>Point Layer</Name>
<UserStyle>
<FeatureTypeStyle>
<Rule>
<Name>Point Layer</Name>
<PointSymbolizer>
<Graphic>
<Mark>
<WellKnownName>mySymbol</WellKnownName>
<Fill>
<CssParameter name="fill">#ff0000</CssParameter>
</Fill>
</Mark>
<Size>10</Size>
</Graphic>
</PointSymbolizer>
</Rule>
</FeatureTypeStyle>
</UserStyle>
</NamedLayer>
...
--
View this message in context: http://n2.nabble.com/Custom-Symbology-using-C-MapScript-and-SLDs-tp4744442p4744442.html
Sent from the Mapserver - User mailing list archive at Nabble.com.
More information about the MapServer-users
mailing list