Exemplo n.º 1
0
        private void ComputeMinDistancePoints(IGeometryList points0,
                                              IGeometryList points1, DistanceLocation[] locGeom)
        {
            int nCount0 = points0.Count;
            int nCount1 = points1.Count;

            for (int i = 0; i < nCount0; i++)
            {
                Point pt0 = (Point)points0[i];
                for (int j = 0; j < nCount1; 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 DistanceLocation(pt0, 0, pt0.Coordinate);
                        locGeom[1] = new DistanceLocation(pt1, 0, pt1.Coordinate);
                    }
                    if (minDistance <= terminateDistance)
                    {
                        return;
                    }
                }
            }
        }
Exemplo n.º 2
0
        private void ComputeMinDistance(LineString line, Point pt,
                                        DistanceLocation[] locGeom)
        {
            if (line.Bounds.Distance(pt.Bounds) > minDistance)
            {
                return;
            }

            ICoordinateList coord0 = line.Coordinates;
            Coordinate      coord  = pt.Coordinate;

            // brute force approach!
            int nCount0 = coord0.Count;

            for (int i = 0; i < nCount0 - 1; i++)
            {
                double dist = CGAlgorithms.DistancePointLine(coord, coord0[i], coord0[i + 1]);
                if (dist < minDistance)
                {
                    minDistance = dist;
                    LineSegment seg =
                        new LineSegment(m_objFactory, coord0[i], coord0[i + 1]);
                    Coordinate segClosestPoint = seg.ClosestPoint(coord);
                    locGeom[0] = new DistanceLocation(line, i, segClosestPoint);
                    locGeom[1] = new DistanceLocation(pt, 0, coord);
                }

                if (minDistance <= terminateDistance)
                {
                    return;
                }
            }
        }
Exemplo n.º 3
0
        private void ComputeContainmentDistance()
        {
            IGeometryList polys0 = PolygonExtracter.GetPolygons(geom[0]);
            IGeometryList polys1 = PolygonExtracter.GetPolygons(geom[1]);

            DistanceLocation[] locPtPoly = new DistanceLocation[2];
            // test if either geometry 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;
                }
            }
        }
Exemplo n.º 4
0
        private void ComputeInside(DistanceLocation ptLoc, Polygon poly,
                                   DistanceLocation[] locPtPoly)
        {
            Coordinate pt = ptLoc.Coordinate;

            if (LocationType.Exterior != ptLocator.Locate(pt, poly))
            {
                minDistance  = 0.0;
                locPtPoly[0] = ptLoc;
                DistanceLocation locPoly = new DistanceLocation(poly, pt);
                locPtPoly[1] = locPoly;
                return;
            }
        }
Exemplo n.º 5
0
        private void ComputeLineDistance()
        {
            DistanceLocation[] locGeom = new DistanceLocation[2];

            /// <summary> Geometries are not wholely inside, so compute Distance from lines and points
            /// of one to lines and points of the other
            /// </summary>
            IGeometryList lines0 = LineStringExtracter.GetLines(geom[0]);
            IGeometryList lines1 = LineStringExtracter.GetLines(geom[1]);

            IGeometryList pts0 = PointExtracter.GetPoints(geom[0]);
            IGeometryList 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);
        }
Exemplo n.º 6
0
        private void ComputeInside(IList locs,
                                   IGeometryList polys, DistanceLocation[] locPtPoly)
        {
            int nLocs  = locs.Count;
            int nPolys = polys.Count;

            for (int i = 0; i < nLocs; i++)
            {
                DistanceLocation loc = (DistanceLocation)locs[i];
                for (int j = 0; j < nPolys; j++)
                {
                    Polygon poly = (Polygon)polys[j];
                    ComputeInside(loc, poly, locPtPoly);
                    if (minDistance <= terminateDistance)
                    {
                        return;
                    }
                }
            }
        }
Exemplo n.º 7
0
        private void ComputeMinDistance(LineString line0, LineString line1, DistanceLocation[] locGeom)
        {
            if (line0.Bounds.Distance(line1.Bounds) > minDistance)
            {
                return;
            }

            ICoordinateList coord0 = line0.Coordinates;
            ICoordinateList coord1 = line1.Coordinates;

            // brute force approach!
            int nCount0 = coord0.Count;
            int nCount1 = coord1.Count;

            for (int i = 0; i < nCount0 - 1; i++)
            {
                for (int j = 0; j < nCount1 - 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(m_objFactory, coord0[i], coord0[i + 1]);

                        LineSegment seg1 =
                            new LineSegment(m_objFactory, coord1[j], coord1[j + 1]);

                        Coordinate[] closestPt = seg0.ClosestPoints(seg1);
                        locGeom[0] = new DistanceLocation(line0, i, closestPt[0]);
                        locGeom[1] = new DistanceLocation(line1, j, closestPt[1]);
                    }
                    if (minDistance <= terminateDistance)
                    {
                        return;
                    }
                }
            }
        }