public void EndFigure()
        {
            var type = _types.Peek();

            if (type == OpenGisGeographyType.Polygon)
            {
                _rings.Add(_coordinateBuffer.ToSequence(_factory.CoordinateSequenceFactory));
                //_rings.Add(_coordinates.ToArray());
            }
            _inFigure = false;
        }
コード例 #2
0
        /// <summary>
        /// Reads a stream and converts the shapefile record to an equilivent geometry object.
        /// </summary>
        /// <param name="file">The stream to read.</param>
        /// <param name="totalRecordLength">Total length of the record we are about to read</param>
        /// <param name="factory">The geometry factory to use when making the object.</param>
        /// <returns>The Geometry object that represents the shape file record.</returns>
        public override IGeometry Read(BigEndianBinaryReader file, int totalRecordLength, IGeometryFactory factory)
        {
            int totalRead = 0;
            ShapeGeometryType type = (ShapeGeometryType)ReadInt32(file, totalRecordLength, ref totalRead);
            //type = (ShapeGeometryType) EnumUtility.Parse(typeof (ShapeGeometryType), shapeTypeNum.ToString());
            if (type == ShapeGeometryType.NullShape)
                return factory.CreatePoint((Coordinate)null);

            if (type != ShapeType)
                throw new ShapefileException(string.Format("Encountered a '{0}' instead of a  '{1}'", type, ShapeType));

            CoordinateBuffer buffer = new CoordinateBuffer(1, NoDataBorderValue, true);
            IPrecisionModel precisionModel = factory.PrecisionModel;

            double x = precisionModel.MakePrecise(ReadDouble(file, totalRecordLength, ref totalRead));
            double y = precisionModel.MakePrecise(ReadDouble(file, totalRecordLength, ref totalRead));

            double? z = null, m = null;
            
            // Trond Benum: Let's read optional Z and M values                                
            if (HasZValue() && totalRead < totalRecordLength)
                z = ReadDouble(file, totalRecordLength, ref totalRead);

            if ((HasMValue() || HasZValue()) &&
                (totalRead < totalRecordLength))
                m = ReadDouble(file, totalRecordLength, ref totalRead);

            buffer.AddCoordinate(x, y, z, m);
            return factory.CreatePoint(buffer.ToSequence(factory.CoordinateSequenceFactory));
        }
コード例 #3
0
        private static void TestToSequenceMethod(ICoordinateSequenceFactory factory)
        {
            var rnd    = new Random(8894);
            var buffer = new CoordinateBuffer(NumCoordinates);

            for (var i = 0; i < NumCoordinates; i++)
            {
                buffer.AddCoordinate(rnd.NextDouble(), rnd.NextDouble());
            }

            System.Diagnostics.Trace.WriteLine(
                string.Format("\nConversion using {0} factory", (factory ?? GeoAPI.GeometryServiceProvider.Instance.DefaultCoordinateSequenceFactory).GetType().Name));

            var sw = new System.Diagnostics.Stopwatch();

            sw.Start();
            var seqCold = buffer.ToSequence(factory);

            sw.Stop();
            System.Diagnostics.Trace.WriteLine(
                string.Format("  Cold converting sequence of {0} coordinates in {1}ms.", NumCoordinates, sw.ElapsedMilliseconds));
            long total = 0;

            foreach (var rndBuffer in (_randomCoordinateBuffers ?? (_randomCoordinateBuffers = RandomCoordinateBuffers(NumTests))))
            {
                sw.Stop();
                sw.Start();
                var seqWarm = rndBuffer.ToSequence(factory);
                sw.Stop();
                Assert.AreEqual(rndBuffer.Count, seqWarm.Count);
                total += sw.ElapsedTicks;
            }
            System.Diagnostics.Trace.WriteLine(
                string.Format("  Warm converting {0} random coordinate buffers in {1}ticks.", NumTests, total));
        }
コード例 #4
0
 /// <summary>
 /// Function to read a <see cref="IPoint"/> from a ShapeFile stream using the specified <paramref name="reader"/>.
 /// </summary>
 /// <param name="reader">The reader to use</param>
 /// <param name="ordinates">The ordinates to read</param>
 /// <returns>The read point geometry</returns>
 protected IGeometry ReadPoint(BinaryReader reader, Ordinates ordinates)
 {
     var buffer = new CoordinateBuffer(1, ShapeFileConstants.NoDataBorder, true);
     ReadCoordinates(reader, 1, new[] { 0 }, ordinates, buffer);
     IGeometry point = _factory.CreatePoint(buffer.ToSequence());
     return point;
 }
コード例 #5
0
 /// <summary>
 /// Function to read a <see cref="IPoint"/> from a ShapeFile stream using the specified <paramref name="reader"/>.
 /// </summary>
 /// <param name="reader">The reader to use</param>
 /// <param name="ordinates">The ordinates to read</param>
 /// <returns>The read point geometry</returns>
 protected IGeometry ReadPoint(BinaryReader reader, Ordinates ordinates)
 {
     var buffer = new CoordinateBuffer(1, ShapeFileConstants.NoDataBorder, true);
     ReadCoordinates(reader, 1, new[] { 0 }, ordinates, buffer);
     IGeometry point = _factory.CreatePoint(buffer.ToSequence());
     return point;
 }
コード例 #6
0
        /// <summary>
        /// Reads a stream and converts the shapefile record to an equilivent geometry object.
        /// </summary>
        /// <param name="file">The stream to read.</param>
        /// <param name="totalRecordLength">Total length of the record we are about to read</param>
        /// <param name="factory">The geometry factory to use when making the object.</param>
        /// <returns>The Geometry object that represents the shape file record.</returns>
        public override IGeometry Read(BigEndianBinaryReader file, int totalRecordLength, IGeometryFactory factory)
        {
            int totalRead = 0;
            ShapeGeometryType type = (ShapeGeometryType)ReadInt32(file, totalRecordLength, ref totalRead);
            //type = (ShapeGeometryType) EnumUtility.Parse(typeof (ShapeGeometryType), shapeTypeNum.ToString());
            if (type == ShapeGeometryType.NullShape)
                return factory.CreatePoint((Coordinate)null);

            if (type != ShapeType)
                throw new ShapefileException(string.Format("Encountered a '{0}' instead of a  '{1}'", type, ShapeType));

            CoordinateBuffer buffer = new CoordinateBuffer(1, NoDataBorderValue, true);
            IPrecisionModel precisionModel = factory.PrecisionModel;

            double x = precisionModel.MakePrecise(ReadDouble(file, totalRecordLength, ref totalRead));
            double y = precisionModel.MakePrecise(ReadDouble(file, totalRecordLength, ref totalRead));

            double? z = null, m = null;
            
            // Trond Benum: Let's read optional Z and M values                                
            if (HasZValue() && totalRead < totalRecordLength)
                z = ReadDouble(file, totalRecordLength, ref totalRead);

            if ((HasMValue() || HasZValue()) &&
                (totalRead < totalRecordLength))
                m = ReadDouble(file, totalRecordLength, ref totalRead);

            buffer.AddCoordinate(x, y, z, m);
            return factory.CreatePoint(buffer.ToSequence(factory.CoordinateSequenceFactory));
        }
コード例 #7
0
        /// <summary>
        /// Function to read a <see cref="IMultiPoint"/> from a ShapeFile stream using the specified <paramref name="reader"/>.
        /// </summary>
        /// <param name="reader">The reader to use</param>
        /// <param name="ordinates">The ordinates to read</param>
        /// <returns>The read polygonal geometry</returns>
        public IGeometry ReadMultiPoint(BinaryReader reader, Ordinates ordinates)
        {
            /*var bbox = */ ReadBoundingBox(reader); // jump boundingbox

            var numPoints = ReadNumPoints(reader);
            var buffer = new CoordinateBuffer(numPoints, ShapeFileConstants.NoDataBorder, true);
            ReadCoordinates(reader, numPoints, new[] { numPoints - 1 }, ordinates, buffer);
            return _factory.CreateMultiPoint(buffer.ToSequence());
        }
コード例 #8
0
        /// <summary>
        /// Function to read a either a <see cref="IPolygon"/> or an <see cref="IMultiPolygon"/> from a ShapeFile stream using the specified <paramref name="reader"/>.
        /// </summary>
        /// <param name="reader">The reader to use</param>
        /// <param name="ordinates">The ordinates to read</param>
        /// <returns>The read polygonal geometry</returns>
        protected IGeometry ReadPolygon(BinaryReader reader, Ordinates ordinates)
        {
            /*var bbox = */ ReadBoundingBox(reader); // jump boundingbox

            var numParts = ReadNumParts(reader);
            var numPoints = ReadNumPoints(reader);
            var indexParts = ReadIndexParts(reader, numParts, numPoints);

            var buffer = new CoordinateBuffer(numPoints, ShapeFileConstants.NoDataBorder, true);
            ReadCoordinates(reader, numPoints, indexParts, ordinates, buffer);

            return numParts == 1
                ? _factory.CreatePolygon(_factory.CreateLinearRing(buffer.ToSequence()), null)
                : CreateSingleOrMultiPolygon(buffer);
        }
コード例 #9
0
        /// <summary>
        /// Function to read a <see cref="ILineString"/> or <see cref="IMultiLineString"/> from a ShapeFile stream using the specified <paramref name="reader"/>.
        /// </summary>
        /// <param name="reader">The reader to use</param>
        /// <param name="ordinates">The ordinates to read</param>
        /// <returns>The read lineal geometry</returns>
        protected IGeometry ReadLineString(BinaryReader reader, Ordinates ordinates)
        {
            /*var bbox = */ ReadBoundingBox(reader); // Jump boundingbox

            var numParts = ReadNumParts(reader);
            var numPoints = ReadNumPoints(reader);
            var indexParts = ReadIndexParts(reader, numParts, numPoints);

            var buffer = new CoordinateBuffer(numPoints, ShapeFileConstants.NoDataBorder, true);
            ReadCoordinates(reader, numPoints, indexParts, ordinates, buffer);

            if (numParts == 1)
                return _factory.CreateLineString(buffer.ToSequence());
            return CreateMultiLineString(buffer.ToSequences());
        }
コード例 #10
0
        /// <summary>
        /// Function to read a <see cref="ILineString"/> or <see cref="IMultiLineString"/> from a ShapeFile stream using the specified <paramref name="reader"/>.
        /// </summary>
        /// <param name="reader">The reader to use</param>
        /// <param name="ordinates">The ordinates to read</param>
        /// <returns>The read lineal geometry</returns>
        protected IGeometry ReadLineString(BinaryReader reader, Ordinates ordinates)
        {
            /*var bbox = */ ReadBoundingBox(reader); // Jump boundingbox

            var numParts = ReadNumParts(reader);
            var numPoints = ReadNumPoints(reader);
            var indexParts = ReadIndexParts(reader, numParts, numPoints);

            var buffer = new CoordinateBuffer(numPoints, ShapeFileConstants.NoDataBorder, true);
            ReadCoordinates(reader, numPoints, indexParts, ordinates, buffer);

            if (numParts == 1)
                return _factory.CreateLineString(buffer.ToSequence());
            return CreateMultiLineString(buffer.ToSequences());
        }
コード例 #11
0
        private static void TestToSequenceMethod(CoordinateBufferToSequenceConverterHandler converter)
        {
            var rnd    = new Random(8894);
            var buffer = new CoordinateBuffer();

            for (var i = 0; i < NumCoordinates; i++)
            {
                buffer.AddCoordinate(rnd.NextDouble(), rnd.NextDouble());
            }

            System.Diagnostics.Trace.WriteLine(
                string.Format("\nConversion using {0} method", converter.Method.Name));

            var sw = new System.Diagnostics.Stopwatch();

            sw.Start();
            var seqCold = buffer.ToSequence(converter);

            sw.Stop();
            System.Diagnostics.Trace.WriteLine(
                string.Format("  Cold converting sequence of {0} coordinates in {1}ms.", NumCoordinates, sw.ElapsedMilliseconds));

            long total = 0;

            foreach (var rndBuffer in (_randomCoordinateBuffers ?? (_randomCoordinateBuffers = RandomCoordinateBuffers(NumTests))))
            {
                sw.Stop();
                sw.Start();
                var seqWarm = rndBuffer.ToSequence(converter);
                sw.Stop();
                Assert.AreEqual(rndBuffer.Count, seqWarm.Count);
                total += sw.ElapsedTicks;
            }
            System.Diagnostics.Trace.WriteLine(
                string.Format("  Warm converting {0} random coordinate buffers in {1}ticks.", NumTests, total));
        }
コード例 #12
0
        private static void TestToSequenceMethod(CoordinateBufferToSequenceConverterHandler converter)
        {
            var rnd = new Random(8894);
            var buffer = new CoordinateBuffer();

            for (var i = 0; i < NumCoordinates; i++)
                buffer.AddCoordinate(rnd.NextDouble(), rnd.NextDouble());

            System.Diagnostics.Trace.WriteLine(
                string.Format("\nConversion using {0} method", converter.Method.Name));

            var sw = new System.Diagnostics.Stopwatch();
            sw.Start();
            var seqCold = buffer.ToSequence(converter);
            sw.Stop();
            System.Diagnostics.Trace.WriteLine(
                string.Format("  Cold converting sequence of {0} coordinates in {1}ms.", NumCoordinates, sw.ElapsedMilliseconds));
            
            long total = 0;
            foreach (var rndBuffer in (_randomCoordinateBuffers ?? (_randomCoordinateBuffers = RandomCoordinateBuffers(NumTests))))
            {
                sw.Stop();
                sw.Start();
                var seqWarm = rndBuffer.ToSequence(converter);
                sw.Stop();
                Assert.AreEqual(rndBuffer.Count, seqWarm.Count);
                total += sw.ElapsedTicks;
            }
            System.Diagnostics.Trace.WriteLine(
                string.Format("  Warm converting {0} random coordinate buffers in {1}ticks.", NumTests, total));

        }
コード例 #13
0
        private static void TestToSequenceMethod(ICoordinateSequenceFactory factory)
        {
            var rnd = new Random(8894);
            var buffer = new CoordinateBuffer(NumCoordinates);

            for (var i = 0; i < NumCoordinates; i++)
                buffer.AddCoordinate(rnd.NextDouble(), rnd.NextDouble());

            System.Diagnostics.Trace.WriteLine(
                string.Format("\nConversion using {0} factory", (factory ?? GeoAPI.GeometryServiceProvider.Instance.DefaultCoordinateSequenceFactory).GetType().Name));

            var sw = new System.Diagnostics.Stopwatch();
            sw.Start();
            var seqCold = buffer.ToSequence(factory);
            sw.Stop();
            System.Diagnostics.Trace.WriteLine(
                string.Format("  Cold converting sequence of {0} coordinates in {1}ms.", NumCoordinates, sw.ElapsedMilliseconds));
            long total = 0;
            foreach (var rndBuffer in (_randomCoordinateBuffers ?? (_randomCoordinateBuffers = RandomCoordinateBuffers(NumTests))))
            {

                sw.Stop();
                sw.Start();
                var seqWarm = rndBuffer.ToSequence(factory);
                sw.Stop();
                Assert.AreEqual(rndBuffer.Count, seqWarm.Count);
                total += sw.ElapsedTicks;
            }
            System.Diagnostics.Trace.WriteLine(
                string.Format("  Warm converting {0} random coordinate buffers in {1}ticks.", NumTests, total));

        }
コード例 #14
0
        /// <summary>
        /// Function to read a either a <see cref="IPolygon"/> or an <see cref="IMultiPolygon"/> from a ShapeFile stream using the specified <paramref name="reader"/>.
        /// </summary>
        /// <param name="reader">The reader to use</param>
        /// <param name="ordinates">The ordinates to read</param>
        /// <returns>The read polygonal geometry</returns>
        protected IGeometry ReadPolygon(BinaryReader reader, Ordinates ordinates)
        {
            /*var bbox = */ ReadBoundingBox(reader); // jump boundingbox

            var numParts = ReadNumParts(reader);
            var numPoints = ReadNumPoints(reader);
            var indexParts = ReadIndexParts(reader, numParts, numPoints);

            var buffer = new CoordinateBuffer(numPoints, ShapeFileConstants.NoDataBorder, true);
            ReadCoordinates(reader, numPoints, indexParts, ordinates, buffer);

            return numParts == 1
                ? _factory.CreatePolygon(_factory.CreateLinearRing(buffer.ToSequence()), null)
                : CreateSingleOrMultiPolygon(buffer);
        }
コード例 #15
0
        /// <summary>
        /// Function to read a <see cref="IMultiPoint"/> from a ShapeFile stream using the specified <paramref name="reader"/>.
        /// </summary>
        /// <param name="reader">The reader to use</param>
        /// <param name="ordinates">The ordinates to read</param>
        /// <returns>The read polygonal geometry</returns>
        public IGeometry ReadMultiPoint(BinaryReader reader, Ordinates ordinates)
        {
            /*var bbox = */ ReadBoundingBox(reader); // jump boundingbox

            var numPoints = ReadNumPoints(reader);
            var buffer = new CoordinateBuffer(numPoints, ShapeFileConstants.NoDataBorder, true);
            ReadCoordinates(reader, numPoints, new[] { numPoints - 1 }, ordinates, buffer);
            return _factory.CreateMultiPoint(buffer.ToSequence());
        }