Esempio n. 1
0
        private IOgcGeometry ReadGeometry(WkbBinaryReader reader)
        {
            var type = reader.ReadUInt32();
            var dimensions = WkbDimensions.XY;
            if (type > 1000)
                dimensions = WkbDimensions.XYZ;
            if (type > 2000)
                dimensions = WkbDimensions.XYM;
            if (type > 3000)
                dimensions = WkbDimensions.XYZM;

            var geometryType = (WkbGeometryType)((int)type % 1000);

            switch (geometryType)
            {
                case WkbGeometryType.Point:
                    return ReadPoint(reader, dimensions);
                case WkbGeometryType.LineString:
                    return ReadLineString(reader, dimensions);
                case WkbGeometryType.Triangle:
                    return ReadTriangle(reader, dimensions);
                case WkbGeometryType.Polygon:
                    return ReadPolygon(reader, dimensions);
                case WkbGeometryType.MultiPoint:
                    return ReadMultiPoint(reader, dimensions);
                case WkbGeometryType.MultiLineString:
                    return ReadMultiLineString(reader, dimensions);
                case WkbGeometryType.MultiPolygon:
                    return ReadMultiPolygon(reader, dimensions);
                case WkbGeometryType.GeometryCollection:
                    return ReadGeometryCollection(reader);
                default:
                    throw new SerializationException("Unknown geometry type.");
            }
        }
Esempio n. 2
0
        private GeometryCollection ReadGeometryCollection(WkbBinaryReader reader)
        {
            var pointsCount = (int)reader.ReadUInt32();
            var geometries  = new List <IGeometry>();

            for (var i = 0; i < pointsCount; i++)
            {
                geometries.Add(ReadGeometry(reader));
            }
            return(new GeometryCollection(geometries));
        }
Esempio n. 3
0
        private MultiPolygon ReadMultiPolygon(WkbBinaryReader reader, WkbDimensions dimensions)
        {
            var pointsCount = (int)reader.ReadUInt32();
            var polygons    = new List <Polygon>();

            for (var i = 0; i < pointsCount; i++)
            {
                polygons.Add(ReadPolygon(reader, dimensions));
            }
            return(new MultiPolygon(polygons));
        }
Esempio n. 4
0
        private MultiLineString ReadMultiLineString(WkbBinaryReader reader, WkbDimensions dimensions)
        {
            var pointsCount = (int)reader.ReadUInt32();
            var lineStrings = new List <LineString>();

            for (var i = 0; i < pointsCount; i++)
            {
                lineStrings.Add(ReadLineString(reader, dimensions));
            }
            return(new MultiLineString(lineStrings));
        }
Esempio n. 5
0
        private List <LinearRing> ReadPolygonInner(WkbBinaryReader reader, WkbDimensions dimensions)
        {
            var result     = new List <LinearRing>();
            var ringsCount = (int)reader.ReadUInt32();

            for (var i = 0; i < ringsCount; i++)
            {
                result.Add(new LinearRing(ReadCoordinates(reader, dimensions)));
            }
            return(result);
        }
Esempio n. 6
0
        private CoordinateSequence ReadCoordinates(WkbBinaryReader reader, WkbDimensions dimensions)
        {
            var pointCount = (int)reader.ReadUInt32();

            var result = new List<Coordinate>(pointCount);
            for (var i = 0; i < pointCount; i++)
            {
                result.Add(ReadCoordinate(reader, dimensions));
            }

            return new CoordinateSequence(result);
        }
Esempio n. 7
0
        private IGeometry ReadGeometry(WkbBinaryReader reader)
        {
            reader.ReadAndSetEncoding();

            var type       = reader.ReadUInt32();
            var dimensions = WkbDimensions.XY;

            if (type > 1000)
            {
                dimensions = WkbDimensions.XYZ;
            }
            if (type > 2000)
            {
                dimensions = WkbDimensions.XYM;
            }
            if (type > 3000)
            {
                dimensions = WkbDimensions.XYZM;
            }

            var geometryType = (WkbGeometryType)((int)type % 1000);

            switch (geometryType)
            {
            case WkbGeometryType.Point:
                return(ReadPoint(reader, dimensions));

            case WkbGeometryType.LineString:
                return(ReadLineString(reader, dimensions));

            case WkbGeometryType.Triangle:
                return(ReadTriangle(reader, dimensions));

            case WkbGeometryType.Polygon:
                return(ReadPolygon(reader, dimensions));

            case WkbGeometryType.MultiPoint:
                return(ReadMultiPoint(reader, dimensions));

            case WkbGeometryType.MultiLineString:
                return(ReadMultiLineString(reader, dimensions));

            case WkbGeometryType.MultiPolygon:
                return(ReadMultiPolygon(reader, dimensions));

            case WkbGeometryType.GeometryCollection:
                return(ReadGeometryCollection(reader));

            default:
                throw new SerializationException("Unknown geometry type.");
            }
        }
Esempio n. 8
0
        private CoordinateSequence ReadCoordinates(WkbBinaryReader reader, WkbDimensions dimensions)
        {
            var pointCount = (int)reader.ReadUInt32();

            var result = new List <Coordinate>(pointCount);

            for (var i = 0; i < pointCount; i++)
            {
                result.Add(ReadCoordinate(reader, dimensions));
            }

            return(new CoordinateSequence(result));
        }
Esempio n. 9
0
        private MultiPolygon ReadMultiPolygon(WkbBinaryReader reader, WkbDimensions dimensions)
        {
            var pointsCount = (int)reader.ReadUInt32();
            var polygons    = new List <Polygon>();

            for (var i = 0; i < pointsCount; i++)
            {
                var polygon = ReadGeometry(reader) as Polygon;
                if (polygon != null)
                {
                    polygons.Add(polygon);
                }
                else
                {
                    throw new SerializationException("Geometry not a polygon.");
                }
            }
            return(new MultiPolygon(polygons));
        }
Esempio n. 10
0
        private MultiLineString ReadMultiLineString(WkbBinaryReader reader, WkbDimensions dimensions)
        {
            var pointsCount = (int)reader.ReadUInt32();
            var lineStrings = new List <LineString>();

            for (var i = 0; i < pointsCount; i++)
            {
                var lineString = ReadGeometry(reader) as LineString;
                if (lineString != null)
                {
                    lineStrings.Add(lineString);
                }
                else
                {
                    throw new SerializationException("Geometry not a linestring.");
                }
            }
            return(new MultiLineString(lineStrings));
        }
Esempio n. 11
0
 private List<LinearRing> ReadPolygonInner(WkbBinaryReader reader, WkbDimensions dimensions)
 {
     var result = new List<LinearRing>();
     var ringsCount = (int)reader.ReadUInt32();
     for (var i = 0; i < ringsCount; i++)
         result.Add(new LinearRing(ReadCoordinates(reader, dimensions)));
     return result;
 }
Esempio n. 12
0
 private MultiPolygon ReadMultiPolygon(WkbBinaryReader reader, WkbDimensions dimensions)
 {
     var pointsCount = (int)reader.ReadUInt32();
     var polygons = new List<Polygon>();
     for (var i = 0; i < pointsCount; i++)
         polygons.Add(ReadPolygon(reader, dimensions));
     return new MultiPolygon(polygons);
 }
Esempio n. 13
0
 private MultiLineString ReadMultiLineString(WkbBinaryReader reader, WkbDimensions dimensions)
 {
     var pointsCount = (int)reader.ReadUInt32();
     var lineStrings = new List<LineString>();
     for (var i = 0; i < pointsCount; i++)
         lineStrings.Add(ReadLineString(reader, dimensions));
     return new MultiLineString(lineStrings);
 }
Esempio n. 14
0
 private GeometryCollection ReadGeometryCollection(WkbBinaryReader reader)
 {
     var pointsCount = (int)reader.ReadUInt32();
     var geometries = new List<IGeometry>();
     for (var i = 0; i < pointsCount; i++)
         geometries.Add(ReadGeometry(reader));
     return new GeometryCollection(geometries);
 }
Esempio n. 15
0
 private MultiPolygon ReadMultiPolygon(WkbBinaryReader reader, WkbDimensions dimensions)
 {
     var pointsCount = (int)reader.ReadUInt32();
     var polygons = new List<Polygon>();
     for (var i = 0; i < pointsCount; i++)
     {
         var polygon = ReadGeometry(reader) as Polygon;
         if (polygon != null)
             polygons.Add(polygon);
         else
             throw new SerializationException("Geometry not a polygon.");
     }
     return new MultiPolygon(polygons);
 }
Esempio n. 16
0
 private MultiLineString ReadMultiLineString(WkbBinaryReader reader, WkbDimensions dimensions)
 {
     var pointsCount = (int)reader.ReadUInt32();
     var lineStrings = new List<LineString>();
     for (var i = 0; i < pointsCount; i++)
     {
         var lineString = ReadGeometry(reader) as LineString;
         if (lineString != null)
             lineStrings.Add(lineString);
         else
             throw new SerializationException("Geometry not a linestring.");
     }
     return new MultiLineString(lineStrings);
 }