Hello, I am attempting to write a few unit tests to write shapeless out to database. Ultimately, this will be going to PostGIS but I’m trying to write JUnit tests for an in-mem H2 database. It looks like the H2 database I am using is not spatially enabled and I am not sure what I should be doing to make it be spatially enabled. I am able to create a GEOMETRY column using Liquibase but I am unable to get GeoTools to properly read/understand it when creating a FeatureWriter.
I begin the test by kicking off an in-memory H2 database using the "inmemdb-maven-plugin”: https://github.com/isuftin/DSASWeb/blob/ac5f64f9e206b3b55794bf771dcde8abfabacccf/dsas-uncy-reader/pom.xml#L99-L127 <https://github.com/isuftin/DSASWeb/blob/ac5f64f9e206b3b55794bf771dcde8abfabacccf/dsas-uncy-reader/pom.xml#L99-L127> In the integration test, I use Liquibase to create a table I plan on writing to: Liquibase script: https://github.com/isuftin/DSASWeb/blob/ac5f64f9e206b3b55794bf771dcde8abfabacccf/dsas-uncy-reader/src/test/resources/liquibase/changelogs/create-shoreline-points-table.xml <https://github.com/isuftin/DSASWeb/blob/ac5f64f9e206b3b55794bf771dcde8abfabacccf/dsas-uncy-reader/src/test/resources/liquibase/changelogs/create-shoreline-points-table.xml> Using the script: https://github.com/isuftin/DSASWeb/blob/ac5f64f9e206b3b55794bf771dcde8abfabacccf/dsas-uncy-reader/src/test/java/gov/usgs/cida/dsas/uncy/XploderH2IntegrationTest.java#L67-L70 <https://github.com/isuftin/DSASWeb/blob/ac5f64f9e206b3b55794bf771dcde8abfabacccf/dsas-uncy-reader/src/test/java/gov/usgs/cida/dsas/uncy/XploderH2IntegrationTest.java#L67-L70> I create the feature type I plan the FeatureWriter to write to here: https://github.com/isuftin/DSASWeb/blob/ac5f64f9e206b3b55794bf771dcde8abfabacccf/dsas-uncy-reader/src/test/java/gov/usgs/cida/dsas/uncy/XploderH2IntegrationTest.java#L118-L124 <https://github.com/isuftin/DSASWeb/blob/ac5f64f9e206b3b55794bf771dcde8abfabacccf/dsas-uncy-reader/src/test/java/gov/usgs/cida/dsas/uncy/XploderH2IntegrationTest.java#L118-L124> Finally, I try to create the feature writer here: https://github.com/isuftin/DSASWeb/blob/ac5f64f9e206b3b55794bf771dcde8abfabacccf/dsas-uncy-reader/src/main/java/gov/usgs/cida/dsas/uncy/H2DatabaseOutputXploder.java#L64 <https://github.com/isuftin/DSASWeb/blob/ac5f64f9e206b3b55794bf771dcde8abfabacccf/dsas-uncy-reader/src/main/java/gov/usgs/cida/dsas/uncy/H2DatabaseOutputXploder.java#L64> Problem 1: You’ll notice that in the liquibase script, I commented out lines 35 through 40 and instead am using raw SQL commands on line 48 to create the row. Running the integration tests results in the following error: > 386-0600 WARNING Error occured determing srid for POINTS.GEOM > org.h2.jdbc.JdbcSQLException: Function "ST_SRID" not found; SQL statement: > SELECT ST_SRID("GEOM") FROM "POINTS" WHERE "GEOM" is not null LIMIT 1 > [90022-178] ( full stack trace here http://pastebin.com/rTvLePPG <http://pastebin.com/rTvLePPG> ) Problem 2: If I comment out "<sql dbms="h2">ALTER TABLE POINTS ADD COLUMN GEOM GEOMETRY COMMENT 'POINT' BEFORE ID</sql>" and instead allow the column to be created through Liquibase by using the column tag that’s commented out in that commit, I get the following error: WARNING Could not find mapping for 'GEOM', ignoring the column and setting the feature type read only …followed by… java.io.IOException: POINTS is read only ( full stack trace here http://pastebin.com/cX738jjX <http://pastebin.com/cX738jjX> ) Problem 3: I can also opt to bypass Liquibase completely and just have the datastore attempt to create the schema based on the Featuretype I give by calling ds.createSchema(outputFeatureType); java.io.IOException: Error occurred creating table at gov.usgs.cida.dsas.uncy.H2DBOutputExploderIntegrationTest.testCreateXploder(H2DBOutputExploderIntegrationTest.java:127) Caused by: org.h2.jdbc.JdbcSQLException: Function "ADDGEOMETRYCOLUMN" not found; SQL statement: CALL AddGeometryColumn('PUBLIC', 'POINTS', 'GEOM', 4326, 'Point', 2) [90022-190] at gov.usgs.cida.dsas.uncy.H2DBOutputExploderIntegrationTest.testCreateXploder(H2DBOutputExploderIntegrationTest.java:127) ( full stack trace here: http://pastebin.com/eBUdJn8n <http://pastebin.com/eBUdJn8n> ) All of this leads me to believe that my database is not geosnatially aware. At least not enough to provide what Geotools is looking for. What is it that the Geotools team does to successfully prime their H2 database for unit testing and what is it that I am missing?
------------------------------------------------------------------------------
_______________________________________________ GeoTools-GT2-Users mailing list GeoTools-GT2-Users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users