Hello Florian

My pleasure if I can be of any help :-)

Le 30/10/2022 à 13:32, Florian Micklich via user a écrit :

What happens (for some reason) the db is not available anymore. Is there an exception I can catch to handle something like this?

If SIS needs to use the EPSG database and an error occurred, an org.opengis.util.FactoryException will be thrown (this is a checked exception). The cause of that exception should be the SQLException.


Is there a method in SIS that I can use to verify that the DataSource has been set up correctly?

The easiest way is to request an EPSG code, for example System.out.println(CRS.forCode("EPSG::3395")). This is not fully reliable however for two reasons:

 * If that EPSG code was requested before, SIS may return a cached
   value, in which case database problem that may have occurred in the
   meantime will be unnoticed.
 * If the EPSG database is not available at all, SIS fallback on
   hard-coded values for a few commonly used CRS. The EPSG::3395 code
   is not in current list [1], but it may be in a future version.

A good way to know the status of Apache SIS is to execute the following code:

   System.out.println(org.apache.setup.About.configuration());

It should prints a tree. Among the first lines, there is information about the EPSG database used. It should show something like "EPSG database 9.1 on PostgreSQL". If it shows something like "EPSG database subset", then it is not using the database.


Also thanks for the hint with the index. I see there is also a prepare.sql script. Is this also necessary or what is its purpose?

Not if you create the EPSG tables yourself from the SQL scripts published by EPSG. But SIS has another way to create the EPSG database. You can just give a connection to an initially empty database, i.e. same as what you currently do but without executing any SQL script. If the org.apache.sis.non-free:sis-epsg (instead of sis-embedded) JAR is on the classpath ([2] but without Derby), SIS will automatically execute installation scripts when first needed, including the index creation. However during the installation process, SIS perform a few changes on-the-fly:

 * It creates an "epsg" schema.
 * The "epsg_" prefix is table names is replaced by "epsg.", i.e. the
   tables are written in "epsg" schema.
 * A few VARCHAR columns which were used as enumerations are replaced
   by real enumeration (this is slightly more efficient). This is where
   the "Prepare.sql" script come into play: it creates the enumerations
   before to run the EPSG scripts.

All those steps are automatic if sis-epsg is on the classpath and you let SIS creates the "epsg" schema itself when first needed. A message is logged at the INFO level when this creation is running.

    Martin

[1]https://sis.apache.org/apidocs/org/apache/sis/referencing/CRS.html#forCode(java.lang.String)
[2]https://sis.apache.org/epsg.html#maven-epsg

Reply via email to