本文整理汇总了Java中org.h2gis.utilities.SFSUtilities类的典型用法代码示例。如果您正苦于以下问题:Java SFSUtilities类的具体用法?Java SFSUtilities怎么用?Java SFSUtilities使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
SFSUtilities类属于org.h2gis.utilities包,在下文中一共展示了SFSUtilities类的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: open
import org.h2gis.utilities.SFSUtilities; //导入依赖的package包/类
public boolean open( String dbPath ) throws Exception {
h2Db.setCredentials(user, password);
if (dbPath != null && dbPath.endsWith(EDb.H2GIS.getExtension())) {
dbPath = dbPath.substring(0, dbPath.length() - (EDb.H2GIS.getExtension().length() + 1));
}
boolean dbExists = h2Db.open(dbPath);
if (dbExists) {
wasInitialized = true;
}
jdbcConn = SFSUtilities.wrapConnection(h2Db.getJdbcConnection());
if (!dbExists)
initSpatialMetadata(null);
this.mDbPath = h2Db.getDatabasePath();
mConn = h2Db.getConnection();
if (mPrintInfos) {
if (!wasInitialized) {
initSpatialMetadata(null);
}
String[] dbInfo = getDbInfo();
Logger.INSTANCE.insertDebug(null, "H2GIS Version: " + dbInfo[1]);
}
return dbExists;
}
示例2: run
import org.h2gis.utilities.SFSUtilities; //导入依赖的package包/类
@Override
public void run() {
//Creates the session workspace
File workspaceFolder = new File("workspace", token.toString());
workspaceFolder.mkdirs();
propertyMap.put(ServiceFactory.WORKSPACE_FOLDER_PROP, workspaceFolder);
//Creates the session ExecutorService
ExecutorService executorService = Executors.newFixedThreadPool(3);
propertyMap.put(ServiceFactory.EXECUTOR_SERVICE_PROP, executorService);
//Creates the session DataSource
DataSource dataSource = null;
try {
dataSource = SFSUtilities.wrapSpatialDataSource(H2GISDBFactory.createDataSource("/../../../workspace/"+this.token+"/h2_db", true));
} catch (SQLException e) {
LOGGER.error("Unable to create the database : \n"+e.getMessage());
}
LOGGER.info("Session database started.");
propertyMap.put(ServiceFactory.DATA_SOURCE_PROP, dataSource);
//Sets the session with the options
List<Service> serviceList = new ArrayList<>();
for(ServiceFactory factory : serviceFactoryList) {
Service service = factory.createService(propertyMap);
serviceList.add(service);
LOGGER.info("Service "+service.getClass().getSimpleName()+" started.");
}
propertyMap.put(Session.SERVICE_LIST, serviceList);
session.setProperties(propertyMap);
}
示例3: getDatabaseContent
import org.h2gis.utilities.SFSUtilities; //导入依赖的package包/类
/**
* Returns the DatabaseContent object which contains the representation of the Database.
* @return The DatabaseContent object.
*/
public DatabaseContent getDatabaseContent(){
DatabaseContent dbContent = new DatabaseContent();
try(Connection connection = ds.getConnection()) {
for(String tableName : JDBCUtilities.getTableNames(connection.getMetaData(), null, null, null, new String[]{"TABLE","LINKED TABLE","VIEW","EXTERNAL","UIodfsghjmodfhjgodujhfg"})){
DatabaseTable dbTable = new DatabaseTable(TableLocation.parse(tableName));
//Get the list of the columns of a table
ResultSet rs1 = connection.createStatement().executeQuery(String.format("select * from %s limit 1",
dbTable.getName()));
ResultSetMetaData metaData = rs1.getMetaData();
//If the column isn't a geometry, add it to the map
for(int i=1; i<=metaData.getColumnCount(); i++){
if(!metaData.getColumnTypeName(i).equalsIgnoreCase("GEOMETRY")){
dbTable.addField(metaData.getColumnLabel(i), metaData.getColumnTypeName(i));
}
}
//Once the non geometric columns are get, do the same with the geometric one.
Statement statement = connection.createStatement();
String query = String.format("SELECT * FROM GEOMETRY_COLUMNS WHERE F_TABLE_NAME LIKE '%s';",
TableLocation.parse(dbTable.getName()).getTable());
ResultSet rs = statement.executeQuery(query);
while (rs.next()) {
dbTable.addField(rs.getString(4), SFSUtilities.getGeometryTypeNameFromCode(rs.getInt(6)));
}
dbContent.addTable(dbTable);
}
} catch (SQLException e) {
LOGGER.error("Unable to get the database information.\nCause : "+e.getMessage());
}
return dbContent;
}
示例4: main
import org.h2gis.utilities.SFSUtilities; //导入依赖的package包/类
public static void main (String[] args) {
try {
// Use H2 DataSourceFactory
DataSourceFactory dataSourceFactory = new OsgiDataSourceFactory(org.h2.Driver.load());
// Set properties for in-memory connection
Properties properties = JDBCUrlParser.parse("jdbc:h2:/"+new File("sample_db").getAbsolutePath());
// Create instance of data manager.
DataManager dataManager = new DataManagerImpl(SFSUtilities.wrapSpatialDataSource(
dataSourceFactory.createDataSource(properties)));
// Init spatial functions
try(Connection connection = dataManager.getDataSource().getConnection();
Statement st = connection.createStatement()) {
// Import spatial functions, domains and drivers
// If you are using a file database, you have to do only that once.
st.execute("DROP TABLE IF EXISTS landcover2000");
CreateSpatialExtension.initSpatialExtension(connection);
// Read OWS context file
MapContext mc = new OwsMapContext(dataManager);
String owsFile = "landcover2000.ows";
// Set where to fetch resources
mc.setLocation(Main.class.getResource("landcover2000.ows").toURI());
mc.read(Main.class.getResourceAsStream(owsFile));
// Read the file
// Open it (it will link the database with the shape file)
mc.open(new NullProgressMonitor());
// Render it in buffered image
MapImageWriter mapImageWriter = new MapImageWriter(mc.getLayerModel());
FileOutputStream out = new FileOutputStream(new File("landcover2000.png").getAbsoluteFile());
mapImageWriter.setFormat(MapImageWriter.Format.PNG);
mapImageWriter.write(out, new NullProgressMonitor());
}
} catch (Exception ex) {
ex.printStackTrace();
}
}