您的位置:首页 > 数据库

使用SQL操作SQLite存储的ST_Geometry

2014-01-02 13:33 417 查看
在以前的博客曾经写过关于ArcGIS10.2与SQlite的文章
当ArcGIS10.2遇到SQLite
/article/1426432.html

里面还留下了个引子:
未完待续:还有一个问题没有弄清楚,ArcGIS10.2桌面也提供了关于SQLite的Dll,这个现在还不太清楚干什么用1:有可能使用桌面操作SQLite就是调用这个dll2:使用SQL可以直接操作SQLite类似SQL 操作Oracle数据库编辑空间数据。
那么今天就将这个问题给解答了
在ArcGIS10.2.1这个版本中,Esri已经给予了相关的解决方案。
至于ArcGIS Desktop怎么创建SQlite,SQLite怎么下载,客户端怎么下载可以参考上面的文档,里面都写的很清楚。
1:引用SQLite的ST_Geometry的dll

上面提到了在桌面安装后有支持的不同数据库的dll,那么这些dll就是我们所谓的SQL操作函数的文件,我们需要将这些dll加载到环境变量中
比如:PATH=c:\stgeometry_sqlite.dll



提示:由上所示,里面有支持两个操作系统和分布32Bit、64Bit四个文件,所以我们需要知道我们使用的数据库客户端的位数,比如你下载的sqlite3的位数或者sqlite database brower的位数,如果位数加载不对,肯定是看不了的。
加载文件,该操作是针对每一个Session的如果添加了环境变量:
--Load the ST_Geometry library on Windows.
SELECT load_extension('stgeometry_sqlite.dll','SDE_SQL_funcs_init');

--Load the ST_Geometry library on Linux.
SELECT load_extension('libstgeometry_sqlite.so', 'SDE_SQL_funcs_init');


如果没有添加环境变量,直接加载绝对路径
--Load the ST_Geometry library on Windows.
SELECT load_extension(
 'c:\Program Files (x86)\ArcGIS\Desktop10.2\DatabaseSupport\SQLite\Windows32\stgeometry_sqlite.dll',
 'SDE_SQL_funcs_init'
);

--Load the ST_Geometry library on Linux.
SELECT load_extension(
 '/arcgis/server/usr/DatabaseSupport/SQLite/Linux64/libstgeometry_sqlite.so',
 'SDE_SQL_funcs_init'
);


2:测试首先,我们看看ArcMap的显示效果



C:\>sqlite3 ext.sqlite
SQLite version 3.8.2 2013-12-06 14:53:30
Enter ".help" for instructions
Enter SQL statements terminated with a ";"
sqlite> .table
poly                              st_spindex__poly_Shape_parent
pt                                st_spindex__poly_Shape_rowid
st_aux_spatial_reference_systems  st_spindex__pt_Shape
st_geometry_columns               st_spindex__pt_Shape_node
st_spatial_reference_systems      st_spindex__pt_Shape_parent
st_spindex__poly_Shape            st_spindex__pt_Shape_rowid
st_spindex__poly_Shape_node       st_vtspindex_interface

sqlite> SELECT load_extension('stgeometry_sqlite.dll','SDE_SQL_funcs_init');
Error: 鎵句笉鍒版寚瀹氱殑妯″潡銆?

sqlite> SELECT load_extension('stgeometry_sqlite.dll','SDE_SQL_funcs_init');

sqlite> select pt.objectid from pt,poly where st_intersects(poly.shape,pt.shape)=1;
187
598
2401
2444
4595
5164
7834
8359
8711
9545
9720

从上面的报错原因就是因为我的sqlite3.exe是32Bit的,我加载了64Bit的dll报的错误。我们可以看到执行SQL与Oracle的ST_Geometry函数SQL操作基本类似。

当然了,查看系统帮助,我们就可以看到Esri提供了那些函数是支持SQlite的,其实跟Oracle使用的函数基本类似。
http://resources.arcgis.com/en/help/main/10.2/index.html#/A_quick_tour_of_SQL_functions_used_with_ST_Geometry/006z0000003n000000/

--------------------------------------------------------------------------
空间索引
空间索引不会自动与SQLite的任何ST_Geometry的功能使用。

在SQLite的空间索引是R-tree索引表。

主要应用:估计在移动端的离线方案中,也可以引入该技术方案!
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: