Exemple #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(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 g.* , g." + GeometryColumn + ").Get_WKB() As sharpmap_tempgeometry 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 (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);
                        }
                        ds.Tables.Add(fdt);
                    }
                }
            }
        }
Exemple #2
0
        /// <summary>
        /// Returns the features that intersects with 'geom'
        /// </summary>
        /// <param name="geom"></param>
        /// <param name="ds">FeatureDataSet to fill data into</param>
        public IList GetFeatures(GeoAPI.Geometries.IGeometry geom)
        {
            FeatureDataSet   ds       = new FeatureDataSet();
            List <IGeometry> features = new List <IGeometry>();

            using (SqlConnection conn = new SqlConnection(this.ConnectionString))
            {
                string strGeom;
                if (this.TargetSRID > 0 && this.SRID > 0 && this.SRID != this.TargetSRID)
                {
                    strGeom = "ST.Transform(ST.GeomFromText('" + geom.AsText() + "'," + this.TargetSRID.ToString() + ")," + this.SRID.ToString() + ")";
                }
                else
                {
                    strGeom = "ST.GeomFromText('" + geom.AsText() + "', " + this.SRID.ToString() + ")";
                }

                string strSQL = "SELECT " + this.FeatureColumns + ", ST.AsBinary(" + this.BuildGeometryExpression() + ") As sharpmap_tempgeometry ";
                strSQL += "FROM ST.RelateQuery" + this.BuildSpatialQuerySuffix() + "(" + strGeom + ", 'intersects')";

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

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

                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 != this.GeometryColumn && !col.ColumnName.StartsWith(this.GeometryColumn + "_Envelope_") && col.ColumnName != "sharpmap_tempgeometry")
                            {
                                fdt.Columns.Add(col.ColumnName, col.DataType, col.Expression);
                            }
                        }
                        foreach (System.Data.DataRow dr in ds.Tables[0].Rows)
                        {
                            SharpMap.Data.FeatureDataRow fdr = fdt.NewRow();
                            foreach (System.Data.DataColumn col in ds.Tables[0].Columns)
                            {
                                if (col.ColumnName != this.GeometryColumn && !col.ColumnName.StartsWith(this.GeometryColumn + "_Envelope_") && col.ColumnName != "sharpmap_tempgeometry")
                                {
                                    fdr[col.ColumnName] = dr[col];
                                }
                            }
                            if (dr["sharpmap_tempgeometry"] != DBNull.Value)
                            {
                                fdr.Geometry = SharpMap.Converters.WellKnownBinary.GeometryFromWKB.Parse((byte[])dr["sharpmap_tempgeometry"]);
                            }
                            fdt.AddRow(fdr);
                        }
                        ds.Tables.Add(fdt);

                        return(fdt);
                    }
                }
            }

            return(null);
        }
Exemple #3
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))
                {
                    using (var sourceDataSet = new DataSet())
                    {
                        conn.Open();
                        adapter.Fill(sourceDataSet);
                        conn.Close();
                        if (sourceDataSet.Tables.Count > 0)
                        {
                            var fdt = new FeatureDataTable(sourceDataSet.Tables[0]);
                            foreach (DataColumn col in sourceDataSet.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 sourceDataSet.Tables[0].Rows)
                            {
                                var fdr = fdt.NewRow();
                                foreach (DataColumn col in sourceDataSet.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);
                        }
                    }
                }
            }
        }
Exemple #4
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 g.* , g." + GeometryColumn + ").Get_WKB() As sharpmap_tempgeometry 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 (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);
                        }
                        ds.Tables.Add(fdt);
                    }
                }
            }
        }
Exemple #5
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))
                {
                    using (var sourceDataSet = new DataSet())
                    {
                        conn.Open();
                        adapter.Fill(sourceDataSet);
                        conn.Close();
                        if (sourceDataSet.Tables.Count > 0)
                        {
                            var fdt = new FeatureDataTable(sourceDataSet.Tables[0]);
                            foreach (DataColumn col in sourceDataSet.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 sourceDataSet.Tables[0].Rows)
                            {
                                var fdr = fdt.NewRow();
                                foreach (DataColumn col in sourceDataSet.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);
                        }
                    }
                }
            }
        }