예제 #1
0
        /// <summary>
        /// Function to get a specific feature from the database.
        /// </summary>
        /// <param name="oid">The object id</param>
        /// <returns>A feature data row</returns>
        protected virtual FeatureDataRow GetFeatureInternal(uint oid)
        {
            using (var cn = CreateOpenDbConnection())
            {
                using (var cmd = cn.CreateCommand())
                {
                    cmd.CommandText = FeatureColumns.GetSelectClause(From)
                                      + string.Format(" WHERE {0}={1};", _dbUtility.DecorateEntity(ObjectIdColumn), oid);

                    Logger.Debug(t => t("Executing query:\n{0}", PrintCommand(cmd)));
                    using (var dr = cmd.ExecuteReader())
                    {
                        if (dr.HasRows)
                        {
                            dr.Read();
                            var            fdt = CreateNewTable();
                            FeatureDataRow row = null;
                            fdt.BeginLoadData();
                            var numColumns = fdt.Columns.Count;
                            var data       = new object[numColumns + 1];
                            if (dr.GetValues(data) > 0)
                            {
                                var loadData = new object[numColumns];
                                Array.Copy(data, 0, loadData, 0, numColumns);
                                row          = (FeatureDataRow)fdt.LoadDataRow(loadData, true);
                                row.Geometry = GeometryFromWKB.Parse((byte[])data[numColumns], Factory);
                            }
                            fdt.EndLoadData();
                            return(row);
                        }
                    }
                }
            }
            return(null);
        }
예제 #2
0
        /// <summary>
        /// Function to get a specific feature from the database.
        /// </summary>
        /// <param name="oid">The object id</param>
        /// <returns>A feature data row</returns>
        protected virtual FeatureDataRow GetFeatureInternal(uint oid)
        {
            using (var cn = CreateOpenDbConnection())
            {
                using (var cmd = cn.CreateCommand())
                {
                    cmd.CommandText = FeatureColumns.GetSelectClause(From)
                                      + string.Format(" WHERE {0}={1};", _dbUtility.DecorateEntity("_smOid_"), oid);

                    using (var dr = cmd.ExecuteReader())
                    {
                        if (dr.HasRows)
                        {
                            var fdr = CreateNewTable().NewRow();
                            fdr.Geometry = GeometryFromWKB.Parse((byte[])dr.GetValue(1), Factory);
                            fdr[0]       = dr.GetValue(0);
                            for (var i = 2; i < dr.FieldCount; i++)
                            {
                                fdr[i - 1] = dr.GetValue(i);
                            }
                            return(fdr);
                        }
                    }
                }
            }
            return(null);
        }
예제 #3
0
        /// <summary>
        /// Function to create a new, empty <see cref="FeatureDataTable"/>
        /// </summary>
        /// <param name="force">Value indicating that a new feature data table should be created, no matter what.</param>
        /// <returns>A feature data table</returns>
        protected virtual FeatureDataTable CreateNewTable(bool force)
        {
            if (force || _baseTable == null)
            {
                var fdt = new FeatureDataTable {
                    TableName = Name
                };

                using (var cn = CreateOpenDbConnection())
                {
                    using (var cmd = cn.CreateCommand())
                    {
                        cmd.CommandText = FeatureColumns.GetSelectClause(From);
                        using (var da = CreateDataAdapter())
                        {
                            da.SelectCommand = cmd;
                            fdt = (FeatureDataTable)da.FillSchema(fdt, SchemaType.Source);
                        }
                    }
                }

                //Remove the geometry column, which is always the last!
                fdt.Columns.RemoveAt(fdt.Columns.Count - 1);
                if (_baseTable == null)
                {
                    _baseTable = fdt;
                    return(_baseTable);
                }
                return(fdt);
            }
            return(_baseTable);

            /*
             * var res = new FeatureDataTable(dt);
             * var resColumns = res.Columns;
             * foreach (var column in dt.Columns)
             * {
             *  resColumns.Add(new DataColumn(column.))
             * }
             * res.PrimaryKey = new [] {res.Columns[0]};
             * return res;
             */
        }
예제 #4
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, FeatureDataSet fds)
        {
            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.Tables.Add(fdt);
        }