Ejemplo n.º 1
0
        /// <summary>
        /// The extents of the data source.
        /// </summary>
        /// <returns>
        /// An <see cref="IExtents"/> instance describing the extents of the
        /// data available in the data source.
        /// </returns>
        public override IExtents GetExtents()
        {
            if (_extents != null)
            {
                return(_extents);
            }

            if (_geometries.Count == 0)
            {
                _extents = _geoFactory.CreateExtents();
            }
            else
            {
                foreach (IGeometry g in Geometries)
                {
                    if (g.IsEmpty)
                    {
                        continue;
                    }

                    if (_extents == null)
                    {
                        _extents = g.Extents;
                    }
                    else
                    {
                        _extents.ExpandToInclude(g.Extents);
                    }
                }
            }

            return(_extents);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Creates a new index node with an empty extents.
        /// </summary>
        /// <returns>A new node for the R-Tree.</returns>
        protected internal virtual RTreeNode <TItem> CreateNode(int level)
        {
            //RTreeNode<TItem> node = new RTreeNode<TItem>(this, _bounder);
            RTreeNode <TItem> node = new RTreeNode <TItem>(this, level, _geoFactory.CreateExtents());

            return(node);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Reads and parses the header of the .shp index file
        /// </summary>
        /// <remarks>
        /// From ESRI ShapeFile Technical Description document
        ///
        /// http://www.esri.com/library/whitepapers/pdfs/shapefile.pdf
        ///
        /// Byte
        /// Position    Field           Value       Type    Order
        /// -----------------------------------------------------
        /// Byte 0      File Code       9994        Integer Big
        /// Byte 4      Unused          0           Integer Big
        /// Byte 8      Unused          0           Integer Big
        /// Byte 12     Unused          0           Integer Big
        /// Byte 16     Unused          0           Integer Big
        /// Byte 20     Unused          0           Integer Big
        /// Byte 24     File Length     File Length Integer Big
        /// Byte 28     Version         1000        Integer Little
        /// Byte 32     Shape Type      Shape Type  Integer Little
        /// Byte 36     Bounding Box    Xmin        Double  Little
        /// Byte 44     Bounding Box    Ymin        Double  Little
        /// Byte 52     Bounding Box    Xmax        Double  Little
        /// Byte 60     Bounding Box    Ymax        Double  Little
        /// Byte 68*    Bounding Box    Zmin        Double  Little
        /// Byte 76*    Bounding Box    Zmax        Double  Little
        /// Byte 84*    Bounding Box    Mmin        Double  Little
        /// Byte 92*    Bounding Box    Mmax        Double  Little
        ///
        /// * Unused, with value 0.0, if not Measured or Z type
        ///
        /// The "Integer" type corresponds to the CLS Int32 type, and "Double" to CLS Double (IEEE 754).
        /// </remarks>
        private void parseHeader(BinaryReader reader)
        {
            reader.BaseStream.Seek(0, SeekOrigin.Begin);

            // Check file header
            if (ByteEncoder.GetBigEndian(reader.ReadInt32()) != ShapeFileConstants.HeaderStartCode)
            {
                throw new ShapeFileIsInvalidException("Invalid ShapeFile (.shp)");
            }

            // Seek to File Length
            reader.BaseStream.Seek(24, 0);

            // Read filelength as big-endian. The length is number of 16-bit words in file
            FileLengthInWords = ByteEncoder.GetBigEndian(reader.ReadInt32());

            // Seek to ShapeType
            reader.BaseStream.Seek(32, 0);
            ShapeType = (ShapeType)reader.ReadInt32();

            // Seek to bounding box of shapefile
            reader.BaseStream.Seek(36, 0);

            // Read the spatial bounding box of the contents
            Double xMin = ByteEncoder.GetLittleEndian(reader.ReadDouble());
            Double yMin = ByteEncoder.GetLittleEndian(reader.ReadDouble());
            Double xMax = ByteEncoder.GetLittleEndian(reader.ReadDouble());
            Double yMax = ByteEncoder.GetLittleEndian(reader.ReadDouble());

            ICoordinate min = _geoFactory.CoordinateFactory.Create(xMin, yMin);
            ICoordinate max = _geoFactory.CoordinateFactory.Create(xMax, yMax);

            Extents = min.Equals(max) && min.Equals(_geoFactory.CoordinateFactory.Create(0, 0)) //jd: if the shapefile has just been created the box wil be 0,0,0,0 in this case create an empty extents
                ? _geoFactory.CreateExtents()
                : _geoFactory.CreateExtents(min, max);


            //jd:allow exmpty extents
            //if (Extents.IsEmpty)
            //{
            //    Extents = null;
            //}
        }
Ejemplo n.º 4
0
        public void SelectFeatures(ICoordinate min, ICoordinate max)
        {
            IExtents extents             = _geoFactory.CreateExtents(min, max);
            FeatureQueryExpression query = FeatureQueryExpression.Intersects(extents);
            List <IFeatureLayer>   layersWithSelection = new List <IFeatureLayer>();

            foreach (IFeatureLayer layer in _layers)
            {
                if (layer == null || !layer.Enabled || !layer.AreFeaturesSelectable)
                {
                    continue;
                }

                layer.Features.SuspendIndexEvents();
                layer.Select(query);
                layersWithSelection.Add(layer);
            }

            foreach (IFeatureLayer layer in layersWithSelection)
            {
                layer.Features.RestoreIndexEvents(false);
            }
        }
Ejemplo n.º 5
0
            private TBounds computeBounds(IList <IBoundable <TBounds> > entries, Int32 count)
            {
                TBounds bounds = (TBounds)_geometryFactory.CreateExtents();

                for (Int32 i = 0; i < count; i++)
                {
                    if (bounds.IsEmpty)
                    {
                        bounds = entries[i].Bounds;
                    }
                    else
                    {
                        bounds = (TBounds)bounds.Union(entries[i].Bounds);
                    }
                }

                return(bounds);
            }
Ejemplo n.º 6
0
        public void InsertFeaturesTest()
        {
            FeatureDataTable <UInt32> schema = new FeatureDataTable <UInt32>("OID", _geoFactory);

            schema.Columns.AddRange(new DataColumn[]
            {
                new DataColumn("Name", typeof(String)),
                new DataColumn("DateCreated", typeof(DateTime)),
                new DataColumn("Visits", typeof(Int64)),
                new DataColumn("Weight", typeof(Double))
            });

            ShapeFileProvider shapeFile = ShapeFileProvider.Create("UnitTestData", "Test3", ShapeType.PolyLine, schema, _geoFactory);

            shapeFile.Open();

            IExtents computedBounds = _geoFactory.CreateExtents();

            List <FeatureDataRow <UInt32> > rows = new List <FeatureDataRow <UInt32> >();

            for (Int32 i = 0; i < 10000; i++)
            {
                DateTime dateCreated            = new DateTime(_rnd.Next(1900, 2155), _rnd.Next(1, 12), _rnd.Next(1, 28));
                FeatureDataRow <UInt32> feature = schema.NewRow((UInt32)i);

                Char[] chars = new Char[_rnd.Next(0, 254)];
                for (Int32 charIndex = 0; charIndex < chars.Length; charIndex++)
                {
                    chars[charIndex] = (Char)(Byte)_rnd.Next(32, 126);
                }

                feature["Name"]        = new String(chars);
                feature["DateCreated"] = dateCreated;
                feature["Visits"]      = _rnd.Next(0, Int32.MaxValue) << _rnd.Next(0, 32);
                feature["Weight"]      = _rnd.NextDouble() * _rnd.Next(0, 100000);

                ICoordinateSequence coordinates
                    = _geoFactory.CoordinateSequenceFactory.Create(generateCoordinates());

                ILineString line = _geoFactory.CreateLineString(coordinates);

                computedBounds.ExpandToInclude(line.Extents);

                feature.Geometry = line;

                rows.Add(feature);
            }

            shapeFile.Insert(rows);
            shapeFile.Close();

            shapeFile = new ShapeFileProvider(@"UnitTestData\Test3.shp", _geoFactory, _coordSysFactory, false);
            shapeFile.Open();

            Assert.AreEqual(10000, shapeFile.GetFeatureCount());
            Assert.AreEqual(computedBounds, shapeFile.GetExtents());

            FeatureDataTable       dataTable = new FeatureDataTable("ShapeFile test", _geoFactory);
            FeatureQueryExpression query     = FeatureQueryExpression.Intersects(shapeFile.GetExtents());
            IFeatureDataReader     reader    = shapeFile.ExecuteFeatureQuery(query);

            dataTable.Load(reader, LoadOption.OverwriteChanges, null);

            Assert.AreEqual(10000, dataTable.Rows.Count);
        }