Beispiel #1
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, FeatureDataSet ds)
        {
            //List<Geometries.Geometry> features = new List<NetTopologySuite.Geometries.Geometry>();
            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 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.Tables.Add(fdt);
                    }
                }
            }
        }
Beispiel #2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="geom"></param>
        /// <param name="ds"></param>
        protected override void OnExecuteIntersectionQuery(Geometry geom, FeatureDataSet ds)
        {
            FeatureDataTable dataTable = CreateFeatureDataTable();

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

            ds.Tables.Add(dataTable);
        }
    public VectorLayer CreateGeometryLayer()
    {
        var gf = new NetTopologySuite.Geometries.GeometryFactory();
        var fdt = new FeatureDataTable();
        fdt.Columns.Add(new DataColumn("Name", typeof (String)));

        fdt.BeginLoadData();
        var fdr = (FeatureDataRow)fdt.LoadDataRow(new[] {(object) "Mayence"}, true);
        fdr.Geometry = gf.CreatePoint(new Point(8.1, 50.0));
        fdt.EndLoadData();

        var vLayer = new VectorLayer("GeometryProvider");
        vLayer.DataSource = new FeatureProvider(fdt);
        vLayer.SRID = 4326;

        return vLayer;
    }
    public VectorLayer CreateGeometryLayer()
    {
        var gf  = new NetTopologySuite.Geometries.GeometryFactory();
        var fdt = new FeatureDataTable();

        fdt.Columns.Add(new DataColumn("Name", typeof(String)));

        fdt.BeginLoadData();
        var fdr = (FeatureDataRow)fdt.LoadDataRow(new[] { (object)"Mayence" }, true);

        fdr.Geometry = gf.CreatePoint(new Point(8.1, 50.0));
        fdt.EndLoadData();

        var vLayer = new VectorLayer("GeometryProvider");

        vLayer.DataSource = new GeometryFeatureProvider(fdt);
        vLayer.SRID       = 4326;

        return(vLayer);
    }
Beispiel #5
0
        private int _oid  = -1; // primary key index from fdt schema or subsequently added unique constraint

        #region constructors

        /// <summary>
        /// Initializes a new instance of the <see cref="GeometryProvider"/>
        /// </summary>
        /// <param name="geometries">Set of geometries that this datasource should contain</param>
        public GeometryFeatureProvider(IEnumerable <Geometry> geometries)
        {
            _features = new FeatureDataTable();
            _features.BeginLoadData();
            foreach (var geom in geometries)
            {
                var fdr = _features.NewRow();
                fdr.Geometry = geom;
                _features.AddRow(fdr);
            }
            _features.AcceptChanges();
            _features.EndLoadData();

            _features.TableCleared += HandleFeaturesCleared;
            _features.Constraints.CollectionChanged += HandleConstraintsCollectionChanged;

            if (_features.Count > 0 && _features[0].Geometry != null)
            {
                SRID = _features[0].Geometry.SRID;
            }
        }
        private static FeatureDataTable CreateTable(string tableName, string columnName, Type columnType,
                                                    params object[] values)
        {
            var res = new FeatureDataTable();

            res.TableName = tableName;
            res.Columns.Add("FID", typeof(int));
            res.Columns.Add(columnName, columnType);
            res.PrimaryKey = new DataColumn[] { res.Columns[0] };

            res.BeginLoadData();
            var i = 1;

            for (; i < values.Length; i++)
            {
                res.LoadDataRow(new [] { i, Convert.ChangeType(values[i], columnType) }, true);
            }

            res.LoadDataRow(new object[] { i, DBNull.Value }, true);
            res.EndLoadData();
            return(res);
        }
Beispiel #7
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, FeatureDataSet ds)
        {
            //List<Geometries.Geometry> features = new List<SharpMap.Geometries.Geometry>();
            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 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.Tables.Add(fdt);
                    }
                }
            }
        }
        private static void FillRealDataTable(FeatureDataTable table)
        {
            table.BeginLoadData();
            var factory = GeoAPI.GeometryServiceProvider.Instance.CreateGeometryFactory(4326);

            uint id = 0;
            foreach (var datas in PointData())
            {
                var row = (FeatureDataRow) table.LoadDataRow(new object[] {id++, datas[0]}, LoadOption.OverwriteChanges);
                row.Geometry = factory.CreatePoint(new Coordinate(datas[2], datas[1]));
            }
            table.EndLoadData();
        }
Beispiel #9
0
        /// <summary>
        /// Returns the features that intersects with 'geom'
        /// </summary>
        /// <param name="geom"></param>
        /// <param name="ds">FeatureDataSet to fill data into</param>
        protected override void OnExecuteIntersectionQuery(IGeometry geom, IFeatureCollectionSet ds, CancellationToken?cancellationToken = null)
        {
            //List<Geometry> features = new List<Geometry>();
            using (var conn = new SqlConnection(ConnectionString))
            {
                //TODO: Convert to SQL Server
                string strGeom = _spatialObject + "::STGeomFromText('" + geom.AsText() + "', #SRID#)";

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

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

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

                strSQL += strGeom;

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

                var fds = new FeatureDataSet();
                using (SqlDataAdapter adapter = new SqlDataAdapter(strSQL, conn))
                {
                    conn.Open();
                    adapter.Fill(fds);
                    conn.Close();
                    if (fds.Tables.Count > 0)
                    {
                        var fdt = new FeatureDataTable(fds.Tables[0]);
                        foreach (System.Data.DataColumn col in fds.Tables[0].Columns)
                        {
                            if (col.ColumnName != GeometryColumn && col.ColumnName != "sharpmap_tempgeometry")
                            {
                                fdt.Columns.Add(col.ColumnName, col.DataType, col.Expression);
                            }
                        }

                        fdt.BeginLoadData();
                        foreach (System.Data.DataRow dr in fds.Tables[0].Rows)
                        {
                            FeatureDataRow fdr = fdt.NewRow();
                            foreach (System.Data.DataColumn col in fds.Tables[0].Columns)
                            {
                                if (col.ColumnName != GeometryColumn && col.ColumnName != "sharpmap_tempgeometry")
                                {
                                    fdr[col.ColumnName] = dr[col];
                                }
                            }
                            fdr.Geometry = Converters.WellKnownBinary.GeometryFromWKB.Parse((byte[])dr["sharpmap_tempgeometry"], Factory);
                            fdt.AddRow(fdr);
                        }
                        fdt.EndLoadData();
                        ds.Add(fdt);
                    }
                }
            }
        }
Beispiel #10
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 ds, CancellationToken? cancellationToken=null)   
       {   
           //List<Geometry> features = new List<Geometry>();   
           using (var conn = new SqlConnection(ConnectionString))   
           {   
               //TODO: Convert to SQL Server   
               string strGeom = _spatialObject + "::STGeomFromText('" + geom.AsText() + "', #SRID#)";

               strGeom = strGeom.Replace("#SRID#", SRID > 0 ? SRID.ToString() : "0");
               strGeom = GeometryColumn + ".STIntersects(" + strGeom + ") = 1";   
 
               string strSQL = "SELECT g.* , g." + GeometryColumn + ".STAsBinary() As sharpmap_tempgeometry FROM " + Table + " g " + BuildTableHints() + " WHERE ";   
 
               if (!String.IsNullOrEmpty(_definitionQuery))   
                   strSQL += DefinitionQuery + " AND ";   
 
               strSQL += strGeom;

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

               var fds = new FeatureDataSet(); 
               using (SqlDataAdapter adapter = new SqlDataAdapter(strSQL, conn))   
               {   
                   conn.Open();   
                   adapter.Fill(fds);   
                   conn.Close();   
                   if (fds.Tables.Count > 0)   
                   {   
                       var fdt = new FeatureDataTable(fds.Tables[0]);   
                       foreach (System.Data.DataColumn col in fds.Tables[0].Columns)   
                           if (col.ColumnName != GeometryColumn && col.ColumnName != "sharpmap_tempgeometry")   
                               fdt.Columns.Add(col.ColumnName, col.DataType, col.Expression);   
                       
                       fdt.BeginLoadData();
                       foreach (System.Data.DataRow dr in fds.Tables[0].Rows)   
                       {   
                           FeatureDataRow fdr = fdt.NewRow();   
                           foreach (System.Data.DataColumn col in fds.Tables[0].Columns)   
                               if (col.ColumnName != GeometryColumn && col.ColumnName != "sharpmap_tempgeometry")   
                                   fdr[col.ColumnName] = dr[col];
                           fdr.Geometry = Converters.WellKnownBinary.GeometryFromWKB.Parse((byte[])dr["sharpmap_tempgeometry"], Factory);   
                           fdt.AddRow(fdr);   
                       }
                       fdt.EndLoadData();
                       ds.Add(fdt);   
                   }   
               }   
           }   
       }