The OGC Well-Known Binary representation for geometry
The OGC Well-Known Binary representation for geometry
|
Release 9.3 |
|
The well-known binary representation for OGC geometry (WKBgeometry) provides a portable representation of a geometry value as a contiguous stream of bytes. It permits geometry values to be exchanged between an ODBC client and a database in binary form. It is not compressed.
This geometry storage type can be used with ArcSDE geodatabases stored in Oracle or SQL Server to store two-dimensional geometry. Feature classes stored in the OGC Well-Known Binary type are also made up of three tables—the business table, the feature table, and the spatial index table—just like feature classes stored in ArcSDE Compressed Binary.
The business table contains attributes and a spatial column. The spatial column is a key to the feature and spatial index tables.
The relationship between the business table and the feature table is managed through the spatial column and the FID column. This key, which is maintained by ArcSDE, is unique.
If you want to store most of your feature class data in OGC Well-Known Binary format, change the value of the GEOMETRY_STORAGE parameter under the DEFAULTS configuration keyword of the DBTUNE table to OGCWKB. If, instead, you want to store only some of your feature classes in the OGC Well-Known Binary format, you can specify the WKB_GEOMETRY configuration keyword when you create those feature classes.
What is the OGC Well-Known Binary representation?
This is part of the Open Geospatial Consortium's Simple Features specification that implements a simple storage model for point, line, and polygon features using x,y coordinates. It is a focused specification that has been adopted and extended by most adopters including ESRI as part of the geodatabase support using ArcGIS and ArcSDE software.
The well-known binary representation for geometry is obtained by serializing a geometry instance as a sequence of numeric types drawn from the set {Unsigned Integer, Double} and serializing each numeric type as a sequence of bytes using one of two well-defined, standard binary representations for numeric types, NDR or XDR.
NOTE: XDR stands for eXtended Data Representation. XDR is an IETF standard of the presentation layer in the OSI model. XDR allows data to be transported in an independent manner so data can be transferred between computer systems. NDR stands for Network Data Representation. It is an implementation of the presentation layer in the OSI model.
The specific binary encoding used for a geometry byte stream is described by a one-byte tag that precedes the serialized bytes. The only difference between the two encodings of geometry is byte order. The XDR encoding is big endian, while the NDR encoding is little endian. That means the XDR encoding representation of an unsigned integer—a 32-bit (4 byte) data type that encodes a nonnegative integer in the range [0, 4294967295]—is big endian, as is the XDR encoding representation of a double—a 64-bit (8 byte) double-precision data type that encodes a double-precision number using the IEEE 754 double-precision format. Conversely, the NDR representation of an unsigned integer is little endian (least significant byte first), and the NDR representation of a double is little endian (sign bit is last byte).
Conversion between the NDR and XDR data types for unsigned integers and doubles is a simple operation involving the reversal of bytes within each unsigned integer or double in the byte stream.
Description of WKB geometry byte streams
The basic building block of the well-known binary representation for geometry is the byte stream for a point that consists of two doubles. The byte streams for other geometries are built using the byte streams for geometries that have already been defined. The following is a definition of the byte stream:
Basic Type definitions
byte : 1 byte
uint32 : 32 bit unsigned integer (4 bytes)
double : double precision number (8 bytes)
Building Blocks : Point, LinearRing
Point {
double x;
double y;
};
LinearRing {
uint32 numPoints;
Point points[numPoints];
}
enum wkbGeometryType {
wkbPoint = 1,
wkbLineString = 2,
wkbPolygon = 3,
wkbMultiPoint = 4,
wkbMultiLineString = 5,
wkbMultiPolygon = 6,
wkbGeometryCollection = 7
};
enum wkbByteOrder {
wkbXDR = 0, Big Endian
wkbNDR = 1 Little Endian
};
WKBPoint {
byte byteOrder;
uint32 wkbType; 1
Point point;
}
WKBLineString {
byte byteOrder;
uint32 wkbType; 2
uint32 numPoints;
Point points[numPoints];
}
WKBPolygon {
byte byteOrder;
uint32 wkbType; 3
uint32 numRings;
LinearRing rings[numRings];
}
WKBMultiPoint {
byte byteOrder;
uint32 wkbType; 4
uint32 num_wkbPoints;
WKBPoint WKBPoints[num_wkbPoints];
}
WKBMultiLineString {
byte byteOrder;
uint32 wkbType; 5
uint32 num_wkbLineStrings;
WKBLineString WKBLineStrings[num_wkbLineStrings];
}
wkbMultiPolygon {
byte byteOrder;
uint32 wkbType; 6
uint32 num_wkbPolygons;
WKBPolygon wkbPolygons[num_wkbPolygons];
}
WKBGeometry {
union {
WKBPoint point;
WKBLineString linestring;
WKBPolygon polygon;
WKBGeometryCollection collection;
WKBMultiPoint mpoint;
WKBMultiLineString mlinestring;
WKBMultiPolygon mpolygon;
}
};
WKBGeometryCollection {
byte byte_order;
uint32 wkbType; 7
uint32 num_wkbGeometries;
WKBGeometry wkbGeometries[num_wkbGeometries]
}
Assertions for well-known binary representation for geometry
The well-known binary representation for geometry is designed to represent instances of the geometry types described in the geometry object model and in the OpenGIS Abstract Specification. These assertions imply the following for rings, polygons, and multipolygons:
- Linear rings—Rings are simple and closed, which means that linear rings may not self-intersect.
- Polygons—No two linear rings in the boundary of a polygon may cross each other. The linear rings in the boundary of a polygon may intersect, at most, at a single point but only as a tangent.
- Multipolygons—The interiors of two polygons that are elements of a multipolygon may not intersect. The boundaries of any two polygons that are elements of a multipolygon may touch at only a finite number of points.