/// <summary>
        /// Adds features from the command to the receiver.
        /// </summary>
        /// <param name="fr">Object that receives features</param>
        /// <param name="commandText">Sql command text</param>
        protected int InternalQueryFeatures(IFeatureReceiver fr, string commandText)
        {
            int result = 0;

            using (DbCommand command = GetCommand())
            {
                if (command != null)
                {
                    command.CommandText = commandText;

                    IDataReader reader = command.ExecuteReader();

                    while (reader.Read())
                    {
                        if (addFeatureToReceiver(fr, reader[_uniqKeyField].ToString(),
                                                 reader[_titleField].ToString(),
                                                 (byte[])reader[_spatialDataField]))
                        {
                            result++;
                        }
                    }
                }
            }

            return(result);
        }
Ejemplo n.º 2
0
        private void addFeaturesToCache(IFeatureReceiver fr,
                                        List <Feature> points,
                                        List <Feature> multiPoints,
                                        List <Feature> polylines,
                                        List <Feature> polygons)
        {
            _cacheAccessor.Key = fr.Alias;
            if (!_cacheAccessor.ExistsInCache)
            {
                BoundingRectangle b   = new BoundingRectangle();
                List <Feature>    pts = new List <Feature>();
                foreach (Feature feature in points)
                {
                    b.Join(feature.BoundingRectangle);
                    pts.Add(feature);
                }
                foreach (Feature feature in multiPoints)
                {
                    b.Join(feature.BoundingRectangle);
                    pts.Add(feature);
                }

                //buildAndSaveIndex(MapAround.Mapping.FeatureType.Point, b, fr.DefaultPointsIndexSettings, pts);

                b = new BoundingRectangle();
                foreach (Feature feature in polylines)
                {
                    b.Join(feature.BoundingRectangle);
                }

                //buildAndSaveIndex(MapAround.Mapping.FeatureType.Polyline, b, fr.DefaultPolylinesIndexSettings, polylines);

                b = new BoundingRectangle();
                foreach (Feature feature in polygons)
                {
                    b.Join(feature.BoundingRectangle);
                }

                //buildAndSaveIndex(MapAround.Mapping.FeatureType.Polygon, b, fr.DefaultPolygonsIndexSettings, polygons);

                if (_processAttributes)
                {
                    _cacheAccessor.SaveAttributeNames(fr.FeatureAttributeNames);
                }
            }
        }
Ejemplo n.º 3
0
        //private IGeometry geometryFromMapRecord(MapFileRecord record)
        //{
        //    switch (record.ShapeType)
        //    {
        //        // point
        //        case 1:
        //            return new PointD(record.Points[0].X, record.Points[0].Y);
        //        // polyline
        //        case 3:
        //            Polyline polyline = new Polyline();
        //            for (int i = 0; i < record.Parts.Count; i++)
        //            {
        //                LinePath path = new LinePath();
        //                int j;
        //                for (j = record.Parts[i]; j < (i == record.Parts.Count - 1 ? record.Points.Count : record.Parts[i + 1]); j++)
        //                    path.Vertices.Add(PlanimetryEnvironment.NewCoordinate(record.Points[j].X, record.Points[j].Y));

        //                polyline.Paths.Add(path);
        //            }
        //            return polyline;
        //        // ground
        //        case 5:
        //            Polygon p = new Polygon();
        //            for (int i = 0; i < record.Parts.Count; i++)
        //            {
        //                Contour contour = new Contour();
        //                int j;
        //                for (j = record.Parts[i]; j < (i == record.Parts.Count - 1 ? record.Points.Count : record.Parts[i + 1]); j++)
        //                    contour.Vertices.Add(PlanimetryEnvironment.NewCoordinate(record.Points[j].X, record.Points[j].Y));

        //                contour.Vertices.RemoveAt(contour.Vertices.Count - 1);
        //                p.Contours.Add(contour);
        //            }
        //            if (p.CoordinateCount > 0)
        //                return p;
        //            else
        //                return null;
        //        // set of points
        //        case 8:
        //            MultiPoint mp = new MultiPoint();
        //            for (int i = 0; i < record.Points.Count; i++)
        //                mp.Points.Add(PlanimetryEnvironment.NewCoordinate(record.Points[i].X, record.Points[i].Y));
        //            return mp;
        //    }

        //    return null;
        //}

        private bool processFeature(Feature feature, IFeatureReceiver fr, List <Feature> points,
                                    List <Feature> multiPoints,
                                    List <Feature> polylines,
                                    List <Feature> polygons)
        {
            if (feature == null)
            {
                return(false);
            }

            bool isAccepted = true;

            if (FeatureFetched != null)
            {
                FeatureOperationEventArgs foea = new FeatureOperationEventArgs(feature);
                FeatureFetched(this, foea);
                isAccepted = foea.IsAccepted;
            }

            if (!isAccepted)
            {
                return(false);
            }

            fr.AddFeature(feature);
            switch (feature.FeatureType)
            {
            case FeatureType.Point: points.Add(feature); break;

            case FeatureType.MultiPoint: multiPoints.Add(feature); break;

            case FeatureType.Polyline: polylines.Add(feature); break;

            case FeatureType.Polygon: polygons.Add(feature); break;
            }

            return(true);
        }
        private bool addFeatureToReceiver(IFeatureReceiver fr, string uniqKey, string title, byte[] spatialData)
        {
            Feature feature = FeatureFromSpatialDataBytes(spatialData);

            feature.UniqKey = uniqKey;
            feature.Title   = title;

            bool isAccepted = true;

            if (FeatureFetched != null)
            {
                FeatureOperationEventArgs foea = new FeatureOperationEventArgs(feature);
                FeatureFetched(this, foea);
                isAccepted = foea.IsAccepted;
            }

            if (isAccepted)
            {
                fr.AddFeature(feature);
            }

            return(isAccepted);
        }
Ejemplo n.º 5
0
 /// <summary>
 /// Adds the features retrieved from data source to the receiver.
 /// </summary>
 /// <param name="receiver">An object that receives features</param> 
 /// <param name="bounds">Rectangular region you want to fill with the objects</param>
 public abstract int QueryFeatures(IFeatureReceiver receiver, BoundingRectangle bounds);
Ejemplo n.º 6
0
 /// <summary>
 /// Adds the features retrieved from data source to the receiver.
 /// </summary>
 /// <param name="receiver">An object that receives features</param> 
 public abstract int QueryFeatures(IFeatureReceiver receiver);
 /// <summary>
 /// Adds features retrieved from the data source to the receiver.
 /// </summary>
 /// <param name="receiver">An object that receives features</param>
 /// <rereturns>A number of retrieved features</rereturns>
 public override int QueryFeatures(IFeatureReceiver receiver)
 {
     return(InternalQueryFeatures(receiver, getSelectString()));
 }
Ejemplo n.º 8
0
        private int internalQueryFeatures(IFeatureReceiver fr, BoundingRectangle bounds, bool checkBounds)
        {
            if (_cacheAccessor != null && !string.IsNullOrEmpty(fr.Alias))
            { 
                _cacheAccessor.Key = fr.Alias;
                if (_cacheAccessor.ExistsInCache)
                    return FillFromCache(_cacheAccessor, fr, bounds, _processAttributes);
                else
                    // If the object is not found in the cache, you must remove all objects from a file, to put them in the cache
                    checkBounds = false;
            }

            ShapeFile shapeFile = new ShapeFile();
            shapeFile.AttributesEncoding = _attributesEncoding;
            shapeFile.Read(_fileName, checkBounds ? bounds : null);

            if (ProcessAttributes)
            {
                fr.FeatureAttributeNames.Clear();
                foreach (string s in shapeFile.AttributeNames)
                    fr.FeatureAttributeNames.Add(s);
            }

            int result = 0;
            string layerHashStr = fr.GetHashCode().ToString();

            List<Feature> points = new List<Feature>();
            List<Feature> multiPoints = new List<Feature>();
            List<Feature> polylines = new List<Feature>();
            List<Feature> polygons = new List<Feature>();

            foreach (ShapeFileRecord record in shapeFile.Records)
            {
                if (!checkBounds ||
                    (record.MaxX >= bounds.MinX && record.MaxY >= bounds.MinY &&
                     record.MinX <= bounds.MaxX && record.MinY <= bounds.MaxY))
                {
                    Feature newFeature = null;
                    IGeometry geometry = geometryFromShapeRecord(record);
                    if (geometry != null)
                    {
                        newFeature = new Feature(geometry);
                        newFeature.UniqKey = layerHashStr + record.RecordNumber.ToString();
                        if (ProcessAttributes && record.Attributes != null)
                            newFeature.Attributes = record.Attributes.ItemArray;

                        if (processFeature(newFeature, fr, points, multiPoints, polylines, polygons))
                            result++;
                    }
                }
            }

            // If the objects are not extracted from the cache may be added to the cache.
            // This should be done only if the retrieval of all objects (checkBounds == false)
            if (_cacheAccessor != null && !string.IsNullOrEmpty(fr.Alias) &&
                checkBounds == false)
            {
                addFeaturesToCache(fr, points, multiPoints, polylines, polygons);
            }

            return result;
        }
Ejemplo n.º 9
0
 /// <summary>
 /// Adds features retrieved from the data source to the receiver.
 /// </summary>
 /// <param name="receiver">An object that receives features</param> 
 /// <rereturns>A number of retrieved features</rereturns>
 public override int QueryFeatures(IFeatureReceiver receiver)
 {
     return InternalQueryFeatures(receiver, getSelectString());
 }
Ejemplo n.º 10
0
        /// <summary>
        /// Adds features from the command to the receiver.
        /// </summary>
        /// <param name="fr">Object that receives features</param>
        /// <param name="commandText">Sql command text</param>
        protected int InternalQueryFeatures(IFeatureReceiver fr, string commandText)
        {
            int result = 0;

            using (DbCommand command = GetCommand())
            {
                if (command != null)
                {
                    command.CommandText = commandText;

                    IDataReader reader = command.ExecuteReader();

                    while (reader.Read())
                    {
                        if(addFeatureToReceiver(fr, reader[_uniqKeyField].ToString(),
                                    reader[_titleField].ToString(),
                                    (byte[])reader[_spatialDataField]))
                            result++;
                    }
                }
            }

            return result;
        }
 /// <summary>
 /// Adds the features retrieved from data source to the receiver.
 /// </summary>
 /// <param name="receiver">An object that receives features</param>
 /// <param name="bounds">Rectangular region you want to fill with the objects</param>
 public abstract int QueryFeatures(IFeatureReceiver receiver, BoundingRectangle bounds);
 /// <summary>
 /// Adds the features retrieved from data source to the receiver.
 /// </summary>
 /// <param name="receiver">An object that receives features</param>
 public abstract int QueryFeatures(IFeatureReceiver receiver);
Ejemplo n.º 13
0
 /// <summary>
 /// Adds features retrieved from the data source to the receiver.
 /// </summary>
 /// <param name="receiver">An object that receives features</param> 
 /// <rereturns>A number of retrieved features</rereturns>
 public override int QueryFeatures(IFeatureReceiver receiver)
 {
     return internalQueryFeatures(receiver, new BoundingRectangle(), false);
 }
Ejemplo n.º 14
0
 /// <summary>
 /// Adds features retrieved from the data source to the receiver.
 /// </summary>
 /// <param name="receiver">An object that receives features</param> 
 /// <param name="bounds">Rectangular region you want to fill with the objects</param>
 /// <rereturns>A number of retrieved features</rereturns>
 public override int QueryFeatures(IFeatureReceiver receiver, BoundingRectangle bounds)
 {
     return internalQueryFeatures(receiver, bounds, true);
 }
Ejemplo n.º 15
0
        private void addFeaturesToCache(IFeatureReceiver fr, 
            List<Feature> points, 
            List<Feature> multiPoints,
            List<Feature> polylines,
            List<Feature> polygons)
        {
            _cacheAccessor.Key = fr.Alias;
            if (!_cacheAccessor.ExistsInCache)
            {
                BoundingRectangle b = new BoundingRectangle();
                List<Feature> pts = new List<Feature>();
                foreach (Feature feature in points)
                {
                    b.Join(feature.BoundingRectangle);
                    pts.Add(feature);
                }
                foreach (Feature feature in multiPoints)
                {
                    b.Join(feature.BoundingRectangle);
                    pts.Add(feature);
                }

                buildAndSaveIndex(MapAround.Mapping.FeatureType.Point, b, fr.DefaultPointsIndexSettings, pts);

                b = new BoundingRectangle();
                foreach (Feature feature in polylines)
                    b.Join(feature.BoundingRectangle);

                buildAndSaveIndex(MapAround.Mapping.FeatureType.Polyline, b, fr.DefaultPolylinesIndexSettings, polylines);

                b = new BoundingRectangle();
                foreach (Feature feature in polygons)
                    b.Join(feature.BoundingRectangle);

                buildAndSaveIndex(MapAround.Mapping.FeatureType.Polygon, b, fr.DefaultPolygonsIndexSettings, polygons);

                if (_processAttributes)
                    _cacheAccessor.SaveAttributeNames(fr.FeatureAttributeNames);
            }
        }
Ejemplo n.º 16
0
        private bool processFeature(Feature feature, IFeatureReceiver fr, List<Feature> points,
            List<Feature> multiPoints,
            List<Feature> polylines,
            List<Feature> polygons)
        {
            if (feature == null)
                return false;

            bool isAccepted = true;
            if (FeatureFetched != null)
            {
                FeatureOperationEventArgs foea = new FeatureOperationEventArgs(feature);
                FeatureFetched(this, foea);
                isAccepted = foea.IsAccepted;
            }

            if (!isAccepted)
                return false;

            fr.AddFeature(feature);
            switch (feature.FeatureType)
            {
                case FeatureType.Point: points.Add(feature); break;
                case FeatureType.MultiPoint: multiPoints.Add(feature); break;
                case FeatureType.Polyline: polylines.Add(feature); break;
                case FeatureType.Polygon: polygons.Add(feature); break;
            }

            return true;
        }
Ejemplo n.º 17
0
        /// <summary>
        /// Adds the features retrieved from cache to the receiver.
        /// </summary>
        /// <param name="processAttributes">A value indicating whether the attributes will be processed or not</param>
        /// <param name="cacheAccessor">Cache accessor instance</param>
        /// <param name="fr">An object that receives the retrieved features</param>
        /// <param name="bounds">Rectangle that defines a query region</param>
        /// <returns>Number of retrieved features</returns>
        public static int FillFromCache(IFeatureCollectionCacheAccessor cacheAccessor, IFeatureReceiver fr, BoundingRectangle bounds, bool processAttributes)
        {
            ISpatialIndex pointsIndex = cacheAccessor.RestoreFeaturesIndex(MapAround.Mapping.FeatureType.Point);
            ISpatialIndex polylinesIndex = cacheAccessor.RestoreFeaturesIndex(MapAround.Mapping.FeatureType.Polyline);
            ISpatialIndex polygonsIndex = cacheAccessor.RestoreFeaturesIndex(MapAround.Mapping.FeatureType.Polygon);

            BoundingRectangle b;
            if (!bounds.IsEmpty())
                b = bounds.GetBoundingRectangle();
            else
            {
                b = new BoundingRectangle();
                b.Join(pointsIndex.IndexedSpace);
                b.Join(polylinesIndex.IndexedSpace);
                b.Join(polygonsIndex.IndexedSpace);
            }

            List<Feature> points = new List<Feature>();
            pointsIndex.QueryObjectsInRectangle(bounds, points);

            List<Feature> polylines = new List<Feature>();
            polylinesIndex.QueryObjectsInRectangle(bounds, polylines);

            List<Feature> polygons = new List<Feature>();
            polygonsIndex.QueryObjectsInRectangle(bounds, polygons);

            points.ForEach(point => fr.AddFeature((Feature)point.Clone()));
            polylines.ForEach(polyline => fr.AddFeature((Feature)polyline.Clone()));
            polygons.ForEach(polygon => fr.AddFeature((Feature)polygon.Clone()));

            if (processAttributes)
            {
                fr.FeatureAttributeNames.Clear();
                IList<string> attributeNames = cacheAccessor.RestoreAttributeNames();
                foreach (string s in attributeNames)
                    fr.FeatureAttributeNames.Add(s);
            }

            return points.Count + polylines.Count + polygons.Count;
        }
Ejemplo n.º 18
0
        private bool addFeatureToReceiver(IFeatureReceiver fr, string uniqKey, string title, byte[] spatialData)
        {
            Feature feature = FeatureFromSpatialDataBytes(spatialData);
            feature.UniqKey = uniqKey;
            feature.Title = title;

            bool isAccepted = true;
            if (FeatureFetched != null)
            {
                FeatureOperationEventArgs foea = new FeatureOperationEventArgs(feature);
                FeatureFetched(this, foea);
                isAccepted = foea.IsAccepted;
            }

            if(isAccepted)
                fr.AddFeature(feature);

            return isAccepted;
        }
        /// <summary>
        /// Adds the features retrieved from cache to the receiver.
        /// </summary>
        /// <param name="processAttributes">A value indicating whether the attributes will be processed or not</param>
        /// <param name="cacheAccessor">Cache accessor instance</param>
        /// <param name="fr">An object that receives the retrieved features</param>
        /// <param name="bounds">Rectangle that defines a query region</param>
        /// <returns>Number of retrieved features</returns>
        public static int FillFromCache(IFeatureCollectionCacheAccessor cacheAccessor, IFeatureReceiver fr, BoundingRectangle bounds, bool processAttributes)
        {
            ISpatialIndex pointsIndex    = cacheAccessor.RestoreFeaturesIndex(MapAround.Mapping.FeatureType.Point);
            ISpatialIndex polylinesIndex = cacheAccessor.RestoreFeaturesIndex(MapAround.Mapping.FeatureType.Polyline);
            ISpatialIndex polygonsIndex  = cacheAccessor.RestoreFeaturesIndex(MapAround.Mapping.FeatureType.Polygon);

            BoundingRectangle b;

            if (!bounds.IsEmpty())
            {
                b = bounds.GetBoundingRectangle();
            }
            else
            {
                b = new BoundingRectangle();
                b.Join(pointsIndex.IndexedSpace);
                b.Join(polylinesIndex.IndexedSpace);
                b.Join(polygonsIndex.IndexedSpace);
            }

            List <Feature> points = new List <Feature>();

            pointsIndex.QueryObjectsInRectangle(bounds, points);

            List <Feature> polylines = new List <Feature>();

            polylinesIndex.QueryObjectsInRectangle(bounds, polylines);

            List <Feature> polygons = new List <Feature>();

            polygonsIndex.QueryObjectsInRectangle(bounds, polygons);

            points.ForEach(point => fr.AddFeature((Feature)point.Clone()));
            polylines.ForEach(polyline => fr.AddFeature((Feature)polyline.Clone()));
            polygons.ForEach(polygon => fr.AddFeature((Feature)polygon.Clone()));

            if (processAttributes)
            {
                fr.FeatureAttributeNames.Clear();
                IList <string> attributeNames = cacheAccessor.RestoreAttributeNames();
                foreach (string s in attributeNames)
                {
                    fr.FeatureAttributeNames.Add(s);
                }
            }

            return(points.Count + polylines.Count + polygons.Count);
        }
Ejemplo n.º 20
0
 /// <summary>
 /// Adds features retrieved from the data source to the receiver.
 /// </summary>
 /// <param name="receiver">An object that receives features</param> 
 /// <param name="bounds">Rectangular region you want to fill with the objects</param>
 /// <rereturns>A number of retrieved features</rereturns>
 public override int QueryFeatures(IFeatureReceiver receiver, BoundingRectangle bounds)
 {
     return InternalQueryFeatures(receiver, getSelectString(bounds));
 }
Ejemplo n.º 21
0
 /// <summary>
 /// Adds features retrieved from the data source to the receiver.
 /// </summary>
 /// <param name="receiver">An object that receives features</param>
 /// <param name="bounds">Rectangular region you want to fill with the objects</param>
 /// <rereturns>A number of retrieved features</rereturns>
 public override int QueryFeatures(IFeatureReceiver receiver, BoundingRectangle bounds)
 {
     throw new NotImplementedException("QueryFeatures");
     //return internalQueryFeatures(receiver, bounds, true);
 }
Ejemplo n.º 22
0
        private int internalQueryFeatures(IFeatureReceiver fr, BoundingRectangle bounds, bool checkBounds)
        {
            if (_cacheAccessor != null && !string.IsNullOrEmpty(fr.Alias))
            {
                _cacheAccessor.Key = fr.Alias;
                if (_cacheAccessor.ExistsInCache)
                {
                    return(FillFromCache(_cacheAccessor, fr, bounds, _processAttributes));
                }
                else
                {
                    // Если объект не найден в кэше, вы должны удалить все объекты из файла, чтобы поместить их в кэш
                    checkBounds = false;
                }
            }

            MapFile shapeFile = new MapFile();

            //shapeFile.AttributesEncoding = _attributesEncoding;
            shapeFile.Open(_fileName); //, checkBounds ? bounds : null

            //    if (ProcessAttributes)
            //    {
            //        fr.FeatureAttributeNames.Clear();
            //        foreach (string s in shapeFile.AttributeNames)
            //            fr.FeatureAttributeNames.Add(s);
            //    }

            int    result       = 0;
            string layerHashStr = fr.GetHashCode().ToString();

            //    List<Feature> points = new List<Feature>();
            //    List<Feature> multiPoints = new List<Feature>();
            //    List<Feature> polylines = new List<Feature>();
            //    List<Feature> polygons = new List<Feature>();

            foreach (MapFileRecord record in shapeFile.objects.fetures)
            {
                //        if (!checkBounds ||
                //            (record.MaxX >= bounds.MinX && record.MaxY >= bounds.MinY &&
                //             record.MinX <= bounds.MaxX && record.MinY <= bounds.MaxY))
                //        {
                //Feature newFeature = null;
                IGeometry geometry = geometryFromShapeRecord(record);
                //            if (geometry != null)
                //            {
                //                newFeature = new Feature(geometry);
                //                newFeature.UniqKey = layerHashStr + record.RecordNumber.ToString();
                //                if (ProcessAttributes && record.Attributes != null)
                //                    newFeature.Attributes = record.Attributes.ItemArray;

                //                if (processFeature(newFeature, fr, points, multiPoints, polylines, polygons))
                //                    result++;
                //            }
                //        }
            }

            //    // If the objects are not extracted from the cache may be added to the cache.
            //    // This should be done only if the retrieval of all objects (checkBounds == false)
            //    if (_cacheAccessor != null && !string.IsNullOrEmpty(fr.Alias) &&
            //        checkBounds == false)
            //    {
            //        addFeaturesToCache(fr, points, multiPoints, polylines, polygons);
            //    }

            return(result);
        }
Ejemplo n.º 23
0
 /// <summary>
 /// Adds features retrieved from the data source to the receiver.
 /// </summary>
 /// <param name="receiver">An object that receives features</param>
 /// <param name="bounds">Rectangular region you want to fill with the objects</param>
 /// <rereturns>A number of retrieved features</rereturns>
 public override int QueryFeatures(IFeatureReceiver receiver, BoundingRectangle bounds)
 {
     return(internalQueryFeatures(receiver, bounds, true));
 }
 /// <summary>
 /// Adds features retrieved from the data source to the receiver.
 /// </summary>
 /// <param name="receiver">An object that receives features</param>
 /// <param name="bounds">Rectangular region you want to fill with the objects</param>
 /// <rereturns>A number of retrieved features</rereturns>
 public override int QueryFeatures(IFeatureReceiver receiver, BoundingRectangle bounds)
 {
     return(InternalQueryFeatures(receiver, getSelectString(bounds)));
 }
Ejemplo n.º 25
0
 /// <summary>
 /// Adds features retrieved from the data source to the receiver.
 /// </summary>
 /// <param name="receiver">An object that receives features</param>
 /// <rereturns>A number of retrieved features</rereturns>
 public override int QueryFeatures(IFeatureReceiver receiver)
 {
     return(internalQueryFeatures(receiver, new BoundingRectangle(), false));
 }
Ejemplo n.º 26
0
 /// <summary>
 /// Adds features retrieved from the data source to the receiver.
 /// </summary>
 /// <param name="receiver">An object that receives features</param>
 /// <rereturns>A number of retrieved features</rereturns>
 public override int QueryFeatures(IFeatureReceiver receiver)
 {
     //throw new NotImplementedException("QueryFeatures(IFeatureReceiver receiver)");
     return(internalQueryFeatures(receiver, new BoundingRectangle(), false));
 }
Ejemplo n.º 27
0
        private int internalQueryFeatures(IFeatureReceiver fr, BoundingRectangle bounds, bool checkBounds)
        {
            if (_cacheAccessor != null && !string.IsNullOrEmpty(fr.Alias))
            {
                _cacheAccessor.Key = fr.Alias;
                if (_cacheAccessor.ExistsInCache)
                {
                    return(FillFromCache(_cacheAccessor, fr, bounds, _processAttributes));
                }
                else
                {
                    // If the object is not found in the cache, you must remove all objects from a file, to put them in the cache
                    checkBounds = false;
                }
            }

            ShapeFile shapeFile = new ShapeFile();

            shapeFile.AttributesEncoding = _attributesEncoding;
            shapeFile.Read(_fileName, checkBounds ? bounds : null);

            if (ProcessAttributes)
            {
                fr.FeatureAttributeNames.Clear();
                foreach (string s in shapeFile.AttributeNames)
                {
                    fr.FeatureAttributeNames.Add(s);
                }
            }

            int    result       = 0;
            string layerHashStr = fr.GetHashCode().ToString();

            List <Feature> points      = new List <Feature>();
            List <Feature> multiPoints = new List <Feature>();
            List <Feature> polylines   = new List <Feature>();
            List <Feature> polygons    = new List <Feature>();

            foreach (ShapeFileRecord record in shapeFile.Records)
            {
                if (!checkBounds ||
                    (record.MaxX >= bounds.MinX && record.MaxY >= bounds.MinY &&
                     record.MinX <= bounds.MaxX && record.MinY <= bounds.MaxY))
                {
                    Feature   newFeature = null;
                    IGeometry geometry   = geometryFromShapeRecord(record);
                    if (geometry != null)
                    {
                        newFeature         = new Feature(geometry);
                        newFeature.UniqKey = layerHashStr + record.RecordNumber.ToString();
                        if (ProcessAttributes && record.Attributes != null)
                        {
                            newFeature.Attributes = record.Attributes.ItemArray;
                        }

                        if (processFeature(newFeature, fr, points, multiPoints, polylines, polygons))
                        {
                            result++;
                        }
                    }
                }
            }

            // If the objects are not extracted from the cache may be added to the cache.
            // This should be done only if the retrieval of all objects (checkBounds == false)
            if (_cacheAccessor != null && !string.IsNullOrEmpty(fr.Alias) &&
                checkBounds == false)
            {
                addFeaturesToCache(fr, points, multiPoints, polylines, polygons);
            }

            return(result);
        }