Example #1
0
        /// <summary>
        /// Returns geometries within the specified bounding box
        /// </summary>
        /// <param name="bbox"></param>
        /// <returns></returns>
        public override Collection <Geometry> GetGeometriesInView(BoundingBox bbox)
        {
            var geoms = new Collection <Geometry>();

            OgrDataSource ogrDataSource;

            using (var ogrLayer = GetLayer(_layerIndex, out ogrDataSource))
            {
                ogrLayer.SetSpatialFilterRect(bbox.MinX, bbox.MinY, bbox.MaxX, bbox.MaxY);
                try
                {
                    var        reader = new OgrGeometryReader(Factory);
                    OgrFeature ogrFeature;
                    while ((ogrFeature = ogrLayer.GetNextFeature()) != null)
                    {
                        using (var gr = ogrFeature.GetGeometryRef())
                        {
                            //var geom = ParseOgrGeometry(gr, Factory);
                            var geom = reader.Read(gr);
                            if (geom != null)
                            {
                                geoms.Add(geom);
                            }
                        }
                        ogrFeature.Dispose();
                    }
                    ogrDataSource.Dispose();
                }
                catch (Exception ex)
                {
                    _log.Debug(t => t(ex.Message));
                }
            }
            return(geoms);
        }
Example #2
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, FeatureDataSet ds)
        {
            OgrDataSource ogrDataSource;

            using (var ogrLayer = GetLayer(_layerIndex, out ogrDataSource))
            {
                ogrLayer.SetSpatialFilterRect(bbox.MinX, bbox.MinY, bbox.MaxX, bbox.MaxY);
                ExecuteIntersectionQuery(ds, ogrLayer);
                ogrDataSource.Dispose();
            }
        }
Example #3
0
        /// <summary>
        /// Returns geometry Object IDs whose bounding box intersects 'bbox'
        /// </summary>
        /// <param name="bbox"></param>
        /// <returns></returns>
        public override Collection <uint> GetObjectIDsInView(BoundingBox bbox)
        {
            var           objectIDs = new Collection <uint>();
            OgrDataSource ogrDataSource;

            using (var ogrLayer = GetLayer(_layerIndex, out ogrDataSource))
            {
                ogrLayer.SetSpatialFilterRect(bbox.MinX, bbox.MinY, bbox.MaxX, bbox.MaxY);

                OgrFeature ogrFeature;
                while ((ogrFeature = ogrLayer.GetNextFeature()) != null)
                {
                    objectIDs.Add((uint)ogrFeature.GetFID());
                    ogrFeature.Dispose();
                }
                ogrDataSource.Dispose();
            }
            return(objectIDs);
        }
Example #4
0
        ///// <summary>
        ///// Loads a Ogr datasource with the first layer
        ///// </summary>
        ///// <param name="datasource">datasource</param>
        ///// <param name="name">Returns the name of the loaded layer</param>
        /////<remarks>
        /////This constructor is obsolete!
        /////If you want this functionality use
        /////<example>
        /////SharpMap.Data.Providers.Ogr prov = new SharpMap.Data.Providers.Ogr(datasource);
        /////string layerName = prov.Layername;
        /////</example>
        /////</remarks>
        //[Obsolete("This constructor does not work well with VB.NET. Use LayerName property instead")]
        //public Ogr(string datasource, out string name)
        //    : this(datasource, 0, out name)
        //{
        //}

        #endregion

        #region IProvider Members

        /// <summary>
        /// Boundingbox of the dataset
        /// </summary>
        /// <returns>boundingbox</returns>
        public override BoundingBox GetExtents()
        {
            if (_bbox == null)
            {
                OgrEnvelope ogrEnvelope = new OgrEnvelope();
                using (var ogrLayer = GetLayer(LayerIndex))
                {
                    if (ogrLayer != null)
                    {
                        ogrLayer.GetExtent(ogrEnvelope, 1);
                    }
                }

                _bbox = new BoundingBox(ogrEnvelope.MinX, ogrEnvelope.MaxX,
                                        ogrEnvelope.MinY, ogrEnvelope.MaxY);
            }

            return(_bbox);
        }
Example #5
0
 public void GetFeaturesInView(BoundingBox bbox, FeatureDataSet ds)
 {
     ExecuteIntersectionQuery(bbox, ds);
 }