internal void Delete()
        {
            try { DB.Connection.ExecuteNonQuery("DELETE FROM " + Table + " WHERE " + Columns.Id + "=" + _id); }
            catch (Exception ex) { Console.Out.WriteLine("Error deleting area:  " + ex.Message); }

            try { DB.Connection.ExecuteNonQuery("DROP TABLE " + AreaBoundingBoxes.GetTableName(this)); }
            catch (Exception ex) { Console.Out.WriteLine("Error deleting area bounding boxes:  " + ex.Message); }

            try { DB.Connection.ExecuteNonQuery("DROP TABLE " + Incident.GetTableName(this, true)); }
            catch (Exception ex) { Console.Out.WriteLine("Error deleting incident table:  " + ex.Message); }
        }
        internal string GetIntersectsCondition(string entityColumn)
        {
            string areaBoundingBoxesTable = AreaBoundingBoxes.GetTableName(this);
            string areaBoundingBoxesRelationshipColumn = areaBoundingBoxesTable + "." + AreaBoundingBoxes.Columns.Relationship;

            return("EXISTS (SELECT 1 " +
                   "FROM " + areaBoundingBoxesTable + "," + _shapefile.GeometryTable + " " +
                   "WHERE st_intersects(" + entityColumn + "," + areaBoundingBoxesTable + "." + AreaBoundingBoxes.Columns.BoundingBox + ") AND " +
                   "(" +
                   areaBoundingBoxesRelationshipColumn + "='" + AreaBoundingBoxes.Relationship.Within + "' OR " +
                   "(" +
                   areaBoundingBoxesRelationshipColumn + "='" + AreaBoundingBoxes.Relationship.Overlaps + "' AND " +
                   "st_intersects(" + entityColumn + "," + _shapefile.GeometryTable + "." + ShapefileGeometry.Columns.Geometry + ")" +                    // this is the slow operation, so we're hiding it behind simpler checks as much as possible
                   ")" +
                   ")" +
                   ")");
        }
        public static Area Create(Shapefile shapefile, string name, int pointContainmentBoundingBoxSize)
        {
            Area area = null;

            try
            {
                area = new Area(Convert.ToInt32(DB.Connection.ExecuteScalar("INSERT INTO " + Area.Table + " (" + Columns.Insert + ") VALUES ('" + name + "'," + shapefile.Id + ") RETURNING " + Columns.Id)));

                AreaBoundingBoxes.Create(area, pointContainmentBoundingBoxSize);

                return(area);
            }
            catch (Exception ex)
            {
                try { area.Delete(); }
                catch (Exception ex2) { Console.Out.WriteLine("Failed to delete area:  " + ex2.Message); }

                throw ex;
            }
        }