ArcEngine为数据添加坐标参考

21 篇文章 0 订阅

为数据添加坐标参考的方式有很多,下面介绍两种方式进行设置。

1、使用IGeoDatasetSchemaEdit接口进行修改。

直接上代码:

public static bool DefineProject(string datasetFile, string tempDatasetFile)
{
    IGPUtilities myGpUt = new GPUtilitiesClass();
    IGeoDataset geoDataset = (IGeoDataset)myGpUt.OpenDatasetFromLocation(datasetFile);
    IGeoDataset tempGeoDataset = (IGeoDataset)myGpUt.OpenDatasetFromLocation(tempDatasetFile);
    if (geoDataset == null || tempGeoDataset == null)
    {
        return false;
    }
   
    ISpatialReference spatialReference = tempGeoDataset.SpatialReference;
    if (spatialReference.Name == "Unknown")
    {
        return false;
    }
 
    IGeoDatasetSchemaEdit geoDatasetSchemaEdit = (IGeoDatasetSchemaEdit)geoDataset;            
    if (!geoDatasetSchemaEdit.CanAlterSpatialReference)
    {
        return false;
    }
 
    geoDatasetSchemaEdit.AlterSpatialReference(spatialReference);

    return true;
}

2、调用GP工具进行修改

直接上代码:

        public bool GP_DefineProjection(string sNoProjectDataPath, ISpatialReference pSpatialReference)
        {
            try
            {
                //创建工具
                DefineProjection myDefFeatureProject = new DefineProjection();
                myDefFeatureProject.in_dataset = sNoProjectDataPath;
                myDefFeatureProject.coor_system = pSpatialReference;

                m_pResult = (IGeoProcessorResult)m_Gp.Execute(myDefFeatureProject, null);

                if (m_pResult == null)
                {
                    //执行出错
                    return false;
                }

                if (m_pResult.Status == ESRI.ArcGIS.esriSystem.esriJobStatus.esriJobSucceeded)
                {
                    //执行成功
                    return true;
                }
                else
                {
                    //执行失败
                    return false;
                }

                return true;
            }
            catch (System.Exception ex)
            {
                //执行出现异常
                return false;
            }
        }



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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值