예제 #1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="line0"></param>
        /// <param name="line1"></param>
        /// <param name="locGeom"></param>
        private void ComputeMinDistance(ILineString line0, ILineString line1, GeometryLocation[] locGeom)
        {
            if (line0.EnvelopeInternal.Distance(line1.EnvelopeInternal) > _minDistance)
            {
                return;
            }
            IList <Coordinate> coord0 = line0.Coordinates;
            IList <Coordinate> coord1 = line1.Coordinates;

            // brute force approach!
            for (int i = 0; i < coord0.Count - 1; i++)
            {
                for (int j = 0; j < coord1.Count - 1; j++)
                {
                    double dist = CgAlgorithms.DistanceLineLine(
                        coord0[i], coord0[i + 1],
                        coord1[j], coord1[j + 1]);
                    if (dist < _minDistance)
                    {
                        _minDistance = dist;
                        LineSegment  seg0      = new LineSegment(coord0[i], coord0[i + 1]);
                        LineSegment  seg1      = new LineSegment(coord1[j], coord1[j + 1]);
                        Coordinate[] closestPt = seg0.ClosestPoints(seg1);
                        locGeom[0] = new GeometryLocation(line0, i, new Coordinate(closestPt[0]));
                        locGeom[1] = new GeometryLocation(line1, j, new Coordinate(closestPt[1]));
                    }
                    if (_minDistance <= _terminateDistance)
                    {
                        return;
                    }
                }
            }
        }
예제 #2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="line"></param>
        /// <param name="pt"></param>
        /// <param name="locGeom"></param>
        private void ComputeMinDistance(ILineString line, Point pt, GeometryLocation[] locGeom)
        {
            if (line.EnvelopeInternal.Distance(pt.EnvelopeInternal) > _minDistance)
            {
                return;
            }
            IList <Coordinate> coord0 = line.Coordinates;
            Coordinate         coord  = pt.Coordinate;

            // brute force approach!
            for (int i = 0; i < coord0.Count - 1; i++)
            {
                double dist = CgAlgorithms.DistancePointLine(coord, coord0[i], coord0[i + 1]);
                if (dist < _minDistance)
                {
                    _minDistance = dist;
                    LineSegment seg             = new LineSegment(coord0[i], coord0[i + 1]);
                    Coordinate  segClosestPoint = new Coordinate(seg.ClosestPoint(coord));
                    locGeom[0] = new GeometryLocation(line, i, segClosestPoint);
                    locGeom[1] = new GeometryLocation(pt, 0, coord);
                }
                if (_minDistance <= _terminateDistance)
                {
                    return;
                }
            }
        }
예제 #3
0
        /// <summary>
        ///
        /// </summary>
        private void ComputeContainmentDistance()
        {
            IList polys0 = PolygonExtracter.GetPolygons(_geom[0]);
            IList polys1 = PolygonExtracter.GetPolygons(_geom[1]);

            GeometryLocation[] locPtPoly = new GeometryLocation[2];
            // test if either point is wholely inside the other
            if (polys1.Count > 0)
            {
                IList insideLocs0 = ConnectedElementLocationFilter.GetLocations(_geom[0]);
                ComputeInside(insideLocs0, polys1, locPtPoly);
                if (_minDistance <= _terminateDistance)
                {
                    _minDistanceLocation[0] = locPtPoly[0];
                    _minDistanceLocation[1] = locPtPoly[1];
                    return;
                }
            }
            if (polys0.Count > 0)
            {
                IList insideLocs1 = ConnectedElementLocationFilter.GetLocations(_geom[1]);
                ComputeInside(insideLocs1, polys0, locPtPoly);
                if (_minDistance <= _terminateDistance)
                {
                    // flip locations, since we are testing geom 1 VS geom 0
                    _minDistanceLocation[0] = locPtPoly[1];
                    _minDistanceLocation[1] = locPtPoly[0];
                    return;
                }
            }
        }
예제 #4
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="ptLoc"></param>
        /// <param name="poly"></param>
        /// <param name="locPtPoly"></param>
        private void ComputeInside(GeometryLocation ptLoc, IGeometry poly, GeometryLocation[] locPtPoly)
        {
            Coordinate pt = ptLoc.Coordinate;

            if (LocationType.Exterior == _ptLocator.Locate(pt, poly))
            {
                return;
            }
            _minDistance = 0.0;
            locPtPoly[0] = ptLoc;
            GeometryLocation locPoly = new GeometryLocation(poly, pt);

            locPtPoly[1] = locPoly;
            return;
        }
예제 #5
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="locs"></param>
 /// <param name="polys"></param>
 /// <param name="locPtPoly"></param>
 private void ComputeInside(IList locs, IList polys, GeometryLocation[] locPtPoly)
 {
     for (int i = 0; i < locs.Count; i++)
     {
         GeometryLocation loc = (GeometryLocation)locs[i];
         for (int j = 0; j < polys.Count; j++)
         {
             Polygon poly = (Polygon)polys[j];
             ComputeInside(loc, poly, locPtPoly);
             if (_minDistance <= _terminateDistance)
             {
                 return;
             }
         }
     }
 }
예제 #6
0
        /// <summary>
        ///
        /// </summary>
        private void ComputeLineDistance()
        {
            GeometryLocation[] locGeom = new GeometryLocation[2];

            /*
             * Geometries are not wholely inside, so compute distance from lines and points
             * of one to lines and points of the other
             */
            IList lines0 = LinearComponentExtracter.GetLines(_geom[0]);
            IList lines1 = LinearComponentExtracter.GetLines(_geom[1]);

            IList pts0 = PointExtracter.GetPoints(_geom[0]);
            IList pts1 = PointExtracter.GetPoints(_geom[1]);

            // bail whenever minDistance goes to zero, since it can't get any less
            ComputeMinDistanceLines(lines0, lines1, locGeom);
            UpdateMinDistance(locGeom, false);
            if (_minDistance <= _terminateDistance)
            {
                return;
            }

            locGeom[0] = null;
            locGeom[1] = null;
            ComputeMinDistanceLinesPoints(lines0, pts1, locGeom);
            UpdateMinDistance(locGeom, false);
            if (_minDistance <= _terminateDistance)
            {
                return;
            }

            locGeom[0] = null;
            locGeom[1] = null;
            ComputeMinDistanceLinesPoints(lines1, pts0, locGeom);
            UpdateMinDistance(locGeom, true);
            if (_minDistance <= _terminateDistance)
            {
                return;
            }

            locGeom[0] = null;
            locGeom[1] = null;
            ComputeMinDistancePoints(pts0, pts1, locGeom);
            UpdateMinDistance(locGeom, false);
        }
예제 #7
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="points0"></param>
 /// <param name="points1"></param>
 /// <param name="locGeom"></param>
 private void ComputeMinDistancePoints(IList points0, IList points1, GeometryLocation[] locGeom)
 {
     for (int i = 0; i < points0.Count; i++)
     {
         Point pt0 = (Point)points0[i];
         for (int j = 0; j < points1.Count; j++)
         {
             Point  pt1  = (Point)points1[j];
             double dist = pt0.Coordinate.Distance(pt1.Coordinate);
             if (dist < _minDistance)
             {
                 _minDistance = dist;
                 // this is wrong - need to determine closest points on both segments!!!
                 locGeom[0] = new GeometryLocation(pt0, 0, pt0.Coordinate);
                 locGeom[1] = new GeometryLocation(pt1, 0, pt1.Coordinate);
             }
             if (_minDistance <= _terminateDistance)
             {
                 return;
             }
         }
     }
 }
예제 #8
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="lines"></param>
 /// <param name="points"></param>
 /// <param name="locGeom"></param>
 private void ComputeMinDistanceLinesPoints(IList lines, IList points, GeometryLocation[] locGeom)
 {
     for (int i = 0; i < lines.Count; i++)
     {
         LineString line = (LineString)lines[i];
         for (int j = 0; j < points.Count; j++)
         {
             Point pt = (Point)points[j];
             ComputeMinDistance(line, pt, locGeom);
             if (_minDistance <= _terminateDistance) return;
         }
     }
 }
예제 #9
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="points0"></param>
 /// <param name="points1"></param>
 /// <param name="locGeom"></param>
 private void ComputeMinDistancePoints(IList points0, IList points1, GeometryLocation[] locGeom)
 {
     for (int i = 0; i < points0.Count; i++)
     {
         Point pt0 = (Point)points0[i];
         for (int j = 0; j < points1.Count; j++)
         {
             Point pt1 = (Point)points1[j];
             double dist = pt0.Coordinate.Distance(pt1.Coordinate);
             if (dist < _minDistance)
             {
                 _minDistance = dist;
                 // this is wrong - need to determine closest points on both segments!!!
                 locGeom[0] = new GeometryLocation(pt0, 0, pt0.Coordinate);
                 locGeom[1] = new GeometryLocation(pt1, 0, pt1.Coordinate);
             }
             if (_minDistance <= _terminateDistance) return;
         }
     }
 }
예제 #10
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="lines0"></param>
 /// <param name="lines1"></param>
 /// <param name="locGeom"></param>
 private void ComputeMinDistanceLines(IList lines0, IList lines1, GeometryLocation[] locGeom)
 {
     for (int i = 0; i < lines0.Count; i++)
     {
         LineString line0 = (LineString)lines0[i];
         for (int j = 0; j < lines1.Count; j++)
         {
             LineString line1 = (LineString)lines1[j];
             ComputeMinDistance(line0, line1, locGeom);
             if (_minDistance <= _terminateDistance) return;
         }
     }
 }
예제 #11
0
        /// <summary>
        ///
        /// </summary>
        private void ComputeLineDistance()
        {
            GeometryLocation[] locGeom = new GeometryLocation[2];

            /*
             * Geometries are not wholely inside, so compute distance from lines and points
             * of one to lines and points of the other
             */
            IList lines0 = LinearComponentExtracter.GetLines(_geom[0]);
            IList lines1 = LinearComponentExtracter.GetLines(_geom[1]);

            IList pts0 = PointExtracter.GetPoints(_geom[0]);
            IList pts1 = PointExtracter.GetPoints(_geom[1]);

            // bail whenever minDistance goes to zero, since it can't get any less
            ComputeMinDistanceLines(lines0, lines1, locGeom);
            UpdateMinDistance(locGeom, false);
            if (_minDistance <= _terminateDistance) return;

            locGeom[0] = null;
            locGeom[1] = null;
            ComputeMinDistanceLinesPoints(lines0, pts1, locGeom);
            UpdateMinDistance(locGeom, false);
            if (_minDistance <= _terminateDistance) return;

            locGeom[0] = null;
            locGeom[1] = null;
            ComputeMinDistanceLinesPoints(lines1, pts0, locGeom);
            UpdateMinDistance(locGeom, true);
            if (_minDistance <= _terminateDistance) return;

            locGeom[0] = null;
            locGeom[1] = null;
            ComputeMinDistancePoints(pts0, pts1, locGeom);
            UpdateMinDistance(locGeom, false);
        }
예제 #12
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="ptLoc"></param>
 /// <param name="poly"></param>
 /// <param name="locPtPoly"></param>
 private void ComputeInside(GeometryLocation ptLoc, IGeometry poly, GeometryLocation[] locPtPoly)
 {
     Coordinate pt = ptLoc.Coordinate;
     if (LocationType.Exterior == _ptLocator.Locate(pt, poly)) return;
     _minDistance = 0.0;
     locPtPoly[0] = ptLoc;
     GeometryLocation locPoly = new GeometryLocation(poly, pt);
     locPtPoly[1] = locPoly;
     return;
 }
예제 #13
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="locs"></param>
 /// <param name="polys"></param>
 /// <param name="locPtPoly"></param>
 private void ComputeInside(IList locs, IList polys, GeometryLocation[] locPtPoly)
 {
     for (int i = 0; i < locs.Count; i++)
     {
         GeometryLocation loc = (GeometryLocation)locs[i];
         for (int j = 0; j < polys.Count; j++)
         {
             Polygon poly = (Polygon)polys[j];
             ComputeInside(loc, poly, locPtPoly);
             if (_minDistance <= _terminateDistance)
                 return;
         }
     }
 }
예제 #14
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="locGeom"></param>
 /// <param name="flip"></param>
 private void UpdateMinDistance(GeometryLocation[] locGeom, bool flip)
 {
     // if not set then don't update
     if (locGeom[0] == null)
         return;
     if (flip)
     {
         _minDistanceLocation[0] = locGeom[1];
         _minDistanceLocation[1] = locGeom[0];
     }
     else
     {
         _minDistanceLocation[0] = locGeom[0];
         _minDistanceLocation[1] = locGeom[1];
     }
 }
예제 #15
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="line0"></param>
 /// <param name="line1"></param>
 /// <param name="locGeom"></param>
 private void ComputeMinDistance(ILineString line0, ILineString line1, GeometryLocation[] locGeom)
 {
     if (line0.EnvelopeInternal.Distance(line1.EnvelopeInternal) > _minDistance) return;
     IList<Coordinate> coord0 = line0.Coordinates;
     IList<Coordinate> coord1 = line1.Coordinates;
     // brute force approach!
     for (int i = 0; i < coord0.Count - 1; i++)
     {
         for (int j = 0; j < coord1.Count - 1; j++)
         {
             double dist = CgAlgorithms.DistanceLineLine(
                                             coord0[i], coord0[i + 1],
                                             coord1[j], coord1[j + 1]);
             if (dist < _minDistance)
             {
                 _minDistance = dist;
                 LineSegment seg0 = new LineSegment(coord0[i], coord0[i + 1]);
                 LineSegment seg1 = new LineSegment(coord1[j], coord1[j + 1]);
                 Coordinate[] closestPt = seg0.ClosestPoints(seg1);
                 locGeom[0] = new GeometryLocation(line0, i, new Coordinate(closestPt[0]));
                 locGeom[1] = new GeometryLocation(line1, j, new Coordinate(closestPt[1]));
             }
             if (_minDistance <= _terminateDistance) return;
         }
     }
 }
예제 #16
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="line"></param>
 /// <param name="pt"></param>
 /// <param name="locGeom"></param>
 private void ComputeMinDistance(ILineString line, Point pt, GeometryLocation[] locGeom)
 {
     if (line.EnvelopeInternal.Distance(pt.EnvelopeInternal) > _minDistance) return;
     IList<Coordinate> coord0 = line.Coordinates;
     Coordinate coord = pt.Coordinate;
     // brute force approach!
     for (int i = 0; i < coord0.Count - 1; i++)
     {
         double dist = CgAlgorithms.DistancePointLine(coord, coord0[i], coord0[i + 1]);
         if (dist < _minDistance)
         {
             _minDistance = dist;
             LineSegment seg = new LineSegment(coord0[i], coord0[i + 1]);
             Coordinate segClosestPoint = new Coordinate(seg.ClosestPoint(coord));
             locGeom[0] = new GeometryLocation(line, i, segClosestPoint);
             locGeom[1] = new GeometryLocation(pt, 0, coord);
         }
         if (_minDistance <= _terminateDistance) return;
     }
 }
예제 #17
0
        /// <summary>
        ///
        /// </summary>
        private void ComputeContainmentDistance()
        {
            IList polys0 = PolygonExtracter.GetPolygons(_geom[0]);
            IList polys1 = PolygonExtracter.GetPolygons(_geom[1]);

            GeometryLocation[] locPtPoly = new GeometryLocation[2];
            // test if either point is wholely inside the other
            if (polys1.Count > 0)
            {
                IList insideLocs0 = ConnectedElementLocationFilter.GetLocations(_geom[0]);
                ComputeInside(insideLocs0, polys1, locPtPoly);
                if (_minDistance <= _terminateDistance)
                {
                    _minDistanceLocation[0] = locPtPoly[0];
                    _minDistanceLocation[1] = locPtPoly[1];
                    return;
                }
            }
            if (polys0.Count > 0)
            {
                IList insideLocs1 = ConnectedElementLocationFilter.GetLocations(_geom[1]);
                ComputeInside(insideLocs1, polys0, locPtPoly);
                if (_minDistance <= _terminateDistance)
                {
                    // flip locations, since we are testing geom 1 VS geom 0
                    _minDistanceLocation[0] = locPtPoly[1];
                    _minDistanceLocation[1] = locPtPoly[0];
                    return;
                }
            }
        }