# HG changeset patch # User Sascha L. Teichmann # Date 1570354891 -7200 # Node ID a413b4a89bcc8ef52773788247796824aab40df9 # Parent 4b3a298b94f8d326aff62a0acd0caec64838c736 Update areas if config has changed. diff -r 4b3a298b94f8 -r a413b4a89bcc pkg/imports/isr.go --- a/pkg/imports/isr.go Sun Oct 06 11:12:32 2019 +0200 +++ b/pkg/imports/isr.go Sun Oct 06 11:41:31 2019 +0200 @@ -44,10 +44,7 @@ } func (isrJobCreator) Depends() [2][]string { - return [2][]string{ - {"sounding_results", "sounding_results_contour_lines"}, - {}, - } + return srJobCreator{}.Depends() } const ( @@ -60,6 +57,10 @@ DELETE FROM waterway.sounding_results_contour_lines WHERE sounding_result_id = $1 ` + deleteIsoAreasSQL = ` +DELETE FROM waterway.sounding_results_iso_areas +WHERE sounding_result_id = $1 +` ) func (isr *IsoRefresh) CleanUp() error { return nil } @@ -166,10 +167,17 @@ } defer tx.Rollback() - insertStmt, err := tx.Prepare(insertContourSQL) + insertContoursStmt, err := tx.Prepare(insertContourSQL) if err != nil { return err } + defer insertContoursStmt.Close() + + insertAreasStmt, err := tx.Prepare(insertIsoAreasSQL) + if err != nil { + return err + } + defer insertAreasStmt.Close() // For all sounding results in bottleneck. for _, sr := range bn.srs { @@ -185,9 +193,14 @@ return err } + // Delete the old iso areas. + if _, err := tx.ExecContext(ctx, deleteIsoAreasSQL, sr); err != nil { + return err + } + octree.DoContours(tree, hs, func(res *octree.ContourResult) { if err == nil && len(res.Lines) > 0 { - _, err = insertStmt.ExecContext( + _, err = insertContoursStmt.ExecContext( ctx, sr, res.Height, tree.EPSG, res.Lines.AsWKB2D(), @@ -197,6 +210,22 @@ if err != nil { return err } + + // Calculate and store the iso areas. + areas := tree.TraceAreas(hs, isoCellSize) + for i, a := range areas { + if len(a) == 0 { + continue + } + if _, err := insertAreasStmt.ExecContext( + ctx, + sr, hs[i], tree.EPSG, + a.AsWKB(), + contourTolerance, + ); err != nil { + return err + } + } } return tx.Commit()