『公告』 预祝您龙年大吉,万事如意, 过节期间, 大家如需数据服务,请拨打400 或直接添加客服微信,再祝大家龙年,心想事成。
关注我们 新浪 腾讯

ArcGIS Engine 10 开发手册(6-3)使用ArcGIS Engine进行临近操作

ArcGIS Engine 10 开发手册(6-3)使用ArcGIS Engine进行临近操作
临近操作用于确定一个到多个要素、或两个要素类间的要素邻近性。

    临近操作用于确定一个到多个要素、或两个要素类间的要素邻近性。它经常用来识别和一个要素最近 的其他要素或 者两个要素间 的最短距离等 ,在 ArcGIS Engine 中, 实现临近分析 操作的接口是 IProximityOperatorIProximityOperator 接口只有三个方法,如下:

    这三个方法主要用于得到两个几何对象之间的距离或得到一个给定点到某个几个对象的最近点之间的距离,比如我们求一个点到一个多边形的最近的点,就可以用这个接口。下图展示了一个查找最近点的示例:

 

 

 

    示例:通过临近分析操作实现Moran'I中的邻接矩阵

    Moran'I 分为全局和局部两种。

 

    通常情况,先做一个地区的全局 I 指数,全局指数只是告诉我们空间是否出现了集聚或异常值, 但并没有告诉我们在哪里出现。换句话说全局 Moran'I 只回答 Yes 还是 NO;如果全局有自相关出现,接着 做局部自相关;局部 Moran'I 会告诉我们哪里出现了异常值或者哪里出现了集聚,是一个回答 Where 的工具。在 计算 Moran 的时候有一个很关键的步骤就是计算邻接矩阵,借助 IProximityOperator 接口我们可以生成这 样一个矩阵表,代码如下:

 

/// <summary>

/// 这个字段要是唯一的

/// </summary>

/// <param name="_FilePath"></param>

/// <param name="_TableName"></param>

/// <param name="_pFeatureClass"></param>

/// <param name="_FieldName"></param>

/// <returns></returns>

 

private ITable CreateWeightTable (string _FilePath, string _TableName, IFeatureClass _pFeatureClass, string _FieldName)

 

{

 

  IWorkspaceFactory pWks = new ShapefileWorkspaceFactoryClass ();

 

  IFeatureWorkspace pFwk = pWks.OpenFromFile (_FilePath, 0) as IFeatureWorkspace;

 

  //用于添加表中的必要字段

  ESRI.ArcGIS.Geodatabase.IObjectClassDescription objectClassDescription = new ESRI.ArcGIS.Geodatabase.ObjectClassDescriptionClass ();

 

  IFields pTableFields = objectClassDescription.RequiredFields;

  IFieldsEdit pTableFieldsEdit = pTableFields as IFieldsEdit;

 

  int index = _pFeatureClass.FindField (_FieldName);

  IField pField = new FieldClass ();

 

  IFieldEdit pFieldEdit = pField as IFieldEdit;

 

  pFieldEdit.Name_2 = _FieldName;

  pTableFieldsEdit.AddField (pFieldEdit);

 

  pFieldEdit.Type_2 = _pFeatureClass.Fields.get_Field (index).Type;

 

  IFeatureCursor pFtCursor = _pFeatureClass.Search (null, false);

  IFeature pFt = pFtCursor.NextFeature ();

 

  while (pFt != null)

 

  {

 

    IField pFieldv = new FieldClass ();

 

    IFieldEdit pFieldEditv = pFieldv as IFieldEdit;

 

    pFieldEditv.Name_2 = pFt.get_Value (index).ToString ();

    pFieldEditv.Type_2 = esriFieldType.esriFieldTypeInteger;

    pTableFieldsEdit.AddField (pFieldEditv);

 

    pFt = pFtCursor.NextFeature ();

 

  }

 

  ITable pTable = pFwk.CreateTable (_TableName, pTableFields, null, null, "");

 

  IFeatureCursor pFtCursor1 = _pFeatureClass.Search (null, false);

  IFeature pFt1 = pFtCursor1.NextFeature ();

 

  while (pFt1 != null)

 

  {

 

    IRow pRow = pTable.CreateRow ();

 

    pRow.set_Value (1, pFt1.get_Value (index));

    pRow.Store ();

 

    pFt1 = pFtCursor1.NextFeature ();

 

  }

 

  return pTable;

 

}

 

IFeatureClass pPolygonFClass = GetFeatureClass (@"D:\空间查询\分析用的空间数据", "行政区");

 

ITable pTable = CreateWeightTable (@"D:\空间查询\分析用的空间数据", "Weight", pPolygonFClass, "NAME");

 

IFeature pFt1, pFt2;

 

IFeatureCursor pFtCur1, pFtCur2;

 

pFtCur1 = pPolygonFClass.Search (null, false);

pFt1 = pFtCur1.NextFeature ();

 

ICursor pCursor = pTable.Update (null, false);

IRow pRow = pCursor.NextRow ();

 

int j = 0;

 

///这里是关键,在这里进行计算,这里可以通过计算上三角或者下三角进行优化

while (pFt1 != null)

 

{

 

  IProximityOperator pProx = pFt1.Shape as IProximityOperator;

  pFtCur2 = pPolygonFClass.Search (null, false);

 

  pFt2 = pFtCur2.NextFeature ();

 

  while (pFt2 != null)

 

  {

 

    double dis = pProx.ReturnDistance (pFt2.Shape);

 

    if (dis == 0)

 

    {

 

      pRow.set_Value (j + 2, 1);

 

      pRow.Store ();

 

    }

 

  }

 

  j = 0;

 

  pFt2 = pFtCur2.NextFeature ();

  j++;

 

  pRow = pCursor.NextRow ();

  pFt1 = pFtCur1.NextFeature ();

 

}


      京ICP备08100627号-22 京公网安备 11010802030428号