/// <summary>
        /// Returns all objects whose boundingbox intersects bbox.
        /// </summary>
        /// <remarks>
        /// <para>
        /// Please note that this method doesn't guarantee that the geometries returned actually intersect 'bbox', but only
        /// that their boundingbox intersects 'bbox'.
        /// </para>
        /// </remarks>
        /// <param name="bbox"></param>
        /// <returns></returns>
        public virtual IEnumerable <IFeature> GetFeatures(Envelope bbox)
        {
            Open(path);

            if (!_IsOpen)
            {
                yield break; //return empty list in case there is no connection
            }
            if (dbaseFile == null)
            {
                yield break;
            }

            //Use the spatial index to get a list of features whose boundingbox intersects bbox
            for (int i = 0; i < _FeatureCount; i++)
            {
                var rect = GetBounds(i);
                if (rect.Intersects(bbox))
                {
                    var fdr = dbaseFile.GetFeature(i);
                    fdr.Geometry = ReadGeometry(i);

                    if (FilterDelegate == null || FilterDelegate(fdr))
                    {
                        yield return(fdr);
                    }
                }
            }
        }
Beispiel #2
0
        /// <summary>
        /// Gets a datarow from the datasource at the specified index belonging to the specified datatable
        /// </summary>
        /// <param name="RowID"></param>
        /// <param name="dt">Datatable to feature should belong to.</param>
        /// <returns></returns>
        public FeatureDataRow GetFeature(uint RowID, FeatureDataTable dt)
        {
            Debug.Assert(dt != null);
            if (dbaseFile != null)
            {
                //MemoryCache
                if (_UseMemoryCache == true)
                {
                    FeatureDataRow dr2 = null;
                    cacheDataTable.TryGetValue(RowID, out dr2);
                    if (dr2 == null)
                    {
                        dr2          = dbaseFile.GetFeature(RowID, dt);
                        dr2.Geometry = ReadGeometry(RowID);
                        cacheDataTable.Add(RowID, dr2);
                    }

                    //Make a copy to return
                    FeatureDataRow drNew = dt.NewRow();
                    for (int i = 0; i < dr2.Table.Columns.Count; i++)
                    {
                        drNew[i] = dr2[i];
                    }
                    drNew.Geometry = dr2.Geometry;
                    return(drNew);
                }
                else
                {
                    //FeatureDataRow dr = (FeatureDataRow)dbaseFile.GetFeature(RowID, (dt == null) ? dbaseFile.NewTable : dt);
                    FeatureDataRow dr = dbaseFile.GetFeature(RowID, dt);
                    dr.Geometry = ReadGeometry(RowID);
                    if (FilterDelegate == null || FilterDelegate(dr))
                    {
                        return(dr);
                    }
                    else
                    {
                        return(null);
                    }
                }
            }
            else
            {
                throw (new ApplicationException(
                           "An attempt was made to read DBase data from a shapefile without a valid .DBF file"));
            }
        }
Beispiel #3
0
        /// <summary>
        /// Returns all objects whose boundingbox intersects bbox.
        /// </summary>
        /// <remarks>
        /// <para>
        /// Please note that this method doesn't guarantee that the geometries returned actually intersect 'bbox', but only
        /// that their boundingbox intersects 'bbox'.
        /// </para>
        /// </remarks>
        /// <param name="bbox"></param>
        /// <returns></returns>
        public virtual IList GetFeatures(IEnvelope bbox)
        {
            Open(path);

            if (!_IsOpen)
            {
                return(new List <IFeature>());         //return empty list in case there is no connection
            }
            long     coordinateCount  = 0;
            DateTime startReadingTime = DateTime.Now;

            if (dbaseFile == null)
            {
                return(new ArrayList());
            }

            //Use the spatial index to get a list of features whose boundingbox intersects bbox
            var objectlist = GetObjectIDsInView(bbox);
            var table      = dbaseFile.NewTable;

            foreach (var o in objectlist)
            {
                var fdr = dbaseFile.GetFeature(o, table);
                fdr.Geometry = ReadGeometry(o);
                if (fdr.Geometry != null)
                {
                    if (fdr.Geometry.EnvelopeInternal.Intersects(bbox))
                    {
                        if (FilterDelegate == null || FilterDelegate(fdr))
                        {
                            table.AddRow(fdr);
                        }
                    }
                    coordinateCount += fdr.Geometry.Coordinates.Length;
                }
            }

            return(table);

            long dt = (DateTime.Now - startReadingTime).Milliseconds;
            //log.DebugFormat("Selected {0} features + attributes with total {1} coordinates in {2} ms", table.Count, coordinateCount, dt);
        }
Beispiel #4
0
 /// <summary>
 /// Gets a datarow from the datasource at the specified index belonging to the specified datatable
 /// </summary>
 /// <param name="RowID"></param>
 /// <param name="dt">Datatable to feature should belong to.</param>
 /// <returns></returns>
 public IFeature GetFeature(uint RowID, IFeatures dt)
 {
     if (dbaseFile != null)
     {
         IFeature dr = (IFeature)dbaseFile.GetFeature(RowID, (dt == null) ? new Features() : dt);
         dr.Geometry = ReadGeometry(RowID);
         if (FilterDelegate == null || FilterDelegate(dr))
         {
             return(dr);
         }
         else
         {
             return(null);
         }
     }
     else
     {
         throw (new ApplicationException("An attempt was made to read DBase data from a shapefile without a valid .DBF file"));
     }
 }
Beispiel #5
0
        /// <summary>
        /// Returns all objects whose boundingbox intersects bbox.
        /// </summary>
        /// <remarks>
        /// <para>
        /// Please note that this method doesn't guarantee that the geometries returned actually intersect 'bbox', but only
        /// that their boundingbox intersects 'bbox'.
        /// </para>
        /// </remarks>
        /// <param name="bbox"></param>
        /// <param name="ds"></param>
        /// <returns></returns>
        public void ExecuteIntersectionQuery(SharpMap.Geometries.BoundingBox bbox, SharpMap.Data.FeatureDataSet ds)
        {
            //Use the spatial index to get a list of features whose boundingbox intersects bbox
            List <uint> objectlist = GetObjectIDsInView(bbox);

            SharpMap.Data.FeatureDataTable dt = dbaseFile.NewTable;

            for (int i = 0; i < objectlist.Count; i++)
            {
                SharpMap.Data.FeatureDataRow fdr = dbaseFile.GetFeature(objectlist[i], dt);
                fdr.Geometry = ReadGeometry(objectlist[i]);
                if (fdr.Geometry != null)
                {
                    if (fdr.Geometry.GetBoundingBox().Intersects(bbox))
                    {
                        if (FilterDelegate == null || FilterDelegate(fdr))
                        {
                            dt.AddRow(fdr);
                        }
                    }
                }
            }
            ds.Tables.Add(dt);
        }