博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
ArcSDE SDK For Java二次开发介绍、演示样例
阅读量:6080 次
发布时间:2019-06-20

本文共 8354 字,大约阅读时间需要 27 分钟。

在一个工作中,遇到了须要java后台来查询ArcGIS 中用到的Oracle数据库空间数据,因为对ArcGIS空间数据首次接触,仅仅知道Oracle能够使用ST_GEOMETRY字段存储,例如以下图

可是查询时会发现这个ST_GEOMETRY字段会在结果中出现个多个子的字段,对于arcgis地理知识了解甚少,不知道单独查询一个坐标怎么弄了,有些朋友说须要配置监听文件。

无论怎么说,至少參考了一个大牛的文章, 依据 ArcSDE For Java的API中,能够对其进行增删改查等操作。

对于ArcSDE for Java的介绍请參考大牛文章,就不反复写了。以下的演示样例代码中,经过改动,加了一些凝视,还是不错的

首先把jsde_sdk.jar、jpe_sdk.jar、concurrent.jar、icu4j_3_2.jar包下载下来导入javaproject中就可以。四个jar包的下载地址例如以下:

详细在查询时有用的常量含义及方法參考官方API解释 :

package cn.sde.test;import java.text.SimpleDateFormat;import java.util.Date;import com.esri.sde.sdk.client.SDEPoint;import com.esri.sde.sdk.client.SeColumnDefinition;import com.esri.sde.sdk.client.SeConnection;import com.esri.sde.sdk.client.SeCoordinateReference;import com.esri.sde.sdk.client.SeException;import com.esri.sde.sdk.client.SeFilter;import com.esri.sde.sdk.client.SeInstance;import com.esri.sde.sdk.client.SeLayer;import com.esri.sde.sdk.client.SeQuery;import com.esri.sde.sdk.client.SeQueryInfo;import com.esri.sde.sdk.client.SeRelease;import com.esri.sde.sdk.client.SeRow;import com.esri.sde.sdk.client.SeShape;import com.esri.sde.sdk.client.SeShapeFilter;import com.esri.sde.sdk.client.SeSqlConstruct;import com.esri.sde.sdk.client.SeTable;public class T {	private static SeConnection conn = null;	private static String server = "172.25.0.253"; // sde服务器	private static String instance = "5151"; // sde端口	private static String database = "orcl"; // sde数据库	private static String username = "sde"; // sde用户名	private static String password = "sde"; // sde密码	// 获得ArcSDE连接	private static SeConnection getConn() {		if (conn == null) {			try {				conn = new SeConnection(server, instance, database, username, password);			} catch (SeException ex) {				ex.printStackTrace();			}		}		return conn;	}	/**	 * ArcSDE管理	 */	public static void GetArcSDEInfo() {		try {			SeInstance instance = new SeInstance(server, "5151");			SeInstance.SeInstanceStatus status = instance.getStatus();			System.out.println("连接数:" + status.getNumConnections());			System.out.println("能够连接:" + status.isAccepting());			System.out.println("------------------------------------------------");			SeInstance.SeInstanceConfiguration config = instance.getConfiguration();			System.out.println("最大连接数:" + config.getMaxConnections());			System.out.println("------------------------------------------------");			SeInstance.SeInstanceStats[] stats = instance.getStats();			for (int i = 0; i < stats.length; i++) {				System.out.println("操作数:" + stats[i].getOperationCount());			}			System.out.println("------------------------------------------------");			SeInstance.SeInstanceUsers[] users = instance.getUsers();			for (int j = 0; j < users.length; j++) {				System.out.println("用户名:" + users[j].getUserName());				System.out.println("系统名:" + users[j].getSysName());				System.out.println("服务器開始时间:" + users[j].getServerStartTime());				System.out.println("服务器PID:" + users[j].getServerPid());				System.out.println("*****************************");			}			System.out.println("------------------------------------------------");			System.out.println("系统名:" + instance.getServerName());			System.out.println("------------------------------------------------");			System.out.println("------------------------------------------------");			SeInstance.SeInstanceTableLocks[] tablelocks = instance.getTableLocks();			for (int i = 0; i < tablelocks.length; i++) {				System.out.println("表级别锁类型:" + tablelocks[i].getLockType());				System.out.println("表级别锁PID:" + tablelocks[i].getPid());				System.out.println("表级别锁注冊ID:" + tablelocks[i].getRegistrationId());				System.out.println("*****************************");			}			System.out.println("------------------------------------------------");		} catch (SeException e) {			e.printStackTrace();		}	}	/**	 * 空间条件查询 X,Y坐标參数传值	 */	public static void SpatialQuery_Hz(double x, double y) {		try {			SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss SS");			long startTime = System.currentTimeMillis();			Date startDate = new Date(startTime);			System.out.println("開始时间:" + formatter.format(startDate));			String tbname = "EZGISDATA.DCQWG_HB";			String[] cols = new String[7];			cols[0] = "JDNAME";			cols[1] = "JDCODE";			cols[2] = "SQNAME";			cols[3] = "SQCODE";			cols[4] = "WGNAME";			cols[5] = "WGCODE";			cols[6] = "TYPE";			SeConnection conn = getConn();			SeLayer layer = new SeLayer(conn, tbname, "SHAPE");			SeCoordinateReference cr = layer.getCoordRef();			SeFilter[] filters = new SeFilter[1];			SeShape shape = new SeShape(cr);			SDEPoint pt = new SDEPoint(x, y);			shape.generatePoint(1, new SDEPoint[] { pt });			// METHOD_ET_OR_AI, METHOD_ET_OR_II, METHOD_II_OR_ET, METHOD_AI,			// METHOD_II, METHOD_AI_NO_ET, METHOD_II_NO_ET,			// METHOD_PC, METHOD_PC_NO_ET, METHOD_PIP,			SeFilter filter = new SeShapeFilter(tbname, layer.getSpatialColumn(), shape, SeShapeFilter.METHOD_PIP);			filters[0] = filter;			SeSqlConstruct sqlCons = new SeSqlConstruct(tbname);			SeQuery query = new SeQuery(conn, cols, sqlCons);			query.prepareQuery();			query.setSpatialConstraints(SeQuery.SE_ATTRIBUTE_FIRST, false, filters);			query.execute();			SeRow row = query.fetch();			while (row != null) {				System.out.println(row.getObject(0).toString() + ", " + row.getObject(2).toString() + ", " + row.getObject(3).toString() + ", " + row.getObject(6).toString());				row = query.fetch();			}			long endTime = System.currentTimeMillis();			Date endDate = new Date(endTime);			System.out.println("结束时间:" + formatter.format(endDate));			System.out.println("相差: " + ((endTime - startTime) / 1000) + "秒\n");		} catch (Exception ex) {			ex.printStackTrace();		}	}	/**	 * 普通查询	 */	public static void CommonQuery() {		try {			SeConnection conn = getConn();			SeTable table = new SeTable(conn, "EZGISDATA.DCQWG_PY");			SeColumnDefinition[] tableDef = table.describe();			String[] cols = new String[tableDef.length];			for (int j = 0; j < cols.length; j++) {				cols[j] = tableDef[j].getName();			}			SeSqlConstruct sqlCons = new SeSqlConstruct("EZGISDATA.DCQWG_PY");			SeQuery query = new SeQuery(conn, cols, sqlCons);			SeQueryInfo queryInfo = new SeQueryInfo();			queryInfo.setQueryType(SeQueryInfo.SE_QUERYTYPE_ATTRIBUTE_FIRST);			queryInfo.setColumns(cols);			queryInfo.setConstruct(sqlCons);			query.prepareQueryInfo(queryInfo);			query.execute();			SeRow row = query.fetch();			while (row != null) {				System.out.println(row.getObject(0).toString() + " : " + row.getObject(1).toString() + " : " + row.getObject(3).toString() + " : " + row.getObject(4).toString() + " : "						+ row.getObject(5).toString() + " : " + row.getObject(6).toString() + " : " + row.getObject(7).toString() + " : " + row.getObject(8).toString());				row = query.fetch();			}		} catch (Exception ex) {			ex.printStackTrace();		}	}	/**	 * 属性条件查询	 */	public static void AttributeQuery() {		try {			String tbname = "EZGISDATA.DCQWG_PY";			String[] cols = new String[4];			cols[0] = "NEWSQMC";			cols[1] = "NEWSQBM";			cols[2] = "NEWWGMC";			cols[3] = "NEWWGBM";			SeConnection conn = getConn();			SeSqlConstruct sqlCons = new SeSqlConstruct(tbname);			sqlCons.setWhere("JDNAME='和平里'");			SeQuery query = new SeQuery(conn, cols, sqlCons);			query.prepareQuery(cols, sqlCons);			query.execute();			SeRow row = query.fetch();			int reccount = 0;			while (row != null) {				reccount = reccount + 1;				System.out.println(Integer.toString(reccount) + " : " + row.getObject(0).toString() + " : " + row.getObject(1).toString() + " : " + row.getObject(2).toString() + " : "						+ row.getObject(3).toString());				row = query.fetch();			}		} catch (Exception ex) {			ex.printStackTrace();		}	}	/**	 * 获得ArcSDE版本号信息	 */	public static void GetVersion() {		SeConnection conn = getConn();		SeRelease release = conn.getRelease();		System.out.println(release.getBugFix());		System.out.println(release.getDesc());		System.out.println(release.getRelease());		System.out.println(release.getMajor());		System.out.println(release.getMinor());	}	public static void main(String[] args) {		GetArcSDEInfo();		CommonQuery();		AttributeQuery();		GetVersion();		SpatialQuery_Hz(506019.02883, 302758.03546);	}}
结果:打印内容过多,省略内容XXXX字

------------------------------------------------

表级别锁PID:526084

表级别锁注冊ID:1966
*****************************

    ....   

1 : JDNAME:东花市 : JDCODE:13 : SQNAME:忠实里社区 : SQCODE:1303 : WGNAME:忠实里社区3号网格 : WGCODE:13033-0152 : TYPE:SG

    .....

你可能感兴趣的文章
01、Handler的那些事
查看>>
Mac OS X x64 环境下覆盖objective-c类结构并通过objc_msgSend获得RIP执行shellcode
查看>>
[译] 如何写出更好的 React 代码?
查看>>
Android动画:这里有一份很详细的 属性动画 使用攻略
查看>>
RxJava2 实战知识梳理(5) 简单及进阶的轮询操作
查看>>
js call,apply,bind总结
查看>>
Spring Boot 中使用 Java API 调用 lucene
查看>>
从 Java 层看 React-Native 通信机制
查看>>
来来来!关于iOS基础总结咱俩好好唠唠
查看>>
兑吧:从自建HBase迁移到阿里云HBase实战经验
查看>>
ECS 控制台诊断系统
查看>>
聊聊servicecomb-saga的alpha-server
查看>>
iOS多线程调研
查看>>
iOS多线程Pthreads篇
查看>>
萌新的node教程
查看>>
【活动】掘金技术征文丨给大家看的 Julia 教程
查看>>
推荐Android两种屏幕适配方案
查看>>
HTML5前端面试常见问题汇总
查看>>
HTTP2 基础入门
查看>>
让数据传输更安全
查看>>