[geotk] Add Postgis data
Cédric Briançon
cedric.briancon at geomatys.fr
Fri Oct 28 03:31:17 EDT 2011
Hi Arnaud,
here you have a namespace by default for your data
(http://geotoolkit.org) which is displayed by your println.
If you want to test "postgisStoreTable.toString().contains("traj")", you
should remove the default namespace by adding the following property to
the datastore :
Parameters.getOrCreate(PostgisNGDataStoreFactory.NAMESPACE,
parameters).setValue("no namespace");
This way, your tables will be traj, speed and releve, not
{http://geotoolkit.org}traj.
Regards,
Cédric Briançon
Le 27/10/2011 19:31, Arnaud Vandecasteele a écrit :
> Hi all,
>
> I'm trying to add some data from postgis in my geotoolkit application.
> All seems to work fine. But the data doesn't appear on the map.
> It must be something I've forgot but I dont see what.
> Below is the code I use (better view in pastbin http://pastebin.com/WR1mymtf ):
>
> ********************************************************
> final ParameterValueGroup parameters =
> PostgisNGDataStoreFactory.PARAMETERS_DESCRIPTOR.createValue();
> Name typeName = null;
>
> Parameters.getOrCreate(PostgisNGDataStoreFactory.HOST,
> parameters).setValue("*******");
> Parameters.getOrCreate(PostgisNGDataStoreFactory.PORT,
> parameters).setValue(5432);
> Parameters.getOrCreate(PostgisNGDataStoreFactory.DATABASE,
> parameters).setValue("vessel");
> Parameters.getOrCreate(PostgisNGDataStoreFactory.USER,
> parameters).setValue("*******");
> Parameters.getOrCreate(PostgisNGDataStoreFactory.PASSWD,
> parameters).setValue("******");
>
> final DataStore postgisStore = DataStoreFinder.getDataStore(parameters);
> if (postgisStore == null) {
> JOptionPane.showMessageDialog(null, "Could not connect - check parameters");
> }else{
> System.out.println("----------------------------------------");
> System.out.println(postgisStore.getNames());
> for(Iterator<Name> postgisStoreTables =
> postgisStore.getNames().iterator(); postgisStoreTables.hasNext();){
> Name postgisStoreTable = postgisStoreTables.next();
> if (postgisStoreTable.toString().contains("traj")){ typeName
> = postgisStoreTable;}
> }
>
> Session postGisSession = postgisStore.createSession(true);
> FeatureCollection collection =
> postGisSession.getFeatureCollection(QueryBuilder.all(typeName));
> final MutableStyle style =
> RandomStyleFactory.createRandomVectorStyle(collection);
> final FeatureMapLayer featMapLayer =
> MapBuilder.createFeatureLayer(collection, style);
> this.MAPCONTEXT.layers().add(featMapLayer);
> ********************************************************
>
> the System.out.println(postgisStore.getNames()) show me the name of my
> tables as : [{http://geotoolkit.org}traj,
> {http://geotoolkit.org}speed, {http://geotoolkit.org}releve]
>
> Do you see what I'm doing wrong ?
>
> Thanks for your help.
>
> Regards
>
> Arnaud
>
More information about the Geotoolkit
mailing list