使用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 > );

查看代码:

 public static ProjectedCoordinateSystem WGS84_UTM(int Zone, bool ZoneIsNorth)
{
List<ProjectionParameter> pInfo = new List<ProjectionParameter>();
pInfo.Add(new ProjectionParameter("latitude_of_origin", ));
pInfo.Add(new ProjectionParameter("central_meridian", Zone * - ));
pInfo.Add(new ProjectionParameter("scale_factor", 0.9996));
pInfo.Add(new ProjectionParameter("false_easting", ));
pInfo.Add(new ProjectionParameter("false_northing", ZoneIsNorth ? : ));
//IProjection projection = cFac.CreateProjection("UTM" + Zone.ToString() + (ZoneIsNorth ? "N" : "S"), "Transverse_Mercator", parameters);
Projection proj = new Projection("Transverse_Mercator", pInfo, "UTM" + Zone.ToString(System.Globalization.CultureInfo.InvariantCulture) + (ZoneIsNorth ? "N" : "S"),
"EPSG", + Zone + (ZoneIsNorth ? : ), String.Empty, String.Empty, String.Empty);
System.Collections.Generic.List<AxisInfo> axes = new List<AxisInfo>();
axes.Add(new AxisInfo("East", AxisOrientationEnum.East));
axes.Add(new AxisInfo("North", AxisOrientationEnum.North));
return new ProjectedCoordinateSystem(ProjNet.CoordinateSystems.HorizontalDatum.WGS84,
ProjNet.CoordinateSystems.GeographicCoordinateSystem.WGS84, ProjNet.CoordinateSystems.LinearUnit.Metre, proj, axes,
"WGS 84 / UTM zone " + Zone.ToString(System.Globalization.CultureInfo.InvariantCulture) + (ZoneIsNorth ? "N" : "S"), "EPSG", + Zone + (ZoneIsNorth ? : ),
String.Empty, "Large and medium scale topographic mapping and engineering survey.", string.Empty);
}

WGS84_UTM

自己尝试写一个工厂没有写完全:

 using System;
using System.Collections.Generic;
using System.Text; namespace ProjNet.CoordinateSystems
{
public class SpatialReferenceEnvironmentClass : ISpatialReferenceFactory
{
public IEllipsoid CreateSpheroid(int spheroidType)
{
IEllipsoid ellipsoid = null;
switch (spheroidType)
{
case (int)RgSRSpheroidType.RgSRSpheroid_WGS1984:
ellipsoid = new Ellipsoid(, , 298.257223563, true, LinearUnit.Metre, "WGS 84", "EPSG", , "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).");
break;
case (int)RgSRSpheroidType.RgSRSpheroid_Krasovsky1940:
ellipsoid = new Ellipsoid(, , 298.30000000000001, true, LinearUnit.Metre, "Krasovsky_1940", "EPSG", , "Krasovsky_1940", "", "");
break;
case (int)RgSRSpheroid2Type.RgSRSpheroid_Xian1980:
ellipsoid = new Ellipsoid(, , 298.25700000000001, true, LinearUnit.Metre, "Xian_1980", "EPSG", , "Xian_1980", "", "");
break;
}
return ellipsoid;
} public IHorizontalDatum CreateDatum(int datumType)
{
IHorizontalDatum datum = null;
switch (datumType)
{
case (int)RgSRDatumType.RgSRDatum_WGS1984:
IEllipsoid ellipsoid = this.CreateSpheroid((int)RgSRSpheroidType.RgSRSpheroid_WGS1984);
datum = new HorizontalDatum(ellipsoid, null, DatumType.HD_Geocentric, "World Geodetic System 1984", "EPSG", , 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);
break;
case (int)RgSRDatumType.RgSRDatum_Beijing1954:
IEllipsoid ellipsoid2 = this.CreateSpheroid((int)RgSRSpheroidType.RgSRSpheroid_Krasovsky1940);
datum = new HorizontalDatum(ellipsoid2, null, DatumType.HD_Geocentric, "D_Beijing1954", "EPSG", , String.Empty, "", String.Empty);
break;
case (int)RgSRDatumType.RgSRDatum_Xian1980:
IEllipsoid ellipsoid3 = this.CreateSpheroid((int)RgSRSpheroid2Type.RgSRSpheroid_Xian1980);
datum = new HorizontalDatum(ellipsoid3, null, DatumType.HD_Geocentric, "D_Xian1980", "EPSG", , String.Empty, "", String.Empty);
break;
}
return datum;
} public IGeographicCoordinateSystem CreateGeographicCoordinateSystem(int gcsType)
{
IGeographicCoordinateSystem gcs = null;
switch (gcsType)
{ case (int)RgSRGeoCSType.RgSRGeoCS_WGS1984:// WGS 1984.
List<AxisInfo> axes = new List<AxisInfo>();
axes.Add(new AxisInfo("Lon", AxisOrientationEnum.East));
axes.Add(new AxisInfo("Lat", AxisOrientationEnum.North));
IHorizontalDatum datum = this.CreateDatum((int)RgSRDatumType.RgSRDatum_WGS1984);
gcs = new GeographicCoordinateSystem(CoordinateSystems.AngularUnit.Degrees,
datum, CoordinateSystems.PrimeMeridian.Greenwich, axes,
"WGS1984", "EPSG", , String.Empty, string.Empty, string.Empty);
break;
case (int)RgSRGeoCSType.RgSRGeoCS_Beijing1954:
List<AxisInfo> axes2 = new List<AxisInfo>();
axes2.Add(new AxisInfo("Lon", AxisOrientationEnum.East));
axes2.Add(new AxisInfo("Lat", AxisOrientationEnum.North));
IHorizontalDatum datum2 = this.CreateDatum((int)RgSRDatumType.RgSRDatum_Beijing1954);
gcs = new GeographicCoordinateSystem(CoordinateSystems.AngularUnit.Degrees,
datum2, CoordinateSystems.PrimeMeridian.Greenwich, axes2,
"Beijing1954", "EPSG", , String.Empty, string.Empty, string.Empty);
break;
case (int)RgSRGeoCS3Type.RgSRGeoCS_Xian1980://Xian80.
List<AxisInfo> axes3 = new List<AxisInfo>();
axes3.Add(new AxisInfo("Lon", AxisOrientationEnum.East));
axes3.Add(new AxisInfo("Lat", AxisOrientationEnum.North));
IHorizontalDatum datum3 = this.CreateDatum((int)RgSRDatumType.RgSRDatum_Xian1980);
gcs = new GeographicCoordinateSystem(CoordinateSystems.AngularUnit.Degrees,
datum3, CoordinateSystems.PrimeMeridian.Greenwich, axes3,
"Xian1980", "EPSG", , String.Empty, string.Empty, string.Empty);
break; }
return gcs;
} public IProjectedCoordinateSystem CreateProjectedCoordinateSystem(int pcsType)
{
throw new NotImplementedException();
}
public IProjection CreateProjection(int projectionType)
{
switch (projectionType)
{
case (int)RgSRProjectionType.RgSRProjection_Albers:
break;
case (int)RgSRProjectionType.RgSRProjection_GaussKruger:
break;
case (int)RgSRProjectionType.RgSRProjection_Mercator:
break;
case (int)RgSRProjectionType.RgSRProjection_TransverseMercator:
break;
case (int)RgSRProjectionType.RgSRProjection_LambertConformalConic:
break;
}
return null;
}
}
}

SpatialReferenceEnvironmentClass

上一篇:Codeforces 1114F Please, another Queries on Array? 线段树


下一篇:Fiddler之iOS手机抓包实战操作