Re: Drawing maps

Discussions related to graphics (2D and 3D), animation and games programming
Hated Moron

Re: Drawing maps

Post by Hated Moron »

On 25/05/2023 04:26, Andrew Cool wrote (cross-posted from the Discussion Group):
Does anyone have BB4W routines to draw maps, e.g. a map of New Zealand?
It's outside my experience, but what makes it difficult? I would have assumed that a map largely consists of polylines, which you can draw using PROC_aapolyline() in the aagfxlib library (any suggestions from me will be for BBC BASIC for SDL 2.0, not BBC BASIC for Windows, although could be converted).

If you can explain what makes drawing maps problematical in BBC BASIC it might make it easier for others to offer advice.
Hated Moron

Re: Drawing maps

Post by Hated Moron »

After a little Googling it appears that a common file format for maps is .SHP. It's easy enough to parse that format in BBC BASIC and plot the contents. You can run an example in your browser here, except that the SHP file is quite big so it takes a while to download.
Hated Moron

Re: Drawing maps

Post by Hated Moron »

The program I've written to parse a SHP file and draw an outline map of New Zealand also runs in BBC BASIC for Windows, but whilst it takes about 4 seconds to draw the map in BBCSDL it takes about 90 seconds in BB4W - about 22 times slower! :shock:

There could hardly be a better example of the value of hardware (GPU) accelerated graphics, and why you really shouldn't be using BB4W unless it's unavoidable (e.g. because your program relies on some Windows-specific feature, and even then it might be possible to do it in BBCSDL). ;)

nz.png
You do not have the required permissions to view the files attached to this post.
DDRM

Re: Drawing maps

Post by DDRM »

I'd be very interested to see the code (especially the parsing code) - would you mind posting it somewhere - perhaps the files repository on groups.io if it is too big to post inline here?

Are the shp files you found simple single files? I read somewhere that they are a group of files packaged as a zip file, with the implication you have to integrate info across them. Where did you find a simple shp file,if you did?

Best wishes,

D
Hated Moron

Re: Drawing maps

Post by Hated Moron »

DDRM wrote: Sat 27 May 2023, 07:44 I'd be very interested to see the code (especially the parsing code) - would you mind posting it somewhere
Certainly. There's currently a slight snag that my laptop suddenly gave up the ghost yesterday (won't even boot into the BIOS) so I'm having to use my Chromebook as a temporary measure, and I don't have the code on that. Once the laptop is replaced (expected to be Tuesday) I will post the code here.
Are the shp files you found simple single files?
Yes, at least to the extent that the program I've written needs. It takes as input just the SHP file, not any other accompanying files, which I have simply ignored.
Hated Moron

Re: Drawing maps

Post by Hated Moron »

On 25/05/2023 04:26, Andrew Cool wrote (cross-posted from the Discussion Group):
SHP files are often created by Lone Wolf individuals or Corporations, and can contain inconsistencies if not outright errors, even though listed on Government websites.
I wouldn't know about that. Indeed I can't even remember where I got the file from (as mentioned above, my laptop failed catastrophically, so although it would be in my browsing history that's gone forever).

SHP files are at least well documented and easy to parse; they also have the advantage that the data they contain is in 64-bit little-endian 'double' format, which BBC BASIC can read directly using INPUT#.
The GSHHS that I initially referred to (now GSHHG) is a professional level reference product.
Maybe. I wrote the code not specifically to solve your problem but to illustrate that parsing a data file (so long as its format is well-documented) and plotting a map from the contained coordinates should be perfectly straightforward. I suggest that's what you do.
Hated Moron

Re: Drawing maps

Post by Hated Moron »

Hated Moron wrote: Sat 27 May 2023, 09:19 Once the laptop is replaced (expected to be Tuesday)
Now delayed to 5th June, grrr.
Hated Moron

Re: Drawing maps

Post by Hated Moron »

Hated Moron wrote: Sat 27 May 2023, 11:16 Now delayed to 5th June, grrr.
The good news is: it arrived early, today. The bad news is: it's running Windows 11 (I had no choice) and it's unusable! For the first time since Windows 95, Microsoft seems to have changed so much that I can't get the things I need for software development to function. Thank you, Microsoft and Dell, for nothing. :cry:
Hated Moron

Re: Drawing maps

Post by Hated Moron »

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
User avatar
JeremyNicoll
Posts: 72
Joined: Sun 26 Jul 2020, 22:22
Location: Edinburgh

Re: Drawing maps

Post by JeremyNicoll »

Hated Moron wrote: Wed 31 May 2023, 21:48
The good news is: it arrived early, today. The bad news is: it's running Windows 11 (I had no choice) and it's unusable! For the first time since Windows 95, Microsoft seems to have changed so much that I can't get the things I need for software development to function. Thank you, Microsoft and Dell, for nothing. :cry:
As someone dreading Windows 11 (of which I've read nothing positive) I find this pretty worrying. Are the tools (if that's what the "things you need" are) ones that other people use too - in which case surely others have had these problems and might have discsussed them somewhere - or software or workflows that you've developed for yourself?

Is this a 32-bit software not working on a 64-bit OS issue?