使用Proj.Net创建空间参考
在RGEOS项目中,投影变换是通过Proj.Net来实现的。
支持的投影主要包括AlbersProjection、TransverseMercator、Mercator、Krovak、Lambert Conformal Conic 2SP,自己扩展了一个GaussKruger投影。
以下实现了一个WGS84椭球的UTM投影(TransverseMercator)
ICoordinateSystem utm = ProjNet.CoordinateSystems.ProjectedCoordinateSystem.WGS84_UTM(zone, pGeo.Y > 0);
查看代码:
1 public static ProjectedCoordinateSystem WGS84_UTM(int Zone, bool ZoneIsNorth)
2 {
3 List<ProjectionParameter> pInfo = new List<ProjectionParameter>();
4 pInfo.Add(new ProjectionParameter("latitude_of_origin", 0));
5 pInfo.Add(new ProjectionParameter("central_meridian", Zone * 6 - 183));
6 pInfo.Add(new ProjectionParameter("scale_factor", 0.9996));
7 pInfo.Add(new ProjectionParameter("false_easting", 500000));
8 pInfo.Add(new ProjectionParameter("false_northing", ZoneIsNorth ? 0 : 10000000));
9 //IProjection projection = cFac.CreateProjection("UTM" + Zone.ToString() + (ZoneIsNorth ? "N" : "S"), "Transverse_Mercator", parameters);
10 Projection proj = new Projection("Transverse_Mercator", pInfo, "UTM" + Zone.ToString(System.Globalization.CultureInfo.InvariantCulture) + (ZoneIsNorth ? "N" : "S"),
11 "EPSG", 32600 + Zone + (ZoneIsNorth ? 0 : 100), String.Empty, String.Empty, String.Empty);
12 System.Collections.Generic.List<AxisInfo> axes = new List<AxisInfo>();
13 axes.Add(new AxisInfo("East", AxisOrientationEnum.East));
14 axes.Add(new AxisInfo("North", AxisOrientationEnum.North));
15 return new ProjectedCoordinateSystem(ProjNet.CoordinateSystems.HorizontalDatum.WGS84,
16 ProjNet.CoordinateSystems.GeographicCoordinateSystem.WGS84, ProjNet.CoordinateSystems.LinearUnit.Metre, proj, axes,
17 "WGS 84 / UTM zone " + Zone.ToString(System.Globalization.CultureInfo.InvariantCulture) + (ZoneIsNorth ? "N" : "S"), "EPSG", 32600 + Zone + (ZoneIsNorth ? 0 : 100),
18 String.Empty, "Large and medium scale topographic mapping and engineering survey.", string.Empty);
19 }
自己尝试写一个工厂没有写完全:
1 using System;
2 using System.Collections.Generic;
3 using System.Text;
4
5 namespace ProjNet.CoordinateSystems
6 {
7 public class SpatialReferenceEnvironmentClass : ISpatialReferenceFactory
8 {
9 public IEllipsoid CreateSpheroid(int spheroidType)
10 {
11 IEllipsoid ellipsoid = null;
12 switch (spheroidType)
13 {
14 case (int)RgSRSpheroidType.RgSRSpheroid_WGS1984:
15 ellipsoid = new Ellipsoid(6378137, 0, 298.257223563, true, LinearUnit.Metre, "WGS 84", "EPSG", 7030, "WGS 84", "", "Inverse flattening derived from four defining parameters (semi-major axis; C20 = -484.16685*10e-6; earth‘s angular velocity w = 7292115e11 rad/sec; gravitational constant GM = 3986005e8 m*m*m/s/s).");
16 break;
17 case (int)RgSRSpheroidType.RgSRSpheroid_Krasovsky1940:
18 ellipsoid = new Ellipsoid(6378245, 0, 298.30000000000001, true, LinearUnit.Metre, "Krasovsky_1940", "EPSG", 7024, "Krasovsky_1940", "", "");
19 break;
20 case (int)RgSRSpheroid2Type.RgSRSpheroid_Xian1980:
21 ellipsoid = new Ellipsoid(6378140, 0, 298.25700000000001, true, LinearUnit.Metre, "Xian_1980", "EPSG", 7049, "Xian_1980", "", "");
22 break;
23 }
24 return ellipsoid;
25 }
26
27 public IHorizontalDatum CreateDatum(int datumType)
28 {
29 IHorizontalDatum datum = null;
30 switch (datumType)
31 {
32 case (int)RgSRDatumType.RgSRDatum_WGS1984:
33 IEllipsoid ellipsoid = this.CreateSpheroid((int)RgSRSpheroidType.RgSRSpheroid_WGS1984);
34 datum = new HorizontalDatum(ellipsoid, null, DatumType.HD_Geocentric, "World Geodetic System 1984", "EPSG", 6326, String.Empty, "EPSG‘s WGS 84 datum has been the then current realisation. No distinction is made between the original WGS 84 frame, WGS 84 (G730), WGS 84 (G873) and WGS 84 (G1150). Since 1997, WGS 84 has been maintained within 10cm of the then current ITRF.", String.Empty);
35 break;
36 case (int)RgSRDatumType.RgSRDatum_Beijing1954:
37 IEllipsoid ellipsoid2 = this.CreateSpheroid((int)RgSRSpheroidType.RgSRSpheroid_Krasovsky1940);
38 datum = new HorizontalDatum(ellipsoid2, null, DatumType.HD_Geocentric, "D_Beijing1954", "EPSG", 6214, String.Empty, "", String.Empty);
39 break;
40 case (int)RgSRDatumType.RgSRDatum_Xian1980:
41 IEllipsoid ellipsoid3 = this.CreateSpheroid((int)RgSRSpheroid2Type.RgSRSpheroid_Xian1980);
42 datum = new HorizontalDatum(ellipsoid3, null, DatumType.HD_Geocentric, "D_Xian1980", "EPSG", 6610, String.Empty, "", String.Empty);
43 break;
44 }
45 return datum;
46 }
47
48 public IGeographicCoordinateSystem CreateGeographicCoordinateSystem(int gcsType)
49 {
50 IGeographicCoordinateSystem gcs = null;
51 switch (gcsType)
52 {
53
54 case (int)RgSRGeoCSType.RgSRGeoCS_WGS1984:// WGS 1984.
55 List<AxisInfo> axes = new List<AxisInfo>(2);
56 axes.Add(new AxisInfo("Lon", AxisOrientationEnum.East));
57 axes.Add(new AxisInfo("Lat", AxisOrientationEnum.North));
58 IHorizontalDatum datum = this.CreateDatum((int)RgSRDatumType.RgSRDatum_WGS1984);
59 gcs = new GeographicCoordinateSystem(CoordinateSystems.AngularUnit.Degrees,
60 datum, CoordinateSystems.PrimeMeridian.Greenwich, axes,
61 "WGS1984", "EPSG", 4326, String.Empty, string.Empty, string.Empty);
62 break;
63 case (int)RgSRGeoCSType.RgSRGeoCS_Beijing1954:
64 List<AxisInfo> axes2 = new List<AxisInfo>(2);
65 axes2.Add(new AxisInfo("Lon", AxisOrientationEnum.East));
66 axes2.Add(new AxisInfo("Lat", AxisOrientationEnum.North));
67 IHorizontalDatum datum2 = this.CreateDatum((int)RgSRDatumType.RgSRDatum_Beijing1954);
68 gcs = new GeographicCoordinateSystem(CoordinateSystems.AngularUnit.Degrees,
69 datum2, CoordinateSystems.PrimeMeridian.Greenwich, axes2,
70 "Beijing1954", "EPSG", 4214, String.Empty, string.Empty, string.Empty);
71 break;
72 case (int)RgSRGeoCS3Type.RgSRGeoCS_Xian1980://Xian80.
73 List<AxisInfo> axes3 = new List<AxisInfo>(2);
74 axes3.Add(new AxisInfo("Lon", AxisOrientationEnum.East));
75 axes3.Add(new AxisInfo("Lat", AxisOrientationEnum.North));
76 IHorizontalDatum datum3 = this.CreateDatum((int)RgSRDatumType.RgSRDatum_Xian1980);
77 gcs = new GeographicCoordinateSystem(CoordinateSystems.AngularUnit.Degrees,
78 datum3, CoordinateSystems.PrimeMeridian.Greenwich, axes3,
79 "Xian1980", "EPSG", 4610, String.Empty, string.Empty, string.Empty);
80 break;
81
82 }
83 return gcs;
84 }
85
86 public IProjectedCoordinateSystem CreateProjectedCoordinateSystem(int pcsType)
87 {
88 throw new NotImplementedException();
89 }
90 public IProjection CreateProjection(int projectionType)
91 {
92 switch (projectionType)
93 {
94 case (int)RgSRProjectionType.RgSRProjection_Albers:
95 break;
96 case (int)RgSRProjectionType.RgSRProjection_GaussKruger:
97 break;
98 case (int)RgSRProjectionType.RgSRProjection_Mercator:
99 break;
100 case (int)RgSRProjectionType.RgSRProjection_TransverseMercator:
101 break;
102 case (int)RgSRProjectionType.RgSRProjection_LambertConformalConic:
103 break;
104 }
105 return null;
106 }
107 }
108 }
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。