Hi Mathieu,

I enjoyed our taks at foss4g :)

So the problem is there there are a number of factores that the datastore
requires that get initialized when you create it via the factory. So I
recommend always using the factory.

If you look at org.geotools.jdbc.JDBCDataStoreFactory you will see a
DATASOURCE parameter. Which is what you will need to supply your own
datasource. So your code will become something like:

PostgisNGDataStoreFactory factory = new PostgisNGDataStoreFactory();

Map params = new HashMap();
params.put(PostgisNGDataStoreFactory.DATASOURCE.key, yourDataSource);

JDBCDataStore dataStore = factory.createDataStore(params);

You can also look at PostgisNGJNDIDataStoreFactory to obtain a connection
via JNDI.

Hope that helps.

-Justin

On Sun, Oct 10, 2010 at 3:53 PM, Mathieu Baudier <[email protected]> wrote:

> 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
>



-- 
Justin Deoliveira
OpenGeo - http://opengeo.org
Enterprise support for open source geospatial.
------------------------------------------------------------------------------
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