DDRM wrote: ↑Sat 27 May 2023, 07:44
I'd be very interested to see the code (especially the parsing code)
Here, at last, is the program for parsing and drawing the SHP file. There are constants to set the scale and offsets, which are specific to the New Zealand file (I attempted to deduce them from the bounding boxes in the SHP file itself, but failed because they define a much larger area):
Code: Select all
VDU 23,22,800;600;8,20,16,128
SCALE = 90
XSHIFT = -14700
YSHIFT = 4260
INSTALL @lib$ + "dlglib"
INSTALL @lib$ + "sortlib"
INSTALL @lib$ + "stringlib"
INSTALL @lib$ + "filedlg"
OSCLI "FONT""" + @lib$ + "DejaVuSans"", 12"
file$ = FN_filedlg("Select SHP file", "Open", @dir$, "SHP files", ".shp", 0)
IF file$ = "" QUIT
file% = OPENIN(file$)
REM Read bounding box:
*FLOAT 64
PTR#file% = 36
INPUT #file%, Xmin, Ymin, Xmax, Ymax, Zmin, Zmax, Mmin, Mmax
REM Read records:
TIME = 0
WHILE NOT EOF#file%
INPUT #file%,header : REM discard record header
type% = FN4le(file%)
CASE type% OF
WHEN 0: REM Null record
WHEN 1: INPUT #file%, x, y : PLOT 69, x * SCALE + XSHIFT, y * SCALE + YSHIFT : REM Point
WHEN 3: PROCpolygon(file%) : REM PolyLine
WHEN 5: PROCpolygon(file%) : REM Polygon
OTHERWISE: PRINT "Unhandled record type "; type% : STOP
ENDCASE
ENDWHILE
CLOSE #file%
PRINT TAB(20,0) TIME/100 " seconds"
END
DEF PROCpolygon(F%)
LOCAL I%, J%, N%, xmin, ymin, xmax, ymax, nparts%, parts%(), x, y
INPUT #F%, xmin, ymin, xmax, ymax
nparts% = FN4le(F%) : DIM parts%(nparts%) : parts%(nparts%) = FN4le(F%)
FOR I% = 0 TO nparts%-1 : parts%(I%) = FN4le(F%) : NEXT
FOR I% = 1 TO nparts%
N% = parts%(I%) - parts%(I%-1)
FOR J% = 0 TO N%-1
INPUT #F%, x, y
x = x * SCALE + XSHIFT
y = y * SCALE + YSHIFT
IF J% DRAW x, y ELSE MOVE x, y
NEXT
NEXT I%
PRINT "Polygons = "; nparts%
ENDPROC
DEF FN4le(F%) = BGET#F% OR BGET#F% << 8 OR BGET#F% << 16 OR BGET#F% << 24