使用SQL操作SQLite存储的ST_Geometry

来源:互联网 发布:一座城池知乎 编辑:程序博客网 时间:2024/06/15 17:17

在以前的博客曾经写过关于ArcGIS10.2与SQlite的文章

当ArcGIS10.2遇到SQLite
http://blog.csdn.net/linghe301/article/details/9056247


里面还留下了个引子:


未完待续:

还有一个问题没有弄清楚,ArcGIS10.2桌面也提供了关于SQLite的Dll,这个现在还不太清楚干什么用

1:有可能使用桌面操作SQLite就是调用这个dll

2:使用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.sqliteSQLite version 3.8.2 2013-12-06 14:53:30Enter ".help" for instructionsEnter SQL statements terminated with a ";"sqlite> .tablepoly                              st_spindex__poly_Shape_parentpt                                st_spindex__poly_Shape_rowidst_aux_spatial_reference_systems  st_spindex__pt_Shapest_geometry_columns               st_spindex__pt_Shape_nodest_spatial_reference_systems      st_spindex__pt_Shape_parentst_spindex__poly_Shape            st_spindex__pt_Shape_rowidst_spindex__poly_Shape_node       st_vtspindex_interfacesqlite> 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;187598240124444595516478348359871195459720

从上面的报错原因就是因为我的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索引表。



主要应用:估计在移动端的离线方案中,也可以引入该技术方案!



0 0
原创粉丝点击