1

I styled a layer with uDig and exported the style as SLD file. I then applied the same style to the a layer (same shapefile) in my code using Geotools. However, uDig's rendering of the map looks much better than mine.

My project uses geotools version 21.2, Java 1.8 and I'm rendering the map with Geotools's JMapPane. Having noticed that the uDig version looks better that mine, I attempted digging into the uDig source to see how the shape files are rendered. I found that shape file are rendered in uDig by ShapefileFeatureRenderer, or so I think. I then copied and pasted the renderer's initialization code and applied it in my project but I didn't notice any difference.

renderer = new StreamingRenderer();
HashMap<String, Object> rendererHints = new HashMap<String, Object>();
rendererHints.put("optimizedDataLoadingEnabled", true); //$NON-NLS-1$
renderer.setRendererHints(rendererHints);
            // renderer.removeRenderListener(StreamingRenderer.DEFAULT_LISTENER);
renderer.addRenderListener(listener);

            // JG - these may be overriden by the preferences before use?
RenderingHints hints = new RenderingHints(RenderingHints.KEY_ANTIALIASING,
                    RenderingHints.VALUE_ANTIALIAS_ON);
renderer.setJava2DHints(hints)
mapPane.setRenderer(renderer);

How do I make my map rendering as good as uDig's (uDig's rendering is to the left in the screenshot below) ? side by side

I would like some one to point me in the right direction on how to go about this. Any help would be appreciated.

Glorfindel
  • 21,988
  • 13
  • 81
  • 109
Yemi Kudaisi
  • 163
  • 1
  • 7
  • 1
    Geotools no longer supports ShapefileFeatureRenderer – Ian Turton Sep 07 '19 at 18:55
  • So what's the alternative, specifically how do i get a better rendering ? – Yemi Kudaisi Sep 09 '19 at 15:33
  • can you clarify exactly what you think is better from one to the other? – Ian Turton Sep 09 '19 at 15:51
  • Notice how the roads are wider, the texts are much clearer, on a larger scale, the map is barely readable. My intention was to use uDig for styling and then simply import the SLD as a resource into my project as-is. But, going with what I have now, i usually have to increase widths and fonts here and there after exporting the SLD to my project. Also, the anti-aliasing hint doesn't appear to work (I suspect this is the issue). – Yemi Kudaisi Sep 09 '19 at 16:48

1 Answers1

0

I think you should leave the default renderer in place and simply add to it's hints, so something like:

renderer = frame.getMapPane().getRenderer();
Map<Object, Object> rendererHints = renderer.getRendererHints();
rendererHints.put("optimizedDataLoadingEnabled", true); 
renderer.setRendererHints(rendererHints);
RenderingHints hints = new RenderingHints(RenderingHints.KEY_ANTIALIASING,
    RenderingHints.VALUE_ANTIALIAS_ON);
renderer.setJava2DHints(hints);

If that doesn't do it then you might want to look at what hints the GeoServer render gets set, for example here

Ian Turton
  • 10,018
  • 1
  • 28
  • 47