Skip to content
Browse files

Create docs. Rename line-primitive to linear-ring

  • Loading branch information...
1 parent f3e3775 commit a946ec92366a14c12c35df77c6430ce164d0e906 @filonenko-mikhail committed May 24, 2011
Showing with 120 additions and 68 deletions.
  1. +99 −14 README
  2. +1 −1 cl-ewkb.asd
  3. +13 −35 cl-ewkb/ewkb.lisp
  4. +7 −18 examples/cl-opengl/main.lisp
View
113 README
@@ -1,23 +1,37 @@
+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.
-cl-postgis - library for encoding/decoding to/from Well-Known Binary format. Also library supports PostGIS EWKB.
-
-DEPENDENCIES:
+Depends on:
ieee-floats (built-in)
flexi-streams
-USING
+PostGIS extension WKB described in postgis-1.5/doc/ZMSgeoms.txt
+All extensions are supported: 3dz, 3dm, 4d, embedded SRID.
+
+
+Exported structs
+
+point-primtive structs contain coordinates (2d, 3d, 4d)
+point-primitive x y
+pointz-primitive x y z
+pointm-primitive x y m
+pointzm-primitive x y z m
+
+
+linear-ring struct contains array of point-primitive
+linear-ring points
-Library supports following PostGIS types:
+gisgeometry parent struct for other types and also contains "GEOMETRYCOLLECTION"
+gisgeometry type srid object
-POINT
-LINSTRING
-POLYGON
-MULTIPOINT
-MULTILINESTRING
-MULTIPOLYGON
-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))
-Functions for decoding:
+Exported functions
(decode octets)
Decode from wkb sequence
@@ -30,4 +44,75 @@ Functions for encoding:
Encode object to vector
(encode-to object stream endianness)
-Encode object to stream with 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))))
View
2 cl-ewkb.asd
@@ -9,7 +9,7 @@
:author "Michael Filonenko <filonenko.mikhail@gmail.com>"
:licence "MIT"
:description "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 :sb-flexi-streams)
+ :depends-on (:ieee-floats :flexi-streams)
:components
((:module :cl-ewkb
:components ((:file "ieee-floats")
View
48 cl-ewkb/ewkb.lisp
@@ -11,7 +11,7 @@
(deftype encoded-uint8 ()
'(or strictly-encoded-uint8 list))
-(deftype uint32 ()x
+(deftype uint32 ()
'(unsigned-byte 32))
(deftype strictly-encoded-uint32 ()
'(vector (unsigned-byte 8) 4))
@@ -191,21 +191,6 @@ endianness designator: :BIG-ENDIAN or :LITTLE-ENDIAN."
;;;; API and COMMON PROCEDURES.
;;;;
-;; (defmacro simple-defstruct-and-export (structure specials &rest members)
-;; "Define a structure STRUCT with members MEMBERS and export the
-;; standard functions created. SPECIALS is a list of extra parameters eg
-;; ((:print-function pf)). Note double parentheses."
-;; (append
-;; `(progn
-;; ,(append `(defstruct ,(append `(,structure) specials)) members)
-;; ,`(export ,`(quote ,(intern (concatenate 'string "MAKE-" (symbol-name structure)))))
-;; ,`(export ,`(quote ,(intern (concatenate 'string "COPY-" (symbol-name structure))))))
-;; (mapcar
-;; #'(lambda (member)
-;; `(export ,`(quote ,(intern (concatenate 'string(symbol-namestructure) "-" (symbol-name member))))))
-;; members)))
-
-
(defmacro defstruct-and-export (structure &rest members)
"Define a structure STRUCT with members MEMBERS and export the
standard functions created. SPECIALS is a list of extra parameters eg
@@ -302,7 +287,6 @@ endianness designator: :BIG-ENDIAN or :LITTLE-ENDIAN."
(:constructor make-multipolygon (type srid object))))
-
;;; FIXME: document these functions.
(defparameter +endiannesses+
'((0 . :big-endian)
@@ -337,32 +321,28 @@ endianness designator: :BIG-ENDIAN or :LITTLE-ENDIAN."
(:method ((type (eql :2d)) in endianness)
(make-point-primitive
(decode-ieee754-double-from endianness in)
- (decode-ieee754-double-from endianness in))
- )
+ (decode-ieee754-double-from endianness in)))
(:method ((type (eql :3dm)) in endianness)
(make-pointm-primitive
(decode-ieee754-double-from endianness in)
(decode-ieee754-double-from endianness in)
- (decode-ieee754-double-from endianness in))
- )
+ (decode-ieee754-double-from endianness in)))
(:method ((type (eql :3dz)) in endianness)
(make-pointz-primitive
(decode-ieee754-double-from endianness in)
(decode-ieee754-double-from endianness in)
- (decode-ieee754-double-from endianness in))
- )
+ (decode-ieee754-double-from endianness in)))
(:method ((type (eql :4d)) in endianness)
(make-pointzm-primitive
(decode-ieee754-double-from endianness in)
(decode-ieee754-double-from endianness in)
(decode-ieee754-double-from endianness in)
- (decode-ieee754-double-from endianness in))
- ))
+ (decode-ieee754-double-from endianness in))))
(defun decode-primitive-point (in type endianness)
(generic-decode-primitive-point (dimension type) in endianness))
-(defun decode-llinear-ring (in type endianness)
+(defun decode-linear-ring (in type endianness)
(let ((data (make-array 0 :fill-pointer 0 :element-type 'vector :adjustable T)))
(dotimes (i (decode-uint32-from endianness in))
(vector-push-extend (decode-primitive-point in type endianness) data))
@@ -379,8 +359,8 @@ endianness designator: :BIG-ENDIAN or :LITTLE-ENDIAN."
(case (cdr (assoc (logand type +wkb-typemask+) +wkb-types+ :test #'=))
(:point
(make-point type srid (decode-primitive-point in type endianness)))
- (:line-string
- (make-linestring type srid (decode-llinear-ring in type endianness)))
+ (:linestring
+ (make-linestring type srid (decode-linear-ring in type endianness)))
(:polygon
(dotimes (i (decode-uint32-from endianness in))
(vector-push-extend (decode-linear-ring in type endianness) data))
@@ -389,7 +369,7 @@ endianness designator: :BIG-ENDIAN or :LITTLE-ENDIAN."
(dotimes (i (decode-uint32-from endianness in))
(vector-push-extend (decode-from in) data))
(make-multipoint type srid data))
- (:multi-line-string
+ (:multi-linestring
(dotimes (i (decode-uint32-from endianness in))
(vector-push-extend (decode-from in) data))
(make-multilinestring type srid data))
@@ -425,8 +405,7 @@ endianness designator: :BIG-ENDIAN or :LITTLE-ENDIAN."
(encode-ieee754-double-to (pointzm-primitive-x object) endianness out)
(encode-ieee754-double-to (pointzm-primitive-y object) endianness out)
(encode-ieee754-double-to (pointzm-primitive-z object) endianness out)
- (encode-ieee754-double-to (pointzm-primitive-m object) endianness out)
- ))
+ (encode-ieee754-double-to (pointzm-primitive-m object) endianness out)))
(defun encode-primitive-point (object out type endianness)
(generic-encode-primitive-point (dimension type) object out endianness))
@@ -447,7 +426,7 @@ endianness designator: :BIG-ENDIAN or :LITTLE-ENDIAN."
(case (cdr (assoc (logand type +wkb-typemask+) +wkb-types+ :test #'=))
(:point
(encode-primitive-point (gisgeometry-object object) stream type endianness))
- (:line-string
+ (:linestring
(encode-linear-ring (gisgeometry-object object) stream type endianness))
(:polygon
(encode-uint32-to (length (gisgeometry-object object)) endianness stream)
@@ -459,7 +438,7 @@ endianness designator: :BIG-ENDIAN or :LITTLE-ENDIAN."
(map 'nil (lambda (object)
(encode-to object stream endianness))
(gisgeometry-object object)))
- (:multi-line-string
+ (:multi-linestring
(encode-uint32-to (length (gisgeometry-object object)) endianness stream)
(map 'nil (lambda (object)
(encode-to object stream endianness))
@@ -473,8 +452,7 @@ endianness designator: :BIG-ENDIAN or :LITTLE-ENDIAN."
(encode-uint32-to (length (gisgeometry-object object)) endianness stream)
(map 'nil (lambda (object)
(encode-to object stream endianness))
- (gisgeometry-object object)))
- )))
+ (gisgeometry-object object))))))
(defun encode (object &optional (endianness :little-endian))
"Function to encode geoobject to WKB/EWKB representation to sequence. Endianness: :little-endian, :big-endian"
View
25 examples/cl-opengl/main.lisp
@@ -40,9 +40,9 @@
(pointz-primitive-z point)
(pointzm-primitive-m point)))))
-(defun draw-line-primitive (line)
+(defun draw-linear-ring (line)
(map 'nil (lambda (point) (draw-point-primitive point))
- (line-primitive-points line)))
+ (linear-ring-points line)))
(defun draw-single-point (point)
(draw-point-primitive (gisgeometry-object point)))
@@ -53,12 +53,12 @@
(defun draw-linestring (line)
(gl:with-primitives :line-strip
- (draw-line-primitive (gisgeometry-object line))))
+ (draw-linear-ring (gisgeometry-object line))))
(defun draw-polygon (polygon)
"Draw only first line of polygon"
(gl:with-primitives :polygon
- (draw-line-primitive (elt (gisgeometry-object polygon) 0))))
+ (draw-linear-ring (elt (gisgeometry-object polygon) 0))))
(defun draw-multipoint (points)
(gl:with-primitive :points
@@ -98,18 +98,8 @@
(cffi:defcallback draw :void ()
(gl:clear :color-buffer)
-
- ;; Letter P
- (dolist (row (query
- (:select
- (:raw "unnest(ARRAY[ST_AsBinary(ST_AsEWKB('GEOMETRYCOLLECTION(LINESTRING(-100 0 0, 100 0 0), LINESTRING(0 -100 0, 0 100 0), LINESTRING(0 0 -100, 0 0 100))'))
--- Letter O
-,ST_AsBinary(ST_AsEWKB('LINESTRING(3.5 0, 2.2 1, 3 3, 4.2 5, 5.2 3, 4.5 1, 3.5 0)'))
--- letter S
-,ST_AsBinary(ST_AsEWKB('LINESTRING(3.5 0, 2.2 1, 3 3, 4.2 5, 5.2 3, 4.5 1, 3.5 0)'))
-])
-"))))
- (draw-gisobject (decode (car row))))
+ (draw-gisobject (decode (caar (query (:select (:ST_AsEWKB "POINT(0 0)"))))))
+ (draw-gisobject (decode (caar (query (:select (:ST_AsEWKB "LINESTRING(1 2 1, 2 3 4)"))))))
(gl:flush))
;;,
@@ -128,8 +118,7 @@
(gl:ortho (- nrange) nrange (- (* nrange (/ height width)))
(* nrange (/ height width)) (- nrange) nrange)
(gl:ortho (- (* nrange (/ height width))) (* nrange (/ height width))
- (- nrange) nrange (- nrange) nrange))
- )
+ (- nrange) nrange (- nrange) nrange)))
(defun main ()
(init-db)

0 comments on commit a946ec9

Please sign in to comment.
Something went wrong with that request. Please try again.