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'");
}
}
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());
}
}
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'");
}
}
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());
}
}
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);
}
}
}
}
Aggregations