Mercurial > gemma
annotate cmd/srsimplify/main.go @ 4325:124a5a7fe8d6
enchange wms styling
* Enable opacity in SLD templates by splitting the corresponding
`_fill` value. The place of the change is in the handlers which are
specfic to geoserver templates. Adding it there keeps the way how opacity
is styled consistent with WFS styles towards the default values
in the database and the client.
author | Bernhard Reiter <bernhard@intevation.de> |
---|---|
date | Wed, 04 Sep 2019 15:30:08 +0200 |
parents | 545304d3ff93 |
children |
rev | line source |
---|---|
3768
9e3d92785918
Simple test driver for point simplification. Reads from STDIN, writes to STDOUT.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
1 // This is Free Software under GNU Affero General Public License v >= 3.0 |
9e3d92785918
Simple test driver for point simplification. Reads from STDIN, writes to STDOUT.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
2 // without warranty, see README.md and license for details. |
9e3d92785918
Simple test driver for point simplification. Reads from STDIN, writes to STDOUT.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
3 // |
9e3d92785918
Simple test driver for point simplification. Reads from STDIN, writes to STDOUT.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
4 // SPDX-License-Identifier: AGPL-3.0-or-later |
9e3d92785918
Simple test driver for point simplification. Reads from STDIN, writes to STDOUT.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
5 // License-Filename: LICENSES/AGPL-3.0.txt |
9e3d92785918
Simple test driver for point simplification. Reads from STDIN, writes to STDOUT.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
6 // |
9e3d92785918
Simple test driver for point simplification. Reads from STDIN, writes to STDOUT.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
7 // Copyright (C) 2019 by via donau |
9e3d92785918
Simple test driver for point simplification. Reads from STDIN, writes to STDOUT.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
8 // – Österreichische Wasserstraßen-Gesellschaft mbH |
9e3d92785918
Simple test driver for point simplification. Reads from STDIN, writes to STDOUT.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
9 // Software engineering by Intevation GmbH |
9e3d92785918
Simple test driver for point simplification. Reads from STDIN, writes to STDOUT.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
10 // |
9e3d92785918
Simple test driver for point simplification. Reads from STDIN, writes to STDOUT.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
11 // Author(s): |
9e3d92785918
Simple test driver for point simplification. Reads from STDIN, writes to STDOUT.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
12 // * Sascha L. Teichmann <sascha.teichmann@intevation.de> |
9e3d92785918
Simple test driver for point simplification. Reads from STDIN, writes to STDOUT.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
13 |
9e3d92785918
Simple test driver for point simplification. Reads from STDIN, writes to STDOUT.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
14 package main |
9e3d92785918
Simple test driver for point simplification. Reads from STDIN, writes to STDOUT.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
15 |
9e3d92785918
Simple test driver for point simplification. Reads from STDIN, writes to STDOUT.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
16 import ( |
9e3d92785918
Simple test driver for point simplification. Reads from STDIN, writes to STDOUT.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
17 "bufio" |
9e3d92785918
Simple test driver for point simplification. Reads from STDIN, writes to STDOUT.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
18 "flag" |
9e3d92785918
Simple test driver for point simplification. Reads from STDIN, writes to STDOUT.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
19 "fmt" |
9e3d92785918
Simple test driver for point simplification. Reads from STDIN, writes to STDOUT.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
20 "io" |
9e3d92785918
Simple test driver for point simplification. Reads from STDIN, writes to STDOUT.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
21 "log" |
9e3d92785918
Simple test driver for point simplification. Reads from STDIN, writes to STDOUT.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
22 "os" |
9e3d92785918
Simple test driver for point simplification. Reads from STDIN, writes to STDOUT.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
23 "strconv" |
9e3d92785918
Simple test driver for point simplification. Reads from STDIN, writes to STDOUT.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
24 "strings" |
9e3d92785918
Simple test driver for point simplification. Reads from STDIN, writes to STDOUT.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
25 |
9e3d92785918
Simple test driver for point simplification. Reads from STDIN, writes to STDOUT.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
26 "gemma.intevation.de/gemma/pkg/octree" |
9e3d92785918
Simple test driver for point simplification. Reads from STDIN, writes to STDOUT.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
27 ) |
9e3d92785918
Simple test driver for point simplification. Reads from STDIN, writes to STDOUT.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
28 |
9e3d92785918
Simple test driver for point simplification. Reads from STDIN, writes to STDOUT.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
29 func loadXYZ(r io.Reader) (octree.MultiPointZ, error) { |
9e3d92785918
Simple test driver for point simplification. Reads from STDIN, writes to STDOUT.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
30 |
9e3d92785918
Simple test driver for point simplification. Reads from STDIN, writes to STDOUT.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
31 scanner := bufio.NewScanner(r) |
9e3d92785918
Simple test driver for point simplification. Reads from STDIN, writes to STDOUT.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
32 |
9e3d92785918
Simple test driver for point simplification. Reads from STDIN, writes to STDOUT.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
33 points := make(octree.MultiPointZ, 0, 2000000) |
9e3d92785918
Simple test driver for point simplification. Reads from STDIN, writes to STDOUT.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
34 |
9e3d92785918
Simple test driver for point simplification. Reads from STDIN, writes to STDOUT.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
35 var x, y, z float64 |
9e3d92785918
Simple test driver for point simplification. Reads from STDIN, writes to STDOUT.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
36 var err error |
9e3d92785918
Simple test driver for point simplification. Reads from STDIN, writes to STDOUT.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
37 |
9e3d92785918
Simple test driver for point simplification. Reads from STDIN, writes to STDOUT.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
38 for scanner.Scan() { |
9e3d92785918
Simple test driver for point simplification. Reads from STDIN, writes to STDOUT.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
39 line := strings.TrimSpace(scanner.Text()) |
9e3d92785918
Simple test driver for point simplification. Reads from STDIN, writes to STDOUT.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
40 if len(line) == 0 || strings.HasPrefix(line, "#") { |
9e3d92785918
Simple test driver for point simplification. Reads from STDIN, writes to STDOUT.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
41 continue |
9e3d92785918
Simple test driver for point simplification. Reads from STDIN, writes to STDOUT.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
42 } |
9e3d92785918
Simple test driver for point simplification. Reads from STDIN, writes to STDOUT.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
43 parts := strings.SplitN(line, " ", 3) |
9e3d92785918
Simple test driver for point simplification. Reads from STDIN, writes to STDOUT.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
44 if len(parts) != 3 { |
9e3d92785918
Simple test driver for point simplification. Reads from STDIN, writes to STDOUT.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
45 continue |
9e3d92785918
Simple test driver for point simplification. Reads from STDIN, writes to STDOUT.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
46 } |
9e3d92785918
Simple test driver for point simplification. Reads from STDIN, writes to STDOUT.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
47 |
9e3d92785918
Simple test driver for point simplification. Reads from STDIN, writes to STDOUT.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
48 if x, err = strconv.ParseFloat(parts[0], 64); err != nil { |
9e3d92785918
Simple test driver for point simplification. Reads from STDIN, writes to STDOUT.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
49 return nil, err |
9e3d92785918
Simple test driver for point simplification. Reads from STDIN, writes to STDOUT.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
50 } |
9e3d92785918
Simple test driver for point simplification. Reads from STDIN, writes to STDOUT.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
51 if y, err = strconv.ParseFloat(parts[1], 64); err != nil { |
9e3d92785918
Simple test driver for point simplification. Reads from STDIN, writes to STDOUT.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
52 return nil, err |
9e3d92785918
Simple test driver for point simplification. Reads from STDIN, writes to STDOUT.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
53 } |
9e3d92785918
Simple test driver for point simplification. Reads from STDIN, writes to STDOUT.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
54 if z, err = strconv.ParseFloat(parts[2], 64); err != nil { |
9e3d92785918
Simple test driver for point simplification. Reads from STDIN, writes to STDOUT.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
55 return nil, err |
9e3d92785918
Simple test driver for point simplification. Reads from STDIN, writes to STDOUT.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
56 } |
9e3d92785918
Simple test driver for point simplification. Reads from STDIN, writes to STDOUT.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
57 points = append(points, octree.Vertex{X: x, Y: y, Z: z}) |
9e3d92785918
Simple test driver for point simplification. Reads from STDIN, writes to STDOUT.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
58 } |
9e3d92785918
Simple test driver for point simplification. Reads from STDIN, writes to STDOUT.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
59 |
9e3d92785918
Simple test driver for point simplification. Reads from STDIN, writes to STDOUT.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
60 return points, nil |
9e3d92785918
Simple test driver for point simplification. Reads from STDIN, writes to STDOUT.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
61 } |
9e3d92785918
Simple test driver for point simplification. Reads from STDIN, writes to STDOUT.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
62 |
9e3d92785918
Simple test driver for point simplification. Reads from STDIN, writes to STDOUT.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
63 func storeXYZ(points octree.MultiPointZ, w io.Writer) error { |
9e3d92785918
Simple test driver for point simplification. Reads from STDIN, writes to STDOUT.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
64 out := bufio.NewWriter(w) |
9e3d92785918
Simple test driver for point simplification. Reads from STDIN, writes to STDOUT.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
65 for i := range points { |
3771
b7530ed07561
Partition recursively. Does not produce good triangles.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3770
diff
changeset
|
66 fmt.Fprintf(out, "%.5f,%.5f,%.5f\n", |
3768
9e3d92785918
Simple test driver for point simplification. Reads from STDIN, writes to STDOUT.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
67 points[i].X, points[i].Y, points[i].Z) |
9e3d92785918
Simple test driver for point simplification. Reads from STDIN, writes to STDOUT.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
68 } |
9e3d92785918
Simple test driver for point simplification. Reads from STDIN, writes to STDOUT.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
69 return out.Flush() |
9e3d92785918
Simple test driver for point simplification. Reads from STDIN, writes to STDOUT.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
70 } |
9e3d92785918
Simple test driver for point simplification. Reads from STDIN, writes to STDOUT.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
71 |
9e3d92785918
Simple test driver for point simplification. Reads from STDIN, writes to STDOUT.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
72 func main() { |
9e3d92785918
Simple test driver for point simplification. Reads from STDIN, writes to STDOUT.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
73 |
9e3d92785918
Simple test driver for point simplification. Reads from STDIN, writes to STDOUT.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
74 var tolerance float64 |
9e3d92785918
Simple test driver for point simplification. Reads from STDIN, writes to STDOUT.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
75 |
9e3d92785918
Simple test driver for point simplification. Reads from STDIN, writes to STDOUT.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
76 flag.Float64Var(&tolerance, "t", 0.1, "accepted tolerance (shorthand)") |
9e3d92785918
Simple test driver for point simplification. Reads from STDIN, writes to STDOUT.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
77 flag.Float64Var(&tolerance, "tolerance", 0.1, "accepted tolerance") |
9e3d92785918
Simple test driver for point simplification. Reads from STDIN, writes to STDOUT.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
78 |
9e3d92785918
Simple test driver for point simplification. Reads from STDIN, writes to STDOUT.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
79 flag.Parse() |
9e3d92785918
Simple test driver for point simplification. Reads from STDIN, writes to STDOUT.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
80 |
9e3d92785918
Simple test driver for point simplification. Reads from STDIN, writes to STDOUT.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
81 points, err := loadXYZ(os.Stdin) |
9e3d92785918
Simple test driver for point simplification. Reads from STDIN, writes to STDOUT.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
82 if err != nil { |
9e3d92785918
Simple test driver for point simplification. Reads from STDIN, writes to STDOUT.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
83 log.Fatalf("err: %v\n", err) |
9e3d92785918
Simple test driver for point simplification. Reads from STDIN, writes to STDOUT.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
84 } |
9e3d92785918
Simple test driver for point simplification. Reads from STDIN, writes to STDOUT.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
85 |
3772
545304d3ff93
Moved simplification algorithm to octree package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3771
diff
changeset
|
86 points = points.Simplify(tolerance) |
3768
9e3d92785918
Simple test driver for point simplification. Reads from STDIN, writes to STDOUT.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
87 |
9e3d92785918
Simple test driver for point simplification. Reads from STDIN, writes to STDOUT.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
88 if err := storeXYZ(points, os.Stdout); err != nil { |
9e3d92785918
Simple test driver for point simplification. Reads from STDIN, writes to STDOUT.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
89 log.Fatalf("err: %v\n", err) |
9e3d92785918
Simple test driver for point simplification. Reads from STDIN, writes to STDOUT.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
90 } |
9e3d92785918
Simple test driver for point simplification. Reads from STDIN, writes to STDOUT.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
91 } |