Mercurial > gemma
view cmd/srsimplify/main.go @ 3793:d428f283fe10 yworks-svg2pdf
client: remove `export SVG` button for waterlevel
* Use html comments to disable the button, this was wrongly activated
with commit d36ccff8de5f.
author | Bernhard Reiter <bernhard@intevation.de> |
---|---|
date | Wed, 03 Jul 2019 17:19:28 +0200 |
parents | 545304d3ff93 |
children |
line wrap: on
line source
// This is Free Software under GNU Affero General Public License v >= 3.0 // without warranty, see README.md and license for details. // // SPDX-License-Identifier: AGPL-3.0-or-later // License-Filename: LICENSES/AGPL-3.0.txt // // Copyright (C) 2019 by via donau // – Österreichische Wasserstraßen-Gesellschaft mbH // Software engineering by Intevation GmbH // // Author(s): // * Sascha L. Teichmann <sascha.teichmann@intevation.de> package main import ( "bufio" "flag" "fmt" "io" "log" "os" "strconv" "strings" "gemma.intevation.de/gemma/pkg/octree" ) func loadXYZ(r io.Reader) (octree.MultiPointZ, error) { scanner := bufio.NewScanner(r) points := make(octree.MultiPointZ, 0, 2000000) var x, y, z float64 var err error for scanner.Scan() { line := strings.TrimSpace(scanner.Text()) if len(line) == 0 || strings.HasPrefix(line, "#") { continue } parts := strings.SplitN(line, " ", 3) if len(parts) != 3 { continue } if x, err = strconv.ParseFloat(parts[0], 64); err != nil { return nil, err } if y, err = strconv.ParseFloat(parts[1], 64); err != nil { return nil, err } if z, err = strconv.ParseFloat(parts[2], 64); err != nil { return nil, err } points = append(points, octree.Vertex{X: x, Y: y, Z: z}) } return points, nil } func storeXYZ(points octree.MultiPointZ, w io.Writer) error { out := bufio.NewWriter(w) for i := range points { fmt.Fprintf(out, "%.5f,%.5f,%.5f\n", points[i].X, points[i].Y, points[i].Z) } return out.Flush() } func main() { var tolerance float64 flag.Float64Var(&tolerance, "t", 0.1, "accepted tolerance (shorthand)") flag.Float64Var(&tolerance, "tolerance", 0.1, "accepted tolerance") flag.Parse() points, err := loadXYZ(os.Stdin) if err != nil { log.Fatalf("err: %v\n", err) } points = points.Simplify(tolerance) if err := storeXYZ(points, os.Stdout); err != nil { log.Fatalf("err: %v\n", err) } }