Esempio n. 1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="reader"></param>
        /// <returns></returns>
        protected IGeometry Read(BinaryReader reader)
        {
            WKBGeometryTypes geometryType = (WKBGeometryTypes)reader.ReadInt32();

            switch (geometryType)
            {
            case WKBGeometryTypes.WKBPoint:
                return(ReadPoint(reader));

            case WKBGeometryTypes.WKBLineString:
                return(ReadLineString(reader));

            case WKBGeometryTypes.WKBPolygon:
                return(ReadPolygon(reader));

            case WKBGeometryTypes.WKBMultiPoint:
                return(ReadMultiPoint(reader));

            case WKBGeometryTypes.WKBMultiLineString:
                return(ReadMultiLineString(reader));

            case WKBGeometryTypes.WKBMultiPolygon:
                return(ReadMultiPolygon(reader));

            case WKBGeometryTypes.WKBGeometryCollection:
                return(ReadGeometryCollection(reader));

            default:
                throw new ArgumentException("Geometry type not recognized. GeometryCode: " + geometryType);
            }
        }
Esempio n. 2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="reader"></param>
        /// <returns></returns>
        protected IGeometry ReadGeometryCollection(BinaryReader reader)
        {
            int numGeometries = reader.ReadInt32();

            IGeometry[] geometries = new IGeometry[numGeometries];

            for (int i = 0; i < numGeometries; i++)
            {
                ReadByteOrder(reader);
                WKBGeometryTypes geometryType = (WKBGeometryTypes)reader.ReadInt32();
                switch (geometryType)
                {
                case WKBGeometryTypes.WKBPoint:
                    geometries[i] = ReadPoint(reader);
                    break;

                case WKBGeometryTypes.WKBLineString:
                    geometries[i] = ReadLineString(reader);
                    break;

                case WKBGeometryTypes.WKBPolygon:
                    geometries[i] = ReadPolygon(reader);
                    break;

                case WKBGeometryTypes.WKBMultiPoint:
                    geometries[i] = ReadMultiPoint(reader);
                    break;

                case WKBGeometryTypes.WKBMultiLineString:
                    geometries[i] = ReadMultiLineString(reader);
                    break;

                case WKBGeometryTypes.WKBMultiPolygon:
                    geometries[i] = ReadMultiPolygon(reader);
                    break;

                case WKBGeometryTypes.WKBGeometryCollection:
                    geometries[i] = ReadGeometryCollection(reader);
                    break;

                default:
                    throw new ArgumentException("Should never reach here!");
                }
            }
            return(Factory.CreateGeometryCollection(geometries));
        }
Esempio n. 3
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="reader"></param>
        /// <returns></returns>
        protected IGeometry ReadMultiLineString(BinaryReader reader)
        {
            int numGeometries = reader.ReadInt32();

            ILineString[] strings = new ILineString[numGeometries];
            for (int i = 0; i < numGeometries; i++)
            {
                ReadByteOrder(reader);
                WKBGeometryTypes geometryType = (WKBGeometryTypes)reader.ReadInt32();
                if (geometryType != WKBGeometryTypes.WKBLineString)
                {
                    throw new ArgumentException("ILineString feature expected");
                }
                strings[i] = ReadLineString(reader) as ILineString;
            }
            return(Factory.CreateMultiLineString(strings));
        }
Esempio n. 4
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="reader"></param>
        /// <returns></returns>
        protected IGeometry ReadMultiPolygon(BinaryReader reader)
        {
            int numGeometries = reader.ReadInt32();

            IPolygon[] polygons = new IPolygon[numGeometries];
            for (int i = 0; i < numGeometries; i++)
            {
                ReadByteOrder(reader);
                WKBGeometryTypes geometryType = (WKBGeometryTypes)reader.ReadInt32();
                if (geometryType != WKBGeometryTypes.WKBPolygon)
                {
                    throw new ArgumentException("IPolygon feature expected");
                }
                polygons[i] = ReadPolygon(reader) as IPolygon;
            }
            return(Factory.CreateMultiPolygon(polygons));
        }
Esempio n. 5
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="reader"></param>
        /// <returns></returns>
        protected virtual IGeometry ReadMultiPoint(BinaryReader reader)
        {
            int numGeometries = reader.ReadInt32();

            Point[] points = new Point[numGeometries];
            for (int i = 0; i < numGeometries; i++)
            {
                ReadByteOrder(reader);
                WKBGeometryTypes geometryType = (WKBGeometryTypes)reader.ReadInt32();
                if (geometryType != WKBGeometryTypes.WKBPoint)
                {
                    throw new ArgumentException("Point feature expected");
                }
                points[i] = ReadPoint(reader) as Point;
            }
            return(Factory.CreateMultiPoint(points));
        }
Esempio n. 6
0
        private static void ReadGeometryCollection(Stream data, FeatureSetPack results)
        {
            int numGeometries = ReadInt32(data);

            // Don't worry about "multi-parting" these. Simply create a separate shape
            // entry for every single geometry here since we have to split out the features
            // based on feature type. (currently we don't have a mixed feature type for drawing.)
            for (int i = 0; i < numGeometries; i++)
            {
                endian = (ByteOrder)data.ReadByte();
                WKBGeometryTypes type = (WKBGeometryTypes)ReadInt32(data);
                switch (type)
                {
                case WKBGeometryTypes.WKBPoint:
                    ReadPoint(data, results);
                    return;

                case WKBGeometryTypes.WKBLineString:
                    ReadLineString(data, results);
                    return;

                case WKBGeometryTypes.WKBPolygon:
                    ReadPolygon(data, results);
                    break;

                case WKBGeometryTypes.WKBMultiPoint:
                    ReadMultiPoint(data, results);
                    break;

                case WKBGeometryTypes.WKBMultiLineString:
                    ReadMultiLineString(data, results);
                    break;

                case WKBGeometryTypes.WKBMultiPolygon:
                    ReadMultiPolygon(data, results);
                    break;

                case WKBGeometryTypes.WKBGeometryCollection:
                    ReadGeometryCollection(data, results);
                    break;
                }
            }
        }
Esempio n. 7
0
        /// <summary>
        /// Reads a <see cref="IMultiPolygon"/> geometry.
        /// </summary>
        /// <param name="reader">The reader</param>
        /// <param name="cs">The coordinate system</param>
        ///<param name="srid">The spatial reference id for the geometry.</param>
        ///<returns>A <see cref="IMultiPolygon"/> geometry</returns>
        protected IGeometry ReadMultiPolygon(BinaryReader reader, CoordinateSystem cs, int srid)
        {
            IGeometryFactory factory = _geometryServices.CreateGeometryFactory(_precisionModel, srid, _sequenceFactory);
            int numGeometries        = reader.ReadInt32();

            IPolygon[] polygons = new IPolygon[numGeometries];
            for (int i = 0; i < numGeometries; i++)
            {
                ReadByteOrder(reader);
                CoordinateSystem cs2;
                int srid2;
                WKBGeometryTypes geometryType = ReadGeometryType(reader, out cs2, out srid2);//(WKBGeometryTypes) reader.ReadInt32();
                if (geometryType != WKBGeometryTypes.WKBPolygon)
                {
                    throw new ArgumentException("IPolygon feature expected");
                }
                polygons[i] = ReadPolygon(reader, cs2, srid2) as IPolygon;
            }
            return(factory.CreateMultiPolygon(polygons));
        }
Esempio n. 8
0
        /// <summary>
        /// Reads a <see cref="IMultiLineString"/> geometry.
        /// </summary>
        /// <param name="reader">The reader</param>
        /// <param name="cs">The coordinate system</param>
        ///<param name="srid">The spatial reference id for the geometry.</param>
        ///<returns>A <see cref="IMultiLineString"/> geometry</returns>
        protected IGeometry ReadMultiLineString(BinaryReader reader, CoordinateSystem cs, int srid)
        {
            IGeometryFactory factory = _geometryServices.CreateGeometryFactory(_precisionModel, srid, _sequenceFactory);
            int numGeometries        = reader.ReadInt32();

            ILineString[] strings = new ILineString[numGeometries];
            for (int i = 0; i < numGeometries; i++)
            {
                ReadByteOrder(reader);
                CoordinateSystem cs2;
                int srid2;
                WKBGeometryTypes geometryType = ReadGeometryType(reader, out cs2, out srid2);//(WKBGeometryTypes) reader.ReadInt32();
                if (geometryType != WKBGeometryTypes.WKBLineString)
                {
                    throw new ArgumentException("ILineString feature expected");
                }
                strings[i] = ReadLineString(reader, cs2, srid2) as ILineString;
            }
            return(factory.CreateMultiLineString(strings));
        }
Esempio n. 9
0
        /// <summary>
        /// Reads only a single geometry into a feature. This may be a multi-part geometry.
        /// </summary>
        /// <param name="data">The data to read the features from.</param>
        /// <param name="results">FeatureSetPack the read features get added to.</param>
        public static void ReadFeature(Stream data, FeatureSetPack results)
        {
            endian = (ByteOrder)data.ReadByte();
            WKBGeometryTypes type = (WKBGeometryTypes)ReadInt32(data);

            switch (type)
            {
            case WKBGeometryTypes.WKBPoint:
                ReadPoint(data, results);
                return;

            case WKBGeometryTypes.WKBLineString:
                ReadLineString(data, results);
                return;

            case WKBGeometryTypes.WKBPolygon:
                ReadPolygon(data, results);
                break;

            case WKBGeometryTypes.WKBMultiPoint:
                ReadMultiPoint(data, results);
                break;

            case WKBGeometryTypes.WKBMultiLineString:
                ReadMultiLineString(data, results);
                break;

            case WKBGeometryTypes.WKBMultiPolygon:
                ReadMultiPolygon(data, results);
                break;

            case WKBGeometryTypes.WKBGeometryCollection:
                ReadGeometryCollection(data, results);
                break;
            }
        }
Esempio n. 10
0
        /// <summary>
        /// Attempts to read in an entry to the specified feature type. If the feature type does not match
        /// the geometry type, this will return null. (A Point geometry will be accepted by MultiPoint
        /// feature type, but not the other way arround. Either way, this will advance the reader
        /// through the shape feature. Using the Unspecified will always return the shape it reads,
        /// or null in the case of mixed feature collections which are not supported.
        /// </summary>
        /// <param name="data">Data that contains the WKB feature.</param>
        /// <param name="featureType">The feature type.</param>
        /// <returns>The resulting shape.</returns>
        public static Shape ReadShape(Stream data, FeatureType featureType)
        {
            endian = (ByteOrder)data.ReadByte();
            WKBGeometryTypes type = (WKBGeometryTypes)ReadInt32(data);
            Shape            result;

            switch (type)
            {
            case WKBGeometryTypes.WKBPoint:
                result = ReadPoint(data);
                if (featureType == FeatureType.Point || featureType == FeatureType.MultiPoint || featureType == FeatureType.Unspecified)
                {
                    return(result);
                }

                return(null);

            case WKBGeometryTypes.WKBLineString:
                result = ReadLineString(data);
                if (featureType == FeatureType.Line || featureType == FeatureType.Unspecified)
                {
                    return(result);
                }

                return(null);

            case WKBGeometryTypes.WKBPolygon:
                result = ReadPolygon(data);
                if (featureType == FeatureType.Polygon || featureType == FeatureType.Unspecified)
                {
                    return(result);
                }

                return(null);

            case WKBGeometryTypes.WKBMultiPoint:
                result = ReadMultiPoint(data);
                if (featureType == FeatureType.MultiPoint || featureType == FeatureType.Unspecified)
                {
                    return(result);
                }

                return(null);

            case WKBGeometryTypes.WKBMultiLineString:
                result = ReadMultiLineString(data);
                if (featureType == FeatureType.Line || featureType == FeatureType.Unspecified)
                {
                    return(result);
                }

                return(null);

            case WKBGeometryTypes.WKBMultiPolygon:
                result = ReadMultiPolygon(data);
                if (featureType == FeatureType.Polygon || featureType == FeatureType.Unspecified)
                {
                    return(result);
                }

                return(null);

            case WKBGeometryTypes.WKBGeometryCollection: throw new ArgumentException("Mixed shape type collections are not supported by this method.");
            }

            return(null);
        }
Esempio n. 11
0
        /// <summary>
        /// Reads a <see cref="IGeometryCollection"/> geometry.
        /// </summary>
        /// <param name="reader">The reader</param>
        /// <param name="cs">The coordinate system</param>
        ///<param name="srid">The spatial reference id for the geometry.</param>
        ///<returns>A <see cref="IGeometryCollection"/> geometry</returns>
        protected IGeometry ReadGeometryCollection(BinaryReader reader, CoordinateSystem cs, int srid)
        {
            IGeometryFactory factory = _geometryServices.CreateGeometryFactory(_precisionModel, srid, _sequenceFactory);

            int numGeometries = reader.ReadInt32();

            IGeometry[] geometries = new IGeometry[numGeometries];

            for (int i = 0; i < numGeometries; i++)
            {
                ReadByteOrder(reader);
                CoordinateSystem cs2;
                int srid2;
                WKBGeometryTypes geometryType = ReadGeometryType(reader, out cs2, out srid2);
                switch (geometryType)
                {
                //Point
                case WKBGeometryTypes.WKBPoint:
                case WKBGeometryTypes.WKBPointZ:
                case WKBGeometryTypes.WKBPointM:
                case WKBGeometryTypes.WKBPointZM:
                    geometries[i] = ReadPoint(reader, cs2, srid);
                    break;

                //Line String
                case WKBGeometryTypes.WKBLineString:
                case WKBGeometryTypes.WKBLineStringZ:
                case WKBGeometryTypes.WKBLineStringM:
                case WKBGeometryTypes.WKBLineStringZM:
                    geometries[i] = ReadLineString(reader, cs2, srid2);
                    break;

                //Polygon
                case WKBGeometryTypes.WKBPolygon:
                case WKBGeometryTypes.WKBPolygonZ:
                case WKBGeometryTypes.WKBPolygonM:
                case WKBGeometryTypes.WKBPolygonZM:
                    geometries[i] = ReadPolygon(reader, cs2, srid2);
                    break;

                //Multi Point
                case WKBGeometryTypes.WKBMultiPoint:
                case WKBGeometryTypes.WKBMultiPointZ:
                case WKBGeometryTypes.WKBMultiPointM:
                case WKBGeometryTypes.WKBMultiPointZM:
                    geometries[i] = ReadMultiPoint(reader, cs2, srid2);
                    break;

                //Multi Line String
                case WKBGeometryTypes.WKBMultiLineString:
                case WKBGeometryTypes.WKBMultiLineStringZ:
                case WKBGeometryTypes.WKBMultiLineStringM:
                case WKBGeometryTypes.WKBMultiLineStringZM:
                    geometries[i] = ReadMultiLineString(reader, cs2, srid2);
                    break;

                //Multi Polygon
                case WKBGeometryTypes.WKBMultiPolygon:
                    geometries[i] = ReadMultiPolygon(reader, cs2, srid2);
                    break;

                //Geometry Collection
                case WKBGeometryTypes.WKBGeometryCollection:
                case WKBGeometryTypes.WKBGeometryCollectionZ:
                case WKBGeometryTypes.WKBGeometryCollectionM:
                case WKBGeometryTypes.WKBGeometryCollectionZM:
                    geometries[i] = ReadGeometryCollection(reader, cs2, srid2);
                    break;

                default:
                    throw new ArgumentException("Should never reach here!");
                }
            }
            return(factory.CreateGeometryCollection(geometries));
        }
Esempio n. 12
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="reader"></param>
        /// <returns></returns>
        protected IGeometry Read(BinaryReader reader)
        {
            CoordinateSystem cs;
            int srid;
            WKBGeometryTypes geometryType = ReadGeometryType(reader, out cs, out srid);

            switch (geometryType)
            {
            //Point
            case WKBGeometryTypes.WKBPoint:
            case WKBGeometryTypes.WKBPointZ:
            case WKBGeometryTypes.WKBPointM:
            case WKBGeometryTypes.WKBPointZM:
                return(ReadPoint(reader, cs, srid));

            //Line String
            case WKBGeometryTypes.WKBLineString:
            case WKBGeometryTypes.WKBLineStringZ:
            case WKBGeometryTypes.WKBLineStringM:
            case WKBGeometryTypes.WKBLineStringZM:
                return(ReadLineString(reader, cs, srid));

            //Polygon
            case WKBGeometryTypes.WKBPolygon:
            case WKBGeometryTypes.WKBPolygonZ:
            case WKBGeometryTypes.WKBPolygonM:
            case WKBGeometryTypes.WKBPolygonZM:
                return(ReadPolygon(reader, cs, srid));

            //Multi Point
            case WKBGeometryTypes.WKBMultiPoint:
            case WKBGeometryTypes.WKBMultiPointZ:
            case WKBGeometryTypes.WKBMultiPointM:
            case WKBGeometryTypes.WKBMultiPointZM:
                return(ReadMultiPoint(reader, cs, srid));

            //Multi Line String
            case WKBGeometryTypes.WKBMultiLineString:
            case WKBGeometryTypes.WKBMultiLineStringZ:
            case WKBGeometryTypes.WKBMultiLineStringM:
            case WKBGeometryTypes.WKBMultiLineStringZM:
                return(ReadMultiLineString(reader, cs, srid));

            //Multi Polygon
            case WKBGeometryTypes.WKBMultiPolygon:
            case WKBGeometryTypes.WKBMultiPolygonZ:
            case WKBGeometryTypes.WKBMultiPolygonM:
            case WKBGeometryTypes.WKBMultiPolygonZM:
                return(ReadMultiPolygon(reader, cs, srid));

            //Geometry Collection
            case WKBGeometryTypes.WKBGeometryCollection:
            case WKBGeometryTypes.WKBGeometryCollectionZ:
            case WKBGeometryTypes.WKBGeometryCollectionM:
            case WKBGeometryTypes.WKBGeometryCollectionZM:
                return(ReadGeometryCollection(reader, cs, srid));

            default:
                throw new ArgumentException("Geometry type not recognized. GeometryCode: " + geometryType);
            }
        }
Esempio n. 13
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="reader"></param>
        /// <returns></returns>
        protected IGeometry Read(BinaryReader reader)
        {
            WKBGeometryTypes geometryType = (WKBGeometryTypes)reader.ReadInt32();

            switch (geometryType)
            {
            //Point
            case WKBGeometryTypes.WKBPoint:
                return(ReadPoint(reader, CoordinateSystem.XY));

            case WKBGeometryTypes.WKBPointZ:
                return(ReadPoint(reader, CoordinateSystem.XYZ));

            case WKBGeometryTypes.WKBPointM:
                return(ReadPoint(reader, CoordinateSystem.XYM));

            case WKBGeometryTypes.WKBPointZM:
                return(ReadPoint(reader, CoordinateSystem.XYZM));

            //Line String
            case WKBGeometryTypes.WKBLineString:
                return(ReadLineString(reader, CoordinateSystem.XY));

            case WKBGeometryTypes.WKBLineStringZ:
                return(ReadLineString(reader, CoordinateSystem.XYZ));

            case WKBGeometryTypes.WKBLineStringM:
                return(ReadLineString(reader, CoordinateSystem.XYM));

            case WKBGeometryTypes.WKBLineStringZM:
                return(ReadLineString(reader, CoordinateSystem.XYZM));

            //Polygon
            case WKBGeometryTypes.WKBPolygon:
                return(ReadPolygon(reader, CoordinateSystem.XY));

            case WKBGeometryTypes.WKBPolygonZ:
                return(ReadPolygon(reader, CoordinateSystem.XYZ));

            case WKBGeometryTypes.WKBPolygonM:
                return(ReadPolygon(reader, CoordinateSystem.XYM));

            case WKBGeometryTypes.WKBPolygonZM:
                return(ReadPolygon(reader, CoordinateSystem.XYZM));

            //Multi Point
            case WKBGeometryTypes.WKBMultiPoint:
                return(ReadMultiPoint(reader, CoordinateSystem.XY));

            case WKBGeometryTypes.WKBMultiPointZ:
                return(ReadMultiPoint(reader, CoordinateSystem.XYZ));

            case WKBGeometryTypes.WKBMultiPointM:
                return(ReadMultiPoint(reader, CoordinateSystem.XYM));

            case WKBGeometryTypes.WKBMultiPointZM:
                return(ReadMultiPoint(reader, CoordinateSystem.XYZM));

            //Multi Line String
            case WKBGeometryTypes.WKBMultiLineString:
                return(ReadMultiLineString(reader, CoordinateSystem.XY));

            case WKBGeometryTypes.WKBMultiLineStringZ:
                return(ReadMultiLineString(reader, CoordinateSystem.XYZ));

            case WKBGeometryTypes.WKBMultiLineStringM:
                return(ReadMultiLineString(reader, CoordinateSystem.XYM));

            case WKBGeometryTypes.WKBMultiLineStringZM:
                return(ReadMultiLineString(reader, CoordinateSystem.XYZM));

            //Multi Polygon
            case WKBGeometryTypes.WKBMultiPolygon:
                return(ReadMultiPolygon(reader, CoordinateSystem.XY));

            case WKBGeometryTypes.WKBMultiPolygonZ:
                return(ReadMultiPolygon(reader, CoordinateSystem.XYZ));

            case WKBGeometryTypes.WKBMultiPolygonM:
                return(ReadMultiPolygon(reader, CoordinateSystem.XYM));

            case WKBGeometryTypes.WKBMultiPolygonZM:
                return(ReadMultiPolygon(reader, CoordinateSystem.XYZM));

            //Geometry Collection
            case WKBGeometryTypes.WKBGeometryCollection:
                return(ReadGeometryCollection(reader, CoordinateSystem.XY));

            case WKBGeometryTypes.WKBGeometryCollectionZ:
                return(ReadGeometryCollection(reader, CoordinateSystem.XYZ));

            case WKBGeometryTypes.WKBGeometryCollectionM:
                return(ReadGeometryCollection(reader, CoordinateSystem.XYM));

            case WKBGeometryTypes.WKBGeometryCollectionZM:
                return(ReadGeometryCollection(reader, CoordinateSystem.XYZM));

            default:
                throw new ArgumentException("Geometry type not recognized. GeometryCode: " + geometryType);
            }
        }