示例#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);
                    }
                }
            }
        }
        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);
        }
示例#3
0
        /// <summary>
        /// Throws an NotSupportedException. Attribute data is not supported by this datasource
        /// </summary>
        /// <param name="box"></param>
        /// <param name="ds">FeatureDataSet to fill data into</param>
        public void ExecuteIntersectionQuery(SharpMap.Geometries.BoundingBox box, FeatureDataSet ds)
        {
            FeatureDataTable fdt = new FeatureDataTable();

            fdt = _features.Clone();

            foreach (FeatureDataRow fdr in _features)
            {
                if (fdr.Geometry.GetBoundingBox().Intersects(box))
                {
                    fdt.LoadDataRow(fdr.ItemArray, false);
                    (fdt.Rows[fdt.Rows.Count - 1] as FeatureDataRow).Geometry = fdr.Geometry;
                }
            }

            ds.Tables.Add(fdt);
        }
    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);
    }
示例#6
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(Geometry geom, FeatureDataSet ds)
        {
            FeatureDataTable fdt = new FeatureDataTable();

            fdt = _features.Clone();

            foreach (FeatureDataRow fdr in _features)
            {
                if (FilterDelegate == null || FilterDelegate(fdr))
                {
                    if (fdr.Geometry.GetBoundingBox().Intersects(geom))
                    {
                        fdt.LoadDataRow(fdr.ItemArray, false);
                        (fdt.Rows[fdt.Rows.Count - 1] as FeatureDataRow).Geometry = fdr.Geometry;
                    }
                }
            }

            ds.Tables.Add(fdt);
        }
示例#7
0
        /// <summary>
        /// Creates a new row in the given <see cref="SharpMap.Data.FeatureDataTable"/> <paramref name="dataTable"/>
        /// using data in <see cref="NetTopologySuite.Features.Feature"/> <paramref name="feature"/>.
        /// </summary>
        /// <param name="dataTable">The <see cref="SharpMap.Data.FeatureDataTable"/> to fill.</param>
        /// <param name="feature">Data to insert in the <see cref="SharpMap.Data.FeatureDataTable"/>.</param>
        private static void CreateNewRow(FeatureDataTable dataTable, Feature feature)
        {
            var row = (FeatureDataRow)dataTable.LoadDataRow(feature.Attributes.GetValues(), true);

            row.Geometry = feature.Geometry;
        }
示例#8
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);
                    }
                }
            }
        }
示例#9
0
        //private static Geometry ParseOgrGeometry(OgrGeometry ogrGeometry, WKBReader reader)
        ////private static Geometry ParseOgrGeometry(OgrGeometry ogrGeometry, IGeometryFactory factory)
        //{
        //    if (ogrGeometry != null)
        //    {

        //        //Just in case it isn't 2D
        //        ogrGeometry.FlattenTo2D();
        //        var wkbBuffer = new byte[ogrGeometry.WkbSize()];
        //        ogrGeometry.ExportToWkb(wkbBuffer);
        //        //var geom = GeometryFromWKB.Parse(wkbBuffer, factory);
        //        var geom = reader.Read(wkbBuffer);
        //        if (geom == null)
        //            _log.Debug(t=> t("Failed to parse '{0}'", ogrGeometry.GetGeometryType()));
        //        return geom;

        //        ogrGeometry.GetGeometry()
        //    }
        //    return null;
        //}

        //private static FeatureDataRow LoadOgrFeatureToFeatureDataRow(FeatureDataTable table, OSGeo.OGR.Feature ogrFeature, GeoAPI.Geometries.IGeometryFactory factory)
        private static FeatureDataRow LoadOgrFeatureToFeatureDataRow(FeatureDataTable table, OSGeo.OGR.Feature ogrFeature, OgrGeometryReader reader)
        {
            var values = new object[ogrFeature.GetFieldCount()];

            for (var iField = 0; iField < ogrFeature.GetFieldCount(); iField++)
            {
                // No need to get field value if there's no value available...
                if (!ogrFeature.IsFieldSet(iField))
                {
                    continue;
                }

                int count;
                switch (ogrFeature.GetFieldType(iField))
                {
                case OgrFieldType.OFTString:
                case OgrFieldType.OFTWideString:
                    values[iField] = ogrFeature.GetFieldAsString(iField);
                    break;

                case OgrFieldType.OFTStringList:
                case OgrFieldType.OFTWideStringList:
                    values[iField] = ogrFeature.GetFieldAsStringList(iField);
                    break;

                case OgrFieldType.OFTInteger:
                    values[iField] = ogrFeature.GetFieldAsInteger(iField);
                    break;

                case OgrFieldType.OFTIntegerList:
                    values[iField] = ogrFeature.GetFieldAsIntegerList(iField, out count);
                    break;

                case OgrFieldType.OFTReal:
                    values[iField] = ogrFeature.GetFieldAsDouble(iField);
                    break;

                case OgrFieldType.OFTRealList:
                    values[iField] = ogrFeature.GetFieldAsDoubleList(iField, out count);
                    break;

                case OgrFieldType.OFTDate:
                case OgrFieldType.OFTDateTime:
                case OgrFieldType.OFTTime:
                    Int32 y, m, d, h, mi, tz;
                    float s;
                    ogrFeature.GetFieldAsDateTime(iField, out y, out m, out d, out h, out mi, out s, out tz);
                    try
                    {
                        if (y == 0 && m == 0 && d == 0)
                        {
                            values[iField] = DateTime.MinValue.AddMinutes(h * 60 + mi);
                        }
                        else
                        {
                            values[iField] = new DateTime(y, m, d, h, mi, (int)s);
                        }
                    }
// ReSharper disable once EmptyGeneralCatchClause
                    catch { }
                    break;

                default:
                    var iTmpField = iField;
                    _log.Debug(t => t("Cannot handle Ogr DataType '{0}'", ogrFeature.GetFieldType(iTmpField)));
                    break;
                }
            }

            var fdr = (FeatureDataRow)table.LoadDataRow(values, true);

            using (var gr = ogrFeature.GetGeometryRef())
            {
                //fdr.Geometry = ParseOgrGeometry(gr, factory);
                fdr.Geometry = reader.Read(gr);
            }
            return(fdr);
        }
示例#10
0
        private static FeatureDataRow LoadOgrFeatureToFeatureDataRow(FeatureDataTable table, OSGeo.OGR.Feature ogrFeature, GeoAPI.Geometries.IGeometryFactory factory)
        {
            var values = new object[ogrFeature.GetFieldCount()];
            
            for (var iField = 0; iField < ogrFeature.GetFieldCount(); iField++)
            {
                // No need to get field value if there's no value available...
                if (!ogrFeature.IsFieldSet(iField))
                {
                    continue;
                }

                int count;
                switch (ogrFeature.GetFieldType(iField))
                {
                    case OgrFieldType.OFTString:
                    case OgrFieldType.OFTWideString:
                        values[iField] = ogrFeature.GetFieldAsString(iField);
                        break;
                    case OgrFieldType.OFTStringList:
                    case OgrFieldType.OFTWideStringList:
                        values[iField] = ogrFeature.GetFieldAsStringList(iField);
                        break;
                    case OgrFieldType.OFTInteger:
                        values[iField] = ogrFeature.GetFieldAsInteger(iField);
                        break;
                    case OgrFieldType.OFTIntegerList:
                        values[iField] = ogrFeature.GetFieldAsIntegerList(iField, out count);
                        break;
                    case OgrFieldType.OFTReal:
                        values[iField] = ogrFeature.GetFieldAsDouble(iField);
                        break;
                    case OgrFieldType.OFTRealList:
                        values[iField] = ogrFeature.GetFieldAsDoubleList(iField, out count);
                        break;
                    case OgrFieldType.OFTDate:
                    case OgrFieldType.OFTDateTime:
                    case OgrFieldType.OFTTime:
                        Int32 y, m, d, h, mi, s, tz;
                        ogrFeature.GetFieldAsDateTime(iField, out y, out m, out d, out h, out mi, out s, out tz);
                        try
                        {
                            if (y == 0 && m == 0 && d == 0)
                                values[iField] = DateTime.MinValue.AddMinutes(h * 60 + mi);
                            else
                                values[iField] = new DateTime(y, m, d, h, mi, s);
                        }
// ReSharper disable once EmptyGeneralCatchClause
                        catch { }
                        break;
                    default:
                        Debug.WriteLine("Cannot handle Ogr DataType '{0}'", ogrFeature.GetFieldType(iField));
                        break;
                }
            }

            var fdr = (FeatureDataRow)table.LoadDataRow(values, true);

            using (var gr = ogrFeature.GetGeometryRef())
            {
                fdr.Geometry = ParseOgrGeometry(gr, factory);
                gr.Dispose();
            }
            return fdr;
        }
示例#11
0
 /// <summary>
 /// Creates a new row in the given <see cref="SharpMap.Data.FeatureDataTable"/> <paramref name="dataTable"/>
 /// using data in <see cref="NetTopologySuite.Features.Feature"/> <paramref name="feature"/>.
 /// </summary>
 /// <param name="dataTable">The <see cref="SharpMap.Data.FeatureDataTable"/> to fill.</param>
 /// <param name="feature">Data to insert in the <see cref="SharpMap.Data.FeatureDataTable"/>.</param>
 private static void CreateNewRow(FeatureDataTable dataTable, Feature feature)
 {
     var row = (FeatureDataRow) dataTable.LoadDataRow(feature.Attributes.GetValues(), true);
     row.Geometry = feature.Geometry;
 }
示例#12
0
        /// <summary>
        /// Throws an NotSupportedException. Attribute data is not supported by this datasource
        /// </summary>
        /// <param name="box"></param>
        /// <param name="ds">FeatureDataSet to fill data into</param>
        public void ExecuteIntersectionQuery(BoundingBox box, FeatureDataSet ds)
        {
            FeatureDataTable fdt = new FeatureDataTable();
            fdt = _features.Clone();

            foreach (FeatureDataRow fdr in _features)
                if (fdr.Geometry.GetBoundingBox().Intersects(box))
                {
                    fdt.LoadDataRow(fdr.ItemArray, false);
                    (fdt.Rows[fdt.Rows.Count - 1] as FeatureDataRow).Geometry = fdr.Geometry;
                }

            ds.Tables.Add(fdt);
        }
示例#13
0
        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();
        }
示例#14
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(Geometry geom, FeatureDataSet ds)
        {
            FeatureDataTable fdt = new FeatureDataTable();
            fdt = _features.Clone();

            foreach (FeatureDataRow fdr in _features)
                if (FilterDelegate == null || FilterDelegate(fdr))
                {
                    if (fdr.Geometry.GetBoundingBox().Intersects(geom))
                    {
                        fdt.LoadDataRow(fdr.ItemArray, false);
                        (fdt.Rows[fdt.Rows.Count - 1] as FeatureDataRow).Geometry = fdr.Geometry;
                    }
                }

            ds.Tables.Add(fdt);
        }