If your PostgreSQL instance includes the PostGIS extension, you can use PROC SQL to Read and work with geography or geometry values. SAS checks for the version of PostGIS that is installed to ensure that the extension is present. If the PostgreSQL server that you specify does not have PostGIS installed, SAS writes an error to the SAS log.
Geography and geometry data is represented as VARCHAR values in SAS. These values, such as 010100000000000000000000000000000000000000, are not very useful. However, if you use available PostGIS functions, such as ST_AsText, then data points are rendered in a more understandable form. Other functions that help you to render geography and geometry data in a readable form are ST_AsEWKT, ST_AsGML, ST_AsGeoJSON, and ST_AsSVG.
For example, the following query to a table called Geometries with libref Mydb renders data similar to the output shown below:
proc sql;
select name, ST_AsText(geom) as geom from mydb.geometries;
quit;
|
name |
geom |
|---|---|
|
Point |
POINT(0 0) |
|
Linestring |
LINESTRING(0 0,1 1,2 1,2 2) |
|
Polygon |
POLYGON((0 0,1 0,1 1,0 1,0 0)) |
|
PolygonWithHole |
POLYGON((0 0,10 0,10 10,0 10,0 0),(1 1,1 2,2 2,2 1,1 1)) |
|
Collection |
GEOMETRYCOLLECTION(POINT(2 0),POLYGON((0 0,1 0,1 1,0 1,0 0))) |
Here is the list of PostGIS functions that you can call with PROC SQL:
| ST_Area | ST_GeomFromWKB |
| ST_AsBinary | ST_InteriorRingN |
| ST_AsEWKB | ST_Intersects |
| ST_AsEWKT | ST_IsValid |
| ST_AsGeoJSON | ST_IsValidReason |
| ST_AsGML | ST_Length |
| ST_AsSVG | ST_MakeValid |
| ST_AsText | ST_NDims |
| ST_Contains | ST_NPoints |
| ST_ContainsProperly | ST_NRings |
| ST_Crosses | ST_NumGeometries |
| ST_Disjoint | ST_OrderingEquals |
| ST_Distance | ST_Overlaps |
| ST_DWithin | ST_Perimeter |
| ST_EndPoint | ST_SRID |
| ST_Equals | ST_StartPoint |
| ST_ExteriorRing | ST_Touches |
| ST_GeometryN | ST_Transform |
| ST_GeometryType | ST_Within |
| ST_GeomFromGML | ST_X |
| ST_GeomFromText | ST_Y |
For descriptions and explanations about usage of these functions, see your PostGIS documentation.