public static PointN ExploringSearch(F function, PointN basisPoint, VectorN h) { double fb = function.Value(basisPoint); int dimensionsCount = basisPoint.Coordinates.Count; for (int i = 0; i < dimensionsCount; i++) { // hi * ei PointN hi_ei = new PointN(dimensionsCount); hi_ei.Coordinates[i] = h.Components[i]; double f = function.Value(basisPoint + hi_ei); if (f < fb) { basisPoint = basisPoint + hi_ei; fb = f; } else { f = function.Value(basisPoint - hi_ei); if (f < fb) { basisPoint = basisPoint - hi_ei; fb = f; } } } return(basisPoint); }
/// <summary> /// Create a CIMPointGaphic which can be added to the MapView overlay. /// </summary> /// <param name="point">The location for the point (as a CIM point)</param> /// <returns></returns> public CIMPointGraphic MakeCIMPointGraphic(PointN point) { CIMMarker marker = SymbolFactory.Instance.ConstructMarker(Red, 10, SimpleMarkerStyle.Star); CIMSymbolLayer[] layers = new CIMSymbolLayer[1]; layers[0] = marker; CIMPointSymbol pointSymbol = new CIMPointSymbol() { SymbolLayers = layers, ScaleX = 1 }; CIMSymbolReference symbolRef = new CIMSymbolReference() { Symbol = pointSymbol }; CIMPointGraphic pointGraphic = new CIMPointGraphic(); ArcGIS.Core.Geometry.SpatialReference spatialRef = SpatialReferenceBuilder.CreateSpatialReference(point.SpatialReference.WKID); MapPoint mapPoint = MapPointBuilder.CreateMapPoint(point.X, point.Y, spatialRef); pointGraphic.Location = mapPoint; pointGraphic.Symbol = symbolRef; return(pointGraphic); }
/// <summary> /// Update the CIMPointGraphic location /// </summary> /// <param name="point"></param> public void UpdateLocation(PointN point) { ArcGIS.Core.Geometry.SpatialReference sptlRef = SpatialReferenceBuilder.CreateSpatialReference(point.SpatialReference.WKID); MapPoint mapPoint = MapPointBuilder.CreateMapPoint(point.X, point.Y, sptlRef); _graphic.Location = mapPoint; }
public static Vector3d ToCadVector3d(PointN basePt, PointN destPt) { Point3d point3d = GIS2CAD.ToCadPoint3d(basePt); Point3d point3d2 = GIS2CAD.ToCadPoint3d(destPt); return(point3d.GetVectorTo(point3d2)); }
public OptimalGradientMethod(FunctionND funcND, PointN x0) { this.funcND = funcND; this.x0 = new PointN(x0); Log = new List <string>(); }
public static void AdjustZ(ref Point[] plainPoints, double defaultElevation) { if (defaultElevation == 0.0) { return; } PointN[] array = (PointN[])plainPoints; double z = array[0].Z; PointN[] array2 = array; int i = 0; while (i < array2.Length) { PointN pointN = array2[i]; if (pointN.Z == z) { if (pointN.Z == 0.0) { i++; continue; } } return; } PointN[] array3 = array; for (int j = 0; j < array3.Length; j++) { PointN pointN2 = array3[j]; pointN2.Z = defaultElevation; } }
public PointN FindMin(double eps) { int dimensionsCount = x0.Coordinates.Count; int k = 0; double ak = 0.0; PointN xk = x0; while (true) { VectorN gradFxk = Gradient.Calculate(funcND, xk); // Градиент все время прыгает во все стороны, а xk все наращивается Log.Add(String.Format("Grad(F({0, -23})) = {1, -25}", xk, gradFxk)); if (gradFxk.Length <= eps) { return(xk); } Function1D func1D = (double alpha) => { return(funcND(xk - gradFxk * alpha)); }; // TODO alpha >= 0 ak = OneDimensionalMinimization.FindMin(func1D, ak, eps); // TODO негибкая стратегия выбора eps Log.Add(String.Format("ak = {0}", ak)); xk = xk - gradFxk * ak; k++; Log.Add("==================Next Iteration===================="); } }
public static PointN MethodHookJivs(F function, PointN b1, VectorN h, double eps, double z = 0.1) { PointN x; do { do { PointN xk = b1; PointN b2 = HookJivsHelper.ExploringSearch(function, xk, h); Console.WriteLine("> Exploring search ( xk{0} ) = b2{1}", xk.ToString(), b2.ToString()); do { Console.WriteLine("> Doing step xk = b1 + (b2 - b1) * 2, will give xk{0}", xk.ToString()); xk = b1 + (b2 - b1) * 2; x = HookJivsHelper.ExploringSearch(function, xk, h); Console.WriteLine("> Exploring search ( xk{0} ) = x{1}", xk.ToString(), x.ToString()); b1 = b2; b2 = x; } while (function.Value(x) < function.Value(b1)); } while (function.Value(x) > function.Value(b1)); if (h.Length <= eps) { break; } h = h * z; }while(true); return(b1); }
public static string CoordinatesConvertor(double InputX,double InputY, int InputWKID, int OutputWKID) { Geometry_GeometryServer geometryService = new Geometry_GeometryServer(); SpatialReference inputSpatialReference = new GeographicCoordinateSystem(); inputSpatialReference.WKID = InputWKID; inputSpatialReference.WKIDSpecified = true; SpatialReference outputSpatialReference = new ProjectedCoordinateSystem(); outputSpatialReference.WKID = OutputWKID; outputSpatialReference.WKIDSpecified = true; PointN pt = new PointN(); pt.X = InputX; pt.Y = InputY; Geometry[] inGeo = new Geometry[] { pt }; Geometry[] geo = geometryService.Project(inputSpatialReference, outputSpatialReference, false, null, null, inGeo); PointN nPt = (PointN)geo[0]; return (nPt.X.ToString() + ',' + nPt.Y.ToString()); }
public PointN FindMin(double eps) { int k = 0; int dimensionsCount = x0.Coordinates.Count; // Промежуточные данные PointN xk = new PointN(x0); PointN x_rk; double rk = r0; do { // Поиск минимума F(x, r) F Fxr = new F((PointN point) => { return(F(point, rk)); }); Console.WriteLine(">>> ++++++++++++++++++++HookJivs started++++++++++++++++++++"); x_rk = HookJivs.MethodHookJivs(Fxr, xk, new VectorN(dimensionsCount, 1.0), eps); Console.WriteLine(">>> ++++++++++++++++++++HookJivs finished++++++++++++++++++++"); // Значение штрафной функции в xrk double P_x_rk = P(x_rk, rk); // TODO в данных условиях не имеет смысла, т.к. нигде далее не используется и пересчитывается заново Console.WriteLine("P(xk, rk) = {0}", P(xk, rk)); //Log.Add(String.Format("P(xrk, rk) = {0}", P_x_rk)); Console.WriteLine("f(xk) = {0}", f(xk)); Console.WriteLine("F(xk, rk) = {0}", F(xk, rk)); // Инкремент цикла rk = rk * z; xk = x_rk; k++; Console.WriteLine("==================Next Iteration===================="); //Log.Add("==================Next Iteration===================="); } while (P(x_rk, rk) >= eps); return(x_rk); }
/// <summary> /// Create a CIMPointGaphic which can be added to the MapView overlay. /// </summary> /// <param name="point">The location for the point (as a CIM point)</param> /// <returns></returns> public CIMPointGraphic MakeCIMPointGraphic(PointN point) { ////CIMMarker marker = SymbolHelper.ConstructMarker(Red, 10, SimpleMarkerStyle.Circle); CIMMarker marker = SymbolHelper.ConstructMarker(Red, 10, SimpleMarkerStyle.Star); CIMSymbolLayer[] layers = new CIMSymbolLayer[1]; layers[0] = marker; CIMPointSymbol pointSymbol = new CIMPointSymbol(); pointSymbol.SymbolLayers = layers; pointSymbol.ScaleX = 1; CIMSymbolReference symbolRef = new CIMSymbolReference(); symbolRef.Symbol = pointSymbol; CIMPointGraphic pointGraphic = new CIMPointGraphic(); pointGraphic.Location = point; pointGraphic.Symbol = symbolRef; return(pointGraphic); }
private void GetCenterPointAndDistance(EnvelopeN extent, out PointN center, out double distance) { center = new PointN(); center.SpatialReference = extent.SpatialReference; center.X = extent.XMin + (Math.Abs(extent.XMax - extent.XMin) / 2); center.Y = extent.YMin + (Math.Abs(extent.YMax - extent.YMin) / 2); distance = Math.Abs(extent.XMax - extent.XMin) / 10; }
private void GetCenterPointAndDistance(EnvelopeN extent, out PointN center, out double distance) { center = new PointN(); center.SpatialReference = extent.SpatialReference; center.X = extent.XMin + (Math.Abs(extent.XMax - extent.XMin)/2); center.Y = extent.YMin + (Math.Abs(extent.YMax - extent.YMin)/2); distance = Math.Abs(extent.XMax - extent.XMin)/10; }
public AGSMultipoint(MultipointN srcMp) { Point[] pointArray = srcMp.PointArray; for (int i = 0; i < pointArray.Length; i++) { PointN srcPt = (PointN)pointArray[i]; this.Points.Add(new AGSPoint(srcPt)); } }
// Вызов метода и форматированный вывод результатов его работы static void TestPenaltyFunctionMethod(FunctionND funcND, List <FunctionND> limitFunctions, PointN x0, int m, int p, double eps) { PenaltyFunctionMethod pfm = new PenaltyFunctionMethod(funcND, limitFunctions, x0, m, p); PointN result = pfm.FindMin(eps); Console.Write(String.Join("\n", pfm.Log)); // Выводим все сообщения от этого метода Console.WriteLine("\n---------------------------------------------"); Console.WriteLine("Variable metric method: x_min = {0}", result); Console.WriteLine("F(x_min) = {0}", funcND(result)); Console.WriteLine("============================================="); }
/// <summary> /// Make a CIM Point /// </summary> /// <param name="x"></param> /// <param name="y"></param> /// <param name="wkid"></param> /// <returns></returns> public PointN MakePointN(double x, double y, int wkid) { PointN pointN = new PointN() { X = x, Y = y, SpatialReference = this.CreateSpatialReference(wkid) }; return(pointN); }
private static Entity DrawCircle(CircularArc arc, double defaultElevation) { PointN pointN = arc.FromPoint as PointN; PointN pointN2 = arc.CenterPoint as PointN; double num = Math.Sqrt((pointN.X - pointN2.X) * (pointN.X - pointN2.X) + (pointN.Y - pointN2.Y) * (pointN.Y - pointN2.Y)); Point3d point3d = new Point3d(pointN2.X, pointN2.Y, pointN2.Z); Entity entity = new Circle(point3d, Vector3d.ZAxis, num); entity.ColorIndex = (256); return(entity); }
/// <summary> /// Метод последовательной безусловной оптимизации /// Метод штрафных функций /// </summary> /// <param name="f">Минимизируемая функция</param> /// <param name="fi"> Список функций ограничений fi от 1 до m</param> /// <param name="_fi">Список функций ограничений _fi от m+1 до p</param> /// <param name="x0"> Начальная точка</param> /// <param name="eps">Параметр точности поиска (>0)</param> /// <param name="m">Число функций ограничений _fi</param> /// <param name="p">(p - m) Число функций ограничений fi</param> /// <param name="r0">Начальное значение параметра штрафа</param> /// <param name="z">Коэффициент умножения параметра штрафа</param> public PenaltyFunctionMethod(FunctionND f, List <FunctionND> limitFunctions, PointN x0, int m, int p, double r0 = 0.1, double z = 6) { this.f = f; this.limitFunctions = limitFunctions; this.x0 = x0; this.r0 = r0; this.z = z; this.m = m; this.p = p; Log = new List <string>(); // TODO: здесь концепция Log не работает }
/// <summary> /// Convert the location to a CIM Point /// </summary> /// <returns></returns> public PointN ToPointN() { if (_point == null) { CIMHelpers cimHelper = new CIMHelpers(); _point = cimHelper.MakePointN(Feature.Location.X, Feature.Location.Y, WKID); } return(_point); }
public static List <Entity> ToEntity(Geometry obj, Geometry denseObj, double defaultElevation, ObjectId blockDefId) { List <Entity> list = null; List <Entity> result; try { if (obj == null) { result = null; } else { PolygonN polygonN = obj as PolygonN; PolylineN polylineN = obj as PolylineN; PointN pointN = obj as PointN; MultipointN multipointN = obj as MultipointN; if (polygonN != null) { list = GIS2CAD.ToEntity(polygonN, denseObj as PolygonN, defaultElevation); } else if (polylineN != null) { list = GIS2CAD.ToEntity(polylineN, denseObj as PolylineN, defaultElevation); } else if (pointN != null) { list = GIS2CAD.ToEntity(pointN, defaultElevation, blockDefId); } else if (multipointN != null) { list = GIS2CAD.ToEntity(multipointN, defaultElevation); } else { DocUtil.ShowDebugMessage(AfaStrings.EncounteredUnknownObjectType); } if (list == null) { result = list; } else { result = list; } } } catch { result = null; } return(result); }
private static Entity DrawCircularArc(CircularArc arc, double defaultElevation, Point[] densifiedPoints) { PointN pointN = arc.FromPoint as PointN; PointN pointN2 = arc.ToPoint as PointN; PointN pointN3 = arc.CenterPoint as PointN; Point3d point3d = new Point3d(pointN.X, pointN.Y, pointN.Z); Point3d point3d2 = new Point3d(pointN3.X, pointN3.Y, pointN3.Z); Point3d point3d3 = new Point3d(pointN2.X, pointN2.Y, pointN2.Z); Point2d centerPoint = new Point2d(pointN3.X, pointN3.Y); Point2d point2d = new Point2d(pointN.X, pointN.Y); Math.Abs(centerPoint.GetDistanceTo(point2d)); CircularArc3d circArc; if (densifiedPoints != null) { int num = densifiedPoints.Length / 2; PointN pointN4 = (PointN)densifiedPoints[num]; if (arc.IsCounterClockwise) { PointN arg_CC_0 = (PointN)densifiedPoints[0]; PointN arg_D9_0 = (PointN)densifiedPoints[densifiedPoints.Length - 1]; } else { PointN arg_E4_0 = (PointN)densifiedPoints[0]; PointN arg_F1_0 = (PointN)densifiedPoints[densifiedPoints.Length - 1]; } Point3d point3d4 = new Point3d(pointN4.X, pointN4.Y, pointN4.Z); circArc = new CircularArc3d(point3d, point3d4, point3d3); } else { Point2d point2d2 = new Point2d(point3d.X, point3d.Y); Point2d point2d3 = new Point2d(point3d3.X, point3d3.Y); double num2 = GIS2CAD.CalcThetaFromVectors(point2d2, point2d3, centerPoint, arc.IsCounterClockwise); double num3 = Math.Tan(num2 / 4.0); if (!arc.IsCounterClockwise) { num3 *= -1.0; } CircularArc2d circularArc2d = new CircularArc2d(point2d2, point2d3, num3, false); Point2d[] samplePoints = circularArc2d.GetSamplePoints(3); Point3d point3d5 = new Point3d(samplePoints[1].X, samplePoints[1].Y, point3d2.Z); circArc = new CircularArc3d(point3d, point3d5, point3d3); } new Point3d(pointN3.X, pointN3.Y, pointN3.Z); Arc arc2 = GIS2CAD.CreateFromCircularArc(circArc); arc2.ColorIndex = (256); return(arc2); }
public static Ellipse ToCadEllipse(EllipticArc arc, double defaultElevation) { EllipticArc ellipticArc = (EllipticArc)Utility.CloneObject(arc); PointN pointN = (PointN)ellipticArc.CenterPoint; if (double.IsNaN(pointN.Z)) { pointN.Z = 0.0; } if (!pointN.ZSpecified) { pointN.Z = defaultElevation; ((PointN)ellipticArc.FromPoint).Z = defaultElevation; ((PointN)ellipticArc.ToPoint).Z = defaultElevation; } Point3d point3d = GIS2CAD.ToCadPoint3d((PointN)ellipticArc.FromPoint); Point3d point3d2 = GIS2CAD.ToCadPoint3d((PointN)ellipticArc.ToPoint); if (!ellipticArc.EllipseStd) { AGSEllipticalArc.TransformToEllipseStd(ref ellipticArc); } PointN pointN2 = (PointN)ellipticArc.FromPoint; PointN pointN3 = (PointN)ellipticArc.ToPoint; double arg_B7_0 = pointN2.X; double arg_BF_0 = pointN2.Y; double num = ellipticArc.MinorMajorRatio * ellipticArc.MinorMajorRatio; double x = pointN2.X; double y = pointN2.Y; double x2 = pointN3.X; double y2 = pointN3.Y; double num2 = Math.Sqrt(num * x * x + y * y); double num3 = Math.Sqrt(num * x2 * x2 + y2 * y2); double num4 = 0.5 * (num2 + num3); double num5 = num4 / ellipticArc.MinorMajorRatio; Vector3d vector3d = new Vector3d(num5, 0.0, 0.0); Vector3d vector3d2 = new Vector3d(0.0, num4, 0.0); Vector3d vector3d3 = vector3d.RotateBy(ellipticArc.Rotation, Vector3d.ZAxis); Vector3d vector3d4 = vector3d2.RotateBy(ellipticArc.Rotation, Vector3d.ZAxis); Point3d point3d3 = GIS2CAD.ToCadPoint3d(pointN); EllipticalArc3d ellipticalArc3d = new EllipticalArc3d(point3d3, vector3d3, vector3d4, num5, num4); double num6 = ellipticalArc3d.GetParameterOf(point3d); double num7 = ellipticalArc3d.GetParameterOf(point3d2); if (!ellipticArc.IsCounterClockwise) { double num8 = num6; num6 = num7; num7 = num8; } return(new Ellipse(point3d3, Vector3d.ZAxis, vector3d3, ellipticArc.MinorMajorRatio, num6, num7)); }
// NOTE: Неизвстно, как преобразовать Func<Vector<double>, double> к Func<PointN, double> // Поэтому будут использованы две аналогичные функции // Для них используются ужасно похожие лямбды. // Возможно, этот конфликт можно решить // TODO: надо бы сравнить производительность алгоритмов // Можно привлечь сюда число итераций например // TODO: см в тетради и реши все тестовые задачи // COMPLETE #region TEST2_1 static void Test2_1() { // Input data FunctionNDByAlex funcND = (PointN point) => { return(4 * System.Math.Pow(point.At(0) - 5.0, 2.0) + System.Math.Pow(point.At(1) - 6.0, 2.0)); }; FunctionNDMathNet funcNDMathNet = (VectorNMathNet point) => { return(4 * System.Math.Pow(point.At(0) - 5.0, 2.0) + System.Math.Pow(point.At(1) - 6.0, 2.0)); }; PointN x0 = new PointN(100.0, 100.0); VectorNMathNet x0MathNet = Helpers.PointNToMathNet(x0); const double eps = 0.01; // Testing TestOptimalGradientMethod(funcND, x0, eps); TestVariableMetricMethod(funcNDMathNet, x0MathNet, eps); }
private static Entity DrawPolyline(Point[] points, bool closePart) { var polyline = new Autodesk.AutoCAD.DatabaseServices.Polyline(); int num = 0; for (int i = 0; i < points.Length; i++) { Point point = points[i]; PointN srcPt = (PointN)point; polyline.AddVertexAt(num++, GIS2CAD.ToCadPoint2d(srcPt), 0.0, 0.0, 0.0); } return(polyline); }
private static void TransformToEllipseStd(ref PointN inOutPoint, PointN center, double rotation) { double num = Math.Cos(rotation); double num2 = Math.Sin(rotation); inOutPoint.X -= center.X; inOutPoint.Y -= center.Y; double y = inOutPoint.Y; inOutPoint.Y *= num; inOutPoint.Y -= inOutPoint.X * num2; inOutPoint.X *= num; inOutPoint.X += y * num2; }
private static List <Entity> ToEntity(MultipointN gisGeom, double defaultElevation) { List <Entity> list = new List <Entity>(); Point[] pointArray = gisGeom.PointArray; for (int i = 0; i < pointArray.Length; i++) { Point point = pointArray[i]; PointN pointN = point as PointN; DBPoint item = new DBPoint(new Point3d(pointN.X, pointN.Y, pointN.Z)); list.Add(item); } return(list); }
private static bool CanBeDrawnAsPolyline(Segment[] segs) { Segment segment = segs[0]; PointN pointN = (PointN)segment.FromPoint; PointN pointN2 = (PointN)segment.ToPoint; if (pointN.Z != pointN2.Z) { return(false); } double z = pointN2.Z; int i = 0; while (i < segs.Length) { Segment segment2 = segs[i]; EllipticArc ellipticArc = segment2 as EllipticArc; BezierCurve bezierCurve = segment2 as BezierCurve; bool result; if (bezierCurve != null) { result = false; } else if (ellipticArc != null) { result = false; } else { pointN = (PointN)segment2.FromPoint; pointN2 = (PointN)segment2.ToPoint; if (pointN.Z != z) { result = false; } else { if (pointN2.Z == z) { i++; continue; } result = false; } } return(result); } return(true); }
public static bool IsPlanar(Point[] plainPoints) { double z = ((PointN)plainPoints[0]).Z; for (int i = 0; i < plainPoints.Length; i++) { Point point = plainPoints[i]; PointN pointN = (PointN)point; if (pointN.Z != z) { return(false); } } return(true); }
// FAILED (метод расходится) #region TEST2_4 static void Test2_4() { FunctionND funcND = (PointN point) => { return(point.At(0) - 2 * point.At(1) * point.At(1) + 4 * point.At(1)); }; PointN x0 = new PointN(0.0, 0.0); double eps = 0.01; // Функции ограничений List <FunctionND> limitFunctions = new List <FunctionND> { new FunctionND((PointN point) => { return(-3 * point.At(0) - 2 * point.At(1) - 6); }) }; int m = 0; // Число функций ограничений типа Fi(x) >= 0 int p = 1; // Общее число функций ограничений TestPenaltyFunctionMethod(funcND, limitFunctions, x0, m, p, eps); }
// Эти функции тестируют одноименные методы // И осуществляют форматированный вывод результатов их работы // Работает с NDimensionalPrimitives.PointN; static void TestOptimalGradientMethod(FunctionNDByAlex funcND, PointN x0, double eps) { OptimalGradientMethod ogm = new OptimalGradientMethod(funcND, x0); sw.Start(); PointN result = ogm.FindMin(eps); sw.Stop(); Console.Write(String.Join("\n", ogm.Log)); // Выводим все сообщения от этого метода Console.WriteLine("\n---------------------------------------------"); Console.WriteLine("Optimal gradient method: x_min = {0}", result); Console.WriteLine("F(x_min) = {0}", funcND(result)); Console.WriteLine("Time: {0}ms", sw.ElapsedMilliseconds); Console.WriteLine("============================================="); }
// Центральная разностная схема // f(x+h) - f(x-h) // f(x) = ---------------- // 2h public static VectorN Calculate(Func <PointN, double> f, PointN point, double h = 0.01) { int dimensionsCount = point.Coordinates.Count; VectorN gradient = new VectorN(dimensionsCount); for (int i = 0; i < dimensionsCount; i++) { PointN xMinusH = new PointN(point); xMinusH.Coordinates[i] -= h; PointN xPlusH = new PointN(point); xPlusH.Coordinates[i] += h; gradient.Components[i] = (f(xPlusH) - f(xMinusH)) / (2 * h); } return(gradient); }
private static void TransformToEllipseStd(ref EllipticArc arc) { PointN pointN = (PointN)arc.CenterPoint; if (double.IsNaN(pointN.Z)) { pointN.Z = 0.0; } PointN fromPoint = (PointN)arc.FromPoint; PointN toPoint = (PointN)arc.ToPoint; AGSEllipticalArc.TransformToEllipseStd(ref fromPoint, pointN, arc.Rotation); AGSEllipticalArc.TransformToEllipseStd(ref toPoint, pointN, arc.Rotation); arc.FromPoint = fromPoint; arc.ToPoint = toPoint; }
/// <summary> /// Create a CIMPointGaphic which can be added to the MapView overlay. /// </summary> /// <param name="point">The location for the point (as a CIM point)</param> /// <returns></returns> public CIMPointGraphic MakeCIMPointGraphic(PointN point) { ////CIMMarker marker = SymbolHelper.ConstructMarker(Red, 10, SimpleMarkerStyle.Circle); CIMMarker marker = SymbolHelper.ConstructMarker(Red, 10, SimpleMarkerStyle.Star); CIMSymbolLayer[] layers = new CIMSymbolLayer[1]; layers[0] = marker; CIMPointSymbol pointSymbol = new CIMPointSymbol(); pointSymbol.SymbolLayers = layers; pointSymbol.ScaleX = 1; CIMSymbolReference symbolRef = new CIMSymbolReference(); symbolRef.Symbol = pointSymbol; CIMPointGraphic pointGraphic = new CIMPointGraphic(); pointGraphic.Location = point; pointGraphic.Symbol = symbolRef; return pointGraphic; }
/// <summary> /// Convert the location to a CIM Point /// </summary> /// <returns></returns> public PointN ToPointN() { if (_point == null) { CIMHelpers cimHelper = new CIMHelpers(); _point = cimHelper.MakePointN(Feature.Location.X, Feature.Location.Y, WKID); } return _point ; }
/// <summary> /// Create a CIMPointGaphic which can be added to the MapView overlay. /// </summary> /// <param name="point">The location for the point (as a CIM point)</param> /// <returns></returns> public CIMPointGraphic MakeCIMPointGraphic(PointN point) { CIMMarker marker = SymbolFactory.ConstructMarker(Red, 10, SimpleMarkerStyle.Star); CIMSymbolLayer[] layers = new CIMSymbolLayer[1]; layers[0] = marker; CIMPointSymbol pointSymbol = new CIMPointSymbol(); pointSymbol.SymbolLayers = layers; pointSymbol.ScaleX = 1; CIMSymbolReference symbolRef = new CIMSymbolReference(); symbolRef.Symbol = pointSymbol; CIMPointGraphic pointGraphic = new CIMPointGraphic(); ArcGIS.Core.Geometry.SpatialReference spatialRef = SpatialReferenceBuilder.CreateSpatialReference(point.SpatialReference.WKID); MapPoint mapPoint = MapPointBuilder.CreateMapPoint(point.X, point.Y, spatialRef); pointGraphic.Location = mapPoint; pointGraphic.Symbol = symbolRef; return pointGraphic; }
/// <summary> /// Do reverse geocode. /// </summary> /// <param name="point">Source point</param> /// <param name="returnIntr">Return intersection.</param> /// <param name="propMods">Properties.</param> /// <returns>Property set with result of reverse geocoding request.</returns> private PropertySet _ReverseGeocode(PointN point, bool returnIntr, PropertySet propMods) { PropertySet res = null; try { res = _client.ReverseGeocode(point, returnIntr, propMods); } catch (System.ServiceModel.FaultException ex) { Logger.Info(ex); } // eat FaultException if location cannot be reverse geocoded return res; }
/// <summary> /// Finds address by geographical location. Asynchronous method. /// </summary> /// <param name="location">Location point.</param> /// <param name="userToken">Geocoding operation token.</param> /// <exception cref="ESRI.ArcLogistics.AuthenticationException"> /// Is thrown if server state is unauthorized.</exception> public override void ReverseGeocodeAsync(ESRI.ArcLogistics.Geometry.Point location, object userToken) { _ValidateGeocoderState(); try { PointN point = new PointN(); point.X = location.X; point.Y = location.Y; // REV: we should pass WPG84 since we store our points in this spatial reference SpatialReference sr = new ESRI.ArcLogistics.GeocodeService.GeographicCoordinateSystem(); sr.WKID = GeometryConst.WKID_WGS84; //point.SpatialReference = sr; PropertySet propMods = new PropertySet(); propMods.PropertyArray = new PropertySetProperty[2]; // distance units propMods.PropertyArray[1] = _CreateProp("ReverseDistanceUnits", REV_DISTANCE_UNITS); // distance value propMods.PropertyArray[0] = _CreateProp("ReverseDistance", SNAP_TOL); _client.ReverseGeocodeAsync(point, false, propMods, userToken); } catch (System.ServiceModel.FaultException ex) { Logger.Info(ex); } // eat FaultException if location cannot be reverse geocoded }
/// <summary> /// Finds address by geographical location. /// </summary> /// <param name="location">Location point.</param> /// <returns>Returns found address.</returns> /// <exception cref="ESRI.ArcLogistics.AuthenticationException"> /// Is thrown if server state is unauthorized.</exception> public override Address ReverseGeocode(ESRI.ArcLogistics.Geometry.Point location) { _ValidateGeocoderState(); Address res = null; try { PointN point = new PointN(); point.X = location.X; point.Y = location.Y; // REV: we should pass WPG84 since we store our points in this spatial reference SpatialReference sr = new ESRI.ArcLogistics.GeocodeService.GeographicCoordinateSystem(); sr.WKID = GeometryConst.WKID_WGS84; //point.SpatialReference = sr; // Set properties for reverse geocoder. PropertySet propMods = new PropertySet(); propMods.PropertyArray = new PropertySetProperty[2]; // Distance units. propMods.PropertyArray[1] = _CreateProp("ReverseDistanceUnits", REV_DISTANCE_UNITS); // Distance value. propMods.PropertyArray[0] = _CreateProp("ReverseDistance", SNAP_TOL); // REV: we should ask server to return point in WGS84 // First try reverse geocode intersection. PropertySet pSet = _ReverseGeocode(point, false, propMods); if (pSet != null && pSet.PropertyArray != null) res = _GetAddress(pSet); } catch (System.ServiceModel.FaultException ex) { Logger.Error(ex); } return res; }
static Dictionary<string, object> ToJsonPoint(PointN point) { if (point == null) return null; var output = new Dictionary<string, object>(); output["x"] = point.X; output["y"] = point.Y; var srDict = ToJsonSR(point.SpatialReference); if (srDict != null) { output["spatialReference"] = srDict; } return output; }
static bool TryParse(string locationString, out PointN point) { point = null; if (string.IsNullOrEmpty(locationString)) { return false; } // Try to split coordinates var coordStrings = locationString.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries); if (coordStrings.Length < 2) { return false; } point = new PointN(); bool fail = false; for (int i = 0; i < 2; i++) { double coord; if (double.TryParse(coordStrings[i], out coord)) { if (i == 0) { point.X = coord; } else if (i == 1) { point.Y = coord; } } else { fail = true; break; } } return !fail; }
/// <summary> /// Make a CIM Point /// </summary> /// <param name="x"></param> /// <param name="y"></param> /// <param name="wkid"></param> /// <returns></returns> public PointN MakePointN(double x, double y, int wkid) { PointN pointN = new PointN() { X = x, Y = y, SpatialReference = this.CreateSpatialReference(wkid) }; return pointN; }
/// <summary> /// Default constructor /// </summary> public CIMPointGraphicHelper(PointN point) { _cimHelper = new CIMHelpers(); _graphic = _cimHelper.MakeCIMPointGraphic(point); graphicID = -1; }
/// <summary> /// Update the CIMPointGraphic location /// </summary> /// <param name="point"></param> public void UpdateLocation(PointN point) { ((PointN)_graphic.Location).X = point.X; ((PointN)_graphic.Location).Y = point.Y; }