Mercurial > gemma
annotate cmd/tin2octree/main.go @ 718:c0bba602b60e octree
octree: define a type for LineStringZ.
author | Sascha L. Teichmann <sascha.teichmann@intevation.de> |
---|---|
date | Fri, 21 Sep 2018 14:47:44 +0200 |
parents | 5fa2eaffac84 |
children | aeaa2adf5a8b |
rev | line source |
---|---|
661
af1d4d44a88a
Experimental tin octree indexer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
1 package main |
af1d4d44a88a
Experimental tin octree indexer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
2 |
af1d4d44a88a
Experimental tin octree indexer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
3 import ( |
af1d4d44a88a
Experimental tin octree indexer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
4 "database/sql" |
af1d4d44a88a
Experimental tin octree indexer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
5 "flag" |
af1d4d44a88a
Experimental tin octree indexer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
6 "log" |
664
a3d722e1f593
octree: Load point cloud data projected in a suited UTM zone.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
661
diff
changeset
|
7 "math" |
661
af1d4d44a88a
Experimental tin octree indexer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
8 "os" |
af1d4d44a88a
Experimental tin octree indexer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
9 "time" |
af1d4d44a88a
Experimental tin octree indexer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
10 |
af1d4d44a88a
Experimental tin octree indexer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
11 "github.com/golang/snappy" |
af1d4d44a88a
Experimental tin octree indexer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
12 "github.com/jackc/pgx" |
af1d4d44a88a
Experimental tin octree indexer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
13 "github.com/jackc/pgx/stdlib" |
af1d4d44a88a
Experimental tin octree indexer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
14 ) |
af1d4d44a88a
Experimental tin octree indexer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
15 |
af1d4d44a88a
Experimental tin octree indexer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
16 var ( |
af1d4d44a88a
Experimental tin octree indexer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
17 bottleneck = flag.String("bottleneck", "", "bottleneck id") |
af1d4d44a88a
Experimental tin octree indexer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
18 date = flag.String("date", "", "date info") |
af1d4d44a88a
Experimental tin octree indexer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
19 file = flag.String("file", "", "save to file") |
af1d4d44a88a
Experimental tin octree indexer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
20 |
672
5fa2eaffac84
octree: Always compress the index with snappy as its halves its size.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
664
diff
changeset
|
21 utm = flag.Bool("utm", false, "fetch in matchin UTM zone") |
664
a3d722e1f593
octree: Load point cloud data projected in a suited UTM zone.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
661
diff
changeset
|
22 |
661
af1d4d44a88a
Experimental tin octree indexer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
23 dbhost = flag.String("dbhost", "localhost", "database host") |
af1d4d44a88a
Experimental tin octree indexer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
24 dbport = flag.Uint("dbport", 5432, "database port") |
af1d4d44a88a
Experimental tin octree indexer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
25 dbname = flag.String("dbname", "gemma", "database user") |
af1d4d44a88a
Experimental tin octree indexer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
26 dbuser = flag.String("dbuser", "scott", "database user") |
af1d4d44a88a
Experimental tin octree indexer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
27 dbpassword = flag.String("dbpw", "tiger", "database password") |
af1d4d44a88a
Experimental tin octree indexer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
28 dbssl = flag.String("dbssl", "prefer", "database SSL mode") |
af1d4d44a88a
Experimental tin octree indexer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
29 ) |
af1d4d44a88a
Experimental tin octree indexer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
30 |
af1d4d44a88a
Experimental tin octree indexer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
31 func run(fn func(*sql.DB) error) error { |
af1d4d44a88a
Experimental tin octree indexer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
32 |
af1d4d44a88a
Experimental tin octree indexer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
33 // To ease SSL config ride a bit on parsing. |
af1d4d44a88a
Experimental tin octree indexer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
34 cc, err := pgx.ParseConnectionString("sslmode=" + *dbssl) |
af1d4d44a88a
Experimental tin octree indexer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
35 if err != nil { |
af1d4d44a88a
Experimental tin octree indexer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
36 return err |
af1d4d44a88a
Experimental tin octree indexer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
37 } |
af1d4d44a88a
Experimental tin octree indexer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
38 |
af1d4d44a88a
Experimental tin octree indexer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
39 // Do the rest manually to allow whitespace in user/password. |
af1d4d44a88a
Experimental tin octree indexer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
40 cc.Host = *dbhost |
af1d4d44a88a
Experimental tin octree indexer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
41 cc.Port = uint16(*dbport) |
af1d4d44a88a
Experimental tin octree indexer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
42 cc.User = *dbuser |
af1d4d44a88a
Experimental tin octree indexer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
43 cc.Password = *dbpassword |
af1d4d44a88a
Experimental tin octree indexer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
44 cc.Database = *dbname |
af1d4d44a88a
Experimental tin octree indexer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
45 |
af1d4d44a88a
Experimental tin octree indexer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
46 db := stdlib.OpenDB(cc) |
af1d4d44a88a
Experimental tin octree indexer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
47 defer db.Close() |
af1d4d44a88a
Experimental tin octree indexer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
48 |
af1d4d44a88a
Experimental tin octree indexer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
49 return fn(db) |
af1d4d44a88a
Experimental tin octree indexer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
50 } |
af1d4d44a88a
Experimental tin octree indexer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
51 |
664
a3d722e1f593
octree: Load point cloud data projected in a suited UTM zone.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
661
diff
changeset
|
52 const ( |
a3d722e1f593
octree: Load point cloud data projected in a suited UTM zone.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
661
diff
changeset
|
53 tinSQL = ` |
661
af1d4d44a88a
Experimental tin octree indexer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
54 SELECT ST_AsBinary(ST_DelaunayTriangles(point_cloud::geometry, 0, 2)) |
af1d4d44a88a
Experimental tin octree indexer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
55 FROM waterway.sounding_results |
af1d4d44a88a
Experimental tin octree indexer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
56 WHERE bottleneck_id = $1 AND date_info = $2 |
af1d4d44a88a
Experimental tin octree indexer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
57 ` |
664
a3d722e1f593
octree: Load point cloud data projected in a suited UTM zone.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
661
diff
changeset
|
58 tinUTMSQL = ` |
a3d722e1f593
octree: Load point cloud data projected in a suited UTM zone.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
661
diff
changeset
|
59 SELECT ST_AsBinary( |
a3d722e1f593
octree: Load point cloud data projected in a suited UTM zone.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
661
diff
changeset
|
60 ST_DelaunayTriangles( |
a3d722e1f593
octree: Load point cloud data projected in a suited UTM zone.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
661
diff
changeset
|
61 ST_Transform(point_cloud::geometry, $3::int), 0, 2)) |
a3d722e1f593
octree: Load point cloud data projected in a suited UTM zone.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
661
diff
changeset
|
62 FROM waterway.sounding_results |
a3d722e1f593
octree: Load point cloud data projected in a suited UTM zone.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
661
diff
changeset
|
63 WHERE bottleneck_id = $1 AND date_info = $2 |
a3d722e1f593
octree: Load point cloud data projected in a suited UTM zone.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
661
diff
changeset
|
64 ` |
a3d722e1f593
octree: Load point cloud data projected in a suited UTM zone.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
661
diff
changeset
|
65 centroidSQL = ` |
a3d722e1f593
octree: Load point cloud data projected in a suited UTM zone.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
661
diff
changeset
|
66 SELECT ST_X(ST_Centroid(point_cloud::geometry)), ST_Y(ST_Centroid(point_cloud::geometry)) |
a3d722e1f593
octree: Load point cloud data projected in a suited UTM zone.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
661
diff
changeset
|
67 FROM waterway.sounding_results |
a3d722e1f593
octree: Load point cloud data projected in a suited UTM zone.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
661
diff
changeset
|
68 WHERE bottleneck_id = $1 AND date_info = $2 |
a3d722e1f593
octree: Load point cloud data projected in a suited UTM zone.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
661
diff
changeset
|
69 ` |
a3d722e1f593
octree: Load point cloud data projected in a suited UTM zone.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
661
diff
changeset
|
70 ) |
a3d722e1f593
octree: Load point cloud data projected in a suited UTM zone.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
661
diff
changeset
|
71 |
a3d722e1f593
octree: Load point cloud data projected in a suited UTM zone.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
661
diff
changeset
|
72 func utmZone(x, y float64) int { |
a3d722e1f593
octree: Load point cloud data projected in a suited UTM zone.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
661
diff
changeset
|
73 var pref int |
a3d722e1f593
octree: Load point cloud data projected in a suited UTM zone.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
661
diff
changeset
|
74 if y > 0 { |
a3d722e1f593
octree: Load point cloud data projected in a suited UTM zone.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
661
diff
changeset
|
75 pref = 32600 |
a3d722e1f593
octree: Load point cloud data projected in a suited UTM zone.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
661
diff
changeset
|
76 } else { |
a3d722e1f593
octree: Load point cloud data projected in a suited UTM zone.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
661
diff
changeset
|
77 pref = 32700 |
a3d722e1f593
octree: Load point cloud data projected in a suited UTM zone.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
661
diff
changeset
|
78 } |
a3d722e1f593
octree: Load point cloud data projected in a suited UTM zone.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
661
diff
changeset
|
79 zone := int(math.Floor((x+180)/6)) + 1 |
a3d722e1f593
octree: Load point cloud data projected in a suited UTM zone.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
661
diff
changeset
|
80 return zone + pref |
a3d722e1f593
octree: Load point cloud data projected in a suited UTM zone.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
661
diff
changeset
|
81 } |
661
af1d4d44a88a
Experimental tin octree indexer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
82 |
af1d4d44a88a
Experimental tin octree indexer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
83 func main() { |
af1d4d44a88a
Experimental tin octree indexer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
84 flag.Parse() |
af1d4d44a88a
Experimental tin octree indexer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
85 |
af1d4d44a88a
Experimental tin octree indexer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
86 if *bottleneck == "" || *date == "" { |
af1d4d44a88a
Experimental tin octree indexer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
87 log.Fatalln("missing bottleneck or date option.") |
af1d4d44a88a
Experimental tin octree indexer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
88 } |
af1d4d44a88a
Experimental tin octree indexer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
89 |
af1d4d44a88a
Experimental tin octree indexer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
90 dateInfo, err := time.Parse("2006-01-02", *date) |
af1d4d44a88a
Experimental tin octree indexer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
91 if err != nil { |
af1d4d44a88a
Experimental tin octree indexer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
92 log.Fatalf("error: %v\n", err) |
af1d4d44a88a
Experimental tin octree indexer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
93 } |
af1d4d44a88a
Experimental tin octree indexer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
94 |
af1d4d44a88a
Experimental tin octree indexer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
95 var t tin |
af1d4d44a88a
Experimental tin octree indexer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
96 |
af1d4d44a88a
Experimental tin octree indexer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
97 if err := run(func(db *sql.DB) error { |
664
a3d722e1f593
octree: Load point cloud data projected in a suited UTM zone.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
661
diff
changeset
|
98 var utmZ int |
a3d722e1f593
octree: Load point cloud data projected in a suited UTM zone.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
661
diff
changeset
|
99 |
a3d722e1f593
octree: Load point cloud data projected in a suited UTM zone.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
661
diff
changeset
|
100 if *utm { |
a3d722e1f593
octree: Load point cloud data projected in a suited UTM zone.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
661
diff
changeset
|
101 var cx, cy float64 |
a3d722e1f593
octree: Load point cloud data projected in a suited UTM zone.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
661
diff
changeset
|
102 err := db.QueryRow(centroidSQL, *bottleneck, dateInfo).Scan(&cx, &cy) |
a3d722e1f593
octree: Load point cloud data projected in a suited UTM zone.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
661
diff
changeset
|
103 switch { |
a3d722e1f593
octree: Load point cloud data projected in a suited UTM zone.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
661
diff
changeset
|
104 case err == sql.ErrNoRows: |
a3d722e1f593
octree: Load point cloud data projected in a suited UTM zone.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
661
diff
changeset
|
105 return nil |
a3d722e1f593
octree: Load point cloud data projected in a suited UTM zone.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
661
diff
changeset
|
106 case err != nil: |
a3d722e1f593
octree: Load point cloud data projected in a suited UTM zone.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
661
diff
changeset
|
107 return err |
a3d722e1f593
octree: Load point cloud data projected in a suited UTM zone.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
661
diff
changeset
|
108 } |
a3d722e1f593
octree: Load point cloud data projected in a suited UTM zone.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
661
diff
changeset
|
109 log.Printf("lat/lon: [%f, %f]\n", cx, cy) |
a3d722e1f593
octree: Load point cloud data projected in a suited UTM zone.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
661
diff
changeset
|
110 utmZ = utmZone(cx, cy) |
a3d722e1f593
octree: Load point cloud data projected in a suited UTM zone.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
661
diff
changeset
|
111 log.Printf("UTM zone: %d\n", utmZ) |
a3d722e1f593
octree: Load point cloud data projected in a suited UTM zone.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
661
diff
changeset
|
112 } |
a3d722e1f593
octree: Load point cloud data projected in a suited UTM zone.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
661
diff
changeset
|
113 |
661
af1d4d44a88a
Experimental tin octree indexer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
114 start := time.Now() |
664
a3d722e1f593
octree: Load point cloud data projected in a suited UTM zone.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
661
diff
changeset
|
115 var err error |
a3d722e1f593
octree: Load point cloud data projected in a suited UTM zone.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
661
diff
changeset
|
116 if *utm { |
a3d722e1f593
octree: Load point cloud data projected in a suited UTM zone.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
661
diff
changeset
|
117 err = db.QueryRow(tinUTMSQL, *bottleneck, dateInfo, utmZ).Scan(&t) |
a3d722e1f593
octree: Load point cloud data projected in a suited UTM zone.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
661
diff
changeset
|
118 } else { |
a3d722e1f593
octree: Load point cloud data projected in a suited UTM zone.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
661
diff
changeset
|
119 err = db.QueryRow(tinSQL, *bottleneck, dateInfo).Scan(&t) |
a3d722e1f593
octree: Load point cloud data projected in a suited UTM zone.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
661
diff
changeset
|
120 } |
661
af1d4d44a88a
Experimental tin octree indexer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
121 switch { |
af1d4d44a88a
Experimental tin octree indexer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
122 case err == sql.ErrNoRows: |
af1d4d44a88a
Experimental tin octree indexer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
123 return nil |
af1d4d44a88a
Experimental tin octree indexer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
124 case err != nil: |
af1d4d44a88a
Experimental tin octree indexer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
125 return err |
af1d4d44a88a
Experimental tin octree indexer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
126 } |
af1d4d44a88a
Experimental tin octree indexer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
127 log.Printf("query took: %s\n", time.Since(start)) |
664
a3d722e1f593
octree: Load point cloud data projected in a suited UTM zone.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
661
diff
changeset
|
128 |
a3d722e1f593
octree: Load point cloud data projected in a suited UTM zone.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
661
diff
changeset
|
129 if *utm { |
a3d722e1f593
octree: Load point cloud data projected in a suited UTM zone.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
661
diff
changeset
|
130 t.epsg = uint32(utmZ) |
a3d722e1f593
octree: Load point cloud data projected in a suited UTM zone.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
661
diff
changeset
|
131 } |
a3d722e1f593
octree: Load point cloud data projected in a suited UTM zone.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
661
diff
changeset
|
132 |
661
af1d4d44a88a
Experimental tin octree indexer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
133 return nil |
af1d4d44a88a
Experimental tin octree indexer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
134 }); err != nil { |
af1d4d44a88a
Experimental tin octree indexer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
135 log.Fatalf("error: %v\n", err) |
af1d4d44a88a
Experimental tin octree indexer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
136 } |
af1d4d44a88a
Experimental tin octree indexer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
137 |
af1d4d44a88a
Experimental tin octree indexer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
138 tb := &treeBuilder{t: &t} |
af1d4d44a88a
Experimental tin octree indexer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
139 tb.build() |
af1d4d44a88a
Experimental tin octree indexer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
140 |
af1d4d44a88a
Experimental tin octree indexer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
141 if *file != "" { |
af1d4d44a88a
Experimental tin octree indexer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
142 f, err := os.Create(*file) |
af1d4d44a88a
Experimental tin octree indexer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
143 if err != nil { |
af1d4d44a88a
Experimental tin octree indexer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
144 log.Printf("error: %v\n", err) |
af1d4d44a88a
Experimental tin octree indexer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
145 } |
672
5fa2eaffac84
octree: Always compress the index with snappy as its halves its size.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
664
diff
changeset
|
146 out := snappy.NewBufferedWriter(f) |
661
af1d4d44a88a
Experimental tin octree indexer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
147 if err := t.Serialize(out); err != nil { |
af1d4d44a88a
Experimental tin octree indexer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
148 f.Close() |
af1d4d44a88a
Experimental tin octree indexer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
149 log.Fatalf("error: %v\n", err) |
af1d4d44a88a
Experimental tin octree indexer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
150 } |
af1d4d44a88a
Experimental tin octree indexer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
151 if err := tb.Serialize(out); err != nil { |
af1d4d44a88a
Experimental tin octree indexer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
152 f.Close() |
af1d4d44a88a
Experimental tin octree indexer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
153 log.Fatalf("error: %v\n", err) |
af1d4d44a88a
Experimental tin octree indexer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
154 } |
af1d4d44a88a
Experimental tin octree indexer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
155 if err := out.Flush(); err != nil { |
af1d4d44a88a
Experimental tin octree indexer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
156 f.Close() |
af1d4d44a88a
Experimental tin octree indexer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
157 log.Fatalf("error: %v\n", err) |
af1d4d44a88a
Experimental tin octree indexer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
158 } |
af1d4d44a88a
Experimental tin octree indexer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
159 if err := f.Close(); err != nil { |
af1d4d44a88a
Experimental tin octree indexer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
160 log.Fatalf("error: %v\n", err) |
af1d4d44a88a
Experimental tin octree indexer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
161 } |
af1d4d44a88a
Experimental tin octree indexer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
162 } |
af1d4d44a88a
Experimental tin octree indexer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
163 } |