This is a question I have posted at stackchange( http://gis.stackexchange.com/questions/159551/label-rendered-with-empty-features-using-geotools),however it did not own much attention, so I tried to post it here. And I will update the origin post once it is solved here.
Origin post: I am using geotools to generate some images based on the shapefile data, it works well until I tried to add labels for the line features: the labels are rendered even there are no features in the images. Check http://i.stack.imgur.com/MVVAe.png, and http://i.stack.imgur.com/hNtKi.png As shown, the result is not what I expected, the labels are rendered without attached with the feature. This is the core rendering codes: public BufferedImage render(ShapefileDataStore dataStore, int x, int y, int zoom, int width, int height) { double[] box = new double[]{.....}; ReferencedEnvelope bbox = new ReferencedEnvelope(box[0], box[2], box[1], box[3], crs); BufferedImage image = new BufferedImage(rwidth, rheight, BufferedImage.TYPE_INT_ARGB); Graphics2D g = image.createGraphics(); g.setComposite(AlphaComposite.Clear); g.fillRect(0, 0, rwidth, rheight); g.setComposite(AlphaComposite.Src); MapContent mapContent = new MapContent(); try { String schemaName = dataStore.getSchema().getName().toString(); Style style=createStyle(); mapContent.addLayer(new FeatureLayer(dataStore.getFeatureSource(), style)); synchronized (renderer) { renderer.setMapContent(mapContent); renderer.paint(g, imageSize, bbox); } } catch (Exception e) { } finally { mapContent.dispose(); g.dispose(); } return image; } public Style createStyle(){ SLDParser sldParser = new SLDParser(styleFactory, new File("style.sld").toURL()); Style[] ss = sldParser.readXML(); return ss[0]; } And the style.sld: <StyledLayerDescriptor version="1.0.0"> ... <FeatureTypeStyle> <Rule> <Name>Single symbol</Name> <LineSymbolizer> <Stroke> <CssParameter name="stroke">#ffffff</CssParameter> <CssParameter name="stroke-width">10</CssParameter> .... </Stroke> </LineSymbolizer> <TextSymbolizer> <Label> <ogc:PropertyName>name</ogc:PropertyName> </Label> <Font> <CssParameter name="font-family">Arial</CssParameter> <CssParameter name="font-size">18</CssParameter> </Font> <Fill> <CssParameter name="fill">#a4bdc5</CssParameter> </Fill> <VendorOption name="followLine">true</VendorOption> </TextSymbolizer> </Rule> </FeatureTypeStyle> ... </StyledLayerDescriptor> Did I miss anything? Thanks.
------------------------------------------------------------------------------
_______________________________________________ GeoTools-GT2-Users mailing list GeoTools-GT2-Users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users