johann sorel ha scritto: > Here is a test case : > > CREATE TABLE places > ( > ref_id character(8) NOT NULL, > emplacement geometry, > CONSTRAINT "mainKey" PRIMARY KEY (ref_id) > ) > WITH (OIDS=FALSE); > ALTER TABLE places OWNER TO admin; > > //dont forget to add the column in the geometry_columns > > insert into places values('SCR08123', GeometryFromText('POINT(1 3)',4326)); > > CREATE OR REPLACE VIEW myview AS > SELECT places.ref_id, places.emplacement > FROM places; > > ALTER TABLE myview OWNER TO admin; > > > final Map params = new HashMap<String, Object>(); > params.put("dbtype", "postgis"); > params.put(PostgisDataStoreFactory.HOST.key, "..."); > params.put(PostgisDataStoreFactory.PORT.key, 5432); > params.put(PostgisDataStoreFactory.SCHEMA.key, "public"); > params.put(PostgisDataStoreFactory.DATABASE.key, "..."); > params.put(PostgisDataStoreFactory.USER.key, "..."); > params.put(PostgisDataStoreFactory.PASSWD.key, "..."); > DataStore store = DataStoreFinder.getDataStore(params); > FeatureSource fs = store.getFeatureSource("myview"); > fs.getBounds(); //RAISE ERROR > > First try to connect to the Table, it works > Next try to connect to the view and you will have a : > Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException > at com.vividsolutions.jts.geom.Envelope.init(Envelope.java:254) > at com.vividsolutions.jts.geom.Envelope.<init>(Envelope.java:186) > at > org.geotools.geometry.jts.ReferencedEnvelope.<init>(ReferencedEnvelope.java:203) >
Hum, I run the above code and fs.getBounds() does not raise an error, it return null instead. Are you trying to build a referenced envelope out of it in your code? Mind that if you do, you have to deal with null values, FeatureSource.getBounds() javadoc says that the method can return null if there is no optimized way to compute the bounds. What we do in GeoServer is that when that happens, we fall back on an explicity computation by scanning manually all the features (which might be very expensive, but in our use case, acceptable since it's a one time operation, then the bounds get cached). Also mind that computing the bounds can literally take minutes even using the optimized methods, I have a table with 20 million roads where the optimized getBounds() runs for 2 minutes straight before returning a result. Anyways, you're right that getBounds() fails for a view, there is a design problem in the postgis data store. In practice, postgis ds does not have a stand alone FeatureSource, only a FeatureStore has been coded. When the primary key is missing (as in a view) a plain JDBCFeatureSource is returned, that knows nothing of postgis specifics, and that one always return null to getBounds(). If you add the oid column the datastore will think you're using a old postgres with oid support, assume that one can be treated as a primary key, and return an optimized PostgisFeatureStore instead. Fixing this would require major surgery, that time is better spent porting the postgis data store to the new jdbc architecture instead. I've created a jira issue so that this kind of test will be added to the jdbc-ng standard test suite: http://jira.codehaus.org/browse/GEOT-2067 Cheers Andrea -- Andrea Aime OpenGeo - http://opengeo.org Expert service straight from the developers. ------------------------------------------------------------------------- This SF.Net email is sponsored by the Moblin Your Move Developer's challenge Build the coolest Linux based applications with Moblin SDK & win great prizes Grand prize is a trip for two to an Open Source event anywhere in the world http://moblin-contest.org/redirect.php?banner_id=100&url=/ _______________________________________________ Geotools-devel mailing list Geotools-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/geotools-devel