Example #1
0
        /// <summary>
        /// Retrieves all features within the given BoundingBox.
        /// </summary>
        /// <param name="bounds">Bounds of the region to search.</param>
        /// <param name="fcs">FeatureDataSet to fill data into</param>
        public override void ExecuteIntersectionQuery(Envelope bounds, IFeatureCollectionSet fcs, CancellationToken?cancellationToken = null)
        {
            if (Table.Rows.Count == 0)
            {
                return;
            }

            string statement = XColumn + " > " + bounds.MinX.ToString(Map.NumberFormatEnUs) + " AND " +
                               XColumn + " < " + bounds.MaxX.ToString(Map.NumberFormatEnUs) + " AND " +
                               YColumn + " > " + bounds.MinY.ToString(Map.NumberFormatEnUs) + " AND " +
                               YColumn + " < " + bounds.MaxY.ToString(Map.NumberFormatEnUs);

            var rows = Table.Select(statement);

            var fdt = new FeatureDataTable(Table);

            foreach (DataColumn col in Table.Columns)
            {
                fdt.Columns.Add(col.ColumnName, col.DataType, col.Expression);
            }

            foreach (var dr in rows)
            {
                fdt.ImportRow(dr);
                var fdr = (FeatureDataRow)fdt.Rows[fdt.Rows.Count - 1];
                fdr.Geometry = Factory.CreatePoint(new Coordinate((double)dr[XColumn], (double)dr[YColumn]));
            }

            fcs.Add(fdt);
        }
Example #2
0
        /// <summary>
        /// Returns the data associated with all the geometries that are intersected by 'geom'
        /// </summary>
        /// <param name="box">Geometry to intersect with</param>
        /// <param name="ds">FeatureDataSet to fill data into</param>
        public void ExecuteIntersectionQuery(Envelope box, IFeatureCollectionSet ds)
        {
            if (CoordinateTransformation != null)
            {
#if !DotSpatialProjections
                if (ReverseCoordinateTransformation != null)
                {
                    box = GeometryTransform.TransformBox(box, ReverseCoordinateTransformation.MathTransform);
                }
                else
                {
                    CoordinateTransformation.MathTransform.Invert();
                    box = GeometryTransform.TransformBox(box, CoordinateTransformation.MathTransform);
                    CoordinateTransformation.MathTransform.Invert();
                }
#else
                box = GeometryTransform.TransformBox(box, CoordinateTransformation.Target, CoordinateTransformation.Source);
#endif
            }

            lock (_dataSource)
            {
                _dataSource.Open();
                _dataSource.ExecuteIntersectionQuery(box, ds);
                _dataSource.Close();
            }
        }
Example #3
0
 void ICanQueryLayer.ExecuteIntersectionQuery(IGeometry geometry, IFeatureCollectionSet ds)
 {
     if (_baseLayer is ICanQueryLayer)
     {
         ((ICanQueryLayer)_baseLayer).ExecuteIntersectionQuery(geometry, ds);
     }
 }
Example #4
0
        public void ExecuteIntersectionQuery(IGeometry geom, IFeatureCollectionSet ds, CancellationToken?cancellationToken = null)
        {
            var fdt = (FeatureDataTable)_schemaTable.Copy();

            /* // NOTE WHY IS THIS, No other provider behaves like that?
             * if (ds.Tables.Count > 0)
             * {
             *  fdt = ds.Tables[0];
             * }
             * else
             * {
             *  fdt = new FeatureDataTable();
             * }*/

            var pGeom = NetTopologySuite.Geometries.Prepared.PreparedGeometryFactory.Prepare(geom);

            fdt.BeginLoadData();
            foreach (var feature in _geometrys)
            {
                feature.Value.Where(pGeom.Intersects).ToList()
                .ForEach(v =>
                {
                    var newRow      = (FeatureDataRow)fdt.LoadDataRow(GetAssetProperties(feature.Key), true);
                    newRow.Geometry = v;
                }
                         );
            }
            fdt.EndLoadData();

            ds.Add(fdt);
        }
Example #5
0
 void ICanQueryLayer.ExecuteIntersectionQuery(Envelope box, IFeatureCollectionSet ds)
 {
     if (_baseLayer is ICanQueryLayer)
     {
         ((ICanQueryLayer)_baseLayer).ExecuteIntersectionQuery(box, ds);
     }
 }
Example #6
0
        protected override void OnExecuteIntersectionQuery(IGeometry geom, IFeatureCollectionSet ds, CancellationToken?cancellationToken = null)
        {
            var fds = new FeatureDataSet();

            ExecuteIntersectionQuery(geom.EnvelopeInternal, fds);

            //index of last added feature data table
            var index = fds.Tables.Count - 1;

            if (index <= 0)
            {
                return;
            }

            var res = (FeatureDataTable)CloneTableStructure(fds.Tables[index].Clone());

            res.BeginLoadData();

            var fdt = fds.Tables[index];

            foreach (FeatureDataRow row in fdt.Rows)
            {
                if (PreparedGeometry.Intersects(row.Geometry))
                {
                    var fdr = (FeatureDataRow)res.LoadDataRow(row.ItemArray, true);
                    fdr.Geometry = row.Geometry;
                }
            }

            res.EndLoadData();
            ds.Add(res);
            fds.Dispose();
        }
Example #7
0
        /// <summary>
        /// Method to convert a <see cref="T:SharpMap.Data.FeatureDataSet"/> to a series of <see cref="GeoJSON"/> objects
        /// </summary>
        /// <param name="data">The feature dataset</param>
        /// <returns>A series of <see cref="GeoJSON"/> objects</returns>
        public static IEnumerable <GeoJSON> GetData(IFeatureCollectionSet data)
        {
            if (data == null)
            {
                throw new ArgumentNullException("data");
            }

            foreach (IFeatureCollection table in data)
            {
                IList <IFeatureAttributeDefinition> columns = table.AttributesDefinition;
                string[] keys = new string[columns.Count];
                for (int i = 0; i < columns.Count; i++)
                {
                    keys[i] = columns[i].AttributeName;
                }

                foreach (IFeature row in table)
                {
                    IGeometry geometry = row.Geometry;
                    Dictionary <string, object> values = new Dictionary <string, object>();
                    for (int j = 0; j < keys.Length; j++)
                    {
                        values.Add(keys[j], row.Attributes[j]);
                    }
                    yield return(new GeoJSON(geometry, values));
                }
            }
        }
Example #8
0
        /// <summary>
        /// Returns the data associated with all the geometries that are intersected by 'geom'
        /// </summary>
        /// <param name="box">Geometry to intersect with</param>
        /// <param name="ds">FeatureDataSet to fill data into</param>
        public void ExecuteIntersectionQuery(Envelope box, IFeatureCollectionSet ds)
        {
            if (CoordinateTransformation != null)
            {
#if !DotSpatialProjections
                if (ReverseCoordinateTransformation != null)
                {
                    box = GeometryTransform.TransformBox(box, ReverseCoordinateTransformation.MathTransform);
                }
                else
                {
                    CoordinateTransformation.MathTransform.Invert();
                    box = GeometryTransform.TransformBox(box, CoordinateTransformation.MathTransform);
                    CoordinateTransformation.MathTransform.Invert();
                }
#else
                box = GeometryTransform.TransformBox(box, CoordinateTransformation.Target, CoordinateTransformation.Source);
#endif
            }

            lock (_dataSource)
            {
                _dataSource.Open();
                int tableCount = ds.Count;
                _dataSource.ExecuteIntersectionQuery(box, ds);
                if (ds.Count > tableCount)
                {
                    //We added a table, name it according to layer
                    var table = ds[ds.Count - 1];
                    table.Name = LayerName;
                }
                _dataSource.Close();
            }
        }
Example #9
0
        /// <summary>
        /// Returns the data associated with all the geometries that are intersected by 'geom'
        /// </summary>
        /// <param name="geometry">Geometry to intersect with</param>
        /// <param name="ds">FeatureDataSet to fill data into</param>
        public void ExecuteIntersectionQuery(IGeometry geometry, IFeatureCollectionSet ds)
        {
            if (CoordinateTransformation != null)
            {
#if !DotSpatialProjections
                if (ReverseCoordinateTransformation != null)
                {
                    geometry = GeometryTransform.TransformGeometry(geometry, ReverseCoordinateTransformation.MathTransform,
                                                                   GeometryServiceProvider.Instance.CreateGeometryFactory((int)ReverseCoordinateTransformation.TargetCS.AuthorityCode));
                }
                else
                {
                    CoordinateTransformation.MathTransform.Invert();
                    geometry = GeometryTransform.TransformGeometry(geometry, CoordinateTransformation.MathTransform,
                                                                   GeometryServiceProvider.Instance.CreateGeometryFactory((int)CoordinateTransformation.SourceCS.AuthorityCode));
                    CoordinateTransformation.MathTransform.Invert();
                }
#else
                geometry = GeometryTransform.TransformGeometry(geometry,
                                                               CoordinateTransformation.Target,
                                                               CoordinateTransformation.Source,
                                                               CoordinateTransformation.SourceFactory);
#endif
            }

            lock (_dataSource)
            {
                _dataSource.Open();
                _dataSource.ExecuteIntersectionQuery(geometry, ds);
                _dataSource.Close();
            }
        }
Example #10
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);
                    }
                }
            }
        }
Example #11
0
        /// <summary>
        /// Returns all features with the view box
        /// </summary>
        /// <param name="bbox">view box</param>
        /// <param name="fcs">FeatureDataSet to fill data into</param>
        /// <param name="cancellationToken">A cancellation token</param>
        public override void ExecuteIntersectionQuery(BoundingBox bbox, IFeatureCollectionSet fcs, CancellationToken?cancellationToken = null)
        {
            using (SqlConnection conn = new SqlConnection(ConnectionString))
            {
                //Get bounding box string
                string strBbox = GetBoxFilterStr(bbox);

                string strSQL = String.Format(
                    "SELECT g.* FROM {0} g {1} WHERE ",
                    Table, BuildTableHints());

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

                strSQL += strBbox;

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

                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)
                            {
                                fdt.Columns.Add(col.ColumnName, col.DataType, col.Expression);
                            }
                        }
                        var geometryReader = CreateReader();
                        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)
                                {
                                    fdr[col.ColumnName] = dr[col];
                                }
                            }
                            fdr.Geometry = geometryReader.Read(dr[GeometryColumn]);
                            fdt.AddRow(fdr);
                        }
                        fcs.Add(fdt);
                    }
                }
            }
        }
Example #12
0
        public override void ExecuteIntersectionQuery(Envelope box, IFeatureCollectionSet fcs, CancellationToken?ct = null)
        {
            using (var conn = SpatiaLiteConnection(ConnectionString))
            {
                string cols = "*";
                //If using rowid as oid, we need to explicitly request it!
                if (String.Compare(ObjectIdColumn, "rowid", StringComparison.OrdinalIgnoreCase) == 0)
                {
                    cols = "rowid,*";
                }

                var strSql = "SELECT " + cols + ", AsBinary(" + GeometryColumn + ") AS sharpmap_tempgeometry ";
                strSql += "FROM " + Table + " WHERE ";
                strSql += GetBoxClause(box);

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

                using (var adapter = new SQLiteDataAdapter(strSql, conn))
                {
                    var ds2 = new DataSet();
                    adapter.Fill(ds2);
                    conn.Close();
                    if (ds2.Tables.Count > 0)
                    {
                        var fdt = new FeatureDataTable(ds2.Tables[0]);
                        foreach (DataColumn col in ds2.Tables[0].Columns)
                        {
                            if (col.ColumnName != GeometryColumn && col.ColumnName != "sharpmap_tempgeometry" &&
                                !col.ColumnName.StartsWith("Envelope_"))
                            {
                                fdt.Columns.Add(col.ColumnName, col.DataType, col.Expression);
                            }
                        }
                        foreach (DataRow dr in ds2.Tables[0].Rows)
                        {
                            var fdr = fdt.NewRow();
                            foreach (DataColumn col in ds2.Tables[0].Columns)
                            {
                                if (col.ColumnName != GeometryColumn && col.ColumnName != "sharpmap_tempgeometry" &&
                                    !col.ColumnName.StartsWith("Envelope_"))
                                {
                                    fdr[col.ColumnName] = dr[col];
                                }
                            }
                            if (dr["sharpmap_tempgeometry"] != DBNull.Value)
                            {
                                fdr.Geometry = GeometryFromWKB.Parse((byte[])dr["sharpmap_tempgeometry"], Factory);
                            }
                            fdt.AddRow(fdr);
                        }
                        fcs.Add(fdt);
                    }
                }
            }
        }
Example #13
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);
                }
            }
        }
Example #14
0
        /// <summary>
        /// Returns all features with the view box
        /// </summary>
        /// <param name="bbox">view box</param>
        /// <param name="fcs">FeatureCollectionSet to fill data into</param>
        public override void ExecuteIntersectionQuery(Envelope bbox, IFeatureCollectionSet fcs, CancellationToken?cancellationToken = null)
        {
            using (var conn = new OracleConnection(ConnectionString))
            {
                //Get bounding box string
                var strBbox = GetBoxFilterStr(bbox);

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

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

                strSql += strBbox;

                using (var adapter = new OracleDataAdapter(strSql, conn))
                {
                    conn.Open();
                    var ds2 = new DataSet();
                    adapter.Fill(ds2);
                    conn.Close();
                    if (ds2.Tables.Count > 0)
                    {
                        var fdt = new FeatureDataTable(ds2.Tables[0]);
                        foreach (DataColumn col in ds2.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 ds2.Tables[0].Rows)
                        {
                            FeatureDataRow fdr = fdt.NewRow();
                            foreach (DataColumn col in ds2.Tables[0].Columns)
                            {
                                if (string.Compare(col.ColumnName, GeometryColumn, CultureInfo.InvariantCulture, CompareOptions.OrdinalIgnoreCase) != 0)
                                {
                                    fdr[col.ColumnName] = dr[col];
                                }
                            }

                            var sdoGeom = dr[GeometryColumn] as SdoGeometry;
                            if (sdoGeom != null)
                            {
                                fdr.Geometry = sdoGeom.AsGeometry();
                            }

                            fdt.AddRow(fdr);
                        }
                        fcs.Add(fdt);
                    }
                }
            }
        }
Example #15
0
        /// <summary>
        /// Check if the layer can be queried and retrieve data, if there is any.
        /// </summary>
        protected bool TryGetData(Map map,
                                  float x, float y,
                                  int pixelSensitivity,
                                  WmsServer.InterSectDelegate intersectDelegate,
                                  ICanQueryLayer queryLayer,
                                  string cqlFilter,
                                  out IFeatureCollectionSet fds)
        {
            if (!queryLayer.IsQueryEnabled)
            {
                fds = null;
                return(false);
            }

            float queryBoxMinX = x - pixelSensitivity;
            float queryBoxMinY = y - pixelSensitivity;
            float queryBoxMaxX = x + pixelSensitivity;
            float queryBoxMaxY = y + pixelSensitivity;

            Coordinate minXY    = map.ImageToWorld(new PointF(queryBoxMinX, queryBoxMinY));
            Coordinate maxXY    = map.ImageToWorld(new PointF(queryBoxMaxX, queryBoxMaxY));
            Envelope   queryBox = new Envelope(minXY, maxXY);

            fds = new FeatureCollectionSet();
            queryLayer.ExecuteIntersectionQuery(queryBox, fds);

            if (fds.Count == 0)
            {
                return(false);
            }

            var table = fds[0];

            if (intersectDelegate != null)
            {
                fds.Remove(table);
                fds.Add(intersectDelegate(table, queryBox));
                table = fds[0];
            }

            // filter the rows with the CQLFilter if one is provided
            if (cqlFilter != null)
            {
                var toKeep = table.Clone();
                foreach (var feature in table)
                {
                    if (CqlFilter(feature, cqlFilter))
                    {
                        toKeep.Add(feature);
                    }
                }
                fds.Remove(table);
                fds.Add(toKeep);
            }

            return(fds[0].Count > 0);
        }
Example #16
0
 /// <summary>
 /// Returns the data associated with all the geometries that are intersected by 'geom'
 /// </summary>
 /// <param name="geometry">Geometry to intersect with</param>
 /// <param name="ds">FeatureDataSet to fill data into</param>
 public void ExecuteIntersectionQuery(IGeometry geometry, IFeatureCollectionSet ds)
 {
     foreach (var layer in Layers)
     {
         if (layer is ICanQueryLayer)
         {
             ((ICanQueryLayer)layer).ExecuteIntersectionQuery(geometry, ds);
         }
     }
 }
Example #17
0
 /// <summary>
 /// Returns the data associated with all the geometries that are intersected by 'geom'
 /// </summary>
 /// <param name="box">Geometry to intersect with</param>
 /// <param name="ds">FeatureDataSet to fill data into</param>
 public void ExecuteIntersectionQuery(Envelope box, IFeatureCollectionSet ds)
 {
     foreach (Layer layer in Layers)
     {
         if (layer is ICanQueryLayer)
         {
             ((ICanQueryLayer)layer).ExecuteIntersectionQuery(box, ds);
         }
     }
 }
Example #18
0
        /// <summary>
        /// Returns the data associated with all the geometries that are intersected by 'geom'
        /// </summary>
        /// <param name="bbox">Geometry to intersect with</param>
        /// <param name="ds">FeatureDataSet to fill data into</param>
        public override void ExecuteIntersectionQuery(BoundingBox bbox, IFeatureCollectionSet fcs, CancellationToken?ct = null)
        {
            _ogrLayer.SetSpatialFilterRect(bbox.MinX, bbox.MinY, bbox.MaxX, bbox.MaxY);
            var fds = new FeatureDataSet();

            ExecuteIntersectionQuery(fds);
            foreach (var fd in fds)
            {
                fcs.Add(fd);
            }
        }
Example #19
0
        /// <summary>
        /// Throws an NotSupportedException. Attribute data is not supported by this datasource
        /// </summary>
        /// <param name="view"></param>
        /// <param name="ds">FeatureDataSet to fill data into</param>
        public void ExecuteIntersectionQuery(Envelope view, IFeatureCollectionSet ds, CancellationToken?cancellationToken = null)
        {
            IFeatureCollection fdt;

            lock (_featuresLock)
                fdt = _features.Clone();

            fdt.AddRange(EnumerateFeatures(view));

            ds.Add(fdt);
        }
Example #20
0
        /// <summary>
        /// Throws an NotSupportedException. Attribute data is not supported by this datasource
        /// </summary>
        /// <param name="geom"></param>
        /// <param name="ds">FeatureDataSet to fill data into</param>
        public void ExecuteIntersectionQuery(IGeometry geom, IFeatureCollectionSet ds, CancellationToken?cancellationToken = null)
        {
            IFeatureCollection fdt;

            lock (_featuresLock)
                fdt = _features.Clone();

            var pg = new NetTopologySuite.Geometries.Prepared.PreparedGeometryFactory().Create(geom);

            fdt.AddRange(EnumerateFeatures(pg));
            ds.Add(fdt);
        }
Example #21
0
        public override void ExecuteIntersectionQuery(Envelope box, IFeatureCollectionSet fcs, CancellationToken?cancellationToken = null)
        {
            using (var conn = new SQLiteConnection(ConnectionID))
            {
                string strSQL = "SELECT *, " + GeometryColumn + " AS sharpmap_tempgeometry ";
                strSQL += "FROM " + Table + " WHERE ";
                strSQL += GetBoxClause(box);

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

                using (SQLiteDataAdapter adapter = new SQLiteDataAdapter(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" &&
                                !col.ColumnName.StartsWith("Envelope_"))
                            {
                                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" &&
                                    !col.ColumnName.StartsWith("Envelope_"))
                                {
                                    fdr[col.ColumnName] = dr[col];
                                }
                            }
                            if (dr["sharpmap_tempgeometry"] != DBNull.Value)
                            {
                                fdr.Geometry = GeometryFromWKT.Parse((string)dr["sharpmap_tempgeometry"]);
                            }
                            fdt.AddRow(fdr);
                        }
                        fcs.Add(fdt);
                    }
                }
            }
        }
Example #22
0
 /// <summary>
 /// Returns the data associated with all the geometries that are intersected by 'geom'
 /// </summary>
 /// <param name="geom">Geometry to intersect with</param>
 /// <param name="ds">FeatureDataSet to fill data into</param>
 protected override void OnExecuteIntersectionQuery(Geometry geom, IFeatureCollectionSet fcs, CancellationToken?ct = null)
 {
     using (var ogrGeometry = OgrGeometry.CreateFromWkb(GeometryToWKB.Write(geom)))
     {
         _ogrLayer.SetSpatialFilter(ogrGeometry);
         var fds = new FeatureDataSet();
         ExecuteIntersectionQuery(fds);
         foreach (var fd in fds)
         {
             fcs.Add(fd);
         }
     }
 }
Example #23
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 override void ExecuteIntersectionQuery(Envelope bbox, IFeatureCollectionSet ds, CancellationToken?cancellationToken = null)
        {
            using (var conn = new OracleConnection(ConnectionString))
            {
                //Get bounding box string
                var strBbox = GetBoxFilterStr(bbox);

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

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

                strSQL += strBbox;

                using (var adapter = new OracleDataAdapter(strSQL, conn))
                {
                    conn.Open();
                    var ds2 = new DataSet();
                    adapter.Fill(ds2);
                    conn.Close();
                    if (ds2.Tables.Count > 0)
                    {
                        var 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"], Factory);
                            fdt.AddRow(fdr);
                        }
                        ds.Add(fdt);
                    }
                }
            }
        }
        /// <summary>
        /// Method to perform the intersection query against the data source
        /// </summary>
        /// <param name="geom">The geometry to use as filter</param>
        /// <param name="ds">The feature data set to store the results in</param>
        protected override void OnExecuteIntersectionQuery(IGeometry geom, IFeatureCollectionSet ds, CancellationToken? cancellationToken = null)
        {
            ExecuteIntersectionQuery(geom.EnvelopeInternal, ds);

            //index of last added feature data table
            var index = ds.Count - 1;
            if (index < 0) return;

            var fds = ds[index].Clone();
            fds.AddRange(FilterFeatures(ds[index]));

            ds.Remove(ds[index]);
            ds.Add(fds);
        }
Example #25
0
        /// <summary>
        /// Returns the data associated with all the geometries that are intersected by 'geom'
        ///
        /// Note! The table added should be named according to the LayerName!
        /// </summary>
        /// <param name="geometry">Geometry to intersect with</param>
        /// <param name="ds">FeatureDataSet to fill data into</param>
        public void ExecuteIntersectionQuery(IGeometry geometry, IFeatureCollectionSet ds)
        {
            if (CoordinateTransformation != null)
            {
#if !DotSpatialProjection
                geometry = GeometryTransform.TransformGeometry(geometry, CoordinateTransformation.MathTransform.Inverse(), geometry.Factory);
#else
                geometry = GeometryTransform.TransformGeometry(geometry, CoordinateTransformation.Target, CoordinateTransformation.Source, CoordinateTransformation.TargetFactory);
#endif
            }
            DataSource.ExecuteIntersectionQuery(geometry, ds);
            if (ds.Count > 0)
            {
                ds[0].Name = LayerName;
            }
        }
Example #26
0
        /// <summary>
        /// Returns the data associated with all the geometries that are intersected by 'geom'
        ///
        /// Note! The table added should be named according to the LayerName!
        /// </summary>
        /// <param name="box">Bounding box to intersect with</param>
        /// <param name="ds">FeatureDataSet to fill data into</param>
        public void ExecuteIntersectionQuery(Envelope box, IFeatureCollectionSet ds)
        {
            if (CoordinateTransformation != null)
            {
#if !DotSpatialProjection
                box = GeometryTransform.TransformBox(box, CoordinateTransformation.MathTransform.Inverse());
#else
                box = GeometryTransform.TransformBox(box, CoordinateTransformation.Target, CoordinateTransformation.Source);
#endif
            }
            DataSource.ExecuteIntersectionQuery(box, ds);
            if (ds.Count > 0)
            {
                ds[0].Name = LayerName;
            }
        }
Example #27
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="envelope"></param>
        /// <param name="ds"></param>
        public override void ExecuteIntersectionQuery(BoundingBox envelope, IFeatureCollectionSet ds, CancellationToken?ct = null)
        {
            // Identifies all the features within the given BoundingBox
            var dataTable = CreateFeatureDataTable();

            dataTable.BeginLoadData();
            foreach (Feature feature in _features)
            {
                if (envelope.Intersects(feature.Geometry.EnvelopeInternal))
                {
                    CreateNewRow(dataTable, feature);
                }
            }
            dataTable.EndLoadData();

            ds.Add(dataTable);
        }
        /// <summary>
        /// Method to perform the intersection query against the data source
        /// </summary>
        /// <param name="geom">The geometry to use as filter</param>
        /// <param name="ds">The feature data set to store the results in</param>
        protected override void OnExecuteIntersectionQuery(IGeometry geom, IFeatureCollectionSet ds, CancellationToken?cancellationToken = null)
        {
            ExecuteIntersectionQuery(geom.EnvelopeInternal, ds);

            //index of last added feature data table
            var index = ds.Count - 1;

            if (index < 0)
            {
                return;
            }

            var fds = ds[index].Clone();

            fds.AddRange(FilterFeatures(ds[index]));

            ds.Remove(ds[index]);
            ds.Add(fds);
        }
Example #29
0
        /// <summary>
        /// Returns the data associated with all the geometries that are intersected by 'geom'
        /// </summary>
        /// <param name="geometry">Geometry to intersect with</param>
        /// <param name="ds">FeatureDataSet to fill data into</param>
        public void ExecuteIntersectionQuery(IGeometry geometry, IFeatureCollectionSet ds)
        {
            if (CoordinateTransformation != null)
            {
#if !DotSpatialProjections
                if (ReverseCoordinateTransformation != null)
                {
                    geometry = GeometryTransform.TransformGeometry(geometry, ReverseCoordinateTransformation.MathTransform,
                                                                   GeometryServiceProvider.Instance.CreateGeometryFactory((int)CoordinateTransformation.TargetCS.AuthorityCode));
                }
                else
                {
                    CoordinateTransformation.MathTransform.Invert();
                    geometry = GeometryTransform.TransformGeometry(geometry, CoordinateTransformation.MathTransform,
                                                                   GeometryServiceProvider.Instance.CreateGeometryFactory((int)CoordinateTransformation.SourceCS.AuthorityCode));
                    CoordinateTransformation.MathTransform.Invert();
                }
#else
                geometry = GeometryTransform.TransformGeometry(geometry,
                                                               CoordinateTransformation.Target,
                                                               CoordinateTransformation.Source,
                                                               CoordinateTransformation.SourceFactory);
#endif
            }

            lock (_dataSource)
            {
                _dataSource.Open();
                int tableCount = ds.Count;
                _dataSource.ExecuteIntersectionQuery(geometry, ds);
                if (ds.Count > tableCount)
                {
                    //We added a table, name it according to layer
                    var table = ds[ds.Count - 1];
                    table.Name = LayerName;
                }
                _dataSource.Close();
            }
        }
Example #30
0
        /// <summary>
        /// Method to convert a <see cref="T:SharpMap.Data.FeatureDataSet"/> to a series of <see cref="GeoJSON"/> objects
        /// </summary>
        /// <param name="data">The feature dataset</param>
        /// <returns>A series of <see cref="GeoJSON"/> objects</returns>
        public static IEnumerable<GeoJSON> GetData(IFeatureCollectionSet data)
        {
            if (data == null)
                throw new ArgumentNullException("data");

            foreach (IFeatureCollection table in data)
            {
                IList<IFeatureAttributeDefinition> columns = table.AttributesDefinition;
                string[] keys = new string[columns.Count];
                for (int i = 0; i < columns.Count; i++)
                    keys[i] = columns[i].AttributeName;

                foreach (IFeature row in table)
                {
                    IGeometry geometry = row.Geometry;
                    Dictionary<string, object> values = new Dictionary<string, object>();
                    for (int j = 0; j < keys.Length; j++)
                        values.Add(keys[j], row.Attributes[j]);
                    yield return new GeoJSON(geometry, values);
                }
            }
        }        
Example #31
0
 /// <summary>
 /// Returns the data associated with all the geometries that are intersected by 'geom'
 /// </summary>
 /// <param name="geometry">Geometry to intersect with</param>
 /// <param name="ds">FeatureDataSet to fill data into</param>
 public void ExecuteIntersectionQuery(IGeometry geometry, IFeatureCollectionSet ds)
 {
     foreach (var layer in Layers)
     {
         if (layer is ICanQueryLayer)
         {
             ((ICanQueryLayer)layer).ExecuteIntersectionQuery(geometry, ds);
         }
     }
 }
Example #32
0
 /// <summary>
 /// Returns the data associated with all the geometries that are intersected by 'geom'
 /// </summary>
 /// <param name="box">Geometry to intersect with</param>
 /// <param name="ds">FeatureDataSet to fill data into</param>
 public void ExecuteIntersectionQuery(Envelope box, IFeatureCollectionSet ds)
 {
     foreach (Layer layer in Layers)
     {
         if (layer is ICanQueryLayer)
         {
             ((ICanQueryLayer)layer).ExecuteIntersectionQuery(box, ds);
         }
     }
 }
Example #33
0
 /// <summary>
 /// Method to perform the intersection query against the data source
 /// </summary>
 /// <param name="geom">The geometry to use as filter</param>
 /// <param name="ds">The feature data set to store the results in</param>
 /// <param name="cancellationToken">A cancellation token</param>
 protected abstract void OnExecuteIntersectionQuery(IGeometry geom, IFeatureCollectionSet ds, CancellationToken? cancellationToken = null);
Example #34
0
 public void ExecuteIntersectionQuery(Envelope box, IFeatureCollectionSet ds, CancellationToken? cancellationToken = null)
 {
     ExecuteIntersectionQuery(_geometryFactory.ToGeometry(box), ds);
 }
Example #35
0
        private void ExecuteIntersectionQuery(Coordinate pt, IFeatureCollectionSet ds)
        {

            if (CoordinateTransformation != null)
            {
#if !DotSpatialProjections
                if (ReverseCoordinateTransformation != null)
                {
                    pt = GeometryTransform.TransformCoordinate(pt, ReverseCoordinateTransformation.MathTransform);
                }
                else
                {
                    CoordinateTransformation.MathTransform.Invert();
                    pt = GeometryTransform.TransformCoordinate(pt, CoordinateTransformation.MathTransform);
                    CoordinateTransformation.MathTransform.Invert();
                }
#else
                pt = GeometryTransform.TransformCoordinate(pt, 
                    CoordinateTransformation.Target, 
                    CoordinateTransformation.Source);
#endif
            }
            
            //Setup resulting Table
            var dt = new FeatureDataTable();
            dt.Columns.Add("Ordinate X", typeof(Double));
            dt.Columns.Add("Ordinate Y", typeof(Double));
            for (int i = 1; i <= Bands; i++)
                dt.Columns.Add(string.Format("Value Band {0}", i), typeof(Double));

            //Get location on raster
            var buffer = new double[1];
            var bandMap = new int[Bands];
            for (int i = 1; i <= Bands; i++) bandMap[i - 1] = i;

            var geoTransform = new GeoTransform(_gdalDataset);
            var imgPt = geoTransform.GroundToImage(pt);
            Int32 x = Convert.ToInt32(imgPt.X);
            Int32 y = Convert.ToInt32(imgPt.Y);

            //Test if raster ordinates are within bounds
            if (x < 0) return;
            if (y < 0) return;
            if (x >= _imageSize.Width) return;
            if (y >= _imageSize.Height) return;

            //Create new row, add ordinates and location geometry
            FeatureDataRow dr = dt.NewRow();
            dr.Geometry = Factory.CreatePoint(pt);
            dr[0] = pt.X;
            dr[1] = pt.Y;

            //Add data from raster
            for (int i = 1; i <= Bands; i++)
            {
                Band band = _gdalDataset.GetRasterBand(i);
                //DataType dtype = band.DataType;
                CPLErr res = band.ReadRaster(x, y, 1, 1, buffer, 1, 1, 0, 0);
                if (res == CPLErr.CE_None)
                {
                    dr[1 + i] = buffer[0];
                }
                else
                {
                    dr[1 + i] = Double.NaN;
                }
            }
            //Add new row to table
            dt.Rows.Add(dr);

            //Add table to dataset
            ds.Add(dt);
        }
Example #36
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);
                }
            }
        }
Example #37
0
        /// <summary>
        /// Returns the data associated with all the geometries that are intersected by 'geom'
        /// </summary>
        /// <param name="box">Geometry to intersect with</param>
        /// <param name="ds">FeatureDataSet to fill data into</param>
        public void ExecuteIntersectionQuery(Envelope box, IFeatureCollectionSet ds)
        {
            if (CoordinateTransformation != null)
            {
#if !DotSpatialProjections
                if (ReverseCoordinateTransformation != null)
                {
                    box = GeometryTransform.TransformBox(box, ReverseCoordinateTransformation.MathTransform);
                }
                else
                {
                    CoordinateTransformation.MathTransform.Invert();
                    box = GeometryTransform.TransformBox(box, CoordinateTransformation.MathTransform);
                    CoordinateTransformation.MathTransform.Invert();
                }
#else
                box = GeometryTransform.TransformBox(box, CoordinateTransformation.Target, CoordinateTransformation.Source);
#endif
            }

            lock (_dataSource)
            {
                _dataSource.Open();
                int tableCount = ds.Count;
                _dataSource.ExecuteIntersectionQuery(box, ds);
                if (ds.Count > tableCount)
                {
                    //We added a table, name it according to layer
                    var table = ds[ds.Count - 1];
                    table.Name = LayerName;
                }
                _dataSource.Close();
            }
        }
Example #38
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 override void ExecuteIntersectionQuery(Envelope bbox, IFeatureCollectionSet ds, CancellationToken? cancellationToken = null)
        {
            //List<Geometries.Geometry> features = new List<GeoAPI.Geometries.IGeometry>();
            using (var conn = new OleDbConnection(ConnectionString))
            {
                conn.Open();

                var strSQL = "SELECT * FROM " + Table + " WHERE ";
                //If a definition query has been specified, add this as a filter on the query
                strSQL += GetDefinitionQueryConstraint(true);
                
                //Limit to the points within the boundingbox
                strSQL += GetSpatialConstraint(bbox);
                
                using (var cmd = new OleDbCommand(strSQL, conn))
                {
                    using (var reader = cmd.ExecuteReader())
                    {
                        if (reader == null)
                            throw new InvalidOperationException();
                        
                        //Set up result table
                        var fdt = new FeatureDataTable();
                        fdt.TableName = Table;
                        for (var c = 0; c < reader.FieldCount; c++)
                        {
                            var fieldType = reader.GetFieldType(c);
                            if (fieldType == null)
                                throw new Exception("Failed to retrieve field type for column: " + c);
                            fdt.Columns.Add(reader.GetName(c), fieldType);
                        }
                        var pkColumn = fdt.Columns[ObjectIdColumn];
                        fdt.PrimaryKey = new [] { pkColumn };

                        var dataTransfer = new object[reader.FieldCount];
                        
                        //Get factory and precision model
                        var factory = Factory;
                        var pm = factory.PrecisionModel;

                        fdt.BeginLoadData();
                        while (reader.Read())
                        {
                            var count = reader.GetValues(dataTransfer);
                            System.Diagnostics.Debug.Assert(count == dataTransfer.Length);

                            var fdr = (FeatureDataRow) fdt.LoadDataRow(dataTransfer, true);
                            var c = new Coordinate(Convert.ToDouble(fdr[XColumn]), Convert.ToDouble(fdr[YColumn]));
                            pm.MakePrecise(c);
                            fdr.Geometry = Factory.CreatePoint(c);
                        }
                        fdt.EndLoadData();

                        ds.Add(fdt);
                    }
                }
            }
        }
Example #39
0
        /// <summary>
        /// Returns the data associated with all the geometries that are intersected by 'geom'
        /// </summary>
        /// <param name="geom">Geometry to intersect with</param>
        /// <param name="ds">FeatureDataSet to fill data into</param>
        protected override void OnExecuteIntersectionQuery(Geometry geom, IFeatureCollectionSet fcs, CancellationToken? ct = null)
        {
            using (var ogrGeometry = OgrGeometry.CreateFromWkb(GeometryToWKB.Write(geom)))
            {
                _ogrLayer.SetSpatialFilter(ogrGeometry);
                var fds = new FeatureDataSet();
                ExecuteIntersectionQuery(fds);
                foreach (var fd in fds) fcs.Add(fd);
            }

        }
Example #40
0
 /// <summary>
 /// Method to perform the intersection query against the data source
 /// </summary>
 /// <param name="geom">The geometry to use as filter</param>
 /// <param name="ds">The feature data set to store the results in</param>
 /// <param name="cancellationToken">A cancellation token</param>
 protected abstract void OnExecuteIntersectionQuery(IGeometry geom, IFeatureCollectionSet ds, CancellationToken?cancellationToken = null);
Example #41
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="envelope"></param>
        /// <param name="ds"></param>
        public override void ExecuteIntersectionQuery(BoundingBox envelope, IFeatureCollectionSet ds, CancellationToken? ct = null)
        {
            // Identifies all the features within the given BoundingBox
            var dataTable = CreateFeatureDataTable();
            dataTable.BeginLoadData();
            foreach (Feature feature in _features)
            {
                if (envelope.Intersects(feature.Geometry.EnvelopeInternal))
                    CreateNewRow(dataTable, feature);
            }
            dataTable.EndLoadData();

            ds.Add(dataTable);
        }
Example #42
0
        public override void ExecuteIntersectionQuery(Envelope box, IFeatureCollectionSet fcs, CancellationToken? cancellationToken = null)
        {
            GetNonSpatialColumns();
            using (var conn = GetConnection(ConnectionString))
            {
                var strSql = "SELECT " + _columns + ", \"" + GeometryColumn + "\" AS \"_smtmp_\" ";
                strSql += "FROM " + Table + " WHERE ";

                // Attribute constraint
                if (!String.IsNullOrEmpty(_definitionQuery))
                    strSql += DefinitionQuery + " AND ";
                
                // Spatial constraint
                strSql += GetBoxClause(box);

                using (var cmd = new SQLiteCommand(strSql, conn))
                {
                    using (var reader = cmd.ExecuteReader())
                    {
                        var geomIndex = reader.FieldCount - 1;
                        var fdt = CreateTableFromReader(reader, geomIndex);

                        var dataTransfer = new object[geomIndex];
                        var geoReader = new GaiaGeoReader(Factory.CoordinateSequenceFactory, Factory.PrecisionModel,
                                                          _ordinates);
                        fdt.BeginLoadData();
                        while (reader.Read())
                        {
                            IGeometry g = null;
                            if (!reader.IsDBNull(geomIndex))
                                g = geoReader.Read((byte[])reader.GetValue(geomIndex));

                            //No geometry, no feature!
                            if (g == null)
                                continue;

                            //If not using RTree index we need to filter in code
                            if (_spatiaLiteIndex != SpatiaLiteIndex.RTree && !box.Intersects(g.EnvelopeInternal))
                                continue;

                            //Get all the attribute data
                            var count = reader.GetValues(dataTransfer);
                            System.Diagnostics.Debug.Assert(count == dataTransfer.Length);

                            var fdr = (FeatureDataRow)fdt.LoadDataRow(dataTransfer, true);
                            fdr.Geometry = g;
                        }
                        reader.Close();
                        fdt.EndLoadData();
                        fcs.Add(fdt);
                    }
                }
            }
        }
Example #43
0
 /// <summary>
 /// Returns the data associated with the centroid of the bounding box.
 /// </summary>
 /// <param name="box">Envelope to intersect with</param>
 /// <param name="ds">FeatureDataSet to fill data into</param>
 public void ExecuteIntersectionQuery(Envelope box, IFeatureCollectionSet ds)
 {
     var pt = new Coordinate(box.MinX + 0.5 * box.Width,
                           box.MaxY - 0.5 * box.Height);
     ExecuteIntersectionQuery(pt, ds);
 }
Example #44
0
 /// <summary>
 /// Returns the data associated with all the geometries that are intersected by 'geom'
 /// </summary>
 /// <param name="geom">Geometry to intersect with</param>
 /// <param name="cancellationToken">A cancellation token</param>
 /// <param name="ds">FeatureDataSet to fill data into</param>
 public void ExecuteIntersectionQuery(IGeometry geom, IFeatureCollectionSet ds, CancellationToken? cancellationToken = null)
 {
     OnBeginExecuteIntersectionQuery(geom);
     OnExecuteIntersectionQuery(geom, ds);
     OnEndExecuteIntersectionQuery();
 }
Example #45
0
 /// <summary>
 /// Returns the data associated with all the geometries that are intersected by 'geom'
 /// </summary>
 /// <param name="geometry">Geometry to intersect with</param>
 /// <param name="ds">FeatureDataSet to fill data into</param>
 public void ExecuteIntersectionQuery(Geometry geometry, IFeatureCollectionSet ds)
 {
     ExecuteIntersectionQuery(geometry.EnvelopeInternal, ds);
 }
Example #46
0
        public void ExecuteIntersectionQuery(IGeometry geom, IFeatureCollectionSet ds, CancellationToken? cancellationToken = null)
        {
            var fdt = (FeatureDataTable)_schemaTable.Copy();

            /* // NOTE WHY IS THIS, No other provider behaves like that?
            if (ds.Tables.Count > 0)
            {
                fdt = ds.Tables[0];
            }
            else
            {
                fdt = new FeatureDataTable();
            }*/

            var pGeom = NetTopologySuite.Geometries.Prepared.PreparedGeometryFactory.Prepare(geom);

            fdt.BeginLoadData();
            foreach (var feature in _geometrys)
            {
                feature.Value.Where(pGeom.Intersects).ToList()
                    .ForEach(v =>
                    {
                        var newRow = (FeatureDataRow) fdt.LoadDataRow(GetAssetProperties(feature.Key), true);
                        newRow.Geometry = v;
                    }
                    );
            }
            fdt.EndLoadData();

            ds.Add(fdt);
        }
Example #47
0
        /// <summary>
        /// Returns the data associated with all the geometries that are intersected by 'geom'
        /// </summary>
        /// <param name="geometry">Geometry to intersect with</param>
        /// <param name="ds">FeatureDataSet to fill data into</param>
        public void ExecuteIntersectionQuery(IGeometry geometry, IFeatureCollectionSet ds)
        {
            if (CoordinateTransformation != null)
            {
#if !DotSpatialProjections
                if (ReverseCoordinateTransformation != null)
                {
                    geometry = GeometryTransform.TransformGeometry(geometry, ReverseCoordinateTransformation.MathTransform,
                            GeometryServiceProvider.Instance.CreateGeometryFactory((int)CoordinateTransformation.TargetCS.AuthorityCode));
                }
                else
                {
                    CoordinateTransformation.MathTransform.Invert();
                    geometry = GeometryTransform.TransformGeometry(geometry, CoordinateTransformation.MathTransform,
                            GeometryServiceProvider.Instance.CreateGeometryFactory((int)CoordinateTransformation.SourceCS.AuthorityCode));
                    CoordinateTransformation.MathTransform.Invert();
                }
#else
                geometry = GeometryTransform.TransformGeometry(geometry, 
                    CoordinateTransformation.Target,
                    CoordinateTransformation.Source,
                    CoordinateTransformation.SourceFactory);
#endif
            }

            lock (_dataSource)
            {
                _dataSource.Open();
                int tableCount = ds.Count;
                _dataSource.ExecuteIntersectionQuery(geometry, ds);
                if (ds.Count > tableCount)
                {
                    //We added a table, name it according to layer
                    var table = ds[ds.Count - 1];
                    table.Name = LayerName;
                }
                _dataSource.Close();
            }
        }
Example #48
0
        /// <summary>
        /// Returns the data associated with all the geometries that are intersected by 'geom'
        /// </summary>
        /// <param name="spatialWhere">Geometry to intersect with</param>
        /// <param name="fds">FeatureDataSet to fill data into</param>
        protected virtual void ExecuteIntersectionQueryInternal(object spatialWhere, IFeatureCollectionSet fds, CancellationToken? cancellationToken = null)
        {
            var fdt = CreateNewTable(true);

            fdt.BeginLoadData();

            using (var cn = CreateOpenDbConnection())
            {
                using (var cmd = cn.CreateCommand())
                {
                    string from = null;

                    var spatialWhereString = string.Empty;
                    var env = spatialWhere as Envelope;

                    if (env != null)
                    {
                        from = GetFrom(env, cmd);
                        spatialWhereString = GetSpatialWhere(env, cmd);
                    }
                    else
                    {
                        var geom = spatialWhere as IGeometry;
                        if (geom != null)
                        {
                            from = GetFrom(geom, cmd);
                            spatialWhereString = GetSpatialWhere(geom, cmd);
                        }
                    }

                    cmd.CommandText = FeatureColumns.GetSelectClause(from)
#pragma warning disable 612,618
                        + (string.IsNullOrEmpty(DefinitionQuery)
#pragma warning restore 612,618
                               ? FeatureColumns.GetWhereClause(spatialWhereString)
                               : (" WHERE " + _definitionQuery +
                                    (string.IsNullOrEmpty(spatialWhereString)
                                            ? ""
                                            : " AND " + spatialWhereString)))

                        + FeatureColumns.GetGroupByClause()
                        + FeatureColumns.GetOrderByClause();

                    var numColumns = fdt.Columns.Count;
                    var geomIndex = numColumns;

                    Logger.Debug(t => t("Executing query:\n{0}", PrintCommand(cmd)));
                    using (var dr = cmd.ExecuteReader())
                    {
                        while (dr.Read())
                        {
                            var data = new object[numColumns+1];
                            if (dr.GetValues(data) > 0)
                            {
                                var loadData = new object[geomIndex];
                                Array.Copy(data, 0, loadData, 0, geomIndex);
                                var row = (FeatureDataRow)fdt.LoadDataRow(loadData, true);
                                row.Geometry = GeometryFromWKB.Parse((byte[])data[geomIndex], Factory);
                            }
                        }
                    }
                }
            }

            fdt.EndLoadData();

            fds.Add(fdt);
        }
Example #49
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 override void ExecuteIntersectionQuery(Envelope bbox, IFeatureCollectionSet ds, CancellationToken? cancellationToken = null)
        {
            using (var conn = new OracleConnection(ConnectionString))
            {
                //Get bounding box string
                var strBbox = GetBoxFilterStr(bbox);

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

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

                strSQL += strBbox;

                using (var adapter = new OracleDataAdapter(strSQL, conn))
                {
                    conn.Open();
                    var ds2 = new DataSet();
                    adapter.Fill(ds2);
                    conn.Close();
                    if (ds2.Tables.Count > 0)
                    {
                        var 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"], Factory);
                            fdt.AddRow(fdr);
                        }
                        ds.Add(fdt);
                    }
                }
            }
        }
Example #50
0
        /// <summary>
        /// Returns the data associated with all the geometries that are intersected by 'geom'
        /// 
        /// Note! The table added should be named according to the LayerName!
        /// </summary>
        /// <param name="box">Bounding box to intersect with</param>
        /// <param name="ds">FeatureDataSet to fill data into</param>
        public void ExecuteIntersectionQuery(Envelope box, IFeatureCollectionSet ds)
        {
            if (CoordinateTransformation != null)
            {
#if !DotSpatialProjection
                box = GeometryTransform.TransformBox(box, CoordinateTransformation.MathTransform.Inverse());
#else
                box = GeometryTransform.TransformBox(box, CoordinateTransformation.Target, CoordinateTransformation.Source);
#endif
            }
            DataSource.ExecuteIntersectionQuery(box, ds);
            if (ds.Count > 0)
            {
                ds[0].Name = LayerName;
            }
        }
Example #51
0
        /// <summary>
        /// Returns the data associated with all the geometries that are intersected by 'geom'
        /// 
        /// Note! The table added should be named according to the LayerName!
        /// </summary>
        /// <param name="geometry">Geometry to intersect with</param>
        /// <param name="ds">FeatureDataSet to fill data into</param>
        public void ExecuteIntersectionQuery(IGeometry geometry, IFeatureCollectionSet ds)
        {
            if (CoordinateTransformation != null)
            {
#if !DotSpatialProjection
                geometry = GeometryTransform.TransformGeometry(geometry, CoordinateTransformation.MathTransform.Inverse(), geometry.Factory);
#else
                geometry = GeometryTransform.TransformGeometry(geometry, CoordinateTransformation.Target, CoordinateTransformation.Source, CoordinateTransformation.TargetFactory);
#endif
            }
            DataSource.ExecuteIntersectionQuery(geometry, ds);
            if (ds.Count > 0)
            {
                ds[0].Name = LayerName;
            }
        }
Example #52
0
        /// <summary>
        /// Retrieves all features within the given BoundingBox.
        /// </summary>
        /// <param name="bounds">Bounds of the region to search.</param>
        /// <param name="fcs">FeatureDataSet to fill data into</param>
        public override void ExecuteIntersectionQuery(Envelope bounds, IFeatureCollectionSet fcs, CancellationToken? cancellationToken = null)
        {
            if (Table.Rows.Count == 0)
            {
                return;
            }

            string statement = XColumn + " > " + bounds.MinX.ToString(Map.NumberFormatEnUs) + " AND " +
                               XColumn + " < " + bounds.MaxX.ToString(Map.NumberFormatEnUs) + " AND " +
                               YColumn + " > " + bounds.MinY.ToString(Map.NumberFormatEnUs) + " AND " +
                               YColumn + " < " + bounds.MaxY.ToString(Map.NumberFormatEnUs);

            var rows = Table.Select(statement);

            var fdt = new FeatureDataTable(Table);

            foreach (DataColumn col in Table.Columns)
            {
                fdt.Columns.Add(col.ColumnName, col.DataType, col.Expression);
            }

            foreach (var dr in rows)
            {
                fdt.ImportRow(dr);
                var fdr = (FeatureDataRow)fdt.Rows[fdt.Rows.Count - 1];
                fdr.Geometry = Factory.CreatePoint(new Coordinate((double) dr[XColumn], (double) dr[YColumn]));
            }

            fcs.Add(fdt);
        }
Example #53
0
 /// <summary>
 /// Returns the data associated with all the geometries that are intersected by 'geom'
 /// </summary>
 /// <param name="box">Geometry to intersect with</param>
 /// <param name="ds">FeatureDataSet to fill data into</param>
 public override sealed void ExecuteIntersectionQuery(Envelope box, IFeatureCollectionSet ds, CancellationToken? cancellationToken = null)
 {
     Initialize();
     ExecuteIntersectionQueryInternal(box, ds, cancellationToken);
 }
Example #54
0
 /// <summary>
 /// Returns the data associated with all the geometries that are intersected by 'geom'
 /// </summary>
 /// <param name="box">Geometry to intersect with</param>
 /// <param name="ds">FeatureDataSet to fill data into</param>
 /// <param name="cancellationToken">A cancellation token</param>
 public abstract void ExecuteIntersectionQuery(Envelope box, IFeatureCollectionSet ds, CancellationToken? cancellationToken = null);
Example #55
0
 /// <summary>
 /// Method to perform the intersection query against the data source
 /// </summary>
 /// <param name="geom">The geometry to use as filter</param>
 /// <param name="ds">The feature data set to store the results in</param>
 protected override void OnExecuteIntersectionQuery(IGeometry geom, IFeatureCollectionSet ds, CancellationToken? cancellationToken = null)
 {
     ExecuteIntersectionQueryInternal(geom, ds);
 }
Example #56
0
 /// <summary>
 /// Returns the data associated with all the geometries that are intersected by 'geom'
 /// </summary>
 /// <param name="box">Geometry to intersect with</param>
 /// <param name="ds">FeatureDataSet to fill data into</param>
 public void ExecuteIntersectionQuery(Envelope box, IFeatureCollectionSet ds, CancellationToken? cancellationToken = null)
 {
     if (_labelInfo == null) return;
     ds.Add(_labelInfo);
     // Destroy internal reference
     _labelInfo = null;
 }
Example #57
0
        public override void ExecuteIntersectionQuery(Envelope box, IFeatureCollectionSet fcs, CancellationToken? ct= null)
        {
            using (var conn = SpatiaLiteConnection(ConnectionString))
            {
                string cols = "*";
                //If using rowid as oid, we need to explicitly request it!
                if (String.Compare(ObjectIdColumn, "rowid", StringComparison.OrdinalIgnoreCase) == 0)
                    cols = "rowid,*";

                var strSql = "SELECT " + cols + ", AsBinary(" + GeometryColumn + ") AS sharpmap_tempgeometry ";
                strSql += "FROM " + Table + " WHERE ";
                strSql += GetBoxClause(box);

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

                using (var adapter = new SQLiteDataAdapter(strSql, conn))
                {
                    var ds2 = new DataSet();
                    adapter.Fill(ds2);
                    conn.Close();
                    if (ds2.Tables.Count > 0)
                    {
                        var fdt = new FeatureDataTable(ds2.Tables[0]);
                        foreach (DataColumn col in ds2.Tables[0].Columns)
                            if (col.ColumnName != GeometryColumn && col.ColumnName != "sharpmap_tempgeometry" &&
                                !col.ColumnName.StartsWith("Envelope_"))
                                fdt.Columns.Add(col.ColumnName, col.DataType, col.Expression);
                        foreach (DataRow dr in ds2.Tables[0].Rows)
                        {
                            var fdr = fdt.NewRow();
                            foreach (DataColumn col in ds2.Tables[0].Columns)
                                if (col.ColumnName != GeometryColumn && col.ColumnName != "sharpmap_tempgeometry" &&
                                    !col.ColumnName.StartsWith("Envelope_"))
                                    fdr[col.ColumnName] = dr[col];
                            if (dr["sharpmap_tempgeometry"] != DBNull.Value)
                                fdr.Geometry = GeometryFromWKB.Parse((byte[]) dr["sharpmap_tempgeometry"], Factory);
                            fdt.AddRow(fdr);
                        }
                        fcs.Add(fdt);
                    }
                }
            }
        }
Example #58
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, IFeatureCollectionSet fcs, CancellationToken? cancellationToken=null)
        {
            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;

                var ds = (DataSet) new FeatureDataSet();
                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);
                    }
                }
            }
        }
Example #59
0
 /// <summary>
 /// Returns the data associated with all the geometries that are intersected by 'geom'
 /// </summary>
 /// <param name="box">Geometry to intersect with</param>
 /// <param name="ds">FeatureDataSet to fill data into</param>
 /// <param name="cancellationToken">A cancellation token</param>
 public abstract void ExecuteIntersectionQuery(Envelope box, IFeatureCollectionSet ds, CancellationToken?cancellationToken = null);
Example #60
0
        /// <summary>
        /// Returns all features with the view box
        /// </summary>
        /// <param name="bbox">view box</param>
        /// <param name="fcs">FeatureCollectionSet to fill data into</param>
        public override void ExecuteIntersectionQuery(Envelope bbox, IFeatureCollectionSet fcs, CancellationToken? cancellationToken=null)
        {
            using (var conn = new OracleConnection(ConnectionString))
            {
                //Get bounding box string
                var strBbox = GetBoxFilterStr(bbox);

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

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

                strSql += strBbox;

                using (var adapter = new OracleDataAdapter(strSql, conn))
                {
                    conn.Open();
                    var ds2 = new DataSet();
                    adapter.Fill(ds2);
                    conn.Close();
                    if (ds2.Tables.Count > 0)
                    {
                        var fdt = new FeatureDataTable(ds2.Tables[0]);
                        foreach (DataColumn col in ds2.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 ds2.Tables[0].Rows)
                        {
                            FeatureDataRow fdr = fdt.NewRow();
                            foreach (DataColumn col in ds2.Tables[0].Columns)
                                if (string.Compare(col.ColumnName, GeometryColumn, CultureInfo.InvariantCulture, CompareOptions.OrdinalIgnoreCase) != 0)
                                    fdr[col.ColumnName] = dr[col];

                            var sdoGeom = dr[GeometryColumn] as SdoGeometry;
                            if (sdoGeom != null)
                                fdr.Geometry = sdoGeom.AsGeometry();

                            fdt.AddRow(fdr);
                        }
                        fcs.Add(fdt);
                    }
                }
            }
        }