Esempio n. 1
0
 /**
  * Find the the union of this rectangle and the passed rectangle.
  * Neither rectangle is altered
  * 
  * @param r The rectangle to union with this rectangle
  */
 internal Rectangle union(Rectangle r)
 {
     Rectangle union = this.copy();
     union.add(r);
     return union;
 }
        public void ExecuteIntersectionQuery(SharpMap.Geometries.BoundingBox box, SharpMap.Data.FeatureDataSet ds)
        {
            Rectangle r = new Rectangle((float)box.Left, (float)box.Bottom, (float)box.Right, (float)box.Top, (float)0.0, (float)0.0);
            FdoFeature[] matches = _data.Intersects(r);

            FeatureDataTable table = new FeatureDataTable();
            foreach (DataColumn col in _data.Columns)
            {
                table.Columns.Add(col.ColumnName, col.DataType, col.Expression);
            }

            //Filter the initial result set by inverting the operands. This weeds out non-matches on point intersection tests.
            IEnvelope env = Converter.EnvelopeFromBoundingBox(box);
            FdoGeometry poly = new FdoGeometry(Converter.CreatePolygonFromEnvelope(env));
            foreach (FdoFeature feat in matches)
            {
                FdoGeometry geom = feat.DesignatedGeometry;
                if (geom != null)
                {
                    if (geom.Contains(env) || geom.Intersects(poly))
                    {
                        FeatureDataRow row = table.NewRow();
                        bool add = true;
                        foreach (DataColumn col in _data.Columns)
                        {
                            if (col.ColumnName == _data.GeometryColumn)
                            {
                                try
                                {
                                    row.Geometry = Converter.FromFdoGeometry(geom, _geomFactory);
                                }
                                catch //Can't help you if you fail conversion.
                                {
                                    add = false;
                                }
                            }
                            else
                            {
                                row[col.ColumnName] = feat[col.ColumnName];
                            }
                        }
                        if (add)
                            table.AddRow(row);
                    }
                }
            }
            ds.Tables.Add(table);
        }
Esempio n. 3
0
        /**
         * Calculate the area by which this rectangle would be enlarged if
         * added to the passed rectangle. Neither rectangle is altered.
         * 
         * @param r Rectangle to union with this rectangle, in order to 
         *          compute the difference in area of the union and the
         *          original rectangle
         */
        internal float enlargement(Rectangle r)
        {
            float enlargedArea = (Math.Max(max[0], r.max[0]) - Math.Min(min[0], r.min[0])) *
                                 (Math.Max(max[1], r.max[1]) - Math.Min(min[1], r.min[1]));

            return enlargedArea - area();
        }
Esempio n. 4
0
 /**
  * Computes the union of this rectangle and the passed rectangle, storing
  * the result in this rectangle.
  * 
  * @param r Rectangle to add to this rectangle
  */
 internal void add(Rectangle r)
 {
     for (int i = 0; i < DIMENSIONS; i++)
     {
         if (r.min[i] < min[i])
         {
             min[i] = r.min[i];
         }
         if (r.max[i] > max[i])
         {
             max[i] = r.max[i];
         }
     }
 }
Esempio n. 5
0
        /**
         * Return the furthst possible distance between this rectangle and
         * the passed rectangle. 
         * 
         * Find the distance between this rectangle and each corner of the
         * passed rectangle, and use the maximum.
         *
         */
        internal float furthestDistance(Rectangle r)
        {
            float distanceSquared = 0;

            for (int i = 0; i < DIMENSIONS; i++)
            {
                distanceSquared += Math.Max(r.min[i], r.max[i]);
#warning possible didn't convert properly
                //distanceSquared += Math.Max(distanceSquared(i, r.min[i]), distanceSquared(i, r.max[i]));
            }

            return (float)Math.Sqrt(distanceSquared);
        }
Esempio n. 6
0
        /**
         * Return the distance between this rectangle and the passed rectangle.
         * If the rectangles overlap, the distance is zero.
         * 
         * @param r Rectangle to find the distance to
         * 
         * @return distance between this rectangle and the passed rectangle
         */

        internal float distance(Rectangle r)
        {
            float distanceSquared = 0;
            for (int i = 0; i < DIMENSIONS; i++)
            {
                float greatestMin = Math.Max(min[i], r.min[i]);
                float leastMax = Math.Min(max[i], r.max[i]);
                if (greatestMin > leastMax)
                {
                    distanceSquared += ((greatestMin - leastMax) * (greatestMin - leastMax));
                }
            }
            return (float)Math.Sqrt(distanceSquared);
        }
Esempio n. 7
0
 /**
  * Determine whether this rectangle is contained by the passed rectangle
  * 
  * @param r The rectangle that might contain this rectangle
  * 
  * @return true if the passed rectangle contains this rectangle, false if
  *         it does not
  */
 internal bool containedBy(Rectangle r)
 {
     for (int i = 0; i < DIMENSIONS; i++)
     {
         if (max[i] > r.max[i] || min[i] < r.min[i])
         {
             return false;
         }
     }
     return true;
 }
Esempio n. 8
0
 /**
  * Determine whether this rectangle intersects the passed rectangle
  * 
  * @param r The rectangle that might intersect this rectangle
  * 
  * @return true if the rectangles intersect, false if they do not intersect
  */
 internal bool intersects(Rectangle r)
 {
     // Every dimension must intersect. If any dimension
     // does not intersect, return false immediately.
     for (int i = 0; i < DIMENSIONS; i++)
     {
         if (max[i] < r.min[i] || min[i] > r.max[i])
         {
             return false;
         }
     }
     return true;
 }
Esempio n. 9
0
 /**
  * Determine whether an edge of this rectangle overlies the equivalent 
  * edge of the passed rectangle
  */
 internal bool edgeOverlaps(Rectangle r)
 {
     for (int i = 0; i < DIMENSIONS; i++)
     {
         if (min[i] == r.min[i] || max[i] == r.max[i])
         {
             return true;
         }
     }
     return false;
 }