Re: [Geotools-gt2-users] DataStoreFinder.findDataStore returns null for postgis datastore

2021-09-25 Thread Alessandro Ferrucci
Ok - now I feel outright silly.

I attached a debugger to
org.geotools.data.DataUtilities.canProcess(Map, Param...) and
noticed that it was failing the value = param.lookUp(params); check on the
"host" parameter...and yes...lo and behold, I was passing in a null :)

Once I fixed that the DataStore resolves fine.

Thank you for your assistance.


On Sat, Sep 25, 2021 at 4:02 AM Ian Turton  wrote:

> The only obvious thing I can see is that there is no "create spatial
> index" parameter in the PostGIS data store. I'm not sure if that would
> prevent it matching. In general I would always use
> PostgisNGDataStoreFactory.DBTYPE.key etc rather than raw strings to make
> sure they are correct. The only other thing I can suggest is attach a
> debugger/breakpoint to
> org.geotools.data.DataUtilities.canProcess(Map, Param...) to see
> why it is returning false.
>
> Ian
>
> On Sat, 25 Sept 2021 at 01:43, Alessandro Ferrucci <
> alessandroferru...@gmail.com> wrote:
>
>> Hello -
>>
>> I am using GeoTools 22.2.
>>
>> I am trying to retrieve a PostGIS DataStore utilizing this code:
>>
>> Map postGISParams = new HashMap<>();
>> //must be postgis
>> postGISParams.put("dbtype", "postgis");
>> //the name or ip address of the machine running PostGIS
>> postGISParams.put("host", hostname);
>> //the port that PostGIS is running on (generally 5432)
>> postGISParams.put("port", port);
>> //the name of the database to connect to.
>> postGISParams.put("database", database);
>> //the user to connect with
>> postGISParams.put("user", user);
>> //the password of the user.
>> postGISParams.put("passwd", password);
>> //the schema of the database
>> postGISParams.put("schema", schema);
>>
>> postGISParams.put("create spatial index", Boolean.TRUE);
>> DataStore dataStore = null;
>> try {
>> //storage in PostGIS
>> dataStore = DataStoreFinder.getDataStore(postGISParams);
>> } catch (Exception ex) {
>> logger.error(ex.getMessage(), ex);
>> }
>> if (dataStore == null) {
>> logger.error("ERROR: DataStore is null");
>> Iterator it = DataStoreFinder.getAvailableDataStores();
>> logger.info("Available data stores");
>> while (it.hasNext()) {
>> Object n = it.next();
>> logger.info(n.getClass().toString());
>> }
>> System.exit(-1);
>> }
>>
>> the dataStore returned is null, no exception is thrown and
>> DataStoreFinder returns the following dataStores:
>>
>> class org.geotools.data.postgis.PostgisNGJNDIDataStoreFactory
>> class org.geotools.data.shapefile.ShapefileDirectoryFactory
>> class org.geotools.data.shapefile.ShapefileDataStoreFactory
>> class org.geotools.data.postgis.PostgisNGDataStoreFactory
>>
>> I cannot figure out why the PostgisDataStoreFactory is not returning a
>> DataStore ( but the available stores include PostgisNGDataStoreFactory).
>>
>> Here is my dependency tree output from Maven.
>>
>> Thank you
>>
>> [INFO] --- maven-dependency-plugin:2.8:tree (default-cli) @ TestProject
>> ---
>> [INFO] company:TestProject:jar:1.0.0
>> [INFO] +- com.lmax:disruptor:jar:3.2.0:compile
>> [INFO] +- org.apache.logging.log4j:log4j-api:jar:2.11.2:compile
>> [INFO] +- org.apache.logging.log4j:log4j-core:jar:2.11.2:compile
>> [INFO] +- org.apache.logging.log4j:log4j-slf4j-impl:jar:2.11.2:compile
>> [INFO] |  \- org.slf4j:slf4j-api:jar:1.7.25:compile
>> [INFO] +- commons-io:commons-io:jar:2.4:compile
>> [INFO] +- org.springframework:spring-beans:jar:5.1.3.RELEASE:compile
>> [INFO] |  \- org.springframework:spring-core:jar:5.1.3.RELEASE:compile
>> [INFO] | \- org.springframework:spring-jcl:jar:5.1.3.RELEASE:compile
>> [INFO] +- org.springframework:spring-test:jar:5.1.3.RELEASE:test
>> [INFO] +- net.minidev:json-smart:jar:2.2:compile
>> [INFO] |  \- net.minidev:accessors-smart:jar:1.1:compile
>> [INFO] | \- org.ow2.asm:asm:jar:5.0.3:compile
>> [INFO] +- com.google.code.gson:gson:jar:2.3.1:compile
>> [INFO] +-
>> org.springframework.security:spring-security-core:jar:5.1.2.RELEASE:compile
>> [INFO] |  +- org.springframework:spring-aop:jar:5.1.3.RELEASE:compile
>> [INFO] |  +- org.springframework:spring-context:jar:5.1.3.RELEASE:compile
>> [INFO] |  \-
>> org.springframework:spring-expression:jar:5.1.3.RELEASE:compile
>> [INFO] +-
>> org.springframework.ldap:spring-ldap-core:jar:2.3.2.RELEASE:compile
>> [INFO] |  \- org.springframework:spring-tx:jar:4.3.4.RELEASE:compile
>> [INFO] +- junit:junit:jar:4.10:test
>> [INFO] |  \- org.hamcrest:hamcrest-core:jar:1.1:test
>> [INFO] +- javax.mail:mail:jar:1.4:compile
>> [INFO] |  \- javax.activation:activation:jar:1.1:compile
>> [INFO] +- 

Re: [Geotools-gt2-users] DataStoreFinder.findDataStore returns null for postgis datastore

2021-09-25 Thread Ian Turton
The only obvious thing I can see is that there is no "create spatial index"
parameter in the PostGIS data store. I'm not sure if that would prevent it
matching. In general I would always use
PostgisNGDataStoreFactory.DBTYPE.key etc rather than raw strings to make
sure they are correct. The only other thing I can suggest is attach a
debugger/breakpoint to
org.geotools.data.DataUtilities.canProcess(Map, Param...) to see
why it is returning false.

Ian

On Sat, 25 Sept 2021 at 01:43, Alessandro Ferrucci <
alessandroferru...@gmail.com> wrote:

> Hello -
>
> I am using GeoTools 22.2.
>
> I am trying to retrieve a PostGIS DataStore utilizing this code:
>
> Map postGISParams = new HashMap<>();
> //must be postgis
> postGISParams.put("dbtype", "postgis");
> //the name or ip address of the machine running PostGIS
> postGISParams.put("host", hostname);
> //the port that PostGIS is running on (generally 5432)
> postGISParams.put("port", port);
> //the name of the database to connect to.
> postGISParams.put("database", database);
> //the user to connect with
> postGISParams.put("user", user);
> //the password of the user.
> postGISParams.put("passwd", password);
> //the schema of the database
> postGISParams.put("schema", schema);
>
> postGISParams.put("create spatial index", Boolean.TRUE);
> DataStore dataStore = null;
> try {
> //storage in PostGIS
> dataStore = DataStoreFinder.getDataStore(postGISParams);
> } catch (Exception ex) {
> logger.error(ex.getMessage(), ex);
> }
> if (dataStore == null) {
> logger.error("ERROR: DataStore is null");
> Iterator it = DataStoreFinder.getAvailableDataStores();
> logger.info("Available data stores");
> while (it.hasNext()) {
> Object n = it.next();
> logger.info(n.getClass().toString());
> }
> System.exit(-1);
> }
>
> the dataStore returned is null, no exception is thrown and DataStoreFinder
> returns the following dataStores:
>
> class org.geotools.data.postgis.PostgisNGJNDIDataStoreFactory
> class org.geotools.data.shapefile.ShapefileDirectoryFactory
> class org.geotools.data.shapefile.ShapefileDataStoreFactory
> class org.geotools.data.postgis.PostgisNGDataStoreFactory
>
> I cannot figure out why the PostgisDataStoreFactory is not returning a
> DataStore ( but the available stores include PostgisNGDataStoreFactory).
>
> Here is my dependency tree output from Maven.
>
> Thank you
>
> [INFO] --- maven-dependency-plugin:2.8:tree (default-cli) @ TestProject ---
> [INFO] company:TestProject:jar:1.0.0
> [INFO] +- com.lmax:disruptor:jar:3.2.0:compile
> [INFO] +- org.apache.logging.log4j:log4j-api:jar:2.11.2:compile
> [INFO] +- org.apache.logging.log4j:log4j-core:jar:2.11.2:compile
> [INFO] +- org.apache.logging.log4j:log4j-slf4j-impl:jar:2.11.2:compile
> [INFO] |  \- org.slf4j:slf4j-api:jar:1.7.25:compile
> [INFO] +- commons-io:commons-io:jar:2.4:compile
> [INFO] +- org.springframework:spring-beans:jar:5.1.3.RELEASE:compile
> [INFO] |  \- org.springframework:spring-core:jar:5.1.3.RELEASE:compile
> [INFO] | \- org.springframework:spring-jcl:jar:5.1.3.RELEASE:compile
> [INFO] +- org.springframework:spring-test:jar:5.1.3.RELEASE:test
> [INFO] +- net.minidev:json-smart:jar:2.2:compile
> [INFO] |  \- net.minidev:accessors-smart:jar:1.1:compile
> [INFO] | \- org.ow2.asm:asm:jar:5.0.3:compile
> [INFO] +- com.google.code.gson:gson:jar:2.3.1:compile
> [INFO] +-
> org.springframework.security:spring-security-core:jar:5.1.2.RELEASE:compile
> [INFO] |  +- org.springframework:spring-aop:jar:5.1.3.RELEASE:compile
> [INFO] |  +- org.springframework:spring-context:jar:5.1.3.RELEASE:compile
> [INFO] |  \-
> org.springframework:spring-expression:jar:5.1.3.RELEASE:compile
> [INFO] +-
> org.springframework.ldap:spring-ldap-core:jar:2.3.2.RELEASE:compile
> [INFO] |  \- org.springframework:spring-tx:jar:4.3.4.RELEASE:compile
> [INFO] +- junit:junit:jar:4.10:test
> [INFO] |  \- org.hamcrest:hamcrest-core:jar:1.1:test
> [INFO] +- javax.mail:mail:jar:1.4:compile
> [INFO] |  \- javax.activation:activation:jar:1.1:compile
> [INFO] +- com.oracle.jdbc:ojdbc8:jar:12.2.0.1:compile
> [INFO] +- org.postgresql:postgresql:jar:42.2.24:compile
> [INFO] |  \- org.checkerframework:checker-qual:jar:3.5.0:runtime
> [INFO] +- com.opencsv:opencsv:jar:3.10:compile
> [INFO] +- joda-time:joda-time:jar:2.8.1:compile
> [INFO] +- com.fasterxml.jackson.core:jackson-core:jar:2.8.10:compile
> [INFO] +- com.fasterxml.jackson.core:jackson-databind:jar:2.8.10:compile
> [INFO] +- com.fasterxml.jackson.core:jackson-annotations:jar:2.8.3:compile
> [INFO] +-
>