示例#1
0
        private MultiLineString ReadMultiLineString(bool hasZ)
        {
            int nPolylines = m_objReader.ReadInt32();

            if (nPolylines <= 0)
            {
                return(null);
            }

            LineString[] lines = new LineString[nPolylines];
            for (int i = 0; i < nPolylines; i++)
            {
                BytesOrder byteOrder = (BytesOrder)m_objReader.ReadByte();  // handle the byte order
                m_objReader.Order = byteOrder;

                int  dataType = m_objReader.ReadInt32();
                int  geomType = dataType & 0xFF;
                bool bHasZ    = (dataType & 0x80000000) != 0;
                if (geomType != 2)
                {
                    throw new GeometryIOException("The data is badly formed. "
                                                  + "A LineString geometry is expected");
                }

                lines[i] = ReadLineString(bHasZ);
            }

            return(m_objFactory.CreateMultiLineString(lines));
        }
示例#2
0
        private MultiPolygon ReadMultiPolygon(bool hasZ)
        {
            int nPolygons = m_objReader.ReadInt32();

            if (nPolygons <= 0)
            {
                return(null);
            }

            Polygon[] polygons = new Polygon[nPolygons];
            for (int i = 0; i < nPolygons; i++)
            {
                BytesOrder byteOrder = (BytesOrder)m_objReader.ReadByte();  // handle the byte order
                m_objReader.Order = byteOrder;

                int  dataType = m_objReader.ReadInt32();
                int  geomType = dataType & 0xFF;
                bool bHasZ    = (dataType & 0x80000000) != 0;
                if (geomType != 3)
                {
                    throw new GeometryIOException("The data is badly formed. "
                                                  + "A Polygon geometry is expected");
                }

                polygons[i] = ReadPolygon(bHasZ);
            }

            return(m_objFactory.CreateMultiPolygon(polygons));
        }
示例#3
0
 public BytesReader(byte[] buffer, int offset)
 {
     m_objBuffer = buffer;
     m_nOffset   = offset;
     m_enumOrder = BytesOrder.LittleEndian;
     m_bIsLittle = (m_enumOrder == BytesOrder.LittleEndian);
 }
示例#4
0
 public BytesWriter()
 {
     m_objBuffer = new BytesBuffer();
     m_objData   = new byte[16];
     m_enumOrder = BytesOrder.LittleEndian;
     m_bIsLittle = (m_enumOrder == BytesOrder.LittleEndian);
 }
示例#5
0
        private GeometryCollection ReadGeometryCollection(bool hasZ)
        {
            int nGeometries = m_objReader.ReadInt32();

            if (nGeometries <= 0)
            {
                return(null);
            }

            Geometry[] geometries = new Geometry[nGeometries];

            for (int i = 0; i < nGeometries; i++)
            {
                BytesOrder byteOrder = (BytesOrder)m_objReader.ReadByte();  // handle the byte order
                m_objReader.Order = byteOrder;

                int  dataType = m_objReader.ReadInt32();
                int  geomType = dataType & 0xFF;
                bool bHasZ    = (dataType & 0x80000000) != 0;
                switch (geomType)
                {
                case 1:
                    geometries[i] = ReadPoint(bHasZ);
                    break;

                case 2:
                    geometries[i] = ReadLineString(bHasZ);
                    break;

                case 3:
                    geometries[i] = ReadPolygon(bHasZ);
                    break;

                case 4:
                    geometries[i] = ReadMultiPoint(bHasZ);
                    break;

                case 5:
                    geometries[i] = ReadMultiLineString(bHasZ);
                    break;

                case 6:
                    geometries[i] = ReadMultiPolygon(bHasZ);
                    break;

                case 7:
                    geometries[i] = ReadGeometryCollection(bHasZ);
                    break;

                default:
                    throw new GeometryIOException("The geometry type is not supported.");
                }
            }

            return(m_objFactory.CreateGeometryCollection(geometries));
        }
示例#6
0
        public byte[] Write(Geometry geometry, GeometryWkbMode wkbMode,
                            BytesOrder order)
        {
            if (geometry == null)
            {
                throw new ArgumentNullException("geometry");
            }

            m_objWriter.Initialize();
            m_objWriter.Order = order;

            GeometryWkbMode mode = wkbMode;

            bool bResult = false;

            byte[] geomBytes = null;

            switch (mode)
            {
            case GeometryWkbMode.Standard:
                bResult = WriteStandard(geometry);
                break;

            case GeometryWkbMode.Proposed:
                bResult = WriteProposed(geometry);
                break;

            case GeometryWkbMode.PostGIS:
                bResult = WritePostGIS(geometry);
                break;

            case GeometryWkbMode.Custom:
                bResult = WriteCustom(geometry);
                break;
            }

            if (bResult)
            {
                geomBytes = m_objWriter.GetBuffer();
            }

            m_objWriter.Uninitialize(); // reset the buffer

            return(geomBytes);
        }
示例#7
0
        private Geometry ReadProposed()
        {
            // 1. Determine the byte order of the binary data
            BytesOrder byteOrder = (BytesOrder)m_objReader.ReadByte();

            // 2. Initialize the reader to the appropriate byte order.
            m_objReader.Order = byteOrder;

            // 3. Determine the data type of the object
            int dataType = m_objReader.ReadInt32();

            // 4. Remove high flag bits, if any to obtain the geometry type
            int geomType = dataType & 0xFF;

            bool hasZ = (dataType & 0x80000000) != 0;

            // 5. Handover to the specialized geometry handlers...
            switch (geomType)
            {
            case 1:      // Point
                return(ReadPoint(hasZ));

            case 2:      // LineString
                return(ReadLineString(hasZ));

            case 3:      // Polygon
                return(ReadPolygon(hasZ));

            case 4:      // MultiPoint
                return(ReadMultiPoint(hasZ));

            case 5:      // MultiLineString
                return(ReadMultiLineString(hasZ));

            case 6:      // MultiPolygon
                return(ReadMultiPolygon(hasZ));

            case 7:      // GeometryCollection
                return(ReadGeometryCollection(hasZ));

            default:
                throw new GeometryIOException("The geometry type is not supported.");
            }
        }
示例#8
0
        private MultiPoint ReadMultiPoint()
        {
            int nPoints = m_objReader.ReadInt32();

            Point[] points = new Point[nPoints];
            for (int i = 0; i < nPoints; i++)
            {
                BytesOrder byteOrder = (BytesOrder)m_objReader.ReadByte();  // handle the byte order
                m_objReader.Order = byteOrder;

                int geomType = m_objReader.ReadInt32();
                if (geomType != 1)
                {
                    throw new GeometryIOException("The data is badly formed. "
                                                  + "A Point geometry is expected");
                }

                points[i] = ReadPoint();
            }

            return(m_objFactory.CreateMultiPoint(points));
        }
示例#9
0
        private Geometry ReadStandard()
        {
            // 1. Determine the byte order of the binary data
            BytesOrder byteOrder = (BytesOrder)m_objReader.ReadByte();

            // 2. Initialize the reader to the appropriate byte order.
            m_objReader.Order = byteOrder;

            // 3. Determine the data/geometry type of the object
            int geomType = m_objReader.ReadInt32();

            // 4. Handover to the specialized geometry handlers...
            switch (geomType)
            {
            case 1:      // Point
                return(ReadPoint());

            case 2:      // LineString
                return(ReadLineString());

            case 3:      // Polygon
                return(ReadPolygon());

            case 4:      // MultiPoint
                return(ReadMultiPoint());

            case 5:      // MultiLineString
                return(ReadMultiLineString());

            case 6:      // MultiPolygon
                return(ReadMultiPolygon());

            case 7:      // GeometryCollection
                return(ReadGeometryCollection());

            default:
                throw new GeometryIOException("The geometry type is not supported.");
            }
        }
示例#10
0
        private MultiPoint ReadMultiPoint(bool hasZ, bool hasM)
        {
            int nPoints = m_objReader.ReadInt32();

            Point[] points = new Point[nPoints];
            for (int i = 0; i < nPoints; i++)
            {
                BytesOrder byteOrder = (BytesOrder)m_objReader.ReadByte();  // handle the byte order
                m_objReader.Order = byteOrder;

                int dataType = m_objReader.ReadInt32();
                int geomType = dataType & 0x1FFFFFFF;

                bool bHasZ = (dataType & 0x80000000) != 0;
                bool bHasM = (dataType & 0x40000000) != 0;
                bool bHasS = (dataType & 0x20000000) != 0;

                int nSRID = -1;
                if (bHasS)
                {
                    nSRID = m_objReader.ReadInt32();
                    if (nSRID > 0)
                    {
                    }
                }
                if (geomType != 1)
                {
                    throw new GeometryIOException("The data is badly formed. "
                                                  + "A Point geometry is expected");
                }

                points[i] = ReadPoint(bHasZ, bHasM);
            }

            return(m_objFactory.CreateMultiPoint(points));
        }
示例#11
0
        private Geometry ReadPostGIS()
        {
            // 1. Determine the byte order of the binary data
            BytesOrder byteOrder = (BytesOrder)m_objReader.ReadByte();

            // 2. Initialize the reader to the appropriate byte order.
            m_objReader.Order = byteOrder;

            // 3. Determine the data type of the object
            int dataType = m_objReader.ReadInt32();

            // 4. Remove high flag bits, if any to obtain the geometry type
            int geomType = dataType & 0x1FFFFFFF;

            bool hasZ = (dataType & 0x80000000) != 0;
            bool hasM = (dataType & 0x40000000) != 0;
            bool hasS = (dataType & 0x20000000) != 0;

            int nSRID = -1;

            if (hasS)
            {
                nSRID = m_objReader.ReadInt32();
            }

            Geometry geometry = null;

            // 5. Handover to the specialized geometry handlers...
            switch (geomType)
            {
            case 1:      // Point
                geometry = ReadPoint(hasZ, hasM);
                break;

            case 2:      // LineString
                geometry = ReadLineString(hasZ, hasM);
                break;

            case 3:      // Polygon
                geometry = ReadPolygon(hasZ, hasM);
                break;

            case 4:      // MultiPoint
                geometry = ReadMultiPoint(hasZ, hasM);
                break;

            case 5:      // MultiLineString
                geometry = ReadMultiLineString(hasZ, hasM);
                break;

            case 6:      // MultiPolygon
                geometry = ReadMultiPolygon(hasZ, hasM);
                break;

            case 7:      // GeometryCollection
                geometry = ReadGeometryCollection(hasZ, hasM);
                break;

            default:
                throw new GeometryIOException("The geometry type is not supported.");
            }

            if ((hasS && nSRID > -1) && geometry != null)
            {
                if (geometry.Properties == null)
                {
                    geometry.CreateProperties();
                }
                geometry.Properties["SRID"] = nSRID;
            }

            return(geometry);
        }
示例#12
0
 public BytesReader(byte[] buffer)
 {
     m_objBuffer = buffer;
     m_enumOrder = BytesOrder.LittleEndian;
     m_bIsLittle = (m_enumOrder == BytesOrder.LittleEndian);
 }
示例#13
0
 public BytesReader()
 {
     m_enumOrder = BytesOrder.LittleEndian;
     m_bIsLittle = (m_enumOrder == BytesOrder.LittleEndian);
 }
示例#14
0
        public byte[] Write(Geometry geometry, BytesOrder order)
        {
            if (geometry == null)
            {
                throw new ArgumentNullException("geometry");
            }

            m_objWriter.Initialize();
            m_objWriter.Order = order;

            GeometryWkbMode mode = GeometryWkbMode.Standard;

            GeometryFactory factory = geometry.Factory;

            if (factory != null)
            {
                CoordinateType coordType = factory.CoordinateType;
                if (coordType == CoordinateType.Measured)
                {
                    mode = GeometryWkbMode.PostGIS;
                }
                else
                {
                    IGeometryProperties properties = geometry.Properties;
                    if (properties != null && properties.Contains("SRID"))
                    {
                        mode = GeometryWkbMode.PostGIS;
                    }
                    else
                    {
                        int dim = factory.CoordinateDimension;
                        if (dim == 3)
                        {
                            mode = GeometryWkbMode.Proposed;
                        }
                    }
                }
            }

            bool bResult = false;

            byte[] geomBytes = null;

            switch (mode)
            {
            case GeometryWkbMode.Standard:
                bResult = WriteStandard(geometry);
                break;

            case GeometryWkbMode.Proposed:
                bResult = WriteProposed(geometry);
                break;

            case GeometryWkbMode.PostGIS:
                bResult = WritePostGIS(geometry);
                break;

            case GeometryWkbMode.Custom:
                bResult = WriteCustom(geometry);
                break;
            }

            if (bResult)
            {
                geomBytes = m_objWriter.GetBuffer();
            }

            m_objWriter.Uninitialize(); // reset the buffer

            return(geomBytes);
        }
示例#15
0
        public byte[] Write(Geometry geometry)
        {
            BytesOrder order = m_objWriter.Order;

            return(Write(geometry, order));
        }