ArcGIS Pro SDK (九)几何 15 转换
文章目录
1 创建地理转换
GeographicTransformation gt1478 =
ArcGIS.Core.Geometry.GeographicTransformation.Create(1478);
string name = gt1478.Name;
string wkt = gt1478.Wkt;
int wkid = gt1478.Wkid;
GeographicTransformation another_gt1478 =
ArcGIS.Core.Geometry.GeographicTransformation.Create(wkt);
GeographicTransformation inverse_gt148 =
another_gt1478.GetInverse() as GeographicTransformation;
bool isForward = inverse_gt148.IsForward;
2 创建复合地理变换
CompositeGeographicTransformation cgt =
ArcGIS.Core.Geometry.CompositeGeographicTransformation.Create(108272);
int count = cgt.Count;
IList<GeographicTransformation> gts = cgt.Transformations
as IList<GeographicTransformation>;
gts.Add(ArcGIS.Core.Geometry.GeographicTransformation.Create(1437, false));
count = cgt.Count;
CompositeGeographicTransformation another_cgt =
ArcGIS.Core.Geometry.CompositeGeographicTransformation.Create(gts);
GeographicTransformation gt0 = another_cgt[0];
GeographicTransformation gt1 = another_cgt[1];
CompositeGeographicTransformation inversed_cgt = another_cgt.GetInverse() as CompositeGeographicTransformation;
var wkt = gt0.Wkt;
CompositeGeographicTransformation third_cgt =
ArcGIS.Core.Geometry.CompositeGeographicTransformation.Create(wkt, gt0.IsForward);
count = third_cgt.Count;
string json = cgt.ToJson();
CompositeGeographicTransformation json_cgt =
DatumTransformation.CreateFromJson(json) as CompositeGeographicTransformation;
3 创建投影转换
ArcGIS.Desktop.Framework.Threading.Tasks.QueuedTask.Run(
() =>
{
SpatialReference sr4267 = SpatialReferenceBuilder.CreateSpatialReference(4267);
SpatialReference sr4326 = SpatialReferences.WGS84;
SpatialReference sr3857 = SpatialReferences.WebMercator;
ProjectionTransformation projTransFromSRs =
ArcGIS.Core.Geometry.ProjectionTransformation.Create(sr4267, sr3857);
Envelope env = EnvelopeBuilderEx.CreateEnvelope(
new Coordinate2D(2, 2), new Coordinate2D(3, 3), sr4267);
Envelope projectedEnvEx = GeometryEngine.Instance.ProjectEx(
env, projTransFromSRs) as Envelope;
ProjectionTransformation projTransFromSRsInverse =
ArcGIS.Core.Geometry.ProjectionTransformation.Create(sr3857, sr4267);
Envelope projectedEnvBack =
GeometryEngine.Instance.ProjectEx(
projectedEnvEx, projTransFromSRsInverse) as Envelope;
bool isEqual = env.IsEqual(projectedEnvBack);
});
4 创建高压基准变换
HVDatumTransformation hv110018 = HVDatumTransformation.Create(110018);
int wkid = hv110018.Wkid;
bool isForward = hv110018.IsForward;
string name = hv110018.Name;
string wkt = hv110018.Wkt;
HVDatumTransformation hv110018FromWkt = HVDatumTransformation.Create(wkt);
HVDatumTransformation hv110018Inverse =
hv110018.GetInverse() as HVDatumTransformation;
5 创建复合高压基准变换
HVDatumTransformation hv1 = HVDatumTransformation.Create(108034);
HVDatumTransformation hv2 = HVDatumTransformation.Create(108033, false);
List<HVDatumTransformation> hvs = new List<HVDatumTransformation>() { hv1, hv2 };
CompositeHVDatumTransformation compositehv =
CompositeHVDatumTransformation.Create(hvs);
int count = compositehv.Count;
List<HVDatumTransformation> transforms =
compositehv.Transformations as List<HVDatumTransformation>;
HVDatumTransformation transform = transforms[0];
CompositeHVDatumTransformation inverse_compositehv =
compositehv.GetInverse() as CompositeHVDatumTransformation;
string xml = compositehv.ToXml();
var xml_compositehv = CompositeHVDatumTransformation.CreateFromXml(xml);
string json = compositehv.ToJson();
CompositeHVDatumTransformation json_compositehv =
DatumTransformation.CreateFromJson(json) as CompositeHVDatumTransformation;
6 决定转换
ArcGIS.Desktop.Framework.Threading.Tasks.QueuedTask.Run(
() =>
{
SpatialReference sr4267 =
SpatialReferenceBuilder.CreateSpatialReference(4267);
SpatialReference sr4326 = SpatialReferences.WGS84;
List<ProjectionTransformation> transformations =
ProjectionTransformation.FindTransformations(sr4267, sr4326);
ProjectionTransformation projTrans = transformations[0];
CompositeGeographicTransformation compositeGT =
projTrans.Transformation as CompositeGeographicTransformation;
GeographicTransformation gt = compositeGT[0];
transformations = ProjectionTransformation.FindTransformations(
sr4267, sr4326, numResults: 5);
projTrans = transformations[0];
compositeGT = projTrans.Transformation as CompositeGeographicTransformation;
projTrans = transformations[1];
compositeGT = projTrans.Transformation as CompositeGeographicTransformation;
projTrans = transformations[2];
compositeGT = projTrans.Transformation as CompositeGeographicTransformation;
projTrans = transformations[3];
compositeGT = projTrans.Transformation as CompositeGeographicTransformation;
projTrans = transformations[4];
compositeGT = projTrans.Transformation as CompositeGeographicTransformation;
Coordinate2D coord = new Coordinate2D(-148, 60);
List<ProjectionTransformation> alaskatransforms =
ProjectionTransformation.FindTransformations(sr4267, sr4326, coord);
projTrans = alaskatransforms[0];
compositeGT = projTrans.Transformation as CompositeGeographicTransformation;
gt = compositeGT[0];
SpatialReference sr3857 = SpatialReferences.WebMercator;
transformations = ProjectionTransformation.FindTransformations(sr3857, sr4326);
projTrans = transformations[0];
compositeGT = projTrans.Transformation as CompositeGeographicTransformation;
transformations = ProjectionTransformation.FindTransformations(sr4326, sr3857);
projTrans = transformations[0];
compositeGT = projTrans.Transformation as CompositeGeographicTransformation;
SpatialReference sr7030 = SpatialReferenceBuilder.CreateSpatialReference(7030);
transformations = ProjectionTransformation.FindTransformations(sr4326, sr7030);
projTrans = transformations[0];
compositeGT = projTrans.Transformation as CompositeGeographicTransformation;
});
7 地图点 - 地理坐标字符串转换
SpatialReference sr = SpatialReferences.WGS84;
SpatialReference sr2 = SpatialReferences.WebMercator;
MapPoint point0 = MapPointBuilderEx.CreateMapPoint(0, 0, sr);
MapPoint point1 = MapPointBuilderEx.CreateMapPoint(10, 20, sr);
MapPoint point2 = GeometryEngine.Instance.Project(point1, sr2) as MapPoint;
MapPoint pointEmpty = MapPointBuilderEx.CreateMapPoint(sr);
MapPoint pointwithNoSR = MapPointBuilderEx.CreateMapPoint(1, 1);
MapPoint pointZM = MapPointBuilderEx.CreateMapPoint(1, 2, 3, 4, sr);
ToGeoCoordinateParameter mgrsParam =
new ToGeoCoordinateParameter(GeoCoordinateType.MGRS);
string geoCoordString = point0.ToGeoCoordinateString(mgrsParam);
MapPoint outPoint =
MapPointBuilderEx.FromGeoCoordinateString(
geoCoordString, sr, GeoCoordinateType.MGRS);
geoCoordString = point1.ToGeoCoordinateString(mgrsParam);
outPoint = MapPointBuilderEx.FromGeoCoordinateString(
geoCoordString, sr, GeoCoordinateType.MGRS);
geoCoordString = pointZM.ToGeoCoordinateString(mgrsParam);
outPoint = MapPointBuilderEx.FromGeoCoordinateString(
geoCoordString, sr, GeoCoordinateType.MGRS);
mgrsParam.NumDigits = 2;
geoCoordString = point1.ToGeoCoordinateString(mgrsParam);
outPoint = MapPointBuilderEx.FromGeoCoordinateString(
geoCoordString, sr, GeoCoordinateType.MGRS);
ToGeoCoordinateParameter utmParam =
new ToGeoCoordinateParameter(GeoCoordinateType.UTM);
geoCoordString = point0.ToGeoCoordinateString(utmParam);
geoCoordString = point1.ToGeoCoordinateString(utmParam);
ToGeoCoordinateParameter dmsParam =
new ToGeoCoordinateParameter(GeoCoordinateType.DMS);
geoCoordString = point0.ToGeoCoordinateString(dmsParam);
geoCoordString = point1.ToGeoCoordinateString(dmsParam);
ToGeoCoordinateParameter ddmParam =
new ToGeoCoordinateParameter(GeoCoordinateType.DDM);
geoCoordString = point0.ToGeoCoordinateString(ddmParam);
geoCoordString = point1.ToGeoCoordinateString(ddmParam);
ToGeoCoordinateParameter ddParam =
new ToGeoCoordinateParameter(GeoCoordinateType.DD);
geoCoordString = point0.ToGeoCoordinateString(ddParam);
geoCoordString = point1.ToGeoCoordinateString(ddParam);