/// <summary> /// /// </summary> /// <param name="controlPointsFile"></param> /// <param name="controlPointsInputType"></param> /// <param name="geometry"></param> /// <param name="spatialAdjustMethodType"></param> /// <remarks> /// 这个方法日后要被替换, /// </remarks> public static void Adjust(string controlPointsFile, ControlPointsInputType controlPointsInputType, IGeometry geometry, SpatialAdjustMethodType spatialAdjustMethodType) { switch (controlPointsInputType) { case ControlPointsInputType.File: { var txtStr = File.ReadAllText(controlPointsFile); var lines = txtStr.Split('\n').ToList(); if (String.IsNullOrWhiteSpace(lines.Last()) || String.IsNullOrEmpty(lines.Last())) { lines.RemoveAt(lines.Count - 1); } List <IPoint> fromPoints = new List <IPoint>(); List <IPoint> toPoints = new List <IPoint>(); lines.ForEach((line) => { var nums = line.Split('\t').ToList().Select(numString => Convert.ToDouble(numString)).ToList(); IPoint fromPoint = new PointClass() { X = nums[0], Y = nums[1] }; IPoint toPoint = new PointClass() { X = nums[2], Y = nums[3] }; fromPoints.Add(fromPoint); toPoints.Add(toPoint); }); ITransformationMethodGEN transformMethod = new AffineTransformationMethodClass(); var a = transformMethodMap[spatialAdjustMethodType]; var constructors = a.GetConstructors(); var constructorIWant = a.GetConstructors().Where(constructor => constructor.GetParameters().Length == 0).FirstOrDefault(); var b = constructorIWant.Invoke(null); transformMethod = b as ITransformationMethodGEN; transformMethod.DefineFromControlPoints(fromPoints.ToArray(), toPoints.ToArray(), null, null); transformMethod.TransformShape(geometry); } break; case ControlPointsInputType.Web: throw new NotImplementedException(); break; default: throw new NotImplementedException(); break; } }
public SpatialAdjust(string controlPointsFile, ControlPointsInputType controlPointsInputType, SpatialAdjustMethodType spatialAdjustMethodType) { ControlPointsFile = controlPointsFile; ControlPointsInputType = controlPointsInputType; SpatialAdjustMethodType = spatialAdjustMethodType; string txt = string.Empty; switch (ControlPointsInputType) { case ControlPointsInputType.File: try { txt = File.ReadAllText(ControlPointsFile); } catch (Exception ex) { Console.WriteLine("找不到控制点文件"); throw ex; } break; case ControlPointsInputType.Web: try { txt = new WebClient().DownloadString(ControlPointsFile); } catch (Exception ex) { Console.WriteLine("找不到控制点文件"); throw ex; } break; default: break; } if (String.IsNullOrEmpty(txt)) { TransformationMethod = null; } else { var methodObject = transformMethodMap[SpatialAdjustMethodType] .GetConstructors() .Where(constructor => constructor.GetParameters().Length == 0) .FirstOrDefault() .Invoke(null); TransformationMethod = (ITransformationMethodGEN)methodObject; #region 定义控制点 var lines = txt.Split('\n').ToList(); if (String.IsNullOrWhiteSpace(lines.Last()) || String.IsNullOrEmpty(lines.Last())) { lines.RemoveAt(lines.Count - 1); } List <IPoint> fromPoints = new List <IPoint>(); List <IPoint> toPoints = new List <IPoint>(); lines.ForEach((line) => { var nums = line.Split('\t').ToList().Select(numString => Convert.ToDouble(numString)).ToList(); IPoint fromPoint = new PointClass() { X = nums[0], Y = nums[1] }; IPoint toPoint = new PointClass() { X = nums[2], Y = nums[3] }; fromPoints.Add(fromPoint); toPoints.Add(toPoint); }); TransformationMethod.DefineFromControlPoints(fromPoints.ToArray(), toPoints.ToArray(), null, null); #endregion 定义控制点 } }