|
From: ATI <luo...@ho...> - 2009-06-11 11:39:21
|
Hi,
as some of you might be aware, i'm attempting to display my road names
from my .dbf file onto my shapefile. At present i'm up to the stage where i
am trying to use a style obj to help read/parse the sld file and apply it to
the a layer. I have already harde coded the location of the .sld file which
i am parsing to a function see bellow. I've been investigating around the
geotools guid and the web and i'm not to sure how to use the style object
generated in my map context to help display the road names from my .dbf file
onto my shapefile using my .sld file. I've also looked at this particular
tutorial
http://docs.codehaus.org/display/GEOTDOC/06+Style+Layer+Descriptor+Document,
looking at "How to write an SLD file using only a Style" which i have tried
to use myself which i think might be the answer, but i might need
clarifcation on that.
public void actionPerformed(ActionEvent e) {
if (e.getSource() == menuItem)
{
//boolMenuItem = true;
System.out.println("menuItem has been clicked");
int returnVal = fileChooser.showOpenDialog(menu);
displayShapeFile(fileChooser.getSelectedFile());
displayRoadName(sldFile); // when displaying .shp file send
.sldfile for rendendering
}
// other code missed out
public void displayRoadName(File sldFile)
{
UserLayer myLayer = UserLayers.createUserLayer();
StyleFactory factory = StyleFactory.createStyleFactory();
try {
// using this for faster rleading to wrap any InputStream
sldFIS = new FileInputStream(sldFile);
sldBIS = new BufferedInputStream(sldFIS);
// Create parser to parse SLD File
StyledLayerDescriptor sld = (StyledLayerDescriptor)
sldParser.parse(sldFIS);
SLDStyle stylereader = new SLDStyle(factory, sldFile);
Style[] style = stylereader.readXML();
sld.addStyledLayer(myLayer);
myLayer.addUserStyle(style);
//new FileReader(sldFile);
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (SAXException e) {
e.printStackTrace();
} catch (ParserConfigurationException e) {
e.printStackTrace();
}
}
}
http://n2.nabble.com/file/n3061498/Map_AppV3.zip Map_AppV3.zip
Right now, you could say, i'm a bit lost and need a friendly hand to put me
back on the road. I've uploaded my app for referrence. Thanks again
--
View this message in context: http://n2.nabble.com/Using-Style-in-conjunction-with-my-.SLD-file-tp3061498p3061498.html
Sent from the geotools-gt2-users mailing list archive at Nabble.com.
|