We copied the code from the Quickstart class in the tutorials and made a few modifications. We commented out the file chooser and instead pulled data for roads in Dallas TX from a table on a postgres database. We used ST_ISVALID from postgis to make sure the geometry data in the table is valid. We also added a legend to the map so that we could toggle the visibility of the layer.
We have been hunting for the source of a NullPointerException (NPE) which has persisted through several versions of GeoTools over several years. Although GeoTools provides a wide array of GIS functionality, we are only using GeoTools to facilitate the display of (and interaction with) maps rendered from data stored on a postgres database. We suspect this NPE may be due to a race condition in the drawing of the data. It occurs intermittently, but it seems to be more common when - We are rendering larger datasets. The NPE is far less common on small datasets. - The connection between the GeoTools client and the postgres db has high latency. The NPE is far less common when GeoTools is accessing a postgres db on localhost. - We are adding multiple layers quickly - one after another. - We toggle a layer's visibility quickly using the map legend (after approximately 30+ toggles). All of these conditions seem to make the crash more common lead to the following error: 2016-03-02T14:22:28.347-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:2497) 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:511) at java.util.concurrent.FutureTask.run(FutureTask.java:266) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) at java.lang.Thread.run(Thread.java:745) Since the problem with the NPE is intermittent, the best way we have found to consistently test for it is to quickly toggle a layer's visibility using the map legend. We started with the Quickstart class from the tutorials and loaded a shapefile with the same data for roads in Dallas TX. We COULD NOT reproduce the problem when GeoTools was pulling data from a shapefile. HOWEVER, when we performed the same test with GeoTools pulling the data from a table on a postgres database, we experienced the NPE. If it helps you understand the problem, here is a link to a database dump of the table of the Dallas TX roads we were rendering in GeoTools when it crashed: https://www.dropbox.com/s/6t6ve5by7q1i26g/quick_test_roads.sql?dl=0 The modified Quickstart class is listed below, though I replaced the strings with the db connection details with xxxxxxx. Please let us know if you have any ideas on what may be causing this NullPointerException. Thank you in advance for all of your help. Marty package Geotools_Quickstart; import java.awt.Dimension; import java.awt.GridLayout; import java.io.File; import java.util.HashMap; import java.util.Map; import javax.swing.JFrame; import org.geotools.data.DataStore; import org.geotools.data.DataStoreFinder; import org.geotools.data.FeatureSource; import org.geotools.data.FileDataStore; import org.geotools.data.FileDataStoreFinder; import org.geotools.data.simple.SimpleFeatureSource; import org.geotools.map.FeatureLayer; import org.geotools.map.Layer; import org.geotools.map.MapContent; import org.geotools.styling.SLD; import org.geotools.styling.Style; import org.geotools.swing.JMapFrame; import org.geotools.swing.JMapPane; import org.geotools.swing.MapLayerTable; import org.geotools.swing.data.JFileDataStoreChooser; /** * Prompts the user for a shapefile and displays the contents on the screen in a * map frame. * <p> * This is the GeoTools Quickstart application used in documentationa and * tutorials. * */ public class Quickstart { private static MapLayerTable table; /** * GeoTools Quickstart demo application. Prompts the user for a shapefile * and displays its contents on the screen in a map frame */ public static void main(String[] args) throws Exception { // display a data store file chooser dialog for shapefiles // File file = JFileDataStoreChooser.showOpenFile("shp", null); // if (file == null) { // return; // } // FileDataStore store = FileDataStoreFinder.getDataStore(file); // SimpleFeatureSource featureSource = store.getFeatureSource(); Map<String, String> postgisParams = new HashMap<String, String>(); postgisParams.put(("role"), "postgres"); postgisParams.put("user", "xxxxxxx"); postgisParams.put("passwd", "xxxxxxx"); postgisParams.put("host", "xxxxxxx"); postgisParams.put("dbtype", "postgis"); postgisParams.put("port", "5432"); postgisParams.put("database", "xxxxxxx"); postgisParams.put("schema", "public"); DataStore pgDatastore = DataStoreFinder.getDataStore(postgisParams); SimpleFeatureSource featureSource = pgDatastore.getFeatureSource("quick_test_roads"); JMapPane mapPane = new JMapPane(); MapContent map = new MapContent(); map.setTitle("Quickstart"); table = new MapLayerTable(); table.setMapPane(mapPane); mapPane.setMapContent(map); JFrame frame = new JFrame(); GridLayout myLayout = new GridLayout(2,1); frame.setLayout(myLayout); frame.setSize(1000, 825); frame.add(mapPane); frame.add(table); frame.setVisible(true); Style style = SLD.createSimpleStyle(featureSource.getSchema()); Layer layer = new FeatureLayer(featureSource, style); map.addLayer(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
