博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
ArcEngine实现坐标转换和投影(转载)
阅读量:4839 次
发布时间:2019-06-11

本文共 7006 字,大约阅读时间需要 23 分钟。

3.1 矢量数据投影和坐标转换
相关接口
3.1.1 IGeometry.Project方法
该方法声明如下: (C#语法)
 
public void Project (   ISpatialReference newReferenceSystem);
该方法对实现Igeoemtry的对象进行投影操作,参数为目标空间参考.以下代码中实现了对Point对象从一个空间参考到另一个空间参考的投影操作:
 
//Create Spatial Reference Factory
          ISpatialReferenceFactory srFactory = newSpatialReferenceEnvironmentClass();
          ISpatialReference sr1;
           //GCS toproject from
 
          IGeographicCoordinateSystem gcs =srFactory.CreateGeographicCoordinateSystem((int)esriSRGeoCSType.esriSRGeoCS_NAD1983);
           sr1 =gcs;
          sr1.SetFalseOriginAndUnits(-180, -90, 1000000);
 
          //Projected Coordinate System to project into
          IProjectedCoordinateSystem pcs =srFactory.CreateProjectedCoordinateSystem((int)esriSRProjCSType.esriSRProjCS_NAD1983N_AmericaLambert);
          pcs.SetFalseOriginAndUnits(0, 0, 1000);
          ISpatialReference sr2;
           sr2 =pcs;
 
           //Point toproject
           IPointpoint = new PointClass() as IPoint;
          point.PutCoords(-117.17, 34.06);
           //GeometryInterface to do actual project
           IGeometrygeometry;
           geometry =point;
          geometry.SpatialReference = sr1;
          geometry.Project(sr2);
           point =geometry as IPoint;
           doublex;
           doubley;
          point.QueryCoords(out x, out y);
 
          Debug.Print("X: " + x.ToString());
          Debug.Print("Y: " + y.ToString());
 
IGeometry接口的Project方法提供的投影操作实现了最基本的坐标转换功能. 实际数据处理过程中,比较明确数据转换前后空间参考信息情况下一般用此方法作坐标转换,不同投影带之间的坐标转换就是一个典型.
 
3.1.2 ITransform2D接口
ITransform2D接口不仅提供了图形平移, 旋转和缩放,还提供了更加强大的坐标转换方法Transform.其定义如下:(C#语法)
 
public void Transform (
    esriTransformDirectiondirection,
    ITransformationtransformation
);
 
在该方法中, 参数direction是转换方向, transformation是一个Itransformation接口,而Itransformation接口由很多类实现,这意味着不同的实现类,所包含的坐标转换数学公式是不一的,这里面包括二次多项式转换(AffineTransformation2D),AbridgedMolodensky转换(AbridgedMolodenskyTransformation)等。每一种实现类的转换方法这里不再赘述,可参照ArcObjects联机帮助获得更详细的信息,下面举例来说明该方法的使用:(Delphi代码)
 
procedure Transform_(FromPtColl, ToPtColl: IPointCollection;pGeo as IGeometry);
var
  pAffineTransformation2D:IAffineTransformation2D;
  ControlPtCnt: integer;
  FormPtArray: array of IPoint;
  ToPtArray: array of IPoint;
  i: integer;  
  pTransform2D:ITransform2D; 
begin
  //判断给定的控制点是否合法
  if FromPtColl.PointCount <>ToPtColl.PointCount then
    begin
     //控制点不成对错误
     exit;
    end;
  if FromPtColl.PointCount < 4 then
    begin
     //控制点不能少于4个
     exit;
    end;
  ControlPtCnt :=FromPtColl.PointCount;
  SetLength(FormPtArray, ControlPtCnt);
  SetLength(ToPtArray, ControlPtCnt);
  for i := 0 to ControlPtCnt -1 do
    begin
     FormPtArray[i] := CoPoint.Create as IPoint;
     FormPtArray[i].PutCoords(FromPtColl.Point[i].X, FromPtColl.Point[i].Y);
     ToPtArray[i] := CoPoint.Create as IPoint;
     ToPtArray[i].PutCoords(ToPtColl.Point[i].X, ToPtColl.Point[i].Y);
    end;
  //创建 AffineTransformation2D 对象
  pAffineTransformation2D :=CoAffineTransformation2D.Create as IAffineTransformation2D; 
  //设置控制点信息
 pAffineTransformation2D.DefineFromControlPoints(ControlPtCnt,FormPtArray[0], ToPtArray[0]);  
  //转到ITransform2D接口
  pTransform2D := pGeo as ITransform2D;
  //坐标转换
 pTransform2d.Transform(esriTransformForward,pAffineTransformation2D);
end;
 
ITransform接口较Igeoemtry提供了更加丰富的坐标转换方法。
 
3.2 影像数据纠正。
影像数据纠正可以通过IrasterGeometryProc接口实现。该接口提供了影像Clip, Filp, Merge,Mirror以及Mosaic等操作。如果通过控制点的方式对影像进行纠正处理可以通过该接口的wrap方法。该方法声明如下:(C#语法)
 
public void Warp (
    IPointCollectionsourceControlPoints,
    IPointCollectiontargetControlPoints,
    esriGeoTransTypeEnumtransformType,
    IRaster ipRaster
);
 
参数 sourceControlPoints和targetControlPoint定义了控制点信息,transformType定义了坐标转换方法, ipRaster是需要转换的Raster对象.以下代码是该接口使用的例子:
 
public static void GeoreferenceRaster(IRasterDataset2rasterDataset, IPointCollection sourcePoints, IPointCollectiontargetPoints)
{
  //this sample show how to georeference araster using control points
  // sourcePoints: represents source controlpoints
  // targetPoints: represents target controlpoints  IRasterGeometryProc rasterPropc = newRasterGeometryProcClass();
  IRaster raster =rasterDataset.CreateDefaultRaster();  //set thetransformatin
  rasterPropc.Warp(sourcePoints,targetPoints, esriGeoTransTypeEnum.esriGeoTransPolyOrder1, raster); //There are two ways to get the georeferencedresult: to save the transformation with the input rasterdataset
  rasterPropc.Register(raster); //or save to another new raster dataset
 rasterPropc.Rectify(@"c:\temp\georeferencing_output.img", "IMAGINEImage", raster);
}
需要注意的是当选择不同的转换类型时(参数transformType取值不同时), 对控制点的对数也有不同的要求.这个可以参照联机帮助中的详细说明.
 
此外, 使用IrasterGeometryProc.Wrap方法, 会略微改变影像图的色彩值,当对一幅影像图前后转换作对比时会发现这种色彩的变化情况.
 
个人认为,ArcGIS对影像图的处理功能较其他一些专业影像处理软件来讲,还是稍显逊色了些.
 
矢量图层叠加求交
           IMap pMap= axMapControl1.Map;
           ITablepInTable = ((IFeatureLayer)pMap.get_Layer(0)).FeatureClass asITable;
           ITablepTempTable = ((IFeatureLayer)pMap.get_Layer(1)).FeatureClass asITable;
 
          IFeatureClassName pName = new FeatureClassNameClass();
          pName.FeatureType = esriFeatureType.esriFTSimple;
          pName.ShapeFieldName = "shape";
          pName.ShapeType = esriGeometryType.esriGeometryPolygon;
 
          IWorkspaceName pWsName = new WorkspaceNameClass();
          pWsName.WorkspaceFactoryProgID ="esriDataSourcesFile.ShapefileWorkspaceFactory";
          pWsName.PathName = @"C:\Data";
          IDatasetName pDatasetName = pName as IDatasetName;
          pDatasetName.Name = "Interset_resultaa";
          pDatasetName.WorkspaceName = pWsName;
 
          IBasicGeoprocessor pBGeoOr = new BasicGeoprocessorClass();
          IFeatureClass pFeaCls = pBGeoOr.Intersect(pInTable, false,pTempTable, false, 0, pName);
 
          IFeatureLayer pFeaLyr = new FeatureLayerClass();
          pFeaLyr.FeatureClass = pFeaCls;
          pFeaLyr.Name = pFeaCls.AliasName;
          pMap.AddLayer(pFeaLyr as ILayer);
 
矢量图层合并
本程序实现了对具有同类型数据结构的shapefile的图层合并,并在MapControl中显示.
 
           ILayerpLayer;
          IFeatureLayer pFeatureLayer;
          IFeatureClass pFeatureClass;
          IWorkspaceName pNewWSName;
          IBasicGeoprocessor pBasicGeop;
          IFeatureClassName pFeatureClassName;
          IDatasetName pDatasetName;
          IFeatureClass pOutputFeatClass;
          IFeatureLayer pOutputFeatLayer;
           IArraypArray;
           ITablepTable;
          //合并图层的集合
           pArray =new ArrayClass();
           for (int i= 0; i < this.MapC_main.LayerCount;i++ )
           {
              pLayer =this.MapC_main.get_Layer(i);
              pArray.Add(pLayer);
           }
          //定义输出图层的fields表
           pLayer =this.MapC_main.get_Layer(0);
           pTable =(ITable)pLayer;
 
          pFeatureLayer=(IFeatureLayer)pLayer;
          pFeatureClass = pFeatureLayer.FeatureClass;
          //判断图层是否大于2个
          if(this.MapC_main.LayerCount< 2){
              MessageBox.Show("Table QIfailed");
              return;
           }
          //输出文件类型
          pFeatureClassName = new FeatureClassNameClass();
          pFeatureClassName.FeatureType = esriFeatureType.esriFTSimple;
          pFeatureClassName.ShapeFieldName = "Shape";
          pFeatureClassName.ShapeType = pFeatureClass.ShapeType;
          //输出shapefile的名称和位置
           pNewWSName= new WorkspaceNameClass();
          pNewWSName.WorkspaceFactoryProgID="esriDataSourcesFile.ShapefileWorkspaceFactory";
          pNewWSName.PathName = "E:\\Cshape";
          pDatasetName = (IDatasetName)pFeatureClassName;
          pDatasetName.Name = "Union_result_1";
          pDatasetName.WorkspaceName = pNewWSName;
          
          //合并图层
           pBasicGeop= new BasicGeoprocessorClass();
          pOutputFeatClass=pBasicGeop.Merge(pArray,pTable,pFeatureClassName);
           //Add theoutput layer to the map
          pOutputFeatLayer = new FeatureLayerClass();
          pOutputFeatLayer.FeatureClass = pOutputFeatClass;
          pOutputFeatLayer.Name = pOutputFeatClass.AliasName;
          this.MapC_main.AddLayer(pOutputFeatLayer as ILayer, 0);
参考文献:http://blog.sina.com.cn/s/blog_5ea1c9c90101ib6j.html

转载于:https://www.cnblogs.com/Joetao/articles/8417766.html

你可能感兴趣的文章
30分钟学会如何使用Apache Shiro
查看>>
asp.net部署时加密config文件
查看>>
想开个网店的。。学习一下vancl的分析
查看>>
DDD:在基于关系数据库的领域,聚合的边界等于并发管理的边界。
查看>>
poj 1961 Period
查看>>
BZOJ1560: [JSOI2009]火星藏宝图
查看>>
play framework 相关
查看>>
cf1008 codeforces round #535(div3) E1. Array and Segments (Easy version)
查看>>
React 学习笔记
查看>>
LeetCode_Combinations
查看>>
快手第一题
查看>>
有向图强连通分量的Tarjan算法及模板
查看>>
MEAN教程3-NPM安装
查看>>
leetcode| Count Numbers with Unique Digits
查看>>
flask 模版语言及信息传递
查看>>
Ubuntu14.04下安装Hadoop2.4.0 (单机模式)
查看>>
c++ throw异常(学习)
查看>>
IDEA中Git的使用
查看>>
docker 下mysql 和postgresql 数据库的搭建以及数据文件的迁移和备份
查看>>
Java 常用对象-Math类
查看>>