We have been using GeoTools to render maps in a software project we
have been working on for over five years. However, there is one
problem that has plagued us since day 1, and I'm wondering if anyone
on the list has any suggestions.

We are currently using GeoTools 12.0, but the problems we are
experiencing have been around throughout the various versions for over
five years. However, as our project continues, the scale of the
regions we are examining is increasing, and the problem is becoming
more frequent.

The spatial data we are rendering using GeoTools is stored on a
PostGIS-enabled Postgres DB. The software client we have been writing
connects directly to the DB to read the layers.

The size of the data we are using isn't tremendous, but it isn't
exactly small, either. We often ask GeoTools to render maps drawn from
layers rendered from 100s of MB of spatial data from the DB. For
example, we may want to draw the entire state of Texas at the Block
Group Level along with OSM roads for the entire state and a few other
layers.

We get a Null Pointer Exception message intermittently when we add
layers or when we toggle layers on and off using the user interface.
One way to trigger the problem is by loading a large dataset and
quickly toggling a layer on and off.

The Exception seems to happen more often when the size of the layers
we are viewing in GeoTools are larger and/or when the network latency
is higher.

When we zoom into an area of the map which is outside of the extent of
all of the layers (so that nothing is being rendered in the display)
before we add new layers, the Exception seems to be less likely.

If we add multiple layers quickly, one after another, the problem
seems to be more likely.

When we toggle off most or all of the layers before adding new layers,
the Exception seems to be less likely.

When the latency between the DB and the client is lower, the Exception
seems to be less likely. For instance, if we are accessing the DB
across the internet, it seems to be more likely than if we are
accessing it across the LAN. Further, it seems to be more likely
across the LAN than if we are accessing a DB on localhost.

Following occurrence of this exception, our program still runs, but
the GeoTools object stops rendering maps. Sometimes the map area
becomes all white. Other times, it takes on a fill of one of a color
from one of the line layers. If it takes on this fill, as soon
as a layer is toggled or the extent is changed, the map area becomes
all white, and nothing is rendered.

I have included the Exception Message and the code we are using the
create the layers below.


Please let me know if you have any ideas about how to solve this
problem and what other information you may need.


Thank you,

Marty


Exception Message:

2016-02-12T16:26:07.055-0600  SEVERE  null
java.lang.NullPointerException
at sun.java2d.pipe.LoopPipe.draw(LoopPipe.java:191)
at 
sun.java2d.pipe.PixelToParallelogramConverter.draw(PixelToParallelogramConverter.java:148)
at sun.java2d.SunGraphics2D.draw(SunGraphics2D.java:2438)
at 
org.geotools.renderer.lite.StyledShapePainter.paint(StyledShapePainter.java:316)
at 
org.geotools.renderer.lite.StreamingRenderer$PaintShapeRequest.execute(StreamingRenderer.java:3264)
at 
org.geotools.renderer.lite.StreamingRenderer$PainterThread.run(StreamingRenderer.java:3525)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471)
at java.util.concurrent.FutureTask.run(FutureTask.java:262)
at 
java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at 
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:745)



This is how we are creating the layers:

 public Layer createLayer(String tableName, Style style, String name) {
        Layer layer = null;

        try {
            //the vacuum analyze removes the st_estimated_extent
error. good riddance.
            Connection myconn = PLANNER.getController().getConnection();
            String query = "VACUUM ANALYZE " + UserState.userId + "."
+ tableName + ";";
            Statement stmt = myconn.createStatement();
            stmt.executeUpdate(query);
            Statement my_new_statement = myconn.createStatement();
            String check_rows = "SELECT COUNT(*) as my_int FROM " +
UserState.userId + "." + tableName + ";";
            ResultSet my_results = my_new_statement.executeQuery(check_rows);
            long my_int = 0;
            while (my_results.next()) {
                my_int = my_results.getInt("my_int");
            }

            if (my_int == 0) {
                //if 0 was returned that means the table is empty.
Don't create an empty layer.
                return null;
            }

            Map params = PLANNER.getController().getPostGIS();
            params.remove("schema");
            params.remove("role");
            params.put("schema", UserState.userId);
            params.put("role", UserState.userId);

            DataStore pgDatastore
                    = DataStoreFinder.getDataStore(params);

            FeatureSource fs = pgDatastore.getFeatureSource(tableName);
            layer = new FeatureLayer(fs, style, name);
            if (layer == null) {
                System.out.println("Could not find stuff in database
to create layer.");
            }
            map.layers().add(layer);

        } catch (IOException ex) {
            Logger.getLogger(ScenarioPanel.class.getName()).
                    log(Level.SEVERE, null, ex);
        } catch (Exception e) {
            System.out.println("This is probably: ERROR:
LWGEOM_estimated_extent: couldn't locate table within current schema
\n");
        }

        return layer;
    }

------------------------------------------------------------------------------
Site24x7 APM Insight: Get Deep Visibility into Application Performance
APM + Mobile APM + RUM: Monitor 3 App instances at just $35/Month
Monitor end-to-end web transactions and take corrective actions now
Troubleshoot faster and improve end-user experience. Signup Now!
http://pubads.g.doubleclick.net/gampad/clk?id=272487151&iu=/4140
_______________________________________________
GeoTools-GT2-Users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users

Reply via email to