Search in sources :

Example 1 with ASpatialDb

use of org.hortonmachine.dbs.compat.ASpatialDb in project hortonmachine by TheHortonMachine.

the class TestH2GisServer method createDb.

@BeforeClass
public static void createDb() throws Exception {
    String tempDir = System.getProperty("java.io.tmpdir");
    server = H2GisServer.startTcpServerMode("9092", false, null, true, tempDir);
    dbPath = tempDir + File.separator + "jgt-dbs-testspatialdbsservermain" + EDb.H2GIS.getExtensionOnCreation();
    TestUtilities.deletePrevious(tempDir, dbPath, EDb.H2GIS);
    // create the local db to connect to
    try (ASpatialDb db = EDb.H2GIS.getSpatialDb()) {
        db.open(dbPath);
        db.initSpatialMetadata("'WGS84'");
    }
}
Also used : ASpatialDb(org.hortonmachine.dbs.compat.ASpatialDb) BeforeClass(org.junit.BeforeClass)

Example 2 with ASpatialDb

use of org.hortonmachine.dbs.compat.ASpatialDb in project hortonmachine by TheHortonMachine.

the class TestH2GisServer method testGetGeometriesFromServer.

@Test
public void testGetGeometriesFromServer() throws Exception {
    String tcpServerUrl = TCP_LOCALHOST + dbPath;
    try (ASpatialDb db = EDb.H2GIS.getSpatialDb()) {
        db.open(tcpServerUrl);
        db.initSpatialMetadata("'WGS84'");
        createGeomTablesAndPopulate(db, true);
        List<Geometry> intersecting = db.getGeometriesIn(MPOLY_TABLE, (Envelope) null);
        assertEquals(3, intersecting.size());
    }
}
Also used : Geometry(org.locationtech.jts.geom.Geometry) ASpatialDb(org.hortonmachine.dbs.compat.ASpatialDb) Test(org.junit.Test)

Example 3 with ASpatialDb

use of org.hortonmachine.dbs.compat.ASpatialDb in project hortonmachine by TheHortonMachine.

the class TestH2GisServer_WithDatabasePwd method createDb.

@BeforeClass
public static void createDb() throws Exception {
    String tempDir = System.getProperty("java.io.tmpdir");
    server = H2GisServer.startTcpServerMode("9093", false, null, true, tempDir);
    dbPath = tempDir + File.separator + "jgt-dbs-testspatialdbsserverpwdmain" + EDb.H2GIS.getExtensionOnCreation();
    TestUtilities.deletePrevious(tempDir, dbPath, EDb.H2GIS);
    // create the local db to connect to
    try (ASpatialDb db = EDb.H2GIS.getSpatialDb()) {
        db.setCredentials("dbuser", "dbpwd");
        db.open(dbPath);
        db.initSpatialMetadata("'WGS84'");
    }
}
Also used : ASpatialDb(org.hortonmachine.dbs.compat.ASpatialDb) BeforeClass(org.junit.BeforeClass)

Example 4 with ASpatialDb

use of org.hortonmachine.dbs.compat.ASpatialDb in project hortonmachine by TheHortonMachine.

the class TestH2GisServer_WithDatabasePwd method connect.

private void connect(boolean withDbPwd) throws Exception {
    String tcpServerUrl = TCP_LOCALHOST + dbPath;
    try (ASpatialDb db = EDb.H2GIS.getSpatialDb()) {
        if (withDbPwd) {
            db.setCredentials("dbuser", "dbpwd");
        } else {
            // to avoid slow test when pooling
            // we force single connection
            db.setMakePooled(false);
        }
        db.open(tcpServerUrl);
        db.initSpatialMetadata("'WGS84'");
        createGeomTablesAndPopulate(db, true);
        List<Geometry> intersecting = db.getGeometriesIn(MPOLY_TABLE, (Envelope) null);
        assertEquals(3, intersecting.size());
    }
}
Also used : Geometry(org.locationtech.jts.geom.Geometry) ASpatialDb(org.hortonmachine.dbs.compat.ASpatialDb)

Example 5 with ASpatialDb

use of org.hortonmachine.dbs.compat.ASpatialDb in project hortonmachine by TheHortonMachine.

the class OsmUtils method createBuildings.

public static void createBuildings(File dbFile, String tablePrefix, String newTableName) throws Exception {
    String[] sqls = { "DROP TABLE IF EXISTS " + newTableName + ";", "CREATE TABLE " + newTableName + "(ID_WAY BIGINT PRIMARY KEY) AS SELECT DISTINCT ID_WAY FROM " + tablePrefix + "_WAY_TAG WT, " + tablePrefix + "_TAG T WHERE WT.ID_TAG = T.ID_TAG AND T.TAG_KEY IN ('" + BUILDING + "');", "DROP TABLE IF EXISTS " + newTableName + "_geom;", "CREATE TABLE " + newTableName + "_geom AS SELECT ID_WAY, ST_MAKEPOLYGON(ST_MAKELINE(THE_GEOM)) THE_GEOM FROM (SELECT (SELECT ST_ACCUM(THE_GEOM) " + "THE_GEOM FROM (SELECT N.ID_NODE, N.THE_GEOM,WN.ID_WAY IDWAY FROM " + tablePrefix + "_NODE N," + tablePrefix + "_WAY_NODE WN WHERE N.ID_NODE = WN.ID_NODE ORDER BY WN.NODE_ORDER) WHERE  IDWAY = W.ID_WAY) THE_GEOM ,W.ID_WAY FROM " + tablePrefix + "_WAY W," + newTableName + " B WHERE W.ID_WAY = B.ID_WAY) GEOM_TABLE WHERE ST_GEOMETRYN(THE_GEOM,1) = ST_GEOMETRYN(THE_GEOM, ST_NUMGEOMETRIES(THE_GEOM)) AND ST_NUMGEOMETRIES(THE_GEOM) > 2;" };
    try (ASpatialDb db = EDb.H2GIS.getSpatialDb()) {
        boolean existed = db.open(dbFile.getAbsolutePath());
        if (existed) {
            for (String sql : sqls) {
                System.out.println("RUN: " + sql);
                db.runSql(sql);
            }
        }
    }
}
Also used : ASpatialDb(org.hortonmachine.dbs.compat.ASpatialDb)

Aggregations

ASpatialDb (org.hortonmachine.dbs.compat.ASpatialDb)20 File (java.io.File)11 IOException (java.io.IOException)5 ArrayList (java.util.ArrayList)5 ActionEvent (java.awt.event.ActionEvent)3 FilenameFilter (java.io.FilenameFilter)3 SQLException (java.sql.SQLException)3 AbstractAction (javax.swing.AbstractAction)3 JFrame (javax.swing.JFrame)3 Execute (oms3.annotations.Execute)3 Style (org.geotools.styling.Style)3 QueryResult (org.hortonmachine.dbs.compat.objects.QueryResult)3 SqlName (org.hortonmachine.dbs.utils.SqlName)3 URL (java.net.URL)2 HashMap (java.util.HashMap)2 List (java.util.List)2 SimpleFeatureCollection (org.geotools.data.simple.SimpleFeatureCollection)2 JdbcSQLException (org.h2.jdbc.JdbcSQLException)2 EDb (org.hortonmachine.dbs.compat.EDb)2 GeometryColumn (org.hortonmachine.dbs.compat.GeometryColumn)2