ArcSDE C API创建的图层并register with geodatabase

Pro_RegisterGeoDatabase相当于catalog中的"register with geodatabase"。Pro_UnRegisterGeoDatabase返回到原始状态,只支持SDE.GDB_OBJECTCLASSES,SDE.GDB_FEATURECLASSES ,SDE.GDB_FIELDINFO,不支持GDB_SUBTYPES,所以inIsSubtypeFixed应该全部设置为0。inDataSetID为GDB_FEATUREDATASET的ID字段。特别注意的是SDE.GDB_OBJECTCLASSES中的CLSID字段,{52353152-891A-11D0-BEC6-00805F7C4268}表示featureclass,不能写错了。

 

 

 

CREATE OR REPLACE Package Pac_Layer
As
       
        --图层名称数组类型
        Type Layer_Name_Array is table of VARCHAR2(160) index by binary_integer;
        --字段名称数组类型
        Type Field_Name_Array is table of VARCHAR2(160) index by binary_integer;
        --布尔数组类型
        Type Boolean_Array        is table of INTEGER        index by binary_integer;
       
        --根据别名获取表名
        Procedure Pro_AliasToLayer
        (         
                in_Alias_Array        in        Layer_Name_Array,
                out_Layer_Array        out        Layer_Name_Array
        );
       
        --数字转换为布尔类型
        Function Fun_ToBoolean
        (
                newVal                in        INTEGER
        )
        return INTEGER;
       
        --附加图层到GEODATABASE       
        /*
                inDataSetID:数据集ID(可以设置为null)
                inlayername:图层名称
                inlayeralias:图层别名               
                ingeometrytype:几何类型(1 = point,2 = multipoint ,3 = line,4 = polygon (including anno and dimension) ,9 = multipatch )
                inshapefield:SHAPE字段名称(默认为SHAPE)
                infieldnames:图层字段名称集合
                inaliasnames:图层字段别名集合
                inIsRequired:布尔集合,是否为必填字段,0 (不是必填项)或1 (为必填字段)
                inIsSubTypeFixed:布尔集合,字段是否有子类型,0 = yes ,1 = no
                inIsEditTable:布尔集合,字段值是否可以编辑,0 (不可编辑)或1 (编辑)
        */
        Procedure Pro_RegisterGeoDatabase
        (       
                inDataSetID                        in        INTEGER,       
                inlayername                        in        VARCHAR2,
                inlayeralias                in        VARCHAR2,               
                ingeometrytype                in        INTEGER,
                inshapefield                in        VARCHAR2,
                infieldnames                in        Field_Name_Array,
                inaliasnames                in        Field_Name_Array,
                inIsRequired                in        Boolean_Array,
                inIsSubtypeFixed        in  Boolean_Array,
                inIsEditTable                in        Boolean_Array
        );
        --GEODATABASE反注册图层
        Procedure Pro_UnRegisterGeoDatabase
        (
                inlayername                        in        VARCHAR2               
        );
End Pac_Layer;
/

CREATE OR REPLACE Package Body Pac_Layer
As
        --根据别名获取表名
        Procedure Pro_AliasToLayer
        (         
                in_Alias_Array        in        Layer_Name_Array,
                out_Layer_Array        out        Layer_Name_Array
        )
        Is
                tempName        VARCHAR2(160);
                arry_count        INTEGER;       
        Begin
                arry_count := in_Alias_Array.count;
               
                FOR i IN 1..arry_count LOOP                       
                        Select nvl(min(Name),null) into tempName from SDE.GDB_OBJECTCLASSES WHERE ALIASNAME = in_Alias_Array(i);
                        if tempName is Not NULL then                               
                                out_Layer_Array(i) := tempName;
                        else               
                                out_Layer_Array(i) := in_Alias_Array(i);
                        end if;
                END LOOP;
        End Pro_AliasToLayer;
       
        --数字转换为布尔类型
        Function Fun_ToBoolean
        (
                newVal        in        INTEGER
        )
        return INTEGER
        Is
                val        INTEGER;
        Begin
                if newVal <> 0 then
                        val := 1;
                else
                        val := 0;
                end if;
               
                Return val;
        End Fun_ToBoolean;
       
        --附加图层到GEODATABASE       
        /*
                inDataSetID:数据集ID(可以设置为null)
                inlayername:图层名称
                inlayeralias:图层别名               
                ingeometrytype:几何类型(1 = point,2 = multipoint ,3 = line,4 = polygon (including anno and dimension) ,9 = multipatch )
                inshapefield:SHAPE字段名称(默认为SHAPE)
                infieldnames:图层字段名称集合
                inaliasnames:图层字段别名集合
                inIsRequired:布尔集合,是否为必填字段,0 (不是必填项)或1 (为必填字段)
                inIsSubTypeFixed:布尔集合,字段是否有子类型,0 = yes ,1 = no
                inIsEditTable:布尔集合,字段值是否可以编辑,0 (不可编辑)或1 (编辑)
        */
        Procedure Pro_RegisterGeoDatabase
        (       
                inDataSetID                        in        INTEGER,       
                inlayername                        in        VARCHAR2,
                inlayeralias                in        VARCHAR2,       
                ingeometrytype                in        INTEGER,
                inshapefield                in        VARCHAR2,
                infieldnames                in        Field_Name_Array,
                inaliasnames                in        Field_Name_Array,
                inIsRequired                in        Boolean_Array,
                inIsSubtypeFixed        in  Boolean_Array,
                inIsEditTable                in        Boolean_Array
        )
        Is
                object_classID                        INTEGER;
                search_count                        INTEGER;
                --数组大小
                fieldnames_count                INTEGER;
                aliasnames_count                INTEGER;
                isRequired_count                INTEGER;
                isSubtypeFixed_count        INTEGER;
                isEditTable_count                INTEGER;
                --数字到布尔类型
                required                                INTEGER;
                subtypefixed                        INTEGER;
                edittable                                INTEGER;
                --
                field                                        VARCHAR2(160);
                alias                                        VARCHAR2(160);
               
        Begin
                fieldnames_count := infieldnames.count;
                aliasnames_count := inaliasnames.count;
                isRequired_count := inIsRequired.count;
                isSubTypeFixed_count := inIsSubtypeFixed.count;
                isEditTable_count := inIsEditTable.count;
               
                if fieldnames_count <> aliasnames_count or fieldnames_count <> isRequired_count or fieldnames_count <> isSubtypeFixed_count or fieldnames_count <> isEditTable_count then
                        RAISE_APPLICATION_ERROR(-30005,'输入的参数不正确,数组大小必须一致!');
                end if;
               
               
                --GDB_OBJECTCLASSES表
                Select nvl(max(ID),null) into object_classID from SDE.GDB_OBJECTCLASSES where name = inlayername;
                if object_classID is not null  then
                        --图层已经存在,修改图层别名和所属数据集
                        Update SDE.GDB_OBJECTCLASSES SET ALIASNAME = inlayeralias,DATASETID = inDataSetID where ID = object_classID;
                else
                        --图层不存在,新增图层,图层只能是featureclass                       
                        Select Max(ID) into object_classID from SDE.GDB_OBJECTCLASSES order by ID;
                        object_classID := object_classID + 1;
                        --插入数据到gdb_objectclassesge表
                        --{52353152-891A-11D0-BEC6-00805F7C4268}表示featureclass
                        insert into SDE.gdb_objectclasses(id,owner, name, aliasname, clsid,  datasetid)
                                values(object_classID,'SDE',inlayername,inlayeralias,'{52353152-891A-11D0-BEC6-00805F7C4268}',inDataSetID);
                end if;
               
               
                --GDB_FEATURECLASSES表
                search_count:= 0;
                Select count(OBJECTCLASSID) into search_count From SDE.GDB_FEATURECLASSES Where OBJECTCLASSID = object_classID;
                -- featuretype:1 = point, multipoint, line, polygon, or multipatch,7 = junctions ,8 = simple edges ,10 = complex edges ,11 = annotation ,13 = dimension ,14 = raster
                -- featuretype:只能为1
                if search_count = 0 then               
                        insert into SDE.gdb_featureclasses(objectclassid,featuretype,geometrytype,shapefield)
                                values(object_classID,1,ingeometrytype,inshapefield);
                end if;
               
                --GDB_FIELDINFO
                FOR i IN 1..fieldnames_count LOOP
               
                        --转换为0或1
                        required := Fun_ToBoolean(inIsRequired(i));
                        subtypefixed := Fun_ToBoolean( inIsSubtypeFixed(i) );
                        edittable := Fun_ToBoolean( inIsEditTable(i) );
                       
                        field := infieldnames(i);
                        alias := inaliasnames(i);
                       
                        search_count:= 0;
                       
                        --检查列是否已经注册
                        Select Count(object_classID) into search_count From SDE.GDB_FIELDINFO Where CLASSID = object_classID and FIELDNAME = field;
                        if search_count = 0 then
                                Insert into SDE.GDB_FIELDINFO(CLASSID,FIELDNAME,aliasname,modelname,ISREQUIRED,ISSUBTYPEFIXED,ISEDITABLE)
                                        values(object_classID,field,alias,field,required,subtypefixed,edittable);
                        else
                                Update SDE.GDB_FIELDINFO Set aliasname = alias Where CLASSID = object_classID and FIELDNAME = field;
                        end if;
                END LOOP;
                       
        End Pro_RegisterGeoDatabase;
       
        --GEODATABASE反注册图层
        Procedure Pro_UnRegisterGeoDatabase
        (
                inlayername                        in        VARCHAR2               
        )
        Is
                object_classID                        INTEGER;
        Begin
                Select nvl(max(ID),null) into object_classID from SDE.GDB_OBJECTCLASSES where name = inlayername;
                if object_classID is not null  then
                        DELETE From SDE.GDB_FEATURECLASSES Where OBJECTCLASSID = object_classID;
                        DELETE From SDE.GDB_FIELDINFO Where CLASSID = object_classID;
                        DELETE From SDE.GDB_OBJECTCLASSES where ID = object_classID;
                end if;
        End Pro_UnRegisterGeoDatabase;
       
End Pac_Layer;

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

kmblack1

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值