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)






Andrea Aime a écrit :
> johann sorel ha scritto:
>> Hi,
>>
>> I have uncounter a strange problem in the postgis module.
>>
>> I am trying to use a postgis datastores, It works fine for tables but 
>> when you try to
>> use a view you MUST have a field named "oid".
>> In fact this "oid" name is hard coded in the module source and it 
>> goes crazy when you
>> try to open a view that doesnt have this field.
>>
>> Can someone explain me why there is such a thing ?
>> And eventually how can I avoid to have this field in my postgis views.
>
> oid was a field old Postgres versions always had and that has been
> removed in the latest versions (during the last 2-3 years actually).
> It was a sort of implicit primary key, no two records in the same
> database could have the save oid value.
> The postgis datastore can use that as a pk when no other is available.
> Yet, I'm pretty sure many GeoServer users are using views without
> any oid field and it works fine.
>
> Can you detail a little more your use case, provide a database
> dump and a stand alone test case?
> The most likely thing is that you're hitting the
> datastore in a way that GeoServer is not using, I need details
> to replicate the issue.
>
> Cheers
> Andrea
>


-- 
Johann Sorel

Company - Geomatys GIS Developer
Mail - [EMAIL PROTECTED]


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

Reply via email to