创建要素数据集代码
/// <summary>
/// 创建数据集
/// </summary>
/// <param name="Workspac">工作空间</param>
/// <param name="featureDatasetName">要素数据集名称</param>
/// <param name="spatialReference">空间参考,可以为空</param>
/// <returns></returns>
public static IFeatureDataset CreateOrOpenFeatureDataset(ref IWorkspace Workspac, string featureDatasetName, ISpatialReference spatialReference)
{
IFeatureWorkspace targetWorkspac = Workspac as IFeatureWorkspace;
IFeatureClass pFeaClass = null;
pFeaClass = ExitFeatureClass(Workspac, featureDatasetName, esriDatasetType.esriDTFeatureDataset);
if (pFeaClass != null)
{
return targetWorkspac.OpenFeatureDataset(featureDatasetName);
}
if (spatialReference == null)
{
spatialReference = new UnknownCoordinateSystemClass();
}
IControlPrecision2 pCP = spatialReference as IControlPrecision2;
IFeatureDataset newDataset = null;
try
{
if (!pCP.IsHighPrecision)//判断是否为高精度
{
pCP.IsHighPrecision = true;
}
newDataset = targetWorkspac.CreateFeatureDataset(featureDatasetName, spatialReference);
return newDataset;
}
catch (Exception ex)//低精度创建
{
pCP.IsHighPrecision = false;
IGeographicCoordinateSystem pGeo = spatialReference as IGeographicCoordinateSystem;
bool bGeo = (pGeo == null) ? false : true;
//要素分辨率
ISpatialReferenceResolution spatialReferenceResolution = spatialReference as ISpatialReferenceResolution;
if (bGeo)
{
spatialReferenceResolution.ConstructFromHorizon();//定义XY的分辨率和范围根据空间参考的水平范围
spatialReferenceResolution.SetDefaultXYResolution();//设置默认分辨率容差
}
else
{
spatialReferenceResolution.set_XYResolution(false, 0.04);
}
//要素数据集容差
ISpatialReferenceTolerance spatialReferenceTolerance = spatialReference as ISpatialReferenceTolerance;
if (bGeo)
{
spatialReferenceTolerance.SetDefaultXYTolerance();
}
else
{
spatialReferenceTolerance.SetMinimumXYTolerance();
}
try
{
newDataset = targetWorkspac.CreateFeatureDataset(featureDatasetName, spatialReference);
return newDataset;
}
catch (Exception e)
{
}
return null;
}
}