/// <summary> /// Writes the binary encoded PostGIS header. /// </summary> /// <param name="byteOrder">The byte order specified.</param> /// <param name="type">The PostGIS geometry type.</param> /// <param name="srid">The spatial reference of the geometry</param> /// <param name="ordinates"></param> /// <param name="writer">The writer to use.</param> private static void WriteHeader(PostGisGeometryType type, int srid, Ordinates ordinates, ByteOrder byteOrder, BinaryWriter writer) { writer.Write((byte)byteOrder); // write typeword var typeword = (uint)type; if ((ordinates & Ordinates.Z) != 0) { typeword |= 0x80000000; } if ((ordinates & Ordinates.M) != 0) { typeword |= 0x40000000; } if (srid != -1) { typeword |= 0x20000000; } writer.Write(typeword); if (srid != -1) { writer.Write(srid); } }
/// <summary> /// Writes the binary encoded PostGIS header. /// </summary> /// <param name="type">The PostGIS geometry type.</param> /// <param name="srid">The spatial reference of the geometry</param> /// <param name="emitSrid">Flag indicating that <paramref name="srid"/> should be written</param> /// <param name="ordinates"></param> /// <param name="byteOrder">The byte order specified.</param> /// <param name="writer">The writer to use.</param> private static void WriteHeader(PostGisGeometryType type, int srid, bool emitSrid, Ordinates ordinates, ByteOrder byteOrder, BinaryWriter writer) { writer.Write((byte)byteOrder); // write typeword uint typeword = (uint)type; if (ordinates.HasFlag(Ordinates.Z)) { typeword |= 0x80000000; } if (ordinates.HasFlag(Ordinates.M)) { typeword |= 0x40000000; } emitSrid &= srid > 0; if (emitSrid) { typeword |= 0x20000000; } writer.Write(typeword); if (emitSrid) { writer.Write(srid); } }
/// <summary> /// /// </summary> /// <param name="geometry"></param> /// <param name="type"></param> /// <param name="writer"></param> private void WriteHeader(IGeometry geometry, PostGisGeometryType type, BinaryWriter writer) { writer.Write((byte)encodingType); // write typeword uint typeword = (uint)type; if (hasZ(geometry)) { typeword |= 0x80000000; } //if (geometry.HasMeasure) // typeword |= 0x40000000; if (geometry.SRID != -1) { typeword |= 0x20000000; } writer.Write(typeword); if (geometry.SRID != -1) { writer.Write(geometry.SRID); } }
/// <summary> /// /// </summary> /// <param name="geometry"></param> /// <param name="type"></param> /// <param name="writer"></param> private void WriteHeader(IGeometry geometry, PostGisGeometryType type, BinaryWriter writer) { writer.Write((byte) encodingType); // write typeword uint typeword = (uint) type; if (hasZ(geometry)) typeword |= 0x80000000; //if (geometry.HasMeasure) // typeword |= 0x40000000; if (geometry.SRID != -1) typeword |= 0x20000000; writer.Write(typeword); if (geometry.SRID != -1) writer.Write(geometry.SRID); }
/// <summary> /// /// </summary> /// <param name="reader"></param> /// <returns></returns> protected IGeometry Read(BinaryReader reader) { // Dummy read, just for bytes compatibility. // The byte order is determined only once. reader.ReadByte(); int typeword = reader.ReadInt32(); // cut off high flag bits PostGisGeometryType geometryType = (PostGisGeometryType)(typeword & 0x1FFFFFFF); bool hasZ = (typeword & 0x80000000) != 0; bool hasM = (typeword & 0x40000000) != 0; bool hasS = (typeword & 0x20000000) != 0; int srid = -1; if (hasS) { srid = reader.ReadInt32(); } IGeometry result; switch (geometryType) { case PostGisGeometryType.Point: result = ReadPoint(reader, hasZ, hasM); break; case PostGisGeometryType.LineString: result = ReadLineString(reader, hasZ, hasM); break; case PostGisGeometryType.Polygon: result = ReadPolygon(reader, hasZ, hasM); break; case PostGisGeometryType.MultiPoint: result = ReadMultiPoint(reader); break; case PostGisGeometryType.MultiLineString: result = ReadMultiLineString(reader); break; case PostGisGeometryType.MultiPolygon: result = ReadMultiPolygon(reader); break; case PostGisGeometryType.GeometryCollection: result = ReadGeometryCollection(reader); break; default: throw new ArgumentException("Geometry type not recognized. GeometryCode: " + geometryType); } result.SRID = hasS ? srid : -1; return(result); }
/// <summary> /// Writes the binary encoded PostGIS header. /// </summary> /// <param name="byteOrder">The byte order specified.</param> /// <param name="type">The PostGIS geometry type.</param> /// <param name="srid">The spatial reference of the geometry</param> /// <param name="ordinates"></param> /// <param name="writer">The writer to use.</param> private static void WriteHeader(PostGisGeometryType type, int srid, Ordinates ordinates, ByteOrder byteOrder, BinaryWriter writer) { writer.Write((byte) byteOrder); // write typeword var typeword = (uint) type; if ((ordinates & Ordinates.Z) != 0) typeword |= 0x80000000; if ((ordinates & Ordinates.M) != 0) typeword |= 0x40000000; if (srid != -1) typeword |= 0x20000000; writer.Write(typeword); if (srid != -1) writer.Write(srid); }