0

I downloaded the GeoTools 11.2 binary and am attempting to get it to run in my Netbeans java application.
I tried to run this part of code:

...
SimpleFeatureSource source = dataStore.getFeatureSource("morteza:final");

    SimpleFeatureCollection fc = source.getFeatures();
    try {
        SimpleFeatureIterator iterator;
        iterator = fc.features();
        while (fc.features().hasNext()) {
            SimpleFeature sf = fc.features().next();
            Point geom = (Point) sf.getAttribute("the_geom");
            System.out.println(geom.getCoordinate().x);
            System.out.println(sf.getAttribute("the_geom"));
        }
    } catch (Exception ex) {
        System.out.println("hiiii");
        ex.printStackTrace();
    }
...

and I want to get features of wfs of geoserver.
at the line iterator = fc.features(); I faced this exception:

org.opengis.referencing.FactoryException: Failed to connect to the EPSG database.
at org.geotools.referencing.factory.epsg.ThreadedEpsgFactory.createBackingStore(ThreadedEpsgFactory.java:441)
at org.geotools.referencing.factory.DeferredAuthorityFactory.getBackingStore(DeferredAuthorityFactory.java:133)
at org.geotools.referencing.factory.BufferedAuthorityFactory.isAvailable(BufferedAuthorityFactory.java:235)
at org.geotools.referencing.factory.DeferredAuthorityFactory.isAvailable(DeferredAuthorityFactory.java:119)

......
...
Caused by: org.postgresql.util.PSQLException: Connection refused. Check that the hostname and port are correct and that the postmaster is accepting TCP/IP connections.

how can I fix this exception?
I don't want to fetch features from Postgresql but it tries to fetch from it.
please help!

2

I guess you added in your classpath gt-epsg-postgres instead of gt-epsg-hsql?
Delete gt-epsg-postgresql-11.0.jar from your classpath and add gt-epsg-hsql-11.0.jar into it.

EDIT(Inspired by comments):

For making the answer more understandable for others: GeoTools was set to store the EPSG projection database into PostgreSQL database. The default is to use a local hsql file database. GeoTools did not try to read features from PostgreSQL but definitions of the projection

  • 1
    For making the answer more understandable for others: GeoTools was set to store the EPSG projection database into PostgreSQL database. The default is to use a local hsql file database. GeoTools did not try to read features from PostgreSQL but definitions of the projection. – user30184 Sep 29 '14 at 12:20
  • If I could I kiss you. I have been wasting time for last few days and no where saying that the folder consisting postgres related library and that is overwriting the things. It is very confusing that why it is calling postgras database while no configuration here for post gres. Thank you very much – Amir Jul 19 '18 at 11:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.