Mercurial > gemma
changeset 732:39b5cf9a6b8f
Store sounding results contour lines into right table.
author | Sascha L. Teichmann <sascha.teichmann@intevation.de> |
---|---|
date | Sun, 23 Sep 2018 19:51:02 +0200 |
parents | 4d6329afc1ea |
children | e57955c1996f |
files | cmd/octree2contour/main.go cmd/octree2contour/store.go |
diffstat | 2 files changed, 44 insertions(+), 10 deletions(-) [+] |
line wrap: on
line diff
--- a/cmd/octree2contour/main.go Sun Sep 23 16:01:04 2018 +0200 +++ b/cmd/octree2contour/main.go Sun Sep 23 19:51:02 2018 +0200 @@ -12,9 +12,11 @@ ) var ( - one = flag.Bool("o", false, "create only a single contour") - step = flag.Float64("s", 0.5, "step with") - max = flag.Float64("m", 10, "max height from lowest point") + one = flag.Bool("o", false, "create only a single contour") + step = flag.Float64("s", 0.5, "step with") + max = flag.Float64("m", 10, "max height from lowest point") + bottleneck = flag.String("bottleneck", "", "bottleneck id") + date = flag.String("date", "", "date info") ) func processLevels( @@ -87,6 +89,15 @@ func main() { flag.Parse() + if *bottleneck == "" || *date == "" { + log.Fatalln("missing bottleneck or date option.") + } + + dateInfo, err := time.Parse("2006-01-02", *date) + if err != nil { + log.Fatalf("error: %v\n", err) + } + for _, fname := range flag.Args() { log.Printf("processing %s\n", fname) start := time.Now() @@ -100,7 +111,7 @@ all := process(tree) log.Printf("processing took: %v\n", time.Since(start)) start = time.Now() - if err = store(all, tree.EPSG); err != nil { + if err = store(all, tree.EPSG, *bottleneck, dateInfo); err != nil { log.Printf("error: %v\n", err) } log.Printf("storing took: %v\n", time.Since(start))
--- a/cmd/octree2contour/store.go Sun Sep 23 16:01:04 2018 +0200 +++ b/cmd/octree2contour/store.go Sun Sep 23 19:51:02 2018 +0200 @@ -2,6 +2,7 @@ import ( "database/sql" + "time" "gemma.intevation.de/gemma/pkg/octree" ) @@ -11,13 +12,28 @@ lines octree.MultiLineStringZ } -const insertSQL = ` -INSERT INTO waterway.contour_lines (height, geom) -VALUES ($1, ST_Transform( - ST_SetSRID(ST_GeomFromWKB($2), $3), 4326)::geography) +const ( + deleteSQL = ` +DELETE FROM waterway.sounding_results_lines +WHERE sounding_result_id IN (SELECT id +FROM waterway.sounding_results +WHERE bottleneck_id = $1 AND date_info = $2) ` + insertSQL = ` +INSERT INTO waterway.sounding_results_lines +SELECT + sounding_result_id, + $1, + ST_Transform(ST_SetSRID(ST_GeomFromWKB($2), $3), 4326)::geography +FROM waterway.sounding_results +WHERE bottleneck_id = $4 AND date_info = $5 +` +) -func store(all []result, epsg uint32) error { +func store( + all []result, epsg uint32, + bottleneck string, date time.Time, +) error { return run(func(db *sql.DB) error { @@ -27,13 +43,20 @@ } defer tx.Rollback() + if _, err := tx.Exec(deleteSQL, bottleneck, date); err != nil { + return err + } + stmt, err := tx.Prepare(insertSQL) if err != nil { return err } for _, r := range all { - if _, err := stmt.Exec(r.h, r.lines.AsWKB(), epsg); err != nil { + if _, err := stmt.Exec( + r.h, r.lines.AsWKB(), epsg, + bottleneck, date, + ); err != nil { return err } }