您的位置:首页 > 数据库 > Oracle

ArcGIS——数据库空间SQL(一、oracle中使用sql空间查询及st_astext等函数出错问题)

2017-05-19 20:34 1071 查看

一、引言

        将shp文件导入oracle中就想着直接用sql进行普通查询和空间查询,这样直接通过webserver发布就可以不用arcgis server直接进行接口调用了,感觉这样比较接触底层些,所以就开始摸索了==

        前提是oracle安装好,shp数据也导入oracle里面去了。

二、空间查询sql的使用

        从arcgis官网中找到帮助文档,写了一些简单的查询sql。点击打开链接



        哈哈,看上去很容易吧,不过我高兴的实在太早了==

三、查询出现问题

1、问题惊现



这个官方提供的函数竟然不能使用了,尴尬==

2、查了好多资料,终于找原因

在 Oracle 中,ST_Geometry 和 ST_Raster 的 SQL 函数使用通过 Oracle 的外部过程代理(即 extproc)访问的共享库。要将 SQL 和 ST_Geometry
或 ST_Raster 配合使用或访问 GDB_ITEMS_VW 和 GDB_ITEMRELATIONSHIPS_VW 视图中的 ArcSDE XML 列,Oracle 必须能够访问这些库。因此,这些库必须存在于 Oracle 服务器上,并且必须通过 Oracle 的外部过程框架调用它们。
在 ArcGIS 中,不设置 Oracle 监听器也可以使用 ST_Geometry 和 ST_Raster。但是,您将不会拥有 ArcGIS 客户端的全部功能,也不会拥有 SQL 客户端的任何功能(如
SQL*Plus)。例如,如果未配置 Oracle 监听器,则无法对 ArcMap 的查询图层中的 ST_Geometry 列或包含 ST_Raster 列的版本化表使用 SQL 函数,无法删除包括 ST_Raster 列的行,也无法从 SQL 客户端执行 SQL 函数。另外,如果您不配置 Oracle 监听器,则无法将使用 ST_Geometry 类型作为要素服务的数据发布到空间数据服务器。
ST_Raster 安装为可选操作。有关说明,请参阅在 Oracle 中安装 ST_Raster 类型。

注:

如果您的 Oracle 数据库安装在 Windows 服务器上,但您未安装 ArcSDE 应用程序服务器,则您可能需要安装 Microsoft Visual C++ 2008 SP1 Redistributable
Package (x64)。如果 Oracle 服务器上没有 Microsoft Visual C++ 2008 SP1 Redistributable Package (x64),则可从 Microsoft 网站下载,然后进行安装。

如果您使用的是 Oracle 11g,请编辑 extproc.ora 文件以通过 Oracle 的外部过程框架来调用函数。如果您使用的是 Oracle 10g,请配置 Oracle 监听器。

3、解决办法

st_shapelib.dll


        从desktop中找到st_shapelib.dll文件,找个地儿拷贝下,下面的路径指向该文件



创建ST_SHAPELIB library

       使用sde用户登陆sqlplus

        执行sql查询user_libraries
        select * from user_libraries;

        创建ST_SHAPELIB library
        create or replace library ST_SHAPELIB as 'C:\arcgisdll\st_shapelib.dll';
 

        设置生效
       alter package sde.st_geometry_shapelib_pkg compile reuse settings;

修改oracle外部代理文件
        找到oracle安装目录下的extproc.ora,并进行修改最后的目录,改为st_shapelib.dll的路径。



        然后进行开始的操作st_astext函数,就ok了==v5

四、总结

oracle进行sql查询引入;

oracle进行简单sql空间查询;

oracle进行空间sql查询出错;

oracle空间sql问题解决;

结尾附英文参考:


Setting
up your Oracle geodatabase to work with ST_GEOMETRY

Everyone knows about the fact that they need some extra configuration in Oracle, to work with ST_GEOMETRY outside ArcCatalog/ArcMap. The confusion comes about as to what is considered "outside ArcCatalog/ArcMap" and what if ST_GEOMETRY is not their feature
shape storage type. This blog post will hopefully help answer some of these questions and also help you with setting up your Oracle geodatabase to work with ST_GEOMETRY.

 

I would also like to mention that all the information stated here is published by ESRI in various KB articles, documentation, help resources, etc. I am not stating anything new, just consolidating the information to present it in one location for anyone interested.

 

If you never interact with your geodatabase outside ArcCatalog/ArcMap, then you have nothing to worry about (but come on, when is that really true).

If your feature class storage data type is ST_GEOMETRY and you want to do any sort of spatial queries and/or modify data outside of ArcMap, you will need to set up your geoadatabase for ST_GEOMETRY.

If your feature class storage data type is NOT ST_GEOMETRY, but you would like to query metadata views such as SDE.GDB_ITEMS_VW using SQLPlus or SQLDeveloper, then you will need to set up your geodatabase for ST_GEOMETRY.

If your feature class storage data type is NOT ST_GEOMETRY, and you are not interested in the above mentioned view, then you may not need to set up your geoadatabase for ST_GEOMETRY.

 

My recommendation would be to set up your geodatabase to work with ST_GEOMETRY anyways. In this way you do not have to worry about it down the road when you plan to work with one of the above features.

 

Geodatabase
Setup

 

All the steps in the setup are done on the database server. You will need your DBA to perform these steps. The setup consists of 4 steps.

 

1. ESRI provides a library which is used for ST_GEOMETRY functions and operators with Oracle's external process. This library needs to be on the database server. The library can be found in any ArcGIS Desktop installation under Desktop 10.x\DatabaseSupport
Folder. Choose the appropriate RDBMS\DatabaseServerOS directory and you should see a file (for example st_shaplib.dll for Windows OS or libst_shapelib.so
for Linux OS). Move the library file to a directory of your choosing on the database server (in this example, I am going to use C:\Oracle\ArcGIS directory
as the location of the library file).

     In addition, if your database OS is Windows, ensure that the 64-bit Visual C++ 2008 SP1 Redistributable Package is installed, if not, it can be downloaded from Microsoft.

 

2. Create a library object in the Oracle geodatabase as user SDE. This library object will point to the directory and file (full path) location of the library file located in step 1.

Extending our example from step 1, log into the geodatabase as SDE user and run the following command.

Create or replace library st_shapelib as 'C:\Oracle\ArcGIS\st_shapelib.dll' ;

     The name of the library object created in step 2 has to be st_shapelib.

 

3. Modify the appropriate Oracle files.

If your Oracle version is Oracle 11g and above, then you only need to modify the extproc.ora file
located in the ORACLE_HOME\hs\admin directory. The extproc.ora file has a bunch of comments at the top. The line of interest is the last line which is uncommented.
In a default state the last line reads

SET EXTPROC_DLLS=

Change this line to below for our example.

SET EXTPROC_DLLS=C:\\Oracle\\ArcGIS\\st_shapelib.dll

if you need to add more than one dll they need to separated by ; in windows and : in
Unix/Linux. In windows the path works with \\ and in Unix/Linux the path works with / (I
know that is not what the comments above in extproc.ora say, but trust me that is the only way I have gotten it to work)

 

If your Oracle version is Oracle 10g, then you do not have access to extproc.ora file (was not available in 10g). In this case you have to modify the tnsnames.ora and listener.ora files
on the database server, so that the external calls can be made. Both these files are located in the ORACLE_HOME\network\admin directory.

 

Caution: Before making changes to the tnsnames.ora and listener.ora,
please make back up copies of these files.

 

The tnsnames.ora file contains a directory of known database services (local and remote), one entry is specifically used by the local database server to use external function calls (to the extproc). This entry is labeled EXTPROC_CONNECTION_DATA (must always
be labeled by this name). Add/modify the entry in tnsnames.ora

 

EXTPROC_CONNECTION_DATA =

(DESCRIPTION =

    (ADDRESS_LIST = (ADDRESS = (PROTOCOL = IPC)(Key = EXTPROC1)))

    (CONNECT_DATA = (SID = PLSExtProc)(PRESENTATION = RO))

  )

 

The next step is to modify listener.ora. Add an entry in the SID_LIST_LISTENER (this is an example of a default listener named LISTENER. If your listener uses a different name then add the entry in its SID_LIST). My entire listener.ora looks like below

 

LISTENER =

  (ADDRESS_LIST =

       (ADDRESS= (PROTOCOL= IPC)(KEY = EXTPROC1))

       (ADDRESS= (PROTOCOL= TCP)(Host= hostname.domain.com>)(Port= 1521))

  )

SID_LIST_LISTENER =

  (SID_LIST =

    (SID_DESC =

      (SID_NAME = PLSExtProc)

      (ORACLE_HOME = C:\oracle\product\10.2\db_1)

      (PROGRAM = extproc)

      (ENVS="EXTPROC_DLLS=C:\Oracle\ArcGIS\st_shapelib.dll")

    )

  )

 

The KEY value in listener.ora should match the corresponding service entry in the tnsnames.ora.

 

Oracle listener files are highly configurable and have lots of additional options. All the possible options that can be configured in the listener.ora and tnsnames.ora are beyond the scope of this blog post. The listener,ora and tnsnames,ora on your database
server may look very different from the simple configuration example mentioned above. Please refer to Oracle Database Net Services Administrator's Guide for details about configuring your listeners.

 

4. In case of Oracle 10g you will need to restart your listener so that the new configuration can be implemented. Creating library objects may cause some of the dependent objects to become invalid. To ensure all the objects in SDE schema are valid, it is a
good idea to run recompile on SDE schema as the final step.

Log into the geodatabase as sys user and run the following command.

EXECUTE sys.utl_recomp.recomp_serial('SDE');

 

 

This completes the Oracle geodatabase setup to work with ST_GEOMETRY.
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐