Beispiel #1
0
        /// <summary>
        /// Returns the features that intersects with 'geom'
        /// </summary>
        /// <param name="geom"></param>
        /// <param name="ds">FeatureDataSet to fill data into</param>
        protected override void OnExecuteIntersectionQuery(IGeometry geom, FeatureDataSet ds)
        {
            //List<Geometry> features = new List<Geometry>();
            using (var conn = new SqlConnection(ConnectionString))
            {
                //TODO: Convert to SQL Server
                string strGeom = _spatialObject + "::STGeomFromText('" + geom.AsText() + "', #SRID#)";

                strGeom = strGeom.Replace("#SRID#", SRID > 0 ? SRID.ToString() : "0");
                strGeom = GeometryColumn + ".STIntersects(" + strGeom + ") = 1";

                string strSQL = "SELECT g.* , g." + GeometryColumn + ".STAsBinary() As sharpmap_tempgeometry FROM " + Table + " g " + BuildTableHints() + " WHERE ";

                if (!String.IsNullOrEmpty(_definitionQuery))
                {
                    strSQL += DefinitionQuery + " AND ";
                }

                strSQL += strGeom;

                string extraOptions = GetExtraOptions();
                if (!string.IsNullOrEmpty(extraOptions))
                {
                    strSQL += " " + extraOptions;
                }


                using (SqlDataAdapter adapter = new SqlDataAdapter(strSQL, conn))
                {
                    conn.Open();
                    adapter.Fill(ds);
                    conn.Close();
                    if (ds.Tables.Count > 0)
                    {
                        FeatureDataTable fdt = new FeatureDataTable(ds.Tables[0]);
                        foreach (System.Data.DataColumn col in ds.Tables[0].Columns)
                        {
                            if (col.ColumnName != GeometryColumn && col.ColumnName != "sharpmap_tempgeometry")
                            {
                                fdt.Columns.Add(col.ColumnName, col.DataType, col.Expression);
                            }
                        }
                        foreach (System.Data.DataRow dr in ds.Tables[0].Rows)
                        {
                            FeatureDataRow fdr = fdt.NewRow();
                            foreach (System.Data.DataColumn col in ds.Tables[0].Columns)
                            {
                                if (col.ColumnName != GeometryColumn && col.ColumnName != "sharpmap_tempgeometry")
                                {
                                    fdr[col.ColumnName] = dr[col];
                                }
                            }
                            fdr.Geometry = Converters.WellKnownBinary.GeometryFromWKB.Parse((byte[])dr["sharpmap_tempgeometry"], Factory);
                            fdt.AddRow(fdr);
                        }
                        ds.Tables.Add(fdt);
                    }
                }
            }
        }
Beispiel #2
0
        /// <summary>
        /// Returns the features that intersects with 'geom'
        /// </summary>
        /// <param name="geom"></param>
        /// <param name="ds">FeatureDataSet to fill data into</param>
        protected override void OnExecuteIntersectionQuery(Geometry geom, FeatureDataSet ds)
        {
            using (var conn = new OracleConnection(ConnectionString))
            {
                string strGeom = "MDSYS.SDO_GEOMETRY('" + geom.AsText() + "', #SRID#)";

                strGeom = strGeom.Replace("#SRID#", SRID > 0 ? SRID.ToString(Map.NumberFormatEnUs) : "NULL");

                strGeom = "SDO_RELATE(g." + GeometryColumn + ", " + strGeom +
                          ", 'mask=ANYINTERACT querytype=WINDOW') = 'TRUE'";

                string strSql = "SELECT * FROM " +
                                Table + " g WHERE ";

                if (!String.IsNullOrEmpty(_definitionQuery))
                {
                    strSql += DefinitionQuery + " AND ";
                }

                strSql += strGeom;

                using (var adapter = new OracleDataAdapter(strSql, conn))
                {
                    conn.Open();
                    adapter.Fill(ds);
                    conn.Close();
                    if (ds.Tables.Count > 0)
                    {
                        var fdt = new FeatureDataTable(ds.Tables[0]);
                        foreach (DataColumn col in ds.Tables[0].Columns)
                        {
                            if (string.Compare(col.ColumnName, GeometryColumn, CultureInfo.InvariantCulture, CompareOptions.OrdinalIgnoreCase) != 0)
                            {
                                fdt.Columns.Add(col.ColumnName, col.DataType, col.Expression);
                            }
                        }
                        foreach (DataRow dr in ds.Tables[0].Rows)
                        {
                            var fdr = fdt.NewRow();
                            foreach (DataColumn col in ds.Tables[0].Columns)
                            {
                                if (string.Compare(col.ColumnName, GeometryColumn, CultureInfo.InvariantCulture, CompareOptions.OrdinalIgnoreCase) != 0)
                                {
                                    fdr[col.ColumnName] = dr[col];
                                }
                            }
                            var sdoGeometry = dr[GeometryColumn] as SdoGeometry;

                            if (sdoGeometry != null)
                            {
                                fdr.Geometry = sdoGeometry.AsGeometry();
                            }

                            fdt.AddRow(fdr);
                        }
                        ds.Tables.Add(fdt);
                    }
                }
            }
        }
Beispiel #3
0
        /// <summary>
        /// Returns the features that intersects with 'geom'
        /// </summary>
        /// <param name="geom"></param>
        /// <param name="fcs">FeatureDataSet to fill data into</param>
        /// <param name="cancellationToken">A cancellation token</param>
        protected override void OnExecuteIntersectionQuery(Geometry geom, IFeatureCollectionSet fcs, CancellationToken?cancellationToken = null)
        {
            using (SqlConnection conn = new SqlConnection(ConnectionString))
            {
                string strGeom = SpatialObjectType + "::STGeomFromText('" + geom.AsText() + "', #SRID#)";

                strGeom = strGeom.Replace("#SRID#", SRID > 0 ? SRID.ToString(NumberFormatInfo.InvariantInfo) : "0");
                strGeom = GeometryColumn + ".STIntersects(" + strGeom + ") = 1";

                string strSQL = "SELECT g.* FROM " + Table + " g " + BuildTableHints() + " WHERE ";

                if (!String.IsNullOrEmpty(DefinitionQuery))
                {
                    strSQL += DefinitionQuery + " AND ";
                }

                strSQL += strGeom;

                string extraOptions = GetExtraOptions();
                if (!string.IsNullOrEmpty(extraOptions))
                {
                    strSQL += " " + extraOptions;
                }

                var ds = (System.Data.DataSet) new FeatureDataSet();
                using (SqlDataAdapter adapter = new SqlDataAdapter(strSQL, conn))
                {
                    conn.Open();
                    adapter.Fill(ds);
                    conn.Close();
                    if (ds.Tables.Count > 0)
                    {
                        FeatureDataTable fdt = new FeatureDataTable(ds.Tables[0]);
                        foreach (System.Data.DataColumn col in ds.Tables[0].Columns)
                        {
                            if (col.ColumnName != GeometryColumn)
                            {
                                fdt.Columns.Add(col.ColumnName, col.DataType, col.Expression);
                            }
                        }
                        var geometryReader = CreateReader();
                        foreach (System.Data.DataRow dr in ds.Tables[0].Rows)
                        {
                            FeatureDataRow fdr = fdt.NewRow();
                            foreach (System.Data.DataColumn col in ds.Tables[0].Columns)
                            {
                                if (col.ColumnName != GeometryColumn)
                                {
                                    fdr[col.ColumnName] = dr[col];
                                }
                            }
                            fdr.Geometry = geometryReader.Read(dr[GeometryColumn]);
                            fdt.AddRow(fdr);
                        }
                        fcs.Add(fdt);
                    }
                }
            }
        }
        /// <summary>
        /// Returns the features that intersects with 'geom'
        /// </summary>
        /// <param name="geom"></param>
        /// <param name="ds">FeatureDataSet to fill data into</param>
        protected override void OnExecuteIntersectionQuery(Geometry geom, FeatureDataSet ds)
        {
            using (var conn = new SqlConnection(ConnectionString))
            {
                string strGeom = SpatialObject + "::STGeomFromText('" + geom.AsText() + "', #SRID#)";

                strGeom = strGeom.Replace("#SRID#", SRID > 0 ? SRID.ToString(CultureInfo.InvariantCulture) : "0");
                strGeom = GeometryColumn + ".STIntersects(" + strGeom + ") = 1";

                string strSql = "SELECT g.* FROM " + Table + " g " + BuildTableHints() + " WHERE ";

                if (!String.IsNullOrEmpty(DefinitionQuery))
                {
                    strSql += DefinitionQuery + " AND ";
                }

                strSql += strGeom;

                using (var adapter = new SqlDataAdapter(strSql, conn))
                {
                    conn.Open();
                    adapter.Fill(ds);
                    conn.Close();
                    if (ds.Tables.Count > 0)
                    {
                        var fdt = new FeatureDataTable(ds.Tables[0]);
                        foreach (System.Data.DataColumn col in ds.Tables[0].Columns)
                        {
                            if (col.ColumnName != GeometryColumn)
                            {
                                fdt.Columns.Add(col.ColumnName, col.DataType, col.Expression);
                            }
                        }
                        foreach (System.Data.DataRow dr in ds.Tables[0].Rows)
                        {
                            FeatureDataRow fdr = fdt.NewRow();
                            foreach (System.Data.DataColumn col in ds.Tables[0].Columns)
                            {
                                if (col.ColumnName != GeometryColumn)
                                {
                                    fdr[col.ColumnName] = dr[col];
                                }
                            }

                            var      ogeom       = dr[GeometryColumn];
                            Geometry sqlGeometry = null;
                            if (ogeom != null && ogeom != DBNull.Value)
                            {
                                sqlGeometry = SqlGeometryConverter.ToSharpMapGeometry((Microsoft.SqlServer.Types.SqlGeometry)ogeom);
                            }
                            fdr.Geometry = sqlGeometry;
                            fdt.AddRow(fdr);
                        }
                        ds.Tables.Add(fdt);
                    }
                }
            }
        }
Beispiel #5
0
        /// <summary>
        /// Returns geometries within the specified bounding box
        /// </summary>
        /// <param name="bbox"></param>
        /// <returns></returns>
        public Collection <Geometry> GetGeometriesInView(BoundingBox bbox)
        {
            Collection <Geometry> features = new Collection <Geometry>();

            using (NpgsqlConnection conn = new NpgsqlConnection(_ConnectionString))
            {
                string strBbox = "box2d('BOX3D(" +
                                 bbox.Min.X.ToString(Map.NumberFormatEnUs) + " " +
                                 bbox.Min.Y.ToString(Map.NumberFormatEnUs) + "," +
                                 bbox.Max.X.ToString(Map.NumberFormatEnUs) + " " +
                                 bbox.Max.Y.ToString(Map.NumberFormatEnUs) + ")'::box3d)";
                if (SRID > 0)
                {
                    strBbox = "setSRID(" + strBbox + "," + SRID.ToString(Map.NumberFormatEnUs) + ")";
                }

                string strSQL = "SELECT AsBinary(\"" + GeometryColumn + "\") AS Geom ";
                strSQL += "FROM " + QualifiedTable + " WHERE ";

                if (!String.IsNullOrEmpty(_defintionQuery))
                {
                    strSQL += DefinitionQuery + " AND ";
                }

                if (_SupportSTIntersects)
                {
                    strSQL += "ST_Intersects(\"" + GeometryColumn + "\"," + strBbox + ")";
                }
                else
                {
                    strSQL += "\"" + GeometryColumn + "\" && " + strBbox;
                }

#if DEBUG
                Debug.WriteLine(string.Format("{0}\n{1}", "GetGeometriesInView: executing sql:", strSQL));
#endif
                using (NpgsqlCommand command = new NpgsqlCommand(strSQL, conn))
                {
                    conn.Open();
                    using (NpgsqlDataReader dr = command.ExecuteReader())
                    {
                        while (dr.Read())
                        {
                            if (dr[0] != DBNull.Value)
                            {
                                Geometry geom = GeometryFromWKB.Parse((byte[])dr[0]);
                                if (geom != null)
                                {
                                    features.Add(geom);
                                }
                            }
                        }
                    }
                    conn.Close();
                }
            }
            return(features);
        }
Beispiel #6
0
        /// <summary>
        /// Returns the features that intersects with 'geom'
        /// </summary>
        /// <param name="geom"></param>
        /// <param name="fcs">FeatureCollectionSet to fill data into</param>
        protected override void OnExecuteIntersectionQuery(IGeometry geom, IFeatureCollectionSet fcs, CancellationToken?cancellationToken = null)
        {
            using (var conn = new OracleConnection(ConnectionString))
            {
                var strGeom = "MDSYS.SDO_GEOMETRY('" + geom.AsText() + "', #SRID#)";

                strGeom = strGeom.Replace("#SRID#", SRID > 0 ? SRID.ToString(Map.NumberFormatEnUs) : "NULL");

                strGeom = "SDO_RELATE(g." + GeometryColumn + ", " + strGeom +
                          ", 'mask=ANYINTERACT querytype=WINDOW') = 'TRUE'";

                var strSQL = "SELECT g.* , g." + GeometryColumn + ").Get_WKB() As sharpmap_tempgeometry FROM " +
                             Table + " g WHERE ";

                if (!String.IsNullOrEmpty(_definitionQuery))
                {
                    strSQL += DefinitionQuery + " AND ";
                }

                strSQL += strGeom;
                var ds = new FeatureDataSet();

                using (var adapter = new OracleDataAdapter(strSQL, conn))
                {
                    conn.Open();
                    adapter.Fill(ds);
                    conn.Close();
                    if (ds.Tables.Count <= 0)
                    {
                        return;
                    }

                    var fdt = new FeatureDataTable(ds.Tables[0]);
                    foreach (DataColumn col in ds.Tables[0].Columns)
                    {
                        if (col.ColumnName != GeometryColumn && col.ColumnName != "sharpmap_tempgeometry")
                        {
                            fdt.Columns.Add(col.ColumnName, col.DataType, col.Expression);
                        }
                    }

                    foreach (DataRow dr in ds.Tables[0].Rows)
                    {
                        var fdr = fdt.NewRow();
                        foreach (DataColumn col in ds.Tables[0].Columns)
                        {
                            if (col.ColumnName != GeometryColumn && col.ColumnName != "sharpmap_tempgeometry")
                            {
                                fdr[col.ColumnName] = dr[col];
                            }
                        }
                        fdr.Geometry = GeometryFromWKB.Parse((byte[])dr["sharpmap_tempgeometry"], Factory);
                        fdt.AddRow(fdr);
                    }
                    fcs.Add(fdt);
                }
            }
        }
Beispiel #7
0
        private static void LogError(string rule, SRID srid, params object[] args)
        {
            string str = SR.Get(srid, args);

            throw new FormatException(string.Format(CultureInfo.InvariantCulture, "Rule=\"{0}\" - ", new object[1]
            {
                rule
            }) + str);
        }
Beispiel #8
0
        /// <summary>
        /// Returns the features that intersects with 'geom'
        /// </summary>
        /// <param name="geom"></param>
        /// <param name="ds">FeatureDataSet to fill data into</param>
        public void ExecuteIntersectionQuery(Geometry geom, FeatureDataSet ds)
        {
            //List<Geometry> features = new List<Geometry>();
            using (SqlConnection conn = new SqlConnection(_connectionString))
            {
                //TODO: Convert to SQL Server
                string strGeom = _spatialObject + "::STGeomFromText('" + geom.AsText() + "', #SRID#)";

                strGeom = strGeom.Replace("#SRID#", SRID > 0 ? SRID.ToString() : "0");
                strGeom = GeometryColumn + ".STIntersects(" + strGeom + ") = 1";

                string strSQL = string.Format("SELECT g.* , g.{0}{1}.STAsBinary() As sharpmap_tempgeometry FROM {2} g WHERE ",
                                              GeometryColumn, MakeValidString, Table);

                if (!String.IsNullOrEmpty(_defintionQuery))
                {
                    strSQL += DefinitionQuery + " AND ";
                }

                strSQL += strGeom;

                using (SqlDataAdapter adapter = new SqlDataAdapter(strSQL, conn))
                {
                    conn.Open();
                    System.Data.DataSet ds2 = new System.Data.DataSet();
                    adapter.Fill(ds2);
                    conn.Close();
                    if (ds2.Tables.Count > 0)
                    {
                        FeatureDataTable fdt = new FeatureDataTable(ds2.Tables[0]);
                        foreach (System.Data.DataColumn col in ds2.Tables[0].Columns)
                        {
                            if (col.ColumnName != GeometryColumn && col.ColumnName != "sharpmap_tempgeometry")
                            {
                                fdt.Columns.Add(col.ColumnName, col.DataType, col.Expression);
                            }
                        }
                        foreach (System.Data.DataRow dr in ds2.Tables[0].Rows)
                        {
                            FeatureDataRow fdr = fdt.NewRow();
                            foreach (System.Data.DataColumn col in ds2.Tables[0].Columns)
                            {
                                if (col.ColumnName != GeometryColumn && col.ColumnName != "sharpmap_tempgeometry")
                                {
                                    fdr[col.ColumnName] = dr[col];
                                }
                            }
                            fdr.Geometry = Converters.WellKnownBinary.GeometryFromWKB.Parse((byte[])dr["sharpmap_tempgeometry"]);
                            fdt.AddRow(fdr);
                        }
                        ds.Tables.Add(fdt);
                    }
                }
            }
        }
Beispiel #9
0
        /// <summary>
        /// Returns the features that intersects with 'geom'
        /// </summary>
        /// <param name="geom"></param>
        /// <param name="ds">FeatureDataSet to fill data into</param>
        public void ExecuteIntersectionQuery(Geometry geom, FeatureDataSet ds)
        {
            //List<Geometries.Geometry> features = new List<SharpMap.Geometries.Geometry>();
            using (PgConnection conn = new PgConnection(_ConnectionString))
            {
                string strGeom = "GeomFromText('" + geom.AsText() + "')";
                if (SRID > 0)
                {
                    strGeom = "setSRID(" + strGeom + "," + SRID.ToString() + ")";
                }

                string strSQL = "SELECT * , AsBinary(" + GeometryColumn + ") As sharpmap_tempgeometry FROM " + Table +
                                " WHERE ";

                if (!String.IsNullOrEmpty(_defintionQuery))
                {
                    strSQL += DefinitionQuery + " AND ";
                }

                strSQL += GeometryColumn + " && " + strGeom + " AND distance(" + GeometryColumn + ", " + strGeom + ")<0";

                using (PgDataAdapter adapter = new PgDataAdapter(strSQL, conn))
                {
                    conn.Open();
                    adapter.Fill(ds);
                    conn.Close();
                    if (ds.Tables.Count > 0)
                    {
                        FeatureDataTable fdt = new FeatureDataTable(ds.Tables[0]);
                        foreach (DataColumn col in ds.Tables[0].Columns)
                        {
                            if (col.ColumnName != GeometryColumn && col.ColumnName != "sharpmap_tempgeometry")
                            {
                                fdt.Columns.Add(col.ColumnName, col.DataType, col.Expression);
                            }
                        }
                        foreach (DataRow dr in ds.Tables[0].Rows)
                        {
                            FeatureDataRow fdr = fdt.NewRow();
                            foreach (DataColumn col in ds.Tables[0].Columns)
                            {
                                if (col.ColumnName != GeometryColumn && col.ColumnName != "sharpmap_tempgeometry")
                                {
                                    fdr[col.ColumnName] = dr[col];
                                }
                            }
                            fdr.Geometry = GeometryFromWKB.Parse((byte[])dr["sharpmap_tempgeometry"]);
                            fdt.AddRow(fdr);
                        }
                        ds.Tables.Add(fdt);
                    }
                }
            }
        }
Beispiel #10
0
        /// <summary>
        /// Returns the box filter string needed in SQL query
        /// </summary>
        /// <param name="bbox"></param>
        /// <returns></returns>
        protected string GetBoxFilterStr(Envelope bbox)
        {
            string strBbox = "SDO_FILTER(g." + GeometryColumn + ", mdsys.sdo_geometry(2003,#SRID#,NULL," +
                             "mdsys.sdo_elem_info_array(1,1003,3)," +
                             "mdsys.sdo_ordinate_array(" +
                             bbox.MinX.ToString(Map.NumberFormatEnUs) + ", " +
                             bbox.MinY.ToString(Map.NumberFormatEnUs) + ", " +
                             bbox.MaxX.ToString(Map.NumberFormatEnUs) + ", " +
                             bbox.MaxY.ToString(Map.NumberFormatEnUs) + ")), " +
                             "'querytype=window') = 'TRUE'";

            strBbox = strBbox.Replace("#SRID#", SRID > 0 ? SRID.ToString(Map.NumberFormatEnUs) : "NULL");
            return(strBbox);
        }
Beispiel #11
0
        internal static string Get(SRID id, params object[] args)
        {
            string text = _resourceManager.GetString(id.ToString());

            if (string.IsNullOrEmpty(text))
            {
                text = _resourceManager.GetString("Unavailable");
            }
            else if (args != null && args.Length != 0)
            {
                text = string.Format(CultureInfo.InvariantCulture, text, args);
            }
            return(text);
        }
Beispiel #12
0
        /// <summary>
        /// Returns geometry Object IDs whose bounding box intersects 'bbox'
        /// </summary>
        /// <param name="bbox"></param>
        /// <returns></returns>
        public Collection <uint> GetObjectIDsInView(BoundingBox bbox)
        {
            Collection <uint> objectlist = new Collection <uint>();

            using (NpgsqlConnection conn = new NpgsqlConnection(_ConnectionString))
            {
                string strBbox = "box2d('BOX3D(" +
                                 bbox.Min.X.ToString(Map.NumberFormatEnUs) + " " +
                                 bbox.Min.Y.ToString(Map.NumberFormatEnUs) + "," +
                                 bbox.Max.X.ToString(Map.NumberFormatEnUs) + " " +
                                 bbox.Max.Y.ToString(Map.NumberFormatEnUs) + ")'::box3d)";
                if (SRID > 0)
                {
                    strBbox = "setSRID(" + strBbox + "," + SRID.ToString(Map.NumberFormatEnUs) + ")";
                }

                string strSQL = "SELECT \"" + ObjectIdColumn + "\" ";
                strSQL += "FROM " + QualifiedTable + " WHERE ";

                if (!String.IsNullOrEmpty(_defintionQuery))
                {
                    strSQL += DefinitionQuery + " AND ";
                }

                strSQL += "\"" + GeometryColumn + "\" && " + strBbox;
#if DEBUG
                Debug.WriteLine(string.Format("{0}\n{1}", "GetObjectIDsInView: executing sql:", strSQL));
#endif

                using (NpgsqlCommand command = new NpgsqlCommand(strSQL, conn))
                {
                    conn.Open();
                    using (NpgsqlDataReader dr = command.ExecuteReader())
                    {
                        while (dr.Read())
                        {
                            if (dr[0] != DBNull.Value)
                            {
                                uint ID = (uint)(int)dr[0];
                                objectlist.Add(ID);
                            }
                        }
                    }
                    conn.Close();
                }
            }
            return(objectlist);
        }
        /// <summary>
        /// Paralelně zapíše data z XYZ souboru do tabulky bodů
        /// </summary>
        /// <param name="filepath">Cesta k souboru</param>
        /// <param name="inputSrid">SRID dat v souboru</param>
        /// <returns>Počet zapsaných řádků</returns>
        public static int LoadXyzFileParallel(string filepath, SRID inputSrid)
        {
            IEnumerable <Xyz> xyzs = ExtractXyzs(filepath);
            int       rowCount     = 0;
            Stopwatch s            = Stopwatch.StartNew();

            Parallel.ForEach(xyzs, () => 0, (xyz, state, subCount) =>
            {
                using (var conn = new NpgsqlConnection(CONNECTION_STRING))
                {
                    conn.Open();
                    conn.MapEnum <Source>();
                    using (var cmd = new NpgsqlCommand())
                    {
                        cmd.Connection = conn;
                        //Transformace z S-JTSK (5514) -> WGS84 (4326) | Vytvoření pointu -> Nastavení S-JTSK -> Trasformace na WGS84
                        cmd.CommandText =
                            "INSERT INTO points(point, latitude, longitude, elevation, resolution, Source, time_added) " +
                            "SELECT Transform.Result, ST_Y(Transform.Result), ST_X(Transform.Result), @z, 0, @Source, now() " +
                            "FROM(SELECT ST_Transform(ST_SetSRID(ST_MakePoint(@x, @y), @input_srid), @wgs84) AS Result) AS Transform";
                        cmd.Parameters.AddWithValue("Source", NpgsqlDbType.Enum, Source.File);
                        cmd.Parameters.AddWithValue("x", NpgsqlDbType.Double, xyz.x);
                        cmd.Parameters.AddWithValue("y", NpgsqlDbType.Double, xyz.y);
                        cmd.Parameters.AddWithValue("z", NpgsqlDbType.Double, xyz.z);
                        cmd.Parameters.AddWithValue("input_srid", NpgsqlDbType.Smallint, inputSrid);
                        cmd.Parameters.AddWithValue("wgs84", NpgsqlDbType.Smallint, SRID.WGS84);
                        cmd.Prepare();
                        try
                        {
                            subCount += cmd.ExecuteNonQuery();
                        }
                        catch (Exception e)
                        {
                            Console.WriteLine(e.Message);
                            logger.Error(e);
                        }
                    }
                }
                return(subCount);
            }, (finalCount) => Interlocked.Add(ref rowCount, finalCount));
            s.Stop();
            Console.WriteLine("{0} rows added it took {1} ms", rowCount, s.ElapsedMilliseconds);
            logger.Info("{0} rows added it took {1} ms", rowCount, s.ElapsedMilliseconds);
            return(rowCount);
        }
Beispiel #14
0
        /// <summary>
        /// Returns the box filter string needed in SQL query
        /// </summary>
        /// <param name="bbox"></param>
        /// <returns></returns>
        private string GetBoxFilterStr(BoundingBox bbox)
        {
            string strBbox = "SDO_FILTER(g." + GeometryColumn + ", mdsys.sdo_geometry(2003,#SRID#,NULL," +
                             "mdsys.sdo_elem_info_array(1,1003,3)," +
                             "mdsys.sdo_ordinate_array(" +
                             bbox.Min.X.ToString(Map.NumberFormatEnUs) + ", " +
                             bbox.Min.Y.ToString(Map.NumberFormatEnUs) + ", " +
                             bbox.Max.X.ToString(Map.NumberFormatEnUs) + ", " +
                             bbox.Max.Y.ToString(Map.NumberFormatEnUs) + ")), " +
                             "'querytype=window') = 'TRUE'";

            if (SRID > 0)
            {
                strBbox = strBbox.Replace("#SRID#", SRID.ToString(Map.NumberFormatEnUs));
            }
            else
            {
                strBbox = strBbox.Replace("#SRID#", "NULL");
            }
            return(strBbox);
        }
        /// <summary>Convert Coordinates from one Spatial Reference Identification system to another.</summary>
        /// <param name="SRIDSource">The SRID for the source input coordinates.</param>
        /// <param name="SRIDTarget">The SRID for the target output coordinates.</param>
        /// <param name="RevisionSource">The revision year for the source coordinate system.</param>
        /// <param name="RevisionTarget">The revision year for the target coordinate system.</param>
        /// <param name="SourceCoordinates">Input parameter containing the source coordinates.</param>
        /// <param name="TargetCoordinates">Output parameter containing the target coordinates.</param>
        /// <param name="DatumCode">Irish vertical datum code.</param>
        /// <returns>Whether the conversion was a Success.</returns>
        public static bool ConvertCoordinates(SRID SRIDSource, SRID SRIDTarget, int RevisionSource, int RevisionTarget, Coordinates SourceCoordinates, Coordinates TargetCoordinates, IrishDatum DatumCode)
        {
            bool   ok     = false;
            IntPtr pDatum = IntPtr.Zero;

            try
            {
                pDatum = Marshal.AllocHGlobal(Marshal.SizeOf((int)DatumCode));
                Marshal.WriteInt32(pDatum, (int)DatumCode);
                ok        = UnsafeNativeMethods.ConvertCoordinates((int)SRIDSource, (int)SRIDTarget, RevisionSource, RevisionTarget, SourceCoordinates._Native, TargetCoordinates._Native, pDatum);
                DatumCode = (IrishDatum)Marshal.ReadInt32(pDatum);
            }
            finally
            {
                if (pDatum != IntPtr.Zero)
                {
                    Marshal.FreeHGlobal(pDatum);
                }
            }
            return(ok);
        }
Beispiel #16
0
 private string WrapScriptOuterVB(string innerCode)
 {
     if (!string.IsNullOrEmpty(innerCode))
     {
         int num = 0;
         foreach (string importNamespace in _importNamespaces)
         {
             num += importNamespace.Length;
         }
         SRID   sRID       = SRID.ArrayOfNullIllegal;
         string @namespace = sRID.GetType().Namespace;
         string text       = string.Format(CultureInfo.InvariantCulture, "#ExternalSource (\"{0}\", 1)\nImports System\nImports System.Collections.Generic\nImports System.Diagnostics\nImports {1}\nImports {1}.Recognition\nImports {1}.Recognition.SrgsGrammar\n", new object[2]
         {
             "<Does Not Exist>",
             @namespace
         });
         StringBuilder stringBuilder = new StringBuilder(_script.Length + text.Length + 200);
         stringBuilder.Append(text);
         foreach (string importNamespace2 in _importNamespaces)
         {
             stringBuilder.Append("Imports ");
             stringBuilder.Append(importNamespace2);
             stringBuilder.Append("\n");
         }
         if (_namespace != null)
         {
             stringBuilder.Append("Namespace ");
             stringBuilder.Append(_namespace);
             stringBuilder.Append("\n");
         }
         stringBuilder.Append("#End ExternalSource\n");
         stringBuilder.Append(innerCode);
         if (_namespace != null)
         {
             stringBuilder.Append("End Namespace\n");
         }
         return(stringBuilder.ToString());
     }
     return(null);
 }
Beispiel #17
0
 private string WrapScriptOuterCSharp(string innerCode)
 {
     if (!string.IsNullOrEmpty(innerCode))
     {
         int num = 0;
         foreach (string importNamespace in _importNamespaces)
         {
             num += importNamespace.Length;
         }
         SRID   sRID       = SRID.ArrayOfNullIllegal;
         string @namespace = sRID.GetType().Namespace;
         string text       = string.Format(CultureInfo.InvariantCulture, "#line 1 \"{0}\"\nusing System;\nusing System.Collections.Generic;\nusing System.Diagnostics;\nusing {1};\nusing {1}.Recognition;\nusing {1}.Recognition.SrgsGrammar;\n", new object[2]
         {
             "<Does Not Exist>",
             @namespace
         });
         StringBuilder stringBuilder = new StringBuilder(_script.Length + text.Length + 200);
         stringBuilder.Append(text);
         foreach (string importNamespace2 in _importNamespaces)
         {
             stringBuilder.Append("using ");
             stringBuilder.Append(importNamespace2);
             stringBuilder.Append(";\n");
         }
         if (_namespace != null)
         {
             stringBuilder.Append("namespace ");
             stringBuilder.Append(_namespace);
             stringBuilder.Append("\n{\n");
         }
         stringBuilder.Append(innerCode);
         if (_namespace != null)
         {
             stringBuilder.Append("}\n");
         }
         return(stringBuilder.ToString());
     }
     return(null);
 }
Beispiel #18
0
        public FeatureDataTable QueryFeatures(Geometry geom, double distance)
        {
            //List<Geometries.Geometry> features = new List<SharpMap.Geometries.Geometry>();
            using (OracleConnection conn = new OracleConnection(_ConnectionString))
            {
                string strGeom = "MDSYS.SDO_GEOMETRY('" + geom.AsText() + "', #SRID#)";

                if (SRID > 0)
                {
                    strGeom = strGeom.Replace("#SRID#", SRID.ToString(Map.NumberFormatEnUs));
                }
                else
                {
                    strGeom = strGeom.Replace("#SRID#", "NULL");
                }

                strGeom = "SDO_WITHIN_DISTANCE(g." + GeometryColumn + ", " + strGeom + ", 'distance = " +
                          distance.ToString(Map.NumberFormatEnUs) + "') = 'TRUE'";

                string strSQL = "SELECT g.* , g." + GeometryColumn + ").Get_WKB() As sharpmap_tempgeometry FROM " +
                                Table + " g WHERE ";

                if (!String.IsNullOrEmpty(_defintionQuery))
                {
                    strSQL += DefinitionQuery + " AND ";
                }

                strSQL += strGeom;

                using (OracleDataAdapter adapter = new OracleDataAdapter(strSQL, conn))
                {
                    DataSet ds = new DataSet();
                    conn.Open();
                    adapter.Fill(ds);
                    conn.Close();
                    if (ds.Tables.Count > 0)
                    {
                        FeatureDataTable fdt = new FeatureDataTable(ds.Tables[0]);
                        foreach (DataColumn col in ds.Tables[0].Columns)
                        {
                            if (col.ColumnName != GeometryColumn && col.ColumnName != "sharpmap_tempgeometry")
                            {
                                fdt.Columns.Add(col.ColumnName, col.DataType, col.Expression);
                            }
                        }
                        foreach (DataRow dr in ds.Tables[0].Rows)
                        {
                            FeatureDataRow fdr = fdt.NewRow();
                            foreach (DataColumn col in ds.Tables[0].Columns)
                            {
                                if (col.ColumnName != GeometryColumn && col.ColumnName != "sharpmap_tempgeometry")
                                {
                                    fdr[col.ColumnName] = dr[col];
                                }
                            }
                            fdr.Geometry = GeometryFromWKB.Parse((byte[])dr["sharpmap_tempgeometry"]);
                            fdt.AddRow(fdr);
                        }
                        return(fdt);
                    }
                    else
                    {
                        return(null);
                    }
                }
            }
        }
 /// <summary>Convert Coordinates from one Spatial Reference Identification system to another.</summary>
 /// <param name="SRIDSource">The SRID for the source input coordinates.</param>
 /// <param name="SRIDTarget">The SRID for the target output coordinates.</param>
 /// <param name="SourceCoordinates">Input parameter containing the source coordinates.</param>
 /// <param name="TargetCoordinates">Output parameter containing the target coordinates.</param>
 /// <param name="DatumCode">Irish vertical datum code.</param>
 /// <returns>Whether the conversion was a Success.</returns>
 public static bool ConvertCoordinates(SRID SRIDSource, SRID SRIDTarget, Coordinates SourceCoordinates, Coordinates TargetCoordinates, IrishDatum DatumCode)
 => ConvertCoordinates(SRIDSource, SRIDTarget, 0, 0, SourceCoordinates, TargetCoordinates, DatumCode);
Beispiel #20
0
        public FeatureDataTable QueryFeatures(Geometry geom, double distance)
        {
            //List<Geometries.Geometry> features = new List<SharpMap.Geometries.Geometry>();
            using (SqlConnection conn = new SqlConnection(ConnectionString))
            {
                string strGeom;
                if (TargetSRID > 0 && SRID > 0 && SRID != TargetSRID)
                {
                    strGeom = "ST.Transform(ST.GeomFromText('" + geom.AsText() + "'," + TargetSRID.ToString() + ")," +
                              SRID.ToString() + ")";
                }
                else
                {
                    strGeom = "ST.GeomFromText('" + geom.AsText() + "', " + SRID.ToString() + ")";
                }

                string strSQL = "SELECT " + FeatureColumns + ", ST.AsBinary(" + BuildGeometryExpression() +
                                ") As sharpmap_tempgeometry ";
                strSQL += "FROM ST.IsWithinDistanceQuery" + BuildSpatialQuerySuffix() + "(" + strGeom + ", " +
                          distance.ToString(Map.NumberFormatEnUs) + ")";

                if (!String.IsNullOrEmpty(DefinitionQuery))
                {
                    strSQL += " WHERE " + DefinitionQuery;
                }

                if (!String.IsNullOrEmpty(OrderQuery))
                {
                    strSQL += " ORDER BY " + OrderQuery;
                }

                using (SqlDataAdapter adapter = new SqlDataAdapter(strSQL, conn))
                {
                    DataSet ds = new DataSet();
                    conn.Open();
                    adapter.Fill(ds);
                    conn.Close();
                    if (ds.Tables.Count > 0)
                    {
                        FeatureDataTable fdt = new FeatureDataTable(ds.Tables[0]);
                        foreach (DataColumn col in ds.Tables[0].Columns)
                        {
                            if (col.ColumnName != GeometryColumn &&
                                !col.ColumnName.StartsWith(GeometryColumn + "_Envelope_") &&
                                col.ColumnName != "sharpmap_tempgeometry")
                            {
                                fdt.Columns.Add(col.ColumnName, col.DataType, col.Expression);
                            }
                        }
                        foreach (DataRow dr in ds.Tables[0].Rows)
                        {
                            FeatureDataRow fdr = fdt.NewRow();
                            foreach (DataColumn col in ds.Tables[0].Columns)
                            {
                                if (col.ColumnName != GeometryColumn &&
                                    !col.ColumnName.StartsWith(GeometryColumn + "_Envelope_") &&
                                    col.ColumnName != "sharpmap_tempgeometry")
                                {
                                    fdr[col.ColumnName] = dr[col];
                                }
                            }
                            if (dr["sharpmap_tempgeometry"] != DBNull.Value)
                            {
                                fdr.Geometry = GeometryFromWKB.Parse((byte[])dr["sharpmap_tempgeometry"]);
                            }
                            fdt.AddRow(fdr);
                        }
                        return(fdt);
                    }
                    else
                    {
                        return(null);
                    }
                }
            }
        }
Beispiel #21
0
        /// <summary>
        /// Returns all features with the view box
        /// </summary>
        /// <param name="bbox">view box</param>
        /// <param name="ds">FeatureDataSet to fill data into</param>
        public void ExecuteIntersectionQuery(BoundingBox bbox, FeatureDataSet ds)
        {
            //List<Geometry> features = new List<Geometry>();
            using (NpgsqlConnection conn = new NpgsqlConnection(_ConnectionString))
            {
                string strBbox = "box2d('BOX3D(" +
                                 bbox.Min.X.ToString(Map.NumberFormatEnUs) + " " +
                                 bbox.Min.Y.ToString(Map.NumberFormatEnUs) + "," +
                                 bbox.Max.X.ToString(Map.NumberFormatEnUs) + " " +
                                 bbox.Max.Y.ToString(Map.NumberFormatEnUs) + ")'::box3d)";
                if (SRID > 0)
                {
                    strBbox = "setSRID(" + strBbox + "," + SRID.ToString(Map.NumberFormatEnUs) + ")";
                }

                string strSQL = "SELECT *, AsBinary(\"" + GeometryColumn + "\") AS sharpmap_tempgeometry ";
                strSQL += "FROM " + QualifiedTable + " WHERE ";

                if (!String.IsNullOrEmpty(_defintionQuery))
                {
                    strSQL += DefinitionQuery + " AND ";
                }

                strSQL += "\"" + GeometryColumn + "\" && " + strBbox;
#if DEBUG
                Debug.WriteLine(string.Format("{0}\n{1}\n", "ExecuteIntersectionQuery: executing sql:", strSQL));
#endif
                using (NpgsqlDataAdapter adapter = new NpgsqlDataAdapter(strSQL, conn))
                {
                    conn.Open();
                    DataSet ds2 = new DataSet();
                    adapter.Fill(ds2);
                    conn.Close();
                    if (ds2.Tables.Count > 0)
                    {
                        FeatureDataTable fdt = new FeatureDataTable(ds2.Tables[0]);
                        foreach (DataColumn col in ds2.Tables[0].Columns)
                        {
                            if (col.ColumnName != GeometryColumn && col.ColumnName != "sharpmap_tempgeometry")
                            {
                                fdt.Columns.Add(col.ColumnName, col.DataType, col.Expression);
                            }
                        }

                        foreach (DataRow dr in ds2.Tables[0].Rows)
                        {
                            FeatureDataRow fdr = fdt.NewRow();
                            foreach (DataColumn col in ds2.Tables[0].Columns)
                            {
                                if (col.ColumnName != GeometryColumn && col.ColumnName != "sharpmap_tempgeometry")
                                {
                                    fdr[col.ColumnName] = dr[col];
                                }
                            }
                            fdr.Geometry = GeometryFromWKB.Parse((byte[])dr["sharpmap_tempgeometry"]);
                            fdt.AddRow(fdr);
                        }
                        ds.Tables.Add(fdt);
                    }
                }
            }
        }
        /// <summary>
        /// Returns the features that intersects with 'geom'
        /// </summary>
        /// <param name="geom"></param>
        /// <param name="ds">FeatureDataSet to fill data into</param>
        protected override void OnExecuteIntersectionQuery(Geometry geom, FeatureDataSet ds)
        {
            using (var conn = new SqlConnection(ConnectionString))
            {
                string strGeom = _spatialObject + "::STGeomFromText('" + geom.AsText() + "', #SRID#)";

                strGeom = strGeom.Replace("#SRID#", SRID > 0 ? SRID.ToString(CultureInfo.InvariantCulture) : "0");
                strGeom = GeometryColumn + ".STIntersects(" + strGeom + ") = 1";

                string strSql = "SELECT g.* , g." + GeometryColumn + ".STAsBinary() As sharpmap_tempgeometry FROM " +
                                QualifiedTable + " g " + BuildTableHints() + " WHERE ";

                if (!String.IsNullOrEmpty(_definitionQuery))
                {
                    strSql += DefinitionQuery + " AND ";
                }

                strSql += strGeom;

                string extraOptions = GetExtraOptions();
                if (!string.IsNullOrEmpty(extraOptions))
                {
                    strSql += " " + extraOptions;
                }


                using (var adapter = new SqlDataAdapter(strSql, conn))
                {
                    conn.Open();
                    adapter.Fill(ds);
                    conn.Close();
                    if (ds.Tables.Count > 0)
                    {
                        var fdt = new FeatureDataTable(ds.Tables[0]);
                        foreach (System.Data.DataColumn col in ds.Tables[0].Columns)
                        {
                            if (col.ColumnName != GeometryColumn && col.ColumnName != "sharpmap_tempgeometry")
                            {
                                fdt.Columns.Add(col.ColumnName, col.DataType, col.Expression);
                            }
                        }
                        foreach (System.Data.DataRow dr in ds.Tables[0].Rows)
                        {
                            FeatureDataRow fdr = fdt.NewRow();
                            foreach (System.Data.DataColumn col in ds.Tables[0].Columns)
                            {
                                if (col.ColumnName != GeometryColumn && col.ColumnName != "sharpmap_tempgeometry")
                                {
                                    fdr[col.ColumnName] = dr[col];
                                }
                            }
                            var tmpGeom =
                                Converters.WellKnownBinary.GeometryFromWKB.Parse((byte[])dr["sharpmap_tempgeometry"],
                                                                                 Factory);
                            if (tmpGeom != null && _spatialObjectType == SqlServerSpatialObjectType.Geography)
                            {
                                FlipXY(tmpGeom);
                                tmpGeom.GeometryChanged();
                            }
                            fdr.Geometry = tmpGeom;
                            fdt.AddRow(fdr);
                        }
                        ds.Tables.Add(fdt);
                    }
                }
            }
        }
        /// <summary>
        /// Returns the features that intersects with 'geom'
        /// </summary>
        /// <param name="geom"></param>
        /// <param name="ds">FeatureDataSet to fill data into</param>
        protected override void OnExecuteIntersectionQuery(Geometry geom, FeatureDataSet ds)
        {
            using (var conn = new SqlConnection(ConnectionString))
            {
                string strGeom = SpatialObject + "::STGeomFromText('" + geom.AsText() + "', #SRID#)";

                strGeom = strGeom.Replace("#SRID#", SRID > 0 ? SRID.ToString(CultureInfo.InvariantCulture) : "0");
                strGeom = GeometryColumn + ".STIntersects(" + strGeom + ") = 1";

                string strSql = "SELECT g.* FROM " + QualifiedTable + " g " + BuildTableHints() + " WHERE ";

                if (!String.IsNullOrEmpty(DefinitionQuery))
                {
                    strSql += DefinitionQuery + " AND ";
                }

                if (!ValidateGeometries ||
                    (SpatialObjectType == SqlServerSpatialObjectType.Geometry && (ForceSeekHint || !string.IsNullOrEmpty(ForceIndex))))
                {
                    // Geometry sensitive to invalid geometries, and BuildTableHints (ForceSeekHint, ForceIndex) do not suppport .MakeValid() in GetBoxFilterStr
                    strSql += $"{GeometryColumn}.STIsValid() = 1 AND ";
                }

                strSql += strGeom;

                string extraOptions = GetExtraOptions();
                if (!string.IsNullOrEmpty(extraOptions))
                {
                    strSql += " " + extraOptions;
                }

                using (var adapter = new SqlDataAdapter(strSql, conn))
                {
                    conn.Open();
                    adapter.Fill(ds);
                    conn.Close();
                    if (ds.Tables.Count > 0)
                    {
                        var fdt = new FeatureDataTable(ds.Tables[0]);
                        foreach (System.Data.DataColumn col in ds.Tables[0].Columns)
                        {
                            if (col.ColumnName != GeometryColumn)
                            {
                                fdt.Columns.Add(col.ColumnName, col.DataType, col.Expression);
                            }
                        }
                        foreach (System.Data.DataRow dr in ds.Tables[0].Rows)
                        {
                            FeatureDataRow fdr = fdt.NewRow();
                            foreach (System.Data.DataColumn col in ds.Tables[0].Columns)
                            {
                                if (col.ColumnName != GeometryColumn)
                                {
                                    fdr[col.ColumnName] = dr[col];
                                }
                            }

                            var      ogeom       = dr[GeometryColumn];
                            Geometry sqlGeometry = null;
                            if (ogeom != null && ogeom != DBNull.Value)
                            {
                                sqlGeometry = SqlGeometryConverter.ToSharpMapGeometry((Microsoft.SqlServer.Types.SqlGeometry)ogeom);
                            }
                            fdr.Geometry = sqlGeometry;
                            fdt.AddRow(fdr);
                        }
                        ds.Tables.Add(fdt);
                    }
                }
            }
        }
 public SurfaceRecord()
 {
     srid = new SRID();
     inas = new List<INAS>();
     rias = new List<RIAS>();
 }
 /// <summary>Convert Coordinates from one Spatial Reference Identification system to another.</summary>
 /// <param name="SRIDSource">The SRID for the source input coordinates.</param>
 /// <param name="SRIDTarget">The SRID for the target output coordinates.</param>
 /// <param name="RevisionSource">The revision year for the source coordinate system.</param>
 /// <param name="RevisionTarget">The revision year for the target coordinate system.</param>
 /// <param name="SourceCoordinates">Input parameter containing the source coordinates.</param>
 /// <param name="TargetCoordinates">Output parameter containing the target coordinates.</param>
 /// <returns>Whether the conversion was a Success.</returns>
 public static bool ConvertCoordinates(SRID SRIDSource, SRID SRIDTarget, int RevisionSource, int RevisionTarget, Coordinates SourceCoordinates, Coordinates TargetCoordinates)
 => ConvertCoordinates(SRIDSource, SRIDTarget, RevisionSource, RevisionTarget, SourceCoordinates, TargetCoordinates, IrishDatum.None);
Beispiel #26
0
        public FeatureDataTable QueryFeatures(Geometry geom, double distance)
        {
            Collection <Geometry> features = new Collection <Geometry>();

            using (PgConnection conn = new PgConnection(_ConnectionString))
            {
                string strGeom = "GeomFromText('" + geom.AsText() + "')";
                if (SRID > 0)
                {
                    strGeom = "setSRID(" + strGeom + "," + SRID.ToString() + ")";
                }

                string strSQL = "SELECT * , AsBinary(" + GeometryColumn + ") As sharpmap_tempgeometry FROM " + Table +
                                " WHERE ";

                if (!String.IsNullOrEmpty(_defintionQuery))
                {
                    strSQL += DefinitionQuery + " AND ";
                }

                strSQL += GeometryColumn + " && " + "buffer(" + strGeom + "," + distance.ToString(Map.NumberFormatEnUs) +
                          ")";
                strSQL += " AND distance(" + GeometryColumn + ", " + strGeom + ")<" +
                          distance.ToString(Map.NumberFormatEnUs);

                using (PgDataAdapter adapter = new PgDataAdapter(strSQL, conn))
                {
                    DataSet ds = new DataSet();
                    conn.Open();
                    adapter.Fill(ds);
                    conn.Close();
                    if (ds.Tables.Count > 0)
                    {
                        FeatureDataTable fdt = new FeatureDataTable(ds.Tables[0]);
                        foreach (DataColumn col in ds.Tables[0].Columns)
                        {
                            if (col.ColumnName != GeometryColumn && col.ColumnName != "sharpmap_tempgeometry")
                            {
                                fdt.Columns.Add(col.ColumnName, col.DataType, col.Expression);
                            }
                        }
                        foreach (DataRow dr in ds.Tables[0].Rows)
                        {
                            FeatureDataRow fdr = fdt.NewRow();
                            foreach (DataColumn col in ds.Tables[0].Columns)
                            {
                                if (col.ColumnName != GeometryColumn && col.ColumnName != "sharpmap_tempgeometry")
                                {
                                    fdr[col.ColumnName] = dr[col];
                                }
                            }
                            fdr.Geometry = GeometryFromWKB.Parse((byte[])dr["sharpmap_tempgeometry"]);
                            fdt.AddRow(fdr);
                        }
                        return(fdt);
                    }
                    else
                    {
                        return(null);
                    }
                }
            }
        }