[postgis-devel] OGC TIN of triangles or polygons?
Mateusz Loskot
mateusz at loskot.net
Thu Nov 28 03:55:23 PST 2013
Hi,
I'd like to ask to help me understand specification of TIN
from the OGC SFS 1.2.1 (OGC 06-103r4).
Specifically, specification of WKT and WKB format for TIN.
Diagrams and text in the design part of the document specifies
that TIN geometry is composed of one or more triangles
and a triangle is a subtype of polygon.
So, we've got three non-abstract types involved: TIN [1], triangle [2], polygon.
[1]
"""
A TIN (triangulated irregular network) is a PolyhedralSurface
consisting only of Triangle patches.
"""
[2]
"""
A Triangle is a polygon with 3 distinct, non-collinear vertices
"""
However reasonable it sounds, specification of WKT and WKB formats
that follow, seems to be inconsistent with the design part.
For WKT, triangle is not used anywhere:
<tin tagged text> tin <polyhedralsurface text>
<polyhedralsurface text> ::= <empty set> | <left paren>
<polygon text>
{<comma> <polygon text>}*
<right paren>
For WKB, WKBTriangle object is not used anywhere:
WKBTIN {
byte byteOrder;
static uint32 wkbType = 16;
uint32 numPolygons;
WKBPolygon polygons[numPolygons]
}
So, specification of both formats presents TIN composed of polygon objects.
Triangle, by design, is a polygon of course.
But, correct me if I'm wrong, the WKT/WKB has no capacity to represent
type/subtype relation, has it?
Or, does OGC SFS suddenly expect implementations to interpret WKT and WKB
geometries according to the Liskov Substitution Principle?
It is, while parsing TIN, if I see code of WKBGeometryType::wkbTriangle, take
it as valid WKBGeometryType::wkbPolygon, by is-a relation between the two.
Now, let's look at the TIN implementation in PostGIS:
WKT:
TIN (((0 0, 0 1, 1 0, 0 0)), ((0 1, 1 1, 1 0, 0 1)))
WKB:
01|10000000|02000000|
01|11000000|01000000|04000000|<64 bytes of 4 vertices>
01|11000000|01000000|04000000|<64 bytes of 4 vertices>
The WKB type codes indicate we've got geometry of
WKBTIN (0x10000000=>16 dec) with WKBTriangle (0x11000000=>17 dec)
Two questions here;
1. Shouldn't WKBTriangle read WKBPolygon (0x00000003) as OGC specifies?
2. If WKBTriangle code is correct, shouldn't there be 3 instead of 4 vertices?
Additionally to the question 2., OGC specifies
"""
A Triangle is a polygon with 3 distinct, non-collinear vertices
"""
If a triangle must have exactly 3 points and all points must be distinct,
as I interpret what the space says above, why PostGIS generates 4 points?
Attempt to parse WKT with 3-point triangles, as OGC specifies:
TIN (((0 0, 0 1, 1 0)), ((0 1, 1 1, 1 0)))
generates:
ERROR: triangle must have exactly 4 points
Is that right?
Is it my misunderstanding or from an implementer point,
OGC SFS 1.2.1 is inconsistent in regard to specification of TIN,
triangle and polygon and use of those types in the WKT/WKB formats.
And, the buggy WKBTIN format in the OGC SFS 1.2.1 should be corrected this way:
WKBTIN {
byte byteOrder;
static uint32 wkbType = 17;
uint32 numTriangles;
WKBTriangle triangles[numTriangles]
}
Any insights highly appreciated.
Best regards,
--
Mateusz Loskot, http://mateusz.loskot.net
More information about the postgis-devel
mailing list