Created
January 25, 2021 23:18
-
-
Save cormullion/5f475e720cfa061c21f7d24504f513b9 to your computer and use it in GitHub Desktop.
draw world airport map
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using Shapefile, Luxor, BenchmarkTools | |
cd(@__DIR__) | |
include(joinpath(dirname(pathof(Luxor)), "readshapefiles.jl")) | |
function drawairportmap(outputfilename, countryoutlines, airportdata) | |
Drawing(4000, 2000, outputfilename) | |
origin() | |
background(0.05, 0.2, 0.15) | |
scale(10, 10) | |
setline(1.0) | |
fontsize(0.25) | |
gsave() | |
counter = 1 | |
for shape in countryoutlines.shapes | |
randomhue() | |
pgons, bbox = convert(Array{Luxor.Point, 1}, shape) | |
for pgon in pgons | |
poly(pgon, :fill) | |
counter += 1 | |
end | |
end | |
grestore() | |
sethue("white") | |
for airport in airportdata | |
city, country, lat, long = split(chomp(airport), ",") | |
location = Point(Meta.parse(long), -Meta.parse(lat)) # flip y-coordinate | |
circle(location, .01, :fill) | |
text(string(city), location.x, location.y - 0.02) | |
end | |
finish() | |
preview() | |
@show counter | |
end | |
worldshapefile = "outlines-of-world-countries.shp" | |
airportdata = readlines("airports.csv") | |
worldshapes = open(worldshapefile) do f | |
read(f, Shapefile.Handle) | |
end | |
@btime drawairportmap("/tmp/world-map.png", worldshapes, airportdata) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment