Ejemplo n.º 1
0
        /// <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;
            }
        }
Ejemplo n.º 2
0
        public static void Adjust()
        {
            var txtStr = File.ReadAllText(@"C:\test\v2\cps.txt");
            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();

            transformMethod.DefineFromControlPoints(fromPoints.ToArray(), toPoints.ToArray(), null, null);
            IPoint testPoint = new PointClass()
            {
                X = 14000000, Y = -5300000
            };

            Console.WriteLine($"{testPoint.X} , {testPoint.Y}");
            //Task.Delay(2000).Wait();
            transformMethod.TransformShape(testPoint);
            Task.Delay(1000).Wait();

            Console.WriteLine($"{testPoint.X} , {testPoint.Y}");
            Task.Delay(1000).Wait();
        }