Hello,

I'm trying to use the JDBCDatastore with a PostGIS backend.
I want to load a FeatureSource and add it as a layer in a MapContext
(for display in a JMapPane)

I have already the following code working:

Map params = new HashMap();
params.put("dbtype", "postgis");
params.put("host", "*****");
params.put("port", new Integer(5432));
params.put("database", "******");
params.put("user", "*****");
params.put("passwd", "******");
DataStore pgDatastore = DataStoreFinder.getDataStore(params);

but when I try to replace this with:

JDBCDataStore pgDatastore = new JDBCDataStore();
pgDatastore.setDataSource(dataSource);
pgDatastore.setSQLDialect(new PostGISDialect(pgDatastore));

(the dataSource is defined externally and injected)

I then get:

Oct 10, 2010 11:35:32 PM org.geotools.renderer.lite.StreamingRenderer
drawOptimized
SEVERE: null
java.lang.NullPointerException
        at 
org.geotools.feature.simple.SimpleFeatureBuilder.buildFeature(SimpleFeatureBuilder.java:349)
        at org.geotools.jdbc.JDBCFeatureReader.next(JDBCFeatureReader.java:658)
        at org.geotools.jdbc.JDBCFeatureReader.next(JDBCFeatureReader.java:84)
        at 
org.geotools.data.store.ContentFeatureCollection$WrappingIterator.next(ContentFeatureCollection.java:248)
        at 
org.geotools.renderer.lite.StreamingRenderer.drawOptimized(StreamingRenderer.java:1948)
        at 
org.geotools.renderer.lite.StreamingRenderer.processStylers(StreamingRenderer.java:1815)
        at 
org.geotools.renderer.lite.StreamingRenderer.paint(StreamingRenderer.java:722)
        at 
org.geotools.swing.RenderingExecutor$Task.call(RenderingExecutor.java:148)
        at 
org.geotools.swing.RenderingExecutor$Task.call(RenderingExecutor.java:104)
        at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:334)
        at java.util.concurrent.FutureTask.run(FutureTask.java:166)
        at 
java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
        at 
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
        at java.lang.Thread.run(Thread.java:636)
(many many times)

org.geotools.feature.simple.SimpleFeatureBuilder.buildFeature(SimpleFeatureBuilder.java:349)
is:

SimpleFeature sf = factory.createSimpleFeature(values, featureType, id);

So the factory (org.opengis.feature.FeatureFactory) seems to be null.

Please note that I am in an OSGi environment with all GeoTools code in
one bundle and OpenGIS/GeoAPI in another bundle.
There are known issues with SPI factory loading between separate
bundles (I am still slowly working on fixing this on the side).
Maybe this is the case here??

Or maybe did I not configure enough the JDBCDataStore?

I am using GeoTools 2.6.5 and, in both cases, I add the layer as follow:

FeatureSource<SimpleFeatureType, SimpleFeature> source = pgDatastore
                .getFeatureSource("ways");
mapContext.addLayer(source, createLineStyle());

Thanks in advance for any hints/comments/ideas!

Cheers,

Mathieu

------------------------------------------------------------------------------
Beautiful is writing same markup. Internet Explorer 9 supports
standards for HTML5, CSS3, SVG 1.1,  ECMAScript5, and DOM L2 & L3.
Spend less time writing and  rewriting code and more time creating great
experiences on the web. Be a part of the beta today.
http://p.sf.net/sfu/beautyoftheweb
_______________________________________________
Geotools-gt2-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users

Reply via email to