Oracle Spatial的简单应用补充——shapefile导入ORACLE

 首先介绍一下shapefile:

        Shapefile文件是美国环境系统研究所(ESRI)所研制的GIS文件系统格式文件,是工业标准的矢量数据文件。 Shapefile将空间特征表中的非拓扑几何对象和属性信息存储在数据集中,特征表中的几何对象存为以坐标点集表示的图形文件—SHP文件,Shapefile文件并不含拓扑(Topological)数据结构。一个Shape文件包括三个文件:一个主文件(*.shp),一个索引文件 (*.shx),和一个dBASE(*.dbf)表。

       主文件是一个直接存取,变长度记录的文件,其中每个记录描述构成一个地理特征(Feature)的所有vertices坐标值。在索引文件中,每条记录包含对应主文件记录距离主文件头开始的偏移量,dBASE表包含SHP文件中每一个Feature的特征属性,表中几何记录和属性数据之间的一一对应关系是基于记录数目的ID。在dBASE文件中的属性记录必须和主文件中的记录顺序是相同的。图形数据和属性数据通过索引号建立一一对应的关系。

   

    导入shapefile文件是通过ORACLE提供的一个工具shp2sdo.exe,网上导出可以找到。具体操作步骤如下:

    1 下载shp2sdo.exe,把此文件复制到PATH变量包含的目录下,
      如我的oracle客户端安装后自动注册的环境变量是 path  :D:/oracle/product/10.2.0/client_1/BIN;

   2  在dos(WINDOWS运行CMD)下定位到shp文件的目录,使用命令:cd /d 文件目录 进入需要操作的文件目录。(注意:文件目录不能含有汉字);

   3  在文件目录下操作。输入命令为:shp2sdo.exe BOUNT_poly t_areainfo -g geom -d -x (-180,180) -y (-90,90)

-s 8307 -t 0.5 -v。  命令结束后会在当前目录生成t_areainfo.ctl 和t_areainfo.sql两个文件

   4  连接数据库C:/Documents and Settings/Administrator>sqlplus
user/password@orcl,登陆ORACLE成功后,执行脚本SQL> @t_areainfo.sql; 然后退出 SQL> exit;

   5 导入控制文件t_areainfo.ctl :  C:/Documents and Settings/Administrator>sqlldr
user/password@orcl  回车,然根据提示
control
=  输入t_areainfo.ctl  回车,导入结束。

   最后就是验证成果的时候,首先要创建MDSYS.SPATIAL_INDEX序列 语句如下:

       CREATE INDEX areainfo_idx ON t_areainfo(geom)  INDEXTYPE IS MDSYS.SPATIAL_INDEX;

   接着进行查询,语句如下:

      select * from t_areainfo t
      where SDO_RELATE( t.geom,
      MDSYS.Sdo_Geometry(2001, 8307, MDSYS.Sdo_Point_Type(113.119526, 34.84593, null), null, null ),

      ‘mask=ANYINTERACT querytype=WINDOW’ ) = ‘TRUE’;

      结果如下,大功告成。

 

 

 

 附注:各参数的含义

shp2sdo [-o] <shapefile> <tablename> -g <geometry column>
               -i <id column> -n <start_id> -p -d
               -x (xmin,xmax) -y (ymin,ymax) -s <srid>
  or
       shp2sdo -r <shapefile> <outlayer> -c <ordcount> -n <start_gid> -a -d
               -x (xmin,xmax) -y (ymin,ymax)
    shapefile           – name of input shape file
                          (Do not include suffix .shp .dbf or .shx)
    tablename           – spatial table name
                          if not specified: same as input file name
  Generic options:
    -o                  – Convert to object/relational format (default)
    -r                  – Convert to the relational format
    -d                  – store data in the control file
                          if not specified: keep data in separate files
    -x                  – bounds for the X dimension
    -y                  – bounds for the Y dimension
    -v                  – verbose output
    -h or -?            – print this message
  Options valid for the object model only:
    -g geometry column  – Name of the column used for the SDO_GEOMETRY object
                          if not specified: GEOM
    -i id_column        – Name of the column used for numbering the geometries
                          if not specified, no key column will be generated
                          if specified without name, use ID
    -n start_id         – Start number for IDs
                          if not specified, start at 1
    -p                  – Store points in the SDO_ORDINATES array
                          if not specified, store in SDO_POINT
    -s                  – Load SRID field in geometry and metadata
                          if not specified, SRID field is NULL
    -t                  – Load tolerance fields (x and y) in metadata
                          if not specified, tolerance fields are 0.00000005
    -8                  – Write control file in 8i format
                          if not specified, file written in 9i format
    -f                  – Write geometry data with 10 digits of precision
                          if not specified, 6 digits of precision is used
  Options valid for the relational model only:
    -c ordcount         – Number of ordinates in _SDOGOEM table
                          if not specified: 16 ordinates
    -n start_gid        – Start number for GIDs
                          if not specified, start at 1
    -a                  – attributes go in _SDOGEOM table
                          if not specified, attributes are in separate table

转载自:https://blog.csdn.net/wanglipo/article/details/5894249

You may also like...