I drew the wind barbs on the map based on the coordinates data with the step of 2 degrees. But I am not satisfied with the fact that after the map reprojecting the size of the wind barbs changes. Is it possible to draw a wind barbs with exactly the same size with GeoTools?



The easiest way to produce size invariant wind barbs is to make use of the Windbarbs mark in your style, rather than trying to construct it in map units (which is why yours change size with projection).

Based on this blog post by GeoSolutions you can use a SLD file like this:

                         <CssParameter name="stroke">000000</CssParameter>
                         <CssParameter name="stroke-width">1</CssParameter>
                       <CssParameter name="fill">

This draws a wind barb based on speed, direction and hemisphere and a small dot for the location of your measurement. Modifying your code something like this:

// create the parser with the sld configuration
Configuration config = new SLDConfiguration();
Parser parser = new Parser(config);

// the xml instance document above
InputStream xml = new FileInputStream(new File("wind.sld"));

org.geotools.styling.Style[] styles = null;
// parse

StyleFactory styleFactory = CommonFactoryFinder.getStyleFactory();
SLDParser stylereader = new SLDParser(styleFactory, xml);
styles = stylereader.readXML();
Layer wlayer = new FeatureLayer(DataUtilities.source(features), styles[0]);

Where features is my SimpleFeatureCollection of random wind speeds, you can either follow that or create a DataStore and get a FeatureSource from that.

enter image description here

and if you reproject the map you get:

enter image description here

If you study the blog post you will see some options for changing the size of the marks based on zoom level. Note if you have a grid of u and v then you can use the SLD in the blog post unchanged.

I think you should be able to construct the SLD programmatically but this is left as an exercise for the interested reader.

| improve this answer | |
  • Thanks a lot, Ian! I will try. Thank you for your help – asker May 30 '19 at 14:33
  • Do I need to install GeoServer in this case? – asker May 30 '19 at 14:41
  • no, GeoTools underlies all of GeoServer - see my update – Ian Turton May 30 '19 at 15:23
  • I am sorry, but I need to precise whether it is possible to get SimpleFeatureCollection from sld file or I should use SimpleFeatureCollection which I have created programatically? And also I need to precise how can I make request localhost:8083/geoserver/geosolutions/… from geotools to get windbarb images? – asker Jun 3 '19 at 15:04
  • Is sld file use to getting only Style? Am I right or not? – asker Jun 3 '19 at 15:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.