Created
February 15, 2019 11:16
-
-
Save peterhellberg/1e7eae34a8f3d256625eacdaf57fbcc4 to your computer and use it in GitHub Desktop.
sweden.poly rendered using gfx.
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
package main | |
import ( | |
"io" | |
"net/http" | |
"strconv" | |
"text/scanner" | |
"github.com/peterhellberg/gfx" | |
) | |
const rawurl = "https://download.geofabrik.de/europe/sweden.poly" | |
func main() { | |
resp, err := http.Get(rawurl) | |
if err != nil || resp.StatusCode != http.StatusOK { | |
return | |
} | |
p := scanPoly(resp.Body).Project(gfx.IM. | |
Moved(gfx.V(303, 258)). | |
ScaledXY(gfx.V(320, 320), gfx.V(36, -36))) | |
dst := gfx.NewImage(640, 640, gfx.BlockColorBlack.Dark) | |
p.Fill(dst, gfx.BlockColorBlue.Medium) | |
for i := 1; i < len(p); i++ { | |
gfx.DrawLine(dst, p[i-1], p[i], 1, gfx.BlockColorBlue.Light) | |
} | |
gfx.SavePNG("gfx-sweden.png", dst) | |
} | |
func scanPoly(r io.Reader) (p gfx.Polygon) { | |
var s scanner.Scanner | |
s.Init(r) | |
var floats []float64 | |
for tok := s.Scan(); tok != scanner.EOF; tok = s.Scan() { | |
switch tok { | |
case scanner.Float: | |
if f, err := strconv.ParseFloat(s.TokenText(), 64); err == nil { | |
floats = append(floats, f) | |
} | |
} | |
} | |
for i := len(floats) - 2; i >= 0; i -= 2 { | |
p = append(p, gfx.V(floats[i], floats[i+1])) | |
} | |
return p | |
} |
Author
peterhellberg
commented
Feb 15, 2019
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment