コード例 #1
0
        /// <summary>
        /// Formats an IList of GemsPoint2d objects into a comma separated string of x1,y1, x2,y2... xn,yn
        /// </summary>
        /// <param name="polyPoints">The poly points.</param>
        /// <returns></returns>
        public static string FormatPolygonToPointString(IList <GemsPoint2d> polyPoints)
        {
            string pointString = String.Empty;

            //_logger.Debug("Start FormatPolygonToPointString");
            try
            {
                foreach (GemsPoint2d onePoint in polyPoints)
                {
                    pointString += onePoint.X.ToString() + "," + onePoint.Y.ToString();
                    pointString += ",";
                }
                //Verifying polygon is closed (first point == last point)
                GemsPoint2d firstPoint = polyPoints[0];
                GemsPoint2d lastPoint  = polyPoints[polyPoints.Count - 1];
                if ((firstPoint.X == lastPoint.X) && (firstPoint.Y == lastPoint.Y))
                {
                    //Drop the comma
                    pointString = pointString.Substring(0, pointString.Length - 1);
                }
                else
                {
                    //Add first point as closing point
                    pointString += firstPoint.X.ToString() + "," + firstPoint.Y.ToString();
                }
            }
            catch (System.Exception ex)
            {
                //_logger.Error("Error in FormatPolygonToPointString", ex);
                throw;
            }
            //_logger.Debug("End FormatPolygonToPointString");
            return(pointString);
        }
コード例 #2
0
        /// <summary>
        /// Extracts the points from string.
        /// </summary>
        /// <param name="pointString">The point string.</param>
        /// <returns></returns>
        public static IList <GemsPoint2d> ExtractPointsFromString(string pointString)
        {
            IList <GemsPoint2d> polyPoints = new List <GemsPoint2d>();

            //_logger.Debug("Start ExtractPointsFromString");
            try
            {
                string[]    coordinates = pointString.Split(',');
                bool        isCoordX    = true;
                GemsPoint2d onePoint    = null;
                foreach (string coordinate in coordinates)
                {
                    if (isCoordX == true)
                    {
                        onePoint   = new GemsPoint2d();
                        onePoint.X = Convert.ToDouble(coordinate);
                        isCoordX   = false;
                    }
                    else
                    {
                        onePoint.Y = Convert.ToDouble(coordinate);
                        polyPoints.Add(onePoint);
                        isCoordX = true;
                    }
                }
            }
            catch (System.Exception ex)
            {
                //_logger.Error("Error in ExtractPointsFromString", ex);
                throw;
            }
            //_logger.Debug("End ExtractPointsFromString");
            return(polyPoints);
        }
コード例 #3
0
        // Note: OSGeo references WKText strings for coordinate system definitions.
        // A database lookup table has been populated with AutoCAD Map Coordinate System codes and WKText strings
        // Use the Data Manager method GetWKTextFromMapCsCode to translate MapCS to WKText

        /// <summary>
        /// Coordinate transformation between two world coordinate systems
        /// This Version works with coordinates as AutoCAD Point2d objects
        /// </summary>
        /// <param name="wkTextSource">The wk text source.</param>
        /// <param name="wkTextTarget">The wk text target.</param>
        /// <param name="inputPoint">The input point.</param>
        /// <param name="transformedPoint">The transformed point.</param>
        /// <returns></returns>
        public static bool TransformPoint2d(string wkTextSource, string wkTextTarget, GemsPoint2d inputPoint, ref GemsPoint2d transformedPoint)
        {
            bool RetVal = false;

            //_logger.Debug("Start TransformPoint2d");
            try
            {
                //Creating coordinate system factory
                MgCoordinateSystemFactory CSFactory = new MgCoordinateSystemFactory();
                //Creating coordinate system objects
                MgCoordinateSystem SourceCS = CSFactory.Create(wkTextSource);
                MgCoordinateSystem TargetCS = CSFactory.Create(wkTextTarget);
                //Creating geometry factory
                MgGeometryFactory GeomFactory = new MgGeometryFactory();
                //Populating geometry factory CreateCoordinateXY
                MgCoordinate SourceCoord = GeomFactory.CreateCoordinateXY(inputPoint.X, inputPoint.Y);
                //Getting transformation definition
                MgCoordinateSystemTransform CSTransform = CSFactory.GetTransform(SourceCS, TargetCS);
                //Transforming coordinate
                MgCoordinate TargetCoord = CSTransform.Transform(SourceCoord);
                //Populating return coordinate object
                transformedPoint   = new GemsPoint2d();
                transformedPoint.X = TargetCoord.X;
                transformedPoint.Y = TargetCoord.Y;

                RetVal = true;
            }
            catch (System.Exception ex)
            {
                //_logger.Error("Error in TransformPoint2d", ex);
                throw;
            }
            //_logger.Debug("End TransformPoint2d");
            return(RetVal);
        }
コード例 #4
0
        //private static readonly ILog //_logger = LogManager.GetLogger(typeof(MapUtilities));

        #endregion

        #region MapBreak

        /// <summary>
        /// Maps the break.
        /// </summary>
        /// <param name="polyPoints">The poly points.</param>
        /// <param name="layerFilter">The layer filter.</param>
        /// <returns></returns>
        public static bool MapBreak(IList <GemsPoint2d> polyPoints, string layerFilter)
        {
            bool retval = false;

            //_logger.Debug("Start MapBreak");
            GemsPoint2d minPoint = CoordinateService.GetMinFromPolygon(polyPoints);
            GemsPoint2d maxPoint = CoordinateService.GetMaxFromPolygon(polyPoints);

            // This should return a selection set and check that it contains one or more objects
            // I would need to add a using to get the SelectionSet object in this class...?
            SelectionManager.GetSelectionSet(minPoint.X, minPoint.Y, maxPoint.X, maxPoint.Y, layerFilter, true);

            // The CMDDIA calls should reference SetSystemVariable
            StringBuilder acadCmd = new StringBuilder();

            acadCmd.Append("CMDDIA 0 ");
            acadCmd.Append("_MAPBREAK DEFINE ");
            foreach (GemsPoint2d onePoint in polyPoints)
            {
                acadCmd.Append(onePoint.X.ToString());
                acadCmd.Append(",");
                acadCmd.Append(onePoint.Y.ToString());
                acadCmd.Append("\r");
            }
            acadCmd.Append("\r");
            acadCmd.Append("N Y P  Y Y ");
            acadCmd.Append("CMDDIA 1 ");
            AcadUtilities.SendStringToExecute(acadCmd.ToString());
            retval = true;

            //_logger.Debug("End MapBreak");
            return(retval);
        }
コード例 #5
0
        /// <summary>
        /// Gets the state plane from lat long.
        /// </summary>
        /// <param name="manager">The manager.</param>
        /// <param name="source">The source.</param>
        /// <param name="dest">The dest.</param>
        /// <param name="statePlane">The state plane.</param>
        /// <returns></returns>
        public static bool GetStatePlaneFromLatLong(IDataManager manager, GemsPoint2d source, ref GemsPoint2d dest, ref string statePlane)
        {
            //_logger.Debug("Start GetStatePlaneFromLatLong");
            bool result = false;

            string statePlaneUsed = String.Empty;

            foreach (string sp in CoordinateService.GetStatePlanes())
            {
                try
                {
                    dest       = CoordinateService.TranslateWGS84ToStatePlane(manager, sp, source);
                    result     = true;
                    statePlane = sp;
                    break;
                }
                catch (System.Exception ex)
                {
                    //_logger.Error("Error in GetStatePlaneFromLatLong", ex);
                    throw;
                }
            }
            //_logger.Debug("End GetStatePlaneFromLatLong");
            return(result);
        }
コード例 #6
0
        /// <summary>
        /// Scale a list of points
        /// </summary>
        /// <param name="basePoint">The base point.</param>
        /// <param name="scaleFactor">The scale factor.</param>
        /// <param name="sourcePoints">The source points.</param>
        /// <returns></returns>
        public static IList <GemsPoint2d> ScalePolygon(GemsPoint2d basePoint, double scaleFactor, IList <GemsPoint2d> sourcePoints)
        {
            //_logger.Debug("Start ScalePolygon");
            IList <GemsPoint2d> scaledPoints = new List <GemsPoint2d>();

            try
            {
                foreach (GemsPoint2d ptSource in sourcePoints)
                {
                    double deltaX = ptSource.X - basePoint.X;
                    double deltaY = ptSource.Y - basePoint.Y;
                    deltaX *= scaleFactor;
                    deltaY *= scaleFactor;
                    GemsPoint2d pt = new GemsPoint2d(basePoint.X + deltaX, basePoint.Y + deltaY);
                    scaledPoints.Add(pt);
                }
            }
            catch (System.Exception ex)
            {
                //_logger.Error("Error in ScalePolygon", ex);
                throw;
            }
            //_logger.Debug("Start ScalePolygon");
            return(scaledPoints);
        }
コード例 #7
0
        /// <summary>
        /// Gets the centroid (mathematical) from a list of points
        /// </summary>
        /// <param name="polyPoints">The poly points.</param>
        /// <returns></returns>
        public static GemsPoint2d GetCentroidFromPolygon(IList <GemsPoint2d> polyPoints)
        {
            //_logger.Debug("Start GetCentroidFromPolygon");
            GemsPoint2d minPoint      = GetMinFromPolygon(polyPoints);
            GemsPoint2d maxPoint      = GetMaxFromPolygon(polyPoints);
            GemsPoint2d centroidPoint = new GemsPoint2d();

            centroidPoint.X = minPoint.X + ((maxPoint.X - minPoint.X) / 2.0);
            centroidPoint.Y = minPoint.Y + ((maxPoint.Y - minPoint.Y) / 2.0);
            //_logger.Debug("End GetCentroidFromPolygon");
            return(centroidPoint);
        }
コード例 #8
0
        /// <summary>
        /// Converts to lat long.
        /// </summary>
        /// <param name="dm">The dm.</param>
        /// <param name="sourcePoints">The source points.</param>
        /// <param name="acMapCsCode">The ac map cs code.</param>
        /// <returns></returns>
        public static IList <GemsPoint2d> ConvertToLatLong(IDataManager dm, IList <GemsPoint2d> sourcePoints, string acMapCsCode)
        {
            //_logger.Debug("Start ConvertToLatLong");
            IList <GemsPoint2d> list = new List <GemsPoint2d>();

            foreach (GemsPoint2d ptSource in sourcePoints)
            {
                GemsPoint2d pt = CoordinateService.TranslateStatePlaneToWGS84(dm, acMapCsCode, ptSource);
                list.Add(pt);
            }
            //_logger.Debug("Start ConvertToLatLong");
            return(list);
        }
コード例 #9
0
        /// <summary>
        /// Builds the polygon from min max.
        /// </summary>
        /// <param name="lowerLeft">The lower left.</param>
        /// <param name="upperRight">The upper right.</param>
        /// <returns></returns>
        public static IList <GemsPoint2d> BuildPolygonFromMinMax(GemsPoint2d lowerLeft, GemsPoint2d upperRight)
        {
            //_logger.Debug("Start BuildPolygonFromMinMax");
            IList <GemsPoint2d> polyPoints = new List <GemsPoint2d>();

            polyPoints.Add(new GemsPoint2d(lowerLeft.X, lowerLeft.Y));
            polyPoints.Add(new GemsPoint2d(upperRight.X, lowerLeft.Y));
            polyPoints.Add(new GemsPoint2d(upperRight.X, upperRight.Y));
            polyPoints.Add(new GemsPoint2d(lowerLeft.X, upperRight.Y));
            polyPoints.Add(new GemsPoint2d(lowerLeft.X, lowerLeft.Y));

            //_logger.Debug("End BuildPolygonFromMinMax");
            return(polyPoints);
        }
コード例 #10
0
        /// <summary>
        /// Translates the state plane to WG S84.
        /// </summary>
        /// <param name="manager">The manager.</param>
        /// <param name="statePlaneMapCsCode">The state plane map cs code.</param>
        /// <param name="inputCoord">The input coord.</param>
        /// <returns></returns>
        public static GemsPoint2d TranslateStatePlaneToWGS84(IDataManager manager, string statePlaneMapCsCode, GemsPoint2d inputCoord)
        {
            //_logger.Debug("Start TranslateStatePlaneToWGS84");
            bool retval = false;

            string wgs84mapcscode = "LL84";

            string      wgs84wktext      = manager.GetWKTextFromMapCsCode(wgs84mapcscode);
            string      stateplanewktext = manager.GetWKTextFromMapCsCode(statePlaneMapCsCode);
            GemsPoint2d transformedCoord = new GemsPoint2d();

            retval = MapUtilities.TransformPoint2d(stateplanewktext, wgs84wktext, inputCoord, ref transformedCoord);

            //_logger.Debug("End TranslateStatePlaneToWGS84");
            return(transformedCoord);
        }
コード例 #11
0
        /// <summary>
        /// Gets the lat long to state plane.
        /// </summary>
        /// <param name="manager">The manager.</param>
        /// <param name="source">The source.</param>
        /// <param name="statePlane">The state plane.</param>
        /// <param name="dest">The dest.</param>
        /// <returns></returns>
        public static bool GetLatLongFromStatePlane(IDataManager manager, GemsPoint2d source, string statePlane, ref GemsPoint2d dest)
        {
            //_logger.Debug("Start GetLatLongFromStatePlane");
            bool result = false;

            try
            {
                dest   = CoordinateService.TranslateStatePlaneToWGS84(manager, statePlane, source);
                result = true;
            }
            catch (System.Exception ex)
            {
                //_logger.Error("Error in GetLatLongFromStatePlane", ex);
                throw;
            }
            //_logger.Debug("Start GetLatLongFromStatePlane");
            return(result);
        }
コード例 #12
0
        /// <summary>
        /// Move a list of points by the offset
        /// </summary>
        /// <param name="offsetX">The offset X.</param>
        /// <param name="offsetY">The offset Y.</param>
        /// <param name="sourcePoints">The source points.</param>
        /// <returns></returns>
        public static IList <GemsPoint2d> MovePolygon(double offsetX, double offsetY, IList <GemsPoint2d> sourcePoints)
        {
            //_logger.Debug("Start MovePolygon");
            IList <GemsPoint2d> movedPoints = new List <GemsPoint2d>();

            try
            {
                foreach (GemsPoint2d ptSource in sourcePoints)
                {
                    GemsPoint2d pt = new GemsPoint2d(ptSource.X + offsetX, ptSource.Y + offsetY);
                    movedPoints.Add(pt);
                }
            }
            catch (System.Exception ex)
            {
                //_logger.Error("Error in MovePolygon", ex);
                throw;
            }
            //_logger.Debug("Start MovePolygon");
            return(movedPoints);
        }
コード例 #13
0
        /// <summary>
        /// Gets the minimum bounding point from a list of points
        /// </summary>
        /// <param name="polyPoints">The poly points.</param>
        /// <returns></returns>
        public static GemsPoint2d GetMinFromPolygon(IList <GemsPoint2d> polyPoints)
        {
            //_logger.Debug("Start GetMinFromPolygon");
            GemsPoint2d minPoint   = new GemsPoint2d();
            GemsPoint2d firstPoint = polyPoints[0];

            minPoint.X = firstPoint.X;
            minPoint.Y = firstPoint.Y;

            foreach (GemsPoint2d onePoint in polyPoints)
            {
                if (onePoint.X < minPoint.X)
                {
                    minPoint.X = onePoint.X;
                }
                if (onePoint.Y < minPoint.Y)
                {
                    minPoint.Y = onePoint.Y;
                }
            }
            //_logger.Debug("End GetMinFromPolygon");
            return(minPoint);
        }