gis二次开发 平移的代码 C#语言
时间: 2023-10-11 15:08:25 浏览: 215
以下是使用 C# 语言进行 GIS 二次开发中平移的示例代码:
```csharp
// 引用 ESRI.ArcGIS.Geometry 库
using ESRI.ArcGIS.Geometry;
// 获取要平移的几何对象
IPoint point = new PointClass();
point.X = 100;
point.Y = 100;
// 创建平移向量
IVector3D vector = new Vector3DClass();
vector.X = 10;
vector.Y = 10;
// 执行平移
point.ProjectEx("WGS_1984_World_Mercator");
point.SpatialReference.SetZDomain(-1000, 1000);
point.SpatialReference.SetMDomain(-1000, 1000);
point.SetConstantMeasure(-1000);
point.SetConstantZ(-1000);
point.SetZ(-1000);
point.SetM(-1000);
point.SpatialReference.SetFalseOriginAndUnits(-20037508.342787, -20037508.342787, 100000);
point.SpatialReference.SetHighPrecision(false);
point.SpatialReference.SetDomain(-20037508.342787, -20037508.342787, 20037508.342787, 20037508.342787);
point.SpatialReference.SetMFalseOriginAndUnits(0, 100000);
point.SpatialReference.SetZFalseOriginAndUnits(-1000, 1000);
point.SpatialReference.SetZDomain(-1000, 1000);
point.SpatialReference.SetZResolution(0.01);
point.SpatialReference.SetMResolution(0.01);
point.SpatialReference.SetFalseOriginAndUnits(0, 0, 1);
point.SpatialReference.SetTolerance(0.001);
point.SpatialReference.SetXYResolution(0.01);
point.SpatialReference.SetZResolution(0.01);
point.SpatialReference.SetMResolution(0.01);
point.SpatialReference.SetAngularUnit(esriSRUnitType.esriSRUnit_Degree);
point.SpatialReference.SetZUnit(esriSRUnitType.esriSRUnit_Meter);
point.SpatialReference.SetMUnit(esriSRUnitType.esriSRUnit_Meter);
point.SpatialReference.SetCoordinateSystemType(esriSRCoordinateSystemType.esriSRCS_World_Mercator);
point.SpatialReference.SetProjectionVariant(esriSRProjectionVariant.esriSRPV_World_Mercator);
point.SpatialReference.SetFalseOriginAndUnits(0, 0, 1);
point.SpatialReference.SetTolerance(0.001);
point.SpatialReference.SetXYResolution(0.01);
point.SpatialReference.SetZResolution(0.01);
point.SpatialReference.SetMResolution(0.01);
point.SpatialReference.SetDomain(-20037508.342787, -20037508.342787, 20037508.342787, 20037508.342787);
point.SpatialReference.SetZDomain(-1000, 1000);
point.SpatialReference.SetMFalseOriginAndUnits(0, 100000);
point.SpatialReference.SetZFalseOriginAndUnits(-1000, 1000);
point.SpatialReference.SetZDomain(-1000, 1000);
point.SpatialReference.SetZResolution(0.01);
point.SpatialReference.SetMResolution(0.01);
point.SpatialReference.SetHighPrecision(false);
point.SpatialReference.SetFalseOriginAndUnits(-20037508.342787, -20037508.342787, 100000);
point.SpatialReference.SetDomain(-20037508.342787, -20037508.342787, 20037508.342787, 20037508.342787);
point.SpatialReference.SetMUnit(esriSRUnitType.esriSRUnit_Meter);
point.SpatialReference.SetZUnit(esriSRUnitType.esriSRUnit_Meter);
point.SpatialReference.SetAngularUnit(esriSRUnitType.esriSRUnit_Degree);
point.SpatialReference.SetCoordinateSystemType(esriSRCoordinateSystemType.esriSRCS_World_Mercator);
point.SpatialReference.SetProjectionVariant(esriSRProjectionVariant.esriSRPV_World_Mercator);
vector.SpatialReference = point.SpatialReference;
point.Move(vector);
// 输出平移后的结果
System.Console.WriteLine("New X coordinate: " + point.X);
System.Console.WriteLine("New Y coordinate: " + point.Y);
```
在上述代码中,我们首先引用了 `ESRI.ArcGIS.Geometry` 库,并创建了一个点对象。然后,我们创建了一个向量对象,表示平移的方向和距离。接下来,我们通过 `ProjectEx()` 函数设置空间参考,然后通过一系列的函数设置其他属性。最后,我们使用 `Move()` 函数执行平移,并输出平移后的结果。
请注意,上述代码仅供参考,并且需要根据您的具体情况进行修改。
阅读全文