2. Getting Started with Spatial Features : Representing Geometries as Text
 
Share this page                  
Representing Geometries as Text
When dealing with large quantities of spatial data (during an import, for example), you may be handling binary data. But in these examples we use simple text representations of the geometries in the data. Such representation is called the Well Known Text (WKT) representation of a geometric feature, and follows an industry standard.
A POINT object is defined by X, Y coordinates. X and Y can be any number and can represent a longitude, latitude, or any other value that is meaningful to you. For example, a point object, represented as a text string, may look like this:
'POINT (-121 52)'
In decimal degree coordinates, this is a location in western Canada. But all your points may not be measured in degrees; perhaps you are storing data from an electron microscope in millimeters, or storing data measured in feet. Either way, it is a number (integer or float) that has meaning.
A LINE feature (also known as a LINESTRING) is made up of two or more points, separated by a comma and with a different prefix:
'LINESTRING (-121 52, -0.59 51.51)'
In decimal degrees this is a rough line from western Canada to Slough, U.K.
For POLYGON features, you add more points to the LINESTRING, and one final point the same as the first point, to close the polygon. An unclosed LINESTRING cannot become a polygon. A polygon will always have at least four coordinate pairs defined (start, end, and two that define the 2D shape). Here is a simple example:
'POLYGON ((1 1, 1 10, 10 10, 10 1, 1 1))'
These are simple pairs of coordinates. You can think of them as: ( X1 Y1, X2 Y2, ... Xn Yn ... X1 Y1 ).