[ArcSDE C API]创建矢量数据及坐标系统定义

[ArcSDE C API]创建矢量数据及坐标系统定义
七 18 2010 Published by Jack under .NET/CSharp, ArcSDE

*写了有些天了.上网不方便,总是没更新.罪过.
在ArcSDE API中,要素类(featureclass)被称为Layer[下文均用layer代表featureclass]。Layer可以看作增加了一个空间列定义的Table。
ArcSDE创建Layer的过程:
1,创建DBMS Table,注册Table(增加SDE维护的ROWID类型字段)
2,增加空间列定义 — 坐标系统,几何类型,存储精度等参数定义
3,创建F表(Feature Table)
综上所述,调用API创建Layer步骤:
1,创建Table并注册
2,增加空间列定义
所用相关函数(创建表并注册见上一篇):
SE_coordref_create –创建坐标系结构体
pe_factory_geogcs –设置坐标系定义(也可用其它坐标系定义函数,该函数是指定系统预定义的坐标系代码)
SE_coordref_set_coordsys — 设置坐标系
SE_coordref_set_xy –设置坐标域和存储精度
SE_coordref_set_precision — 确定使用64位还是32位存储
SE_layerinfo_create — 创建layerinfo
SE_layerinfo_set_coordref — 设置坐标系
SE_layerinfo_set_spatial_column — 设置“shape”字段
SE_layerinfo_set_shape_types — 设置几何类型
SE_layerinfo_set_grid_sizes — 设置格网大小
SgCoordRefSetXYClusterTol — 设置xy tolerance

其中:设置xy tolerance的函数在sde c api中并没有提到,使用dumpbin /exports sde.dll就会发现,实际很多函数sde c api文档都没有提到。那就只好去看sdetype.h头文件的定义了。
其中涉及到的几个概念:precision,scale,xy cluster tolerance:
通过观察api定义,SE_coordref_set_precision 用来定义要素类存储精度的。在ArcSDE9.2以前的版本,空间几何形体坐标均以32未整数存储。以后的版本,默认采用64位整型数据存储。
SE_coordref_set_xy 函数用来设置存储数据的范围和scale值。xy是数据存储起始minx,miny值。scale可以看作是存储精度。因为空间数据以整型存储在数据库中,所以,需要要通过小数点位移,来存储小数。这里的scale值就是这个意思。例如,如果一个数据的坐标系为高斯-克里格投影,即地图单位为米,那么,如果数据要能够以厘米存储,即可以存储类似123.12形式的数据,则scale值至少设置为100。通常情况,为了保证数据存储精度,可适当提高scale值。如设置为1000。
SgCoordRefSetXYClusterTol(设置xy cluster tolerance)则表达进行拓扑操作的时候,系统可区分两个点的最小距离。通常情况下,需要将tolerance值设置为存储精度值的两倍或更高。ESRI推荐值为10倍以上。
SDE API声明代码:
//create coodref struct
[DllImport("sde.dll", SetLastError = true, ThrowOnUnmappableChar = true)]
public static extern System.Int32 SE_


coordref_create(out IntPtr coordref);

//create pe_geogc
s struct by gcs CODE
[DllImport("pe.dll", SetLastError = true, ThrowOnUnmappableChar = true)]
public static extern System.IntPtr pe_factory_geogcs(Int16 code);

//set coordref's coordsys
[DllImport("sde.dll", SetLastError = true, ThrowOnUnmappableChar = true)]
public static extern System.Int32 SE_coordref_set_coordsys(IntPtr coordref,IntPtr pe_coordsys);

//set coordref's xy and scale
[DllImport("sde.dll", SetLastError = true, ThrowOnUnmappableChar = true)]
public static extern System.Int32 SE_coordref_set_xy(IntPtr coordref, double x,double y,double xyunits);

//set coordref's precision
[DllImport("sde.dll", SetLastError = true, ThrowOnUnmappableChar = true)]
public static extern System.Int32 SE_coordref_set_precision(IntPtr coordref, Int32 precision);

//create layerinfo struct
[DllImport("sde.dll", SetLastError = true, ThrowOnUnmappableChar = true)]
public static extern System.Int32 SE_layerinfo_create(IntPtr coordref, ref IntPtr layerinfo);

//set spatial column
[DllImport("sde.dll", SetLastError = true, ThrowOnUnmappableChar = true)]
public static extern System.Int32 SE_layerinfo_set_spatial_column(IntPtr layerinfo,string tablename,string spatialColumnName);

//set layerinfo's shapetype property
[DllImport("sde.dll", SetLastError = true, ThrowOnUnmappableChar = true)]
public static extern System.Int32 SE_layerinfo_set_shape_types(IntPtr layerinfo, Int32 shape_type);

//set layerinfo's grid size 3 level
[DllImport("sde.dll", SetLastError = true, ThrowOnUnmappableChar = true)]
public static extern System.Int32 SE_layerinfo_set_grid_sizes(IntPtr layerinfo, double grid1,double grid2,double grid3);

//set xy tolerance
[DllImport("sg.dll", SetLastError = true, ThrowOnUnmappableChar = true)]
public static extern System.Int32 SgCoordRefSetXYClusterTol(IntPtr coordref, double xyTolerance);调用过程代码:
IntPtr coordref;
// create coordinate system struct
int res = SDEAPI.SE_coordref_create(out coordref);

//define coordinate system 4024 --> PE_GCS_KRASOVSKY_1940 (pedef.h)
IntPtr pe_coordsys = SDEAPI.pe_factory_geogcs(4024);

//set coordinate system
res = SDEAPI.SE_coordref_set_coordsys(coordref,pe_coordsys);

//set xy domain
res = SDEAPI.SE_coordref_set_xy(coordref, -400, -400, 1000000000);

//set tolerance
res = SDEAPI.SgCoordRefSetXYClusterTol(coordref, 0.00000005);

//set precision
res = SDEAPI.SE_coordref_set_precision(coordref, 64);

//create layerinfo struct
IntPtr layerinfo = new IntPtr();
res = SDEAPI.SE_layerinfo_create(coordref,ref layerinfo);
res = SDEAPI.SE_layerinfo_set_coordref(layerinfo, coordref);

//create table code
CreateTable( ...... );

//set spatial column
res = SDEAPI.SE_layerinfo_set_spatial_column(layerinfo, FeatureClassPro.FeatureCl

as
sName, "SHAPE");
//set shape type
res = SDEAPI.SE_layerinfo_set_shape_types(layerinfo,getShapeCode(FeatureClassPro.GeoMetryType));
// set grid size
res = SDEA
PI.SE_layerinfo_set_grid_sizes(layerinfo, 0.0, 0.0, 0.0);

//final:::: create layer function
res = SDEAPI.SE_layer_create(sdeConnection,layerinfo,0,0);


相关文档
最新文档