Hi Hans, Aditya, and all,

Me:
I’d like to use the mp-geo Metapost package with ConTeXt to draw simple
globes viewed from various directions. The package is here:

https://melusine.eu.org/syracuse/poulecl/mp-geo/

Aditya:
Actually the data files are fairly simple:
no_of_points
<list of coordinates>
So, it would be much simpler to read and parse it via lua rather than scantokens. Rest of the code simply determines a "view" of what to show. So, it can be a good exercise in lua-MP interface.

Hans:
I was wondering about that too. I admit that I looked into maps years ago but never could find quality data files.

This is great fun! I slightly altered Hans’ code to produce the most basic area preserving projection of North America (code and map below). If anyone else is playing with the mp-geo data, it is in arc minutes, so divide by 60 to get degrees.

For my book I only want 5cm diameter globes with continents, so the map data in the mp-geo package is far more detailed than I need. The code is so fast, the detail doesn’t seem to be a problem.

I just started learning Metapost a month ago, and it’s great. I know almost nothing about Lua, but this looks like a fun project for learning more!

Thanks!
Gavin


P.S. I marked the location of our local ConTeXt users group on the map, in case any of you want to visit.


\starttext

\startluacode
  function mp.maptopath(filename)
      local t = { cycle = true }
      for phi, theta in string.gmatch(io.loaddata(filename),"%(([%+%-%d]+),([%+%-%d]+)%)") do
          t[#t+1] = { math.cosd(tonumber(phi)/60)*tonumber(theta+6125)/12, tonumber(phi)/12 }
      end
      mp.inject.path(t)
  end
\stopluacode

\startMPpage
  fill lua.mp.maptopath("data/usa1.dat");
  fill lua.mp.maptopath("data/usa2.dat") ;
  fill lua.mp.maptopath("data/mexique.dat") ;
  fill lua.mp.maptopath("data/canada.dat") ;
  fill fullcircle scaled 5 shifted (0, 203) withcolor white;
\stopMPpage

\stoptext