Beispiel #1
0
        /// <summary>
        /// Gets the indeces of gridblocks where the centers are contained in the polygon
        /// </summary>
        /// <param name="Polygon"></param>
        /// <returns></returns>
        public List <Tuple <int, int> > GetSubSet(IXYPolygon Polygon)
        {
            List <Tuple <int, int> > toreturn = new List <Tuple <int, int> >();

            List <XYPolygon> pols = new List <XYPolygon>();

            if (Polygon is XYPolygon)
            {
                pols.Add((XYPolygon)Polygon);
            }
            else if (Polygon is MultiPartPolygon)
            {
                pols.AddRange(((MultiPartPolygon)Polygon).Polygons);
            }

            foreach (var pol in pols)
            {
                var bbox = pol.BoundingBox;

                for (int i = GetRowIndex(bbox.Points.Min(p => p.Y)); i <= GetRowIndex(bbox.Points.Max(p => p.Y)); i++)
                {
                    for (int j = GetColumnIndex(bbox.Points.Min(p => p.X)); j <= GetColumnIndex(bbox.Points.Max(p => p.X)); j++)
                    {
                        if (pol.Contains(GetXCenter(j), GetYCenter(i)))
                        {
                            toreturn.Add(new Tuple <int, int>(j, i));
                        }
                    }
                }
            }
            return(toreturn);
        }
Beispiel #2
0
        /// <summary>
        /// Returns true if the polygon is inside or on the edge of this polygon
        /// </summary>
        /// <param name="p"></param>
        /// <returns></returns>
        public bool Contains(IXYPolygon p)
        {
            IEnumerable <IXYPoint> points;

            if (p is XYPolygon)
            {
                points = ((XYPolygon)p).Points;
            }
            else if (p is MultiPartPolygon)
            {
                points = ((MultiPartPolygon)p).Polygons.SelectMany(pp => pp.Points);
            }
            else
            {
                return(false);
            }

            //First check that all points are within the bounding box
            foreach (var point in points)
            {
                if (!XYGeometryTools.IsPointInPolygonOrOnEdge(point.X, point.Y, BoundingBox))
                {
                    return(false);
                }
            }
            foreach (var point in points)
            {
                if (!XYGeometryTools.IsPointInPolygonOrOnEdge(point.X, point.Y, this))
                {
                    return(false);
                }
            }
            return(true);
        }
        public static double CalculateSharedArea(IXYPolygon polygonA, IXYPolygon polygonB)
        {
            double area = 0;

            if (polygonA is XYPolygon & polygonB is XYPolygon)
            {
                area = ClipperTools.GetIntersection((XYPolygon)polygonA, (XYPolygon)polygonB).GetArea();
            }
            else if (polygonA is MultiPartPolygon & polygonB is XYPolygon)
            {
                foreach (XYPolygon poly in ((MultiPartPolygon)polygonA).Polygons)
                {
                    area += ClipperTools.GetIntersection(poly, (XYPolygon)polygonB).GetArea();
                }
            }
            else if (polygonA is XYPolygon & polygonB is MultiPartPolygon)
            {
                foreach (XYPolygon poly in ((MultiPartPolygon)polygonB).Polygons)
                {
                    area += ClipperTools.GetIntersection(poly, (XYPolygon)polygonA).GetArea();
                }
            }
            else if (polygonA is MultiPartPolygon & polygonB is MultiPartPolygon)
            {
                foreach (XYPolygon poly in ((MultiPartPolygon)polygonA).Polygons)
                {
                    foreach (XYPolygon polyb in ((MultiPartPolygon)polygonB).Polygons)
                    {
                        area += ClipperTools.GetIntersection(poly, polyb).GetArea();
                    }
                }
            }
            return(area);
        }
Beispiel #4
0
        public void ContainsTest()
        {
            using (Geometry.Shapes.ShapeReader sr = new Geometry.Shapes.ShapeReader(@"f:\NitrateModel\Overfladevand\oplande\mors.shp"))
            {
                IXYPolygon geo = (IXYPolygon)sr.ReadNext(0);

                Assert.IsTrue(geo.Contains(494131.00000000000, 6309279.00000000000));
            }
        }
    /// <summary>
    /// Returns true if the polygon is inside or on the edge of this polygon
    /// </summary>
    /// <param name="p"></param>
    /// <returns></returns>
    public bool Contains(IXYPolygon p)
    {
      var inner = Polygons.Where(po => po.GetArea() > 0).Any(poly => poly.Contains(p));

      if (inner)
      {
        return !Polygons.Where(po => po.GetArea() < 0).Any(poly => poly.Contains(p));
      }
      return false;
    }
Beispiel #6
0
        /// <summary>
        /// Returns true if the polygon is inside or on the edge of this polygon
        /// </summary>
        /// <param name="p"></param>
        /// <returns></returns>
        public bool Contains(IXYPolygon p)
        {
            var inner = Polygons.Where(po => po.GetArea() > 0).Any(poly => poly.Contains(p));

            if (inner)
            {
                return(!Polygons.Where(po => po.GetArea() < 0).Any(poly => poly.Contains(p)));
            }
            return(false);
        }
Beispiel #7
0
 /// <summary>
 /// Returns true if there is an overlap between this polygon and Poly
 /// </summary>
 /// <param name="Poly"></param>
 /// <returns></returns>
 public bool OverLaps(IXYPolygon Poly)
 {
     if (Poly is XYPolygon)
     {
         return(OverLaps(Poly as XYPolygon));
     }
     else if (Poly is MultiPartPolygon)
     {
         return(((MultiPartPolygon)Poly).Polygons.Any(po => po.OverLaps(this)));
     }
     else
     {
         return(false);
     }
 }
Beispiel #8
0
    /// <summary>
    /// Gets the indeces of gridblocks where the centers are contained in the polygon
    /// </summary>
    /// <param name="Polygon"></param>
    /// <returns></returns>
    public List<Tuple<int, int>> GetSubSet(IXYPolygon Polygon)
    {
      List<Tuple<int, int>> toreturn = new List<Tuple<int, int>>();

      List<XYPolygon> pols = new List<XYPolygon>();
      if(Polygon is XYPolygon)
        pols.Add((XYPolygon)Polygon);
      else if (Polygon is MultiPartPolygon)
        pols.AddRange( ((MultiPartPolygon)Polygon).Polygons);

      foreach(var pol in pols)
      {
        var bbox = pol.BoundingBox;

        for(int i = GetRowIndex(bbox.Points.Min(p=>p.Y));i<=GetRowIndex(bbox.Points.Max(p=>p.Y));i++)
        {
          for (int j = GetColumnIndex(bbox.Points.Min(p => p.X)); j <= GetColumnIndex(bbox.Points.Max(p => p.X)); j++)
          {
            if (pol.Contains(GetXCenter(j), GetYCenter(i)))
              toreturn.Add(new Tuple<int, int>(j, i));
          }
        }
      }
      return toreturn;
    }
 public static double CalculateSharedArea(IXYPolygon polygonA, IXYPolygon polygonB)
 {
   double area = 0;
   if (polygonA is XYPolygon & polygonB is XYPolygon)
     area = ClipperTools.GetIntersection((XYPolygon)polygonA, (XYPolygon)polygonB).GetArea();
   else if (polygonA is MultiPartPolygon & polygonB is XYPolygon)
   {
     foreach (XYPolygon poly in ((MultiPartPolygon)polygonA).Polygons)
       area += ClipperTools.GetIntersection(poly, (XYPolygon)polygonB).GetArea();
   }
   else if (polygonA is XYPolygon & polygonB is MultiPartPolygon)
   {
     foreach (XYPolygon poly in ((MultiPartPolygon)polygonB).Polygons)
       area += ClipperTools.GetIntersection(poly, (XYPolygon)polygonA).GetArea();
   }
   else if (polygonA is MultiPartPolygon & polygonB is MultiPartPolygon)
   {
     foreach (XYPolygon poly in ((MultiPartPolygon)polygonA).Polygons)
       foreach (XYPolygon polyb in ((MultiPartPolygon)polygonB).Polygons)
         area += ClipperTools.GetIntersection(poly, polyb).GetArea();
   }
   return area;
 }
Beispiel #10
0
    /// <summary>
    /// Returns true if the polygon is inside or on the edge of this polygon
    /// </summary>
    /// <param name="p"></param>
    /// <returns></returns>
    public bool Contains(IXYPolygon p)
    {
      IEnumerable<IXYPoint> points;
      if (p is XYPolygon)
        points = ((XYPolygon)p).Points;
      else if (p is MultiPartPolygon)
        points = ((MultiPartPolygon)p).Polygons.SelectMany(pp => pp.Points);
      else return false;

      //First check that all points are within the bounding box
      foreach (var point in points)
      {
        if (!XYGeometryTools.IsPointInPolygonOrOnEdge(point.X, point.Y, BoundingBox)) 
          return false;
      }
      foreach (var point in points)
      {
        if (!XYGeometryTools.IsPointInPolygonOrOnEdge(point.X, point.Y, this))
          return false;
      }
      return true;
    }
Beispiel #11
0
 /// <summary>
 /// Returns true if there is an overlap between this polygon and Poly
 /// </summary>
 /// <param name="Poly"></param>
 /// <returns></returns>
 public bool OverLaps(IXYPolygon Poly)
 {
   if (Poly is XYPolygon)
     return OverLaps(Poly as XYPolygon);
   else if (Poly is MultiPartPolygon)
     return ((MultiPartPolygon)Poly).Polygons.Any(po=>po.OverLaps(this));
   else
     return false;
 }
 public bool OverLaps(IXYPolygon Poly)
 {
   return Polygons.Any(poly => poly.OverLaps(Poly));
 }
Beispiel #13
0
 public bool OverLaps(IXYPolygon Poly)
 {
     return(Polygons.Any(poly => poly.OverLaps(Poly)));
 }