     read-double
     read-double
     header boa ;
-
-SINGLETON: null-shape
-
-TUPLE: point x y ;
-
-: read-point ( -- point )
-    read-double read-double point boa ;
-
-: read-points ( n -- points )
-    [ read-point ] replicate ;
-
-TUPLE: multipoint box points ;
-
-: read-multipoint ( -- multipoint )
-    read-box read-int read-points multipoint boa ;
-
-TUPLE: polyline box parts points ;
-
-: read-polyline ( -- polyline )
-    read-box read-int read-int [ read-ints ] dip
-    read-points polyline boa ;
-
-TUPLE: polygon box parts points ;
-
-: read-polygon ( -- polygon )
-    read-box read-int read-int [ read-ints ] dip
-    read-points polygon boa ;
-
-TUPLE: point-z x y z m ;
-
-: read-point-z ( -- point-z )
-    read-double read-double read-double read-double point-z boa ;
-
-TUPLE: polyline-z box parts points z-range z-array m-range
-m-array ;
-
-: read-polyline-z ( -- polyline-z )
-    read-box read-int read-int [ read-ints ] dip
-    [ read-points read-range ]
-    [ read-doubles read-range ]
-    [ read-doubles ] tri polyline-z boa ;
-
-TUPLE: polygon-z box parts points z-range z-array m-range
-m-array ;
-
-: read-polygon-z ( -- polygon-z )
-    read-box read-int read-int [ read-ints ] dip
-    [ read-points read-range ]
-    [ read-doubles read-range ]
-    [ read-doubles ] tri polygon-z boa ;
-
-TUPLE: multipoint-z box points z-range z-array m-range m-array ;
-
-: read-multipoint-z ( -- multipoint-z )
-    read-box read-int
-    [ read-points read-range ]
-    [ read-doubles read-range ]
-    [ read-doubles ] tri multipoint-z boa ;
-
-TUPLE: point-m x y m ;
-
-: read-point-m ( -- point-m )
-    read-double read-double read-double point-m boa ;
-
-TUPLE: polyline-m box parts points m-range m-array ;
-
-: read-polyline-m ( -- polyline-m )
-    read-box read-int read-int [ read-ints ] dip
-    [ read-points read-range ] [ read-doubles ] bi
-    polyline-m boa ;
-
-TUPLE: polygon-m box parts points m-range m-array ;
-
-: read-polygon-m ( -- polygon-m )
-    read-box read-int read-int [ read-ints ] dip
-    [ read-points read-range ] [ read-doubles ] bi
-    polygon-m boa ;
-
-TUPLE: multipoint-m box points m-range m-array ;
-
-: read-multipoint-m ( -- multipoint-m )
-    read-box read-int
-    [ read-points read-range ] [ read-doubles ] bi
-    multipoint-m boa ;
-
-TUPLE: multipatch box parts part-types points z-range z-array
-m-range m-array ;
-
-: read-multipatch ( -- multipatch )
-    read-box read-int read-int
-    [ [ read-ints ] [ read-ints ] bi ] dip
-    [ read-points read-range ]
-    [ read-doubles read-range ]
-    [ read-doubles ] tri multipatch boa ;
-
-: read-shape ( -- shape )
-    read-int {
-        { 0 [ null-shape ] }
-        { 1 [ read-point ] }
-        { 3 [ read-polyline ] }
-        { 5 [ read-polygon ] }
-        { 8 [ read-multipoint ] }
-        { 11 [ read-point-z ] }
-        { 13 [ read-polyline-z ] }
-        { 15 [ read-polygon-z ] }
-        { 18 [ read-multipoint-z ] }
-        { 21 [ read-point-m ] }
-        { 23 [ read-polyline-m ] }
-        { 25 [ read-polygon-m ] }
-        { 28 [ read-multipoint-m ] }
-        { 31 [ read-multipatch ] }
-    } case ;
 
 TUPLE: record number content-length shape ;
 


: file>shx ( path -- header indices )
    binary [ read-shx ] with-file-reader ;

! Copyright (C) 2018 John Benediktsson
! See http://factorcode.org/license.txt for BSD license

USING: accessors combinators io io.binary io.encodings.binary
io.files kernel math sequences ;

IN: shapefiles

SINGLETON: null-shape
TUPLE: point x y ;
TUPLE: multipoint box points ;
TUPLE: polygon box parts points ;
TUPLE: polyline box parts points ;
TUPLE: point-z < point z m ;
TUPLE: polyline-z < polyline z-range z-array m-range m-array ;
TUPLE: polygon-z < polygon z-range z-array m-range m-array ;
TUPLE: multipoint-z < multipoint z-range z-array m-range m-array ;
TUPLE: point-m < point m ;
TUPLE: polyline-m < polyline m-range m-array ;
TUPLE: polygon-m < polygon m-range m-array ;
TUPLE: multipoint-m < multipoint m-range m-array ;
TUPLE: multipatch box parts part-types points z-range z-array m-range m-array ;

<PRIVATE

