public static void Create(Shapefile shapefile, List<Tuple<Geometry, DateTime>> geometryTimes)
        {
            if (geometryTimes.Count == 0)
                return;

            DB.Connection.ExecuteNonQuery(
                "CREATE TABLE " + shapefile.GeometryTable + " (" +
                Columns.Geometry + " GEOMETRY(GEOMETRY," + shapefile.SRID + ")," +
                Columns.Id + " SERIAL PRIMARY KEY," +
                Columns.Time + " TIMESTAMP);" +
                "CREATE INDEX ON " + shapefile.GeometryTable + " USING GIST (" + Columns.Geometry + ");" +
                "CREATE INDEX ON " + shapefile.GeometryTable + " (" + Columns.Time + ");");

            int numPerBatch = 1000;
            int num = 0;
            StringBuilder cmdTxt = new StringBuilder();
            List<Parameter> cmdParams = new List<Parameter>(numPerBatch);
            NpgsqlCommand cmd = DB.Connection.NewCommand(null);
            foreach (Tuple<Geometry, DateTime> geometryTime in geometryTimes)
            {
                string timeParamName = "time_" + num;
                cmdTxt.Append((cmdTxt.Length == 0 ? "INSERT INTO " + shapefile.GeometryTable + " (" + Columns.Insert + ") VALUES " : ",") + "(" + GetValue(geometryTime.Item1, shapefile.SRID, timeParamName) + ")");
                cmdParams.Add(new Parameter(timeParamName, NpgsqlTypes.NpgsqlDbType.Timestamp, geometryTime.Item2));

                if (++num == numPerBatch)
                {
                    cmd.CommandText = cmdTxt.ToString();
                    ConnectionPool.AddParameters(cmd, cmdParams);
                    cmd.ExecuteNonQuery();
                    cmdTxt.Clear();
                    cmdParams.Clear();
                    cmd.CommandText = null;
                    num = 0;
                }
            }

            if (num > 0)
            {
                cmd.CommandText = cmdTxt.ToString();
                ConnectionPool.AddParameters(cmd, cmdParams);
                cmd.ExecuteNonQuery();
                cmdTxt.Clear();
                cmdParams.Clear();
                cmd.CommandText = null;
                num = 0;
            }
        }
        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;
            }
        }
        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;
            }
        }
        private void Construct(NpgsqlDataReader reader)
        {
            _id = Convert.ToInt32(reader[Table + "_" + Columns.Id]);
            _name = Convert.ToString(reader[Table + "_" + Columns.Name]);
            _shapefile = new Shapefile(Convert.ToInt32(reader[Table + "_" + Columns.ShapefileId]));

            NpgsqlCommand cmd = DB.Connection.NewCommand("SELECT " +
                                                         "st_xmin(" + ShapefileGeometry.Columns.Geometry + ") as left," +
                                                         "st_xmax(" + ShapefileGeometry.Columns.Geometry + ") as right," +
                                                         "st_ymin(" + ShapefileGeometry.Columns.Geometry + ") as bottom," +
                                                         "st_ymax(" + ShapefileGeometry.Columns.Geometry + ") as top " +
                                                         "FROM " + _shapefile.GeometryTable);
            reader = cmd.ExecuteReader();

            double left = double.MaxValue;
            double right = double.MinValue;
            double bottom = double.MaxValue;
            double top = double.MinValue;
            while (reader.Read())
            {
                double l = Convert.ToDouble(reader["left"]);
                if (l < left)
                    left = l;

                double r = Convert.ToDouble(reader["right"]);
                if (r > right)
                    right = r;

                double b = Convert.ToDouble(reader["bottom"]);
                if (b < bottom)
                    bottom = b;

                double t = Convert.ToDouble(reader["top"]);
                if (t > top)
                    top = t;
            }

            reader.Close();
            DB.Connection.Return(cmd.Connection);

            _boundingBox = new PostGIS.Polygon(new PostGIS.LineString(new List<PostGIS.Point>(new PostGIS.Point[]{
                               new PostGIS.Point(left, top, _shapefile.SRID),
                               new PostGIS.Point(right, top, _shapefile.SRID),
                               new PostGIS.Point(right, bottom, _shapefile.SRID),
                               new PostGIS.Point(left, bottom, _shapefile.SRID),
                               new PostGIS.Point(left, top, _shapefile.SRID)}), _shapefile.SRID), _shapefile.SRID);
        }
 public static List<Area> GetForShapefile(Shapefile shapefile)
 {
     return GetAll().Where(a => a.Shapefile.Id == shapefile.Id).ToList();
 }
 public static List <Area> GetForShapefile(Shapefile shapefile)
 {
     return(GetAll().Where(a => a.Shapefile.Id == shapefile.Id).ToList());
 }