Geotools StreamingRenderer point probleme when using Simplefeaturecollection instead of Simplefeaturesource using postgis database

Viewed 65

I am developing my own cartographic server using leaflet and GeoTools in the back end, I use streaming render to draw a map in given bbox, all geometries are in 3857 coordinate reference system,here is a simple request from leaflet http://localhost:8080/server/tile/mymap/12/2083/1598.png where z = 12 and x=2083 and y=1598 when getting such request in backend i convert zxy to a reference envelope,every thing work fine so far, when i use SimpleFeatureSource the result in frontend with leflet looks good

ReferencedEnvelope env = new ReferencedEnvelope(this.getBounds(tile), this.webMercator);
for (MapLayer mapLayer : mapLayers) {
            try {
                SimpleFeatureSource featureSource = postgisDataStore.getFeatureSource(mapLayer.getLayer().getSlug());
                    Style style = createFromSLD(mapLayer);
        mapContent.addLayer(new FeatureLayer(source, style));
            } catch (IOException e) {
                log.error(e.getMessage());
            }
        }

saveMap(mapContent, os, mapBounds);

the result have not problems:

enter image description here

But when i use a FeatureCollection instead of a SimpleFeatureSource I get a problem with the points, they are cropped in some way ,could some one explain what happening:

ReferencedEnvelope env = new ReferencedEnvelope(this.getBounds(tile), this.webMercator);

for (MapLayer mapLayer : mapLayers) {
            try {
                SimpleFeatureCollection fc = featureService.getTile(mapLayer.getLayer(), tile, env);
                Style style = createFromSLD(mapLayer);
                mapContent.addLayer(new FeatureLayer(source, style));
            } catch (IOException e) {
                log.error(e.getMessage());
            }
        }

saveMap(mapContent, os, mapBounds);

enter image description here

1 Answers

The most obvious difference between your two images is the zoom level and bounding box.

Markers getting cropped at the edge of an image is a common problem in nearly all tile engines. Since each request is made using a separate request (possibly to a separate machine) there is no way for GeoTools to know what is just over the boundary and allow for it.

GeoServer uses a system of "gutters" to handle this issue, so each tile is drawn a number of pixels (based on the size of the largest symbol) bigger and then clipped to the exact tile boundary to allow it to draw the "other" half of a nearby symbol. This becomes even more complex when you attempt to handle labels as the label engine doesn't like to draw labels that go off the edge of the image so only features in the centre of your tile will be drawn, again it's worth looking at how GeoServer implements the partials vendor option to handle this.

At the end of the day I wonder if rolling your own tile server is worth the effort when you can use GeoWebCache and GeoServer directly and avoid reinventing these wheels. If there is some specific cartographic element that you need may be talking to the GeoServer developers would allow you to add it to GeoServer.

Related