标题:java操作oracle空间信息介绍
只看楼主
shitainong
Rank: 1
等 级:新手上路
帖 子:70
专家分:0
注 册:2012-7-6
结帖率:0
 问题点数:0 回复次数:1 
java操作oracle空间信息介绍
sde是Spatial Database Engine简写,中文全称:空间数据库引擎。
SDE是一种客户/服务器软件,可使空间数据在工业标准的数据库管理系统中存储、管理和快速查询检索。把GIS数据放在RDBMS中,但是一般的RDBMS都没有提供GIS的数据类型(如点、线、多边形、以及这些feature之间的拓扑关系和投影坐标等相关信息),RDBMS只提供了少量的数据类型支持:int,float,double,Blob,Long ,char等,一般都是数字,字符串和二进制数据几种。并且RDBMS不仅没有提取对GIS数据类型的存储,也没有提供对这些基础类型的操作(如:判断包含关系,相邻、相交、求差、距离、最短路径等)
JAVA对sde操作,首先需要下载sde支持的jar包。jpe92_sdk.jar和jsde92_sdk.jar两个包,这两个包可以从安装的目录下找到。
下面是java获的sde的链接代码:
 
[java] view plaincopyprint?
01./**
02.     * 连接sde服务
03.     * @return
04.     */  
05.    public  SeConnection getConnection () {  
06.        SeConnection conn = null ;  
07.        try {  
08.            conn = new SeConnection(SDE_SERVER_IP, SDE_PROT, SDE_DATEBASE_SID, SDE_USERNAME, SDE_PASSWORD);   
09.        } catch (SeException e) {  
10.            return null;  
11.        }  
12.        return conn;  
13.    }  
对sde数据进行添加,点线面的新增

[java] view plaincopyprint?
01./**
02.     * 添加资源信息点到sde中
03.     * @param pointBean 坐标点 POJO
04.     * @param tbName    图层名称
05.     * @param String typeName 所画的类型 1 点 2 线 3 面
06.     * @return   Long   sde的id
07.     * @throws Exception
08.     */  
09.    public Long addPointObject(PointBean pointBean, List columnList, String tableName, String typeName) throws Exception {  
10.        SeLayer insertLayer = null;  
11.        SeConnection conn = null;  
12.        Long intsertRowID = null;  
13.        SeInsert insert = null;  
14.        try {  
15.            conn = this.getConnection();  
16.            insertLayer = new SeLayer( conn,  tableName, "SHAPE");  
17.            if (insertLayer == null) {  
18.                throw new Exception("找不到空间表:" + tableName);  
19.            }  
20.            conn.startTransaction();  
21.            int arrayLength = columnList.size() + 1 ;  
22.            String[] cols = new String[arrayLength];  
23.            cols[0] = "SHAPE";  
24.            for (int i = 0 ;i<columnList.size() ; i++) {  
25.                ColumnBean columnBean = (ColumnBean)columnList.get(i);  
26.                cols[i+1] = columnBean.getName();  
27.            }  
28.            insert = new SeInsert(conn);  
29.            insert.intoTable(insertLayer.getName(), cols);  
30.            insert.setWriteMode(true);  
31.            SeCoordinateReference coordref = (SeCoordinateReference) insertLayer.getCoordRef();  
32.            SeShape shape = new SeShape(coordref);  
33.              
34.            if ("1".equals(typeName)) {  
35.                this.addPoint(pointBean, shape);  
36.            } else if ("2".equals(typeName)) {  
37.                this.addLine(pointBean, shape);  
38.            } else if ("3".equals(typeName)) {  
39.                this.addPolygon(pointBean, shape);  
40.            }  
41.            SeRow row = insert.getRowToSet();  
42.            row.setShape(0, shape);  
43.            for (int i = 0 ;i<columnList.size() ; i++) {  
44.                ColumnBean columnBean = (ColumnBean)columnList.get(i);  
45.                if (columnBean.getTypeObject() == 1) {  
46.                    row.setNString(i+1, String.valueOf(columnBean.getValObject()));  
47.                } else if (columnBean.getTypeObject() == 2) {  
48.                    row.setInteger(i+1, Integer.parseInt(columnBean.getValObject().toString()));  
49.                }else if (columnBean.getTypeObject() == 3) {  
50.                    row.setDouble(i+1, Double.parseDouble(columnBean.getValObject().toString()));  
51.                }   
52.            }  
53.            insert.execute();  
54.            intsertRowID = new Long(insert.lastInsertedRowId().longValue());  
55.            ();  
56.        } catch (Exception ex) {  
57.            ex.printStackTrace();  
58.            conn.rollbackTransaction();  
59.        } finally {  
60.            if (insert != null) {  
61.                insert.close();  
62.            }  
63.            if (conn != null) {  
64.                conn.close();  
65.            }  
66.        }  
67.        return intsertRowID;  
68.    }  
sde查询接口实现http://www.

[java] view plaincopyprint?
01./**
02.     * 查询sde
03.     * @param productId 产品id
04.     * @throws SeException
05.     */  www.
06.    public SeQuery searchSde (Long productId, String tableName) throws SeException {  
07.        SeConnection conn = getConnection();  
08.        SeLayer layer = new SeLayer( conn,  tableName, "SHAPE");  
09.        SeSqlConstruct sqlConstruct = new SeSqlConstruct(layer.getName());  
10.        if (productId != null) {  
11.            sqlConstruct.setWhere("yid="+productId.intValue());  
12.        }  
13.        String[] cols = null;  
14.        if (tableName.equals("YU_AN_POINT") || tableName.equals("FANG_AN_POINT")) {  
15.            cols = new String[4];  
16.            cols[0] = new String("OBJECTID");  
17.            cols[1] = layer.getSpatialColumn();  
18.            cols[2] = new String("NAME");  
19.            cols[3] = new String("IMAGETYPE");  
20.        } else {  
21.            cols = new String[3];  
22.            cols[0] = new String("OBJECTID");  
23.            cols[1] = layer.getSpatialColumn();  
24.            cols[2] = new String("NAME");  
25.        }  
26.        System.out.println("cols.length : " + cols.length);  
27.        SeQuery query = new SeQuery(conn, cols, sqlConstruct );  
28.        query.prepareQuery();  
29.        query.execute();  
30.        return query;  
31.    }  
SDE信息删除操作

[java] view plaincopyprint?
01./**
02.     *  
03.     * 删除 通过列对应的值
04.     * @param id     值
05.     * @param column 列  
06.     * @param tbName 表名
07.     * @throws SeException
08.     */  
09.     public void deletePointObject(String id, String column, String tbName) throws SeException {  
10.        SeConnection conn = null;  
11.        SeLayer layer = null;  
12.        SeDelete delete = null;  
13.        try {  
14.            conn = this.getConnection();  
15.            layer = new SeLayer(conn, tbName, "SHAPE"); // 得到对应图层   
16.            if (layer == null) {  
17.                throw new Exception("找不到空间表:" + tbName);  
18.            }  
19.            conn.startTransaction();  
20.            delete = new SeDelete(conn);  
21.            delete.fromTable(layer.getName(), column + "='" + id+"'");  
22.            ();  
23.        } catch (Exception ex) {  
24.            conn.rollbackTransaction();  
25.        } finally {  
26.            if (delete != null) {  
27.                try {  
28.                    delete.close();  
29.                } catch (SeException e) {  
30.                    e.printStackTrace();  
31.                    throw e;  
32.                } finally {  
33.                    if (conn != null) {  
34.                        conn.close();  
35.                    }  
36.                }  
37.            }  
38.        }  
39.    }
 
成都计算机培训10年品牌成都达内专注于成都嵌入式培训、成都软件测试培训等成都软件培训。嵌入式培训咨询:http://www.
搜索更多相关主题的帖子: 数据库管理 oracle 服务器 double 二进制 
2013-07-05 17:19
流星雨
Rank: 16Rank: 16Rank: 16Rank: 16
来 自:JAVA风暴
等 级:版主
威 望:43
帖 子:1851
专家分:1858
注 册:2004-5-30
得分:0 
貌似很少用到

感谢你们带我找到星空下美丽神话,无论经历多少苦痛也不放弃的梦;插上希望翅膀乘风我和你们飞翔,飞过海天尽头携手把梦想实现.....
2013-07-10 15:17



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-416739-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.186684 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved