Exemple #1
0
        /// <summary>
        /// Distances the specified other.
        /// </summary>
        /// <param name="other">The other.</param>
        /// <returns></returns>
        public double Distance(LatLonAlt other)
        {
            NetTopologySuite.Geometries.Point p1 = new NetTopologySuite.Geometries.Point(Lon, Lat);
            NetTopologySuite.Geometries.Point p2 = new NetTopologySuite.Geometries.Point(other.Lon, other.Lat);

            return(p1.Distance(p2));
        }
Exemple #2
0
        /// <summary>
        /// Computes a snapped coordinate.  If the mouse is near the selected feature, the output
        /// location of the mouse will be the coordinates on the feature rather than the actual
        /// mouse coords.
        /// </summary>
        /// <param name="mouseRect">The event args.</param>
        /// <param name="feat">set if a coordinate is found</param>
        /// <param name="layer">the feature's layer</param>
        /// <param name="snappedCoord">the coordinate of the mouse</param>
        /// <returns>true if snap found</returns>
        protected bool ComputeSnappedLocation_ForSelectedFeature(Rectangle mouseRect, ref IFeature feat, IFeatureLayer layer, ref Coordinate snappedCoord)
        {
            SnappingType      = string.Empty;
            SnappedCoordIndex = 0;

            if (!DoSnapping)
            {
                return(false);
            }
            if (mouseRect == null || feat == null || layer == null || snappedCoord == null)
            {
                return(false);
            }

            Extent pix = Map.PixelToProj(mouseRect);

            if (pix == null)
            {
                return(false);
            }

            Envelope mouseEnv = pix.ToEnvelope();

            NetTopologySuite.Geometries.Point mouse_onEarth = new NetTopologySuite.Geometries.Point(snappedCoord);
            IGeometry featGeom = feat.Geometry;

            // If the feature is partially or totaly visible in the view.
            if (Map.ViewExtents.Intersects(featGeom.EnvelopeInternal))
            {
                bool doCoord_Snap;

                // System.Console.WriteLine(feat.Fid);
                int coordCounter = 0;
                foreach (Coordinate c in feat.Geometry.Coordinates)
                {
                    doCoord_Snap = true;

                    if (layer.SnapVertices)
                    {
                        if (coordCounter == 0 && !layer.SnapStartPoint)
                        {
                            doCoord_Snap = false;
                        }
                        if (coordCounter == (feat.Geometry.Coordinates.Length - 1) && !layer.SnapEndPoint)
                        {
                            doCoord_Snap = false;
                        }

                        if (doCoord_Snap)
                        {
                            // If the mouse envelope contains the current coordinate, we found a snap location.
                            if (mouseEnv.Contains(c))
                            {
                                snappedCoord      = c;
                                SnappedCoordIndex = coordCounter;
                                SnappedFeature    = feat;
                                SnappingType      = SnappingTypeVertex;
                                return(true);
                            }
                        }
                    }

                    if (coordCounter > 0 && layer.SnapEdges && feat.FeatureType != FeatureType.Point && feat.FeatureType != FeatureType.MultiPoint)
                    {
                        double edge_Distance = 0;
                        if (layer.DataSet.CoordinateType.Equals(CoordinateType.Z))
                        {
                            edge_Distance = feat.Geometry.Coordinates[coordCounter - 1].Distance3D(c);
                        }
                        else
                        {
                            edge_Distance = feat.Geometry.Coordinates[coordCounter - 1].Distance(c);
                        }

                        if (edge_Distance > 0)
                        {
                            List <Coordinate> edgeCoords = new List <Coordinate>();
                            edgeCoords.Add(feat.Geometry.Coordinates[coordCounter - 1]);
                            edgeCoords.Add(c);

                            LineString edge = new LineString(edgeCoords.ToArray());

                            if (mouse_onEarth.Distance(edge) <= (mouseEnv.Width / 2))
                            {
                                NetTopologySuite.LinearReferencing.LengthIndexedLine indexedEedge = new NetTopologySuite.LinearReferencing.LengthIndexedLine(edge);
                                double proj_Index = indexedEedge.Project(mouse_onEarth.Coordinate);

                                if (proj_Index > (mouseEnv.Width / 2) && proj_Index < (edge.Length - (mouseEnv.Width / 2)))
                                {
                                    snappedCoord       = indexedEedge.ExtractPoint(proj_Index);
                                    SnappedCoordKeeped = snappedCoord; /* c.Clone() as Coordinate;*/
                                    SnappedCoordIndex  = coordCounter;
                                    SnappedFeature     = feat;
                                    SnappingType       = SnappingTypeEdge;
                                    return(true);
                                }
                            }
                        }
                    }

                    coordCounter++;
                }
            }

            SnappedFeature = null;
            return(false);
        }