码迷,mamicode.com
首页 > 编程语言 > 详细

ArcSDE SDK For Java二次开发介绍、演示样例

时间:2014-11-07 12:42:02      阅读:363      评论:0      收藏:0      [点我收藏+]

标签:des   style   blog   http   io   ar   os   使用   java   

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

bubuko.com,布布扣

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

无论怎么说,至少參考了一个大牛的文章,http://blog.csdn.net/linghe301/article/details/8058806 依据 ArcSDE For Java的API中,能够对其进行增删改查等操作。


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

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

http://download.csdn.net/detail/xiaokui_wingfly/8032329

详细在查询时有用的常量含义及方法參考官方API解释 :http://help.arcgis.com/en/geodatabase/10.0/sdk/arcsde/api/japi/docs/index.html

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

    .....





ArcSDE SDK For Java二次开发介绍、演示样例

标签:des   style   blog   http   io   ar   os   使用   java   

原文地址:http://www.cnblogs.com/hrhguanli/p/4080970.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!