SDE_GEODATABASE学习

     一直想用SQL直接操作SDE的GEODATABASE,做了些尝试,证明这样的办法的确不理想

先上图:SDE_DATABASE 数据模型

SDE_GEODATABASE学习_第1张图片

                                             图1-1 SDE数据模型

上面的图是安装SDE以后自动生成的数据表,当然还有一些其他的表,是独立的实体集,不存在键的关系,这些表是用来存放feature的。每当添加一个feature(包括toolbox,table这样的元素时,都会在数据库中生成相应的新表和存储过程,同时会在SDE数据表中添加索引表。)

如下图所示,我在ArcCatalog中加入一个table,命名为"TEXT",并加入列"id"。

SDE_GEODATABASE学习_第2张图片

                                   图1-2 加入一个命名为TEXT的表

     然后再回到sde_database,发现多了几个新表。其中f12,i12,s9都是系统索引用表,TEXT就是我们新加入的表。

SDE_GEODATABASE学习_第3张图片

                                   图1-3 GEODATABASE自动添加的表

     同时SDE更新了数据库的存储过程。

     这套机制实在太复杂,直接向GEODATABASE中写入空间数据是行不通了,不过读取是简单易行的。SDE的存储过程很有意思,拿一个例子出来研究。

    

ALTER PROCEDURE sde.SDE_layer_check_lock_conflicts
@sdeIdVal INTEGER,
@layerIdVal INTEGER,
@autoLockVal VARCHAR(1),
@lockTypeVal VARCHAR(1),
@minxVal BIGINT,
@minyVal BIGINT,
@maxxVal BIGINT,
@maxyVal BIGINT,
@lock_conflict INTEGER OUTPUT AS SET NOCOUNT ON
BEGIN
  DECLARE locks_cursor CURSOR LOCAL FAST_FORWARD FOR
    SELECT sde_id
    FROM   sde.sde.SDE_layer_locks WITH (TABLOCKX,HOLDLOCK)
    WHERE  layer_id = @layerIdVal AND
           (sde_id <> @sdeIdVal OR
           autolock = @autoLockVal) AND
           (lock_type = 'E' /* E: Exclusive lock */ OR
            @lockTypeVal = 'E') AND
           ((maxx >= @minxVal AND maxy >= @minyVal AND
             @maxxVal >= minx AND @maxyVal >= miny) OR
             (minx IS NULL OR @minxVal IS NULL))
  /* Find any conflicting locks.  The query we use is sensitive about
     whether we are trying to place an exclusive lock (in which case we
     have to consider all locks as possibly conflicting), or a shared lock
     (in which case we only have to worry about conflicting with exclusive
     locks).  In either case, the query will include a range expression so
     composed that a lock with NULL envelope variables will always match
     any other lock.  This is because a NULL envelope indicates a layer-
     wide lock.  With all of the about constraints in place, if any rows
     are returned, we probably have a conflict.  The last thing we have to
     check is if the connection owning the lock has somehow died without
     cleaning up. */
  OPEN locks_cursor
  DECLARE @id INTEGER
  DECLARE @loop_done INTEGER
  SET @lock_conflict = 0
  SET @loop_done = 0
  DECLARE @f_sde_id INTEGER
  WHILE @loop_done = 0
  BEGIN
    FETCH NEXT FROM locks_cursor INTO @f_sde_id
    IF @@FETCH_STATUS = 0
    BEGIN
      /* We found a matching layer lock.  See if the owning connection
         id is still out there.  If not, then this lock is invalid. */

      SELECT @id = SO.object_id
        FROM tempdb.sys.objects SO INNER JOIN
            sde.sde.SDE_process_information PR ON object_id (PR.table_name) = SO.object_id
        WHERE PR.sde_id = @f_sde_id

      IF @@ROWCOUNT > 0
      BEGIN
          /* we have a lock conflict! */
          SET @lock_conflict = 1
          SET @loop_done = 1
      END
      ELSE
      BEGIN
          /* defunct connection found, clean it up */
         EXECUTE sde.sde.SDE_pinfo_def_delete @f_sde_id
       END
     END
     ELSE
       SET @loop_done = 1
  END /* while */
  CLOSE locks_cursor
  DEALLOCATE locks_cursor
END

     有心人可以应用这样的存储过程,完成诸如锁定图层,修改坐标值等操作。不过用SQL直接操作GEODATABASE似乎是没有必要了,ARCGIS提供了很多非常好的工具,如ARCMAP,SERVER和AO,还是不要自己创造为妙。

你可能感兴趣的:(SDE_GEODATABASE学习)