Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Common Lisp PostGIS EWKB data model and encoder/decoder
Common Lisp
tag: 0.1

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.
cl-ewkb
examples/cl-opengl
test
.gitignore
README
cl-ewkb.asd

README

cl-ewkb is a geospatial library, based on cl-wkb, that implements the OGC Well-Known Binary geographic geometry data model with PostGIS 3d, 4d extensions, and provides WKB and EWKB encoding and decoding functionality. cl-wkb author is J.P. Larocue.

Depends on:
 ieee-floats (built-in)
 flexi-streams

PostGIS extension WKB described in postgis-1.5/doc/ZMSgeoms.txt
All extensions are supported: 3dz, 3dm, 4d, embedded SRID.


Exported structs

point-primitive x y
pointz-primitive x y z
pointm-primitive x y m
pointzm-primitive x y z m
point-primtive structs contain coordinates (2d, 3d, 4d)


linear-ring points
linear-ring struct contains array of point-primitive


gisgeometry type srid object
gisgeometry parent struct for other types and also contains "GEOMETRYCOLLECTION"

point type srid (object as pointXX-primitive)
linestring type srid (object as linear-ring)
polygon type srid (object as (array of linear-ring))
multi-point type srid (object as (array of point))
multi-linestring type srid (object as (array of linestring))
multi-polygon type srid (object as (array of polygon))
geometry-collection type srid (object as (array of other objects))

Exported functions

(decode octets)
Decode from wkb sequence
(decode-from stream)
Decode from wkb stream

Functions for encoding:

(encode object endianness)
Encode object to vector

(encode-to object stream endianness)
Encode object to stream with endianness

Example:

Getting data from postgresql and decode it:

(decode (caar (query (:select (:ST_AsEWKB "SRID=4326;LINESTRING(0 0 1 2, 1 1 2 3, 2 2 3 4)")))))

Result:

#(CL-EWKB::GISGEOMETRY 3758096386 4326
  #(CL-EWKB::LINEAR-RING
    #(#(CL-EWKB::POINT-PRIMITIVE 0.0d0 0.0d0 CL-EWKB::POINTZ-PRIMITIVE 1.0d0
        CL-EWKB::POINTZM-PRIMITIVE 2.0d0)
      #(CL-EWKB::POINT-PRIMITIVE 1.0d0 1.0d0 CL-EWKB::POINTZ-PRIMITIVE 2.0d0
        CL-EWKB::POINTZM-PRIMITIVE 3.0d0)
      #(CL-EWKB::POINT-PRIMITIVE 2.0d0 2.0d0 CL-EWKB::POINTZ-PRIMITIVE 3.0d0
        CL-EWKB::POINTZM-PRIMITIVE 4.0d0)))
  CL-EWKB::LINESTRING)


Drawing data with opengl (using cl-opengl):

Draw pointXX-primitive

(defun draw-point-primitive (point)
    (cond
        ((point-primitive-p point)
            (gl:vertex
                (point-primitive-x point)
                (point-primitive-y point)))
        ((pointz-primitive-p point)
            (gl:vertex
                (point-primitive-x point)
                (point-primitive-y point)
                (pointz-primitive-z point)))
        ((pointm-primitive-p point)
            (gl:vertex
                (point-primitive-x point)
                (point-primitive-y point)
                0.0
                (pointm-primitive-m point)))
        ((pointzm-primitive-p point)
            (gl:vertex
                (point-primitive-x point)
                (point-primitive-y point)
                (pointz-primitive-z point)
                (pointzm-primitive-m point)))))

Drawing linear-ring

(defun draw-linear-ring (line)
    (map 'nil (lambda (point) (draw-point-primitive point))
        (linear-ring-points line)))

Drawing objects

(defun draw-point (point)
    (gl:with-primitives :points
        (draw-point-primitive (gisgeometry-object point))))

(defun draw-linestring (line)
    (gl:with-primitives :line-strip
        (draw-linear-ring (gisgeometry-object line))))


General drawing function

(defun draw-gisobject (object)
    (cond
        ((point-p object) (draw-point object))
        ((linestring-p object) (draw-linestring object))))
Something went wrong with that request. Please try again.