2.1.2 Basic GEOGRAPHY Structure (Version 2)
Version 2 of the GEOGRAPHY structure is formatted as shown in the following packet diagram. All double fields contain doubleprecision floatingpoint numbers that are 64 bits (8 bytes) long. Integers and doubleprecision floatingpoint numbers are expressed in littleendian format.










1 









2 









3 


SRID 

Version 
Serialization Properties 
Number of Points (optional, unsigned) 

... 
Points (optional, variable) (16 * Number of Points bytes) (variable) 

... 

Z Values (optional, 8 * Number of Points bytes) (variable) 

... 

M Values (optional, 8 * Number of Points bytes) (variable) 

... 

Number of Figures (optional, unsigned) 

Figures (optional, 5 * Number of Figure bytes) (variable) 

... 

Number of Shapes (optional, unsigned) 

Shapes (optional, 9 * Number of Shapes bytes) (variable) 

... 

Number of Segments (optional) 

Segments (optional) (1 * Number of Segments bytes) (variable) 

... 
SRID (4 bytes): (32 bit integer) The SRID for the geography. GEOGRAPHY structures MUST use SRID values in the range of 4120 through 4999, inclusive, with the exception of null geographies. A value of 1 indicates a null geography. When a null geography is indicated, all other fields are omitted. Default SRID for GEOGRAPHY instances is 4326. Default SRID for GEOMETRY instances is zero (0). For GEOMETRY instance, SRID can be any value: SRID is not constrained.
Version (1 byte): The version of the GEOGRAPHY structure.<4>
Serialization Properties (1 byte): A bit field that contains individual bit flags that indicate which optional content is present in the structure as well as other attributes of the geography. The first 3 bits of the serialization properties are reserved for future use.

0
1
2
3
4
5
6
70
0
H
L
P
V
M
Z

Where the bits are defined as:

Value
Description
Z
(0x01)
The structure has Z values.
M
(0x02)
The structure has M values.
V
(0x04)
Geography is valid. For GEOGRAPHY structures, V in version 2 is always set.
P
(0x08)
Geography contains a single point. When P is set, Number of Points, Number of Figures, and Number of Shapes are implicitly assumed to be equal to 1 and are omitted from the structure. In addition, Figures is implicitly assumed to contain one figure representing a Stroke with a Point Offset of 0 (zero). Lastly, Shape is implicitly assumed to contain one shape of type Point, with a Figure Offset of 0 (zero) and without any parents (Parent Offset set to 1). This is an optimization for the common case of a single point.
L
(0x10)
Geography contains a single line segment. When L is set, Number of Points is implicitly assumed to be equal to 2 and does not explicitly appear in the serialized data. Number of Figures and Number of Shapes are implicitly assumed to be equal to 1 and do not explicitly appear in the serialized data. In addition, Figures is implicitly assumed to contain one stroke figure (0x01) with a Point Offset of 0 (zero). Lastly, Shape is implicitly assumed to contain one shape of type 0x02 (LineString), with a Figure Offset of 0 and without any parents (Parent Offset set to 1).
P and L are mutually exclusive properties.
H
(0x20)
In version 2 of the serialization format, geography is larger than a hemisphere.
Number of Points (optional, unsigned) (4 bytes): The number of points in the GEOGRAPHY structure. This MUST be a positive number or 0 (zero). If either the P or L bit is set in the Serialization Properties bit field, this field is omitted from the structure.
Points (optional, variable) (16 * Number of Points bytes) (variable): A sequence of point structures. The point coordinates are contained in GEOGRAPHY POINT structures in GEOGRAPHY structures. Likewise, coordinates are contained in GEOMETRY POINT structures in GEOMETRY structures. Both structures contain a pair of doubles.

If neither the P nor L bit is set in the Serialization Properties bit field, there will be Number of Points points in the sequence. If the P bit is set, there will be one point. If the L bit is set, there will be two points.
Z Values (optional, 8 * Number of Points bytes) (variable): A sequence of double values for the Z value of each point. If the Z bit is set, there will be Number of Points doubles in the array. If a Z value for an individual point is NULL, it is represented by QNaN [IEEE754].
M Values (optional, 8 * Number of Points bytes) (variable): A sequence of double values for the M value of each point. If the M bit is set, there will be Number of Points doubles in the array. If an M value for an individual point is NULL, it is represented by QNaN.
Number of Figures (optional, unsigned) (4 bytes): The number of figures in the structure. This MUST be a positive number or 0 (zero).
Figures (optional, 5 * Number of Figure bytes) (variable): A sequence of figure structures.
Number of Shapes (optional, unsigned) (4 bytes): The number of shapes in the structure. This MUST be a positive number.
Shapes (optional, 9 * Number of Shapes bytes) (variable): A sequence of shape structures.
Number of Segments (optional) (4 bytes): In version 2 of the serialization format, the number of segments in the structure. This MUST be a positive number.
Segments (optional) (1 * Number of Segments bytes) (variable): In version 2 of the serialization format, a sequence of segment structures.