ArcSDE SDK Java 快速实践 2

I. 连接和流

· ArcSDE 连接SeConnection

通过ArcSDE SDK可以通过服务连接和直连两种方式进行连接。如果要进行直连可以参考这里:

http://edndoc.esri.com/arcsde/9.3/api/japi/japi.htm

不过直连的配置比较复杂,一般尽量通过服务方式连接到ArcSDE服务器,以下的代码可以通过服务连接到ArcSDE,然后返回一个SeConnection对象:

private SeConnection conn = null;

private static String server = "192.168.200.222";

private static String instance = "5151";

private static String database = "";

private static String username = "sde";

private static String password = "sde";

public SeConnection getConn() {

if (conn == null) {

try {

conn = new SeConnection(server, instance, database, username,

password);

} catch (SeException ex) {

ex.printStackTrace();

}

}

return conn;

}

· 流与数据操作

ArcSDE SDK通过流在客户端和服务器之间交互。这里的“流”的用法类似于数据库的游标,它在ArcSDE SDK Java中封装的比较好,比如进行数据查询就可以使用封装好的SeQuery类、数据添加使用封装好的SeInsert类等——它们都是SeStreamOp的子类。下面的代码展示了如何从一个SeConnection中进行一个查询以获取数据:

String layerName = "cities";

String objectidField = "OBJECTID";

String shapeField = "SHAPE";

SeConnection conn = getConn();

SeLayer layer = new SeLayer(conn, layerName, shapeField);

String[] cols = new String[] { objectidField, shapeField };

SeCoordinateReference cr = layer.getCoordRef();

SeShape shape = new SeShape(cr);

shape.generateFromText("POINT(116 40)");

SeFilter filter = new SeShapeFilter(layerName, layer

.getSpatialColumn(), clipShape, SeShapeFilter.METHOD_AI);

SeFilter[] filters = new SeFilter[] { filter };

SeSqlConstruct sqlCons = new SeSqlConstruct(layerName);

SeQuery query = new SeQuery(conn, cols, sqlCons);

query.prepareQuery();

query .setSpatialConstraints(SeQuery.SE_SPATIAL_FIRST, true,filters);

query.execute();

你可能感兴趣的:(java)