예제 #1
0
        private Geometry CreatePolyline()
        {
            if (Point1 == null || Point2 == null)
            {
                return(null);
            }

            var nameConverter           = new EnumToFriendlyNameConverter();
            GeodeticCurveType curveType = DeriveCurveType(LineType);
            LinearUnit        lu        = DeriveUnit(LineDistanceType);

            try
            {
                // create line
                var polyline = QueuedTask.Run(() =>
                {
                    var point2Proj = GeometryEngine.Instance.Project(Point2, Point1.SpatialReference);
                    var segment    = LineBuilder.CreateLineSegment(Point1, (MapPoint)point2Proj);
                    return(PolylineBuilder.CreatePolyline(segment));
                }).Result;
                Geometry newline = GeometryEngine.Instance.GeodeticDensifyByLength(polyline, 0, lu, curveType);


                var displayValue = nameConverter.Convert(LineDistanceType, typeof(string), new object(), CultureInfo.CurrentCulture);
                // Hold onto the attributes in case user saves graphics to file later
                LineAttributes lineAttributes = new LineAttributes()
                {
                    mapPoint1    = Point1,
                    mapPoint2    = Point2,
                    distance     = distance,
                    angle        = (double)azimuth,
                    angleunit    = LineAzimuthType.ToString(),
                    distanceunit = displayValue.ToString(),
                    originx      = Point1.X,
                    originy      = Point1.Y,
                    destinationx = Point2.X,
                    destinationy = Point2.Y
                };

                CreateLineFeature(newline, lineAttributes);

                ResetPoints();

                return((Geometry)newline);
            }
            catch (Exception ex)
            {
                // do nothing
                System.Diagnostics.Debug.WriteLine(ex.Message);
                return(null);
            }
        }
        /// <summary>
        /// Create a geodetic line
        /// </summary>
        private IGeometry CreatePolyline()
        {
            try
            {
                if (Point1 == null || Point2 == null)
                {
                    return(null);
                }

                var construct = new Polyline() as IConstructGeodetic;

                if (construct == null)
                {
                    return(null);
                }

                if (srf3 == null)
                {
                    // if you don't use the activator, you will get exceptions
                    Type srType = Type.GetTypeFromProgID("esriGeometry.SpatialReferenceEnvironment");
                    srf3 = Activator.CreateInstance(srType) as ISpatialReferenceFactory3;
                }

                var linearUnit        = srf3.CreateUnit((int)esriSRUnitType.esriSRUnit_Meter) as ILinearUnit;
                esriGeodeticType type = GetEsriGeodeticType();
                IGeometry        geo  = Point1;
                if (LineFromType == LineFromTypes.Points)
                {
                    construct.ConstructGeodeticLineFromPoints(GetEsriGeodeticType(), Point1, Point2, GetLinearUnit(), esriCurveDensifyMethod.esriCurveDensifyByDeviation, -1.0);
                }
                else
                {
                    Double bearing = 0.0;
                    if (LineAzimuthType == AzimuthTypes.Mils)
                    {
                        bearing = GetAzimuthAsDegrees();
                    }
                    else
                    {
                        bearing = (double)Azimuth;
                    }
                    construct.ConstructGeodeticLineFromDistance(type, Point1, GetLinearUnit(), Distance, bearing, esriCurveDensifyMethod.esriCurveDensifyByDeviation, -1.0);
                }
                var mxdoc = ArcMap.Application.Document as IMxDocument;
                var av    = mxdoc.FocusMap as IActiveView;
                if (LineFromType == LineFromTypes.Points)
                {
                    UpdateDistance(construct as IGeometry);
                    UpdateAzimuth(construct as IGeometry);
                }

                IDictionary <String, System.Object> lineAttributes = new Dictionary <String, System.Object>();
                lineAttributes.Add("distance", Distance);
                lineAttributes.Add("distanceunit", LineDistanceType.ToString());
                lineAttributes.Add("angle", (double)Azimuth);
                lineAttributes.Add("angleunit", LineAzimuthType.ToString());
                lineAttributes.Add("startx", Point1.X);
                lineAttributes.Add("starty", Point1.Y);
                lineAttributes.Add("endx", Point2.X);
                lineAttributes.Add("endy", Point2.Y);
                var color = new RgbColorClass()
                {
                    Red = 255
                } as IColor;
                AddGraphicToMap(construct as IGeometry, color, attributes: lineAttributes);

                if (HasPoint1 && HasPoint2)
                {
                    //Get line distance type
                    DistanceTypes dtVal = (DistanceTypes)LineDistanceType;
                    //Get azimuth type
                    AzimuthTypes atVal = (AzimuthTypes)LineAzimuthType;
                    //Get mid point of geodetic line
                    var midPoint = new Point() as IPoint;
                    ((IPolyline)((IGeometry)construct)).QueryPoint(esriSegmentExtension.esriNoExtension, 0.5, false, midPoint);
                    //Create text symbol using text and midPoint
                    AddTextToMap(midPoint != null ? midPoint : Point2,
                                 string.Format("{0}:{1} {2}{3}{4}:{5} {6}",
                                               "Distance",
                                               Math.Round(Distance, 2).ToString("N2"),
                                               dtVal.ToString(),
                                               Environment.NewLine,
                                               "Angle",
                                               Math.Round(azimuth.Value, 2),
                                               atVal.ToString()), (double)Azimuth, LineAzimuthType);
                }

                ResetPoints();

                return(construct as IGeometry);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
                return(null);
            }
        }
예제 #3
0
        /// <summary>
        /// Create a geodetic line
        /// </summary>
        private IGeometry CreatePolyline()
        {
            try
            {
                if ((Point1 == null) || (Point2 == null))
                {
                    return(null);
                }

                var construct = (IConstructGeodetic) new Polyline();

                if (srf3 == null)
                {
                    // if you don't use the activator, you will get exceptions
                    Type srType = Type.GetTypeFromProgID("esriGeometry.SpatialReferenceEnvironment");
                    srf3 = Activator.CreateInstance(srType) as ISpatialReferenceFactory3;
                }

                if (srf3 == null)
                {
                    return(null);
                }

                esriGeodeticType type = GetEsriGeodeticType();
                if (LineFromType == LineFromTypes.Points)
                {
                    construct.ConstructGeodeticLineFromPoints(GetEsriGeodeticType(), Point1, Point2, GetLinearUnit(), esriCurveDensifyMethod.esriCurveDensifyByDeviation, -1.0);
                }
                else
                {
                    Double bearing = 0.0;
                    if (LineAzimuthType == AzimuthTypes.Mils)
                    {
                        bearing = GetAzimuthAsDegrees();
                    }
                    else
                    {
                        bearing = (double)Azimuth;
                    }
                    construct.ConstructGeodeticLineFromDistance(type, Point1, GetLinearUnit(), Distance, bearing, esriCurveDensifyMethod.esriCurveDensifyByDeviation, -1.0);
                }

                if (LineFromType == LineFromTypes.Points)
                {
                    UpdateDistance(construct as IGeometry);
                    UpdateAzimuth(construct as IGeometry);
                }

                IDictionary <String, System.Object> lineAttributes = new Dictionary <String, System.Object>();
                lineAttributes.Add("distance", Distance);
                lineAttributes.Add("distanceunit", LineDistanceType.ToString());
                lineAttributes.Add("angle", (double)Azimuth);
                lineAttributes.Add("angleunit", LineAzimuthType.ToString());
                lineAttributes.Add("startx", Point1.X);
                lineAttributes.Add("starty", Point1.Y);
                lineAttributes.Add("endx", Point2.X);
                lineAttributes.Add("endy", Point2.Y);
                var color = new RgbColorClass()
                {
                    Red = 255
                } as IColor;
                AddGraphicToMap(construct as IGeometry, color, attributes: lineAttributes);

                if (HasPoint1 && HasPoint2)
                {
                    if (Point1.SpatialReference != ArcMap.Document.FocusMap.SpatialReference)
                    {
                        Point1.Project(ArcMap.Document.FocusMap.SpatialReference);
                    }
                    //Get line distance type
                    DistanceTypes dtVal = (DistanceTypes)LineDistanceType;
                    //Get azimuth type
                    AzimuthTypes atVal = (AzimuthTypes)LineAzimuthType;
                    //Create text symbol using text and Point1
                    AddTextToMap(Point1, /* Use the start point for label */
                                 string.Format("{0}:{3}{1} {2}{3}{4}:{3}{5} {6}",
                                               "Distance",
                                               Math.Round(Distance, 2).ToString("N2"),
                                               dtVal.ToString(),
                                               Environment.NewLine,
                                               "Angle",
                                               Math.Round(azimuth.Value, 2),
                                               atVal.ToString()), (double)Azimuth, LineAzimuthType, false);
                }

                ResetPoints();

                return(construct as IGeometry);
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine(ex);
                return(null);
            }
        }
예제 #4
0
        private Geometry CreatePolyline()
        {
            if (Point1 == null || Point2 == null)
            {
                return(null);
            }
            GeodeticCurveType curveType = DeriveCurveType(LineType);
            LinearUnit        lu        = DeriveUnit(LineDistanceType);

            try
            {
                // create line
                var polyline = QueuedTask.Run(() =>
                {
                    var point2Proj = GeometryEngine.Instance.Project(Point2, Point1.SpatialReference);
                    var segment    = LineBuilder.CreateLineSegment(Point1, (MapPoint)point2Proj);
                    return(PolylineBuilder.CreatePolyline(segment));
                }).Result;
                Geometry newline = GeometryEngine.Instance.GeodeticDensifyByLength(polyline, 0, lu, curveType);

                // Hold onto the attributes in case user saves graphics to file later
                LineAttributes lineAttributes = new LineAttributes()
                {
                    mapPoint1 = Point1, mapPoint2 = Point2, _distance = distance, angle = (double)azimuth, angleunit = LineAzimuthType.ToString(), distanceunit = LineDistanceType.ToString(), originx = Point1.X, originy = Point1.Y, destinationx = Point2.X, destinationy = Point2.Y
                };

                AddGraphicToMap(newline, (ProGraphicAttributes)lineAttributes);
                ResetPoints();

                return(newline as Geometry);
            }
            catch (Exception ex)
            {
                // do nothing
                return(null);
            }
        }