PIE SDK Geometry的坐标转换

1. 基于SpatialReference对象的坐标转换

1.1 示例简介

    Geometry类是所有几何形体对象的父类,它是一个抽象类,IGeometry接口定义了所有的几何对象都有的方法和属性。

    下面介绍基于Geometry对象的坐标转换的主要接口。

Transform方法

函数原型:

bool Transform(ISpatialReference spatialReference);

bool Transform(CoordinateTransformation coordTransform);

函数说明:

    该方法用于几何体的投影转换,当参数为坐标转换对象时投影转换过程中会忽略原来的空间参考。

参数说明:

名称

说明

spatialReference

空间参考对象

coordTransform

坐标转换对象

返回值

投影转换成功时为true,否则为false

1.2 示例代码

项目路径

百度云盘地址下/PIE示例程序/SpatialReference. CoordinateTransform

视频路径

百度云盘地址下/PIE视频教程/ Geometry的坐标转换avi

示例代码

 1  private void GeometryTest()
 2  {
 3    // 空间参考WKT字符串
 4 string str_BJ54 = "GEOGCS[\"GCS_Beijing_1954\",DATUM[\"D_Beijing_1954\",
 5 SPHEROID[\"Krasovsky_1940\",6378245,298.3]],PRIMEM[\"Greenwich\",0],UNIT[\"Degree\",
 6 0.017453292519943295]]";
string str_BJ54_18 = "PROJCS[\"Beijing_1954_GK_Zone_18\",GEOGCS[\"GCS_Beijing_1954\",
 8 DATUM[\"D_Beijing_1954\",
 9 SPHEROID[\"Krasovsky_1940\",6378245,298.3]],PRIMEM[\"Greenwich\",0],UNIT[\"Degree\",
10 0.017453292519943295]],PROJECTION[\"Transverse_Mercator\"],PARAMETER[\"False_Easting\",
11 18500000],PARAMETER[\"False_Northing\",0],PARAMETER[\"Central_Meridian\",105],PARAMETER
12 [\"Scale_Factor\",1],PARAMETER[\"Latitude_Of_Origin\",0],UNIT[\"Meter\",1]]";
13 
14 ISpatialReference spatialReference1 = new GeographicCoordinateSystem();
15 spatialReference1.ImportFromWkt(str_BJ54);
1  ISpatialReference spatialReference2 = new ProjectedCoordinateSystem();
17 spatialReference2.ImportFromWkt(str_BJ54_18);
18 
19   // 定义点
20   IPoint point = new PIE.Geometry.Point();
21   point.PutCoords(104, 45, 0.0);
22 
23   // 设置空间参考
24   IGeometry geo = point as IGeometry;
25   geo.SpatialReference = spatialReference1;
26 
27   // 空间参考变换
28   geo.Transform(spatialReference2);
29  }

2. 基于CoordinateTransformation对象的坐标转换

2.1 示例简介

    同一个地图上显示的地理数据的空间参考必须是一致的,因此需要实现空间坐标系的相互转换。ICoordinateTransformation接口主要实现了获取源坐标系统和目标坐标系统、实现坐标转换的方法。

    下面对基于CoordinateTransformation对象的坐标转换的方法进行介绍。

TransformEx方法

函数原型:

       bool TransformEx(int count, array<double>pX, array<double>pY,  array<double> pZ, array<int> pSuccess);

函数说明:

    该方法用于坐标系统的坐标转换。

参数说明:

名称

说明

count

要转换的个数

pX

X坐标

pY

Y坐标

pZ

Z坐标

pSuccess

转换结果数组

返回值

坐标转换是否成功,转换成功返回1,否则返回0

2.2 示例代码

示例代码

 1   private void CoordinateTransformationTest()
 2         {
 3             // 空间参考WKT字符串
 4             string str_BJ54 = "GEOGCS[\"GCS_Beijing_1954\",DATUM[\"D_Beijing_1954\",
 5 SPHEROID[\"Krasovsky_1940\",6378245,298.3]],PRIMEM[\"Greenwich\",0],UNIT[\"Degree\",
 6 0.017453292519943295]]";
 7             string str_BJ54_18 = "PROJCS[\"Beijing_1954_GK_Zone_18\",GEOGCS[\"GCS_Beijing_1954\",
 8 DATUM[\"D_Beijing_1954\",
 9 SPHEROID[\"Krasovsky_1940\",6378245,298.3]],PRIMEM[\"Greenwich\",0],UNIT[\"Degree\",
10 0.017453292519943295]],PROJECTION[\"Transverse_Mercator\"],PARAMETER[\"False_Easting\",
11 18500000],PARAMETER[\"False_Northing\",0],PARAMETER[\"Central_Meridian\",105],PARAMETER
12 [\"Scale_Factor\",1],PARAMETER[\"Latitude_Of_Origin\",0],UNIT[\"Meter\",1]]";
13 
14             // 生成空间参考对象
15  ISpatialReference spatialReference1 = SpatialReferenceFactory.CreateSpatialReference(str_BJ54);
16  ISpatialReference spatialReference2 = SpatialReferenceFactory.CreateSpatialReference(str_BJ54_18);
17 
18             // 坐标转换
19             int count = 3;
20             double[] px = new double[] { 104, 105, 106 };
21             double[] py = new double[] { 45, 46, 47 };
22             double[] pz = new double[] { 0, 0, 0 };
23             int[] pSuccess = new int[3];
24 CoordinateTransformation coordTF = new CoordinateTransformation(spatialReference1, spatialReference2);
25 coordTF.TransformEx(count, px, py, null, pSuccess);
26         }

 

posted @ 2019-01-17 10:38  PIESAT  阅读(759)  评论(0编辑  收藏  举报