# HG changeset patch # User Sascha L. Teichmann # Date 1539876653 -7200 # Node ID 4a2ca0e200067903859cbf080bfa47f33b2db443 # Parent c397fdd8c327fd391afa7f971ca60aae67e35120 Fixed build error. Copied file to the wrong place and said 'go build' to another wrong place. Argh. diff -r c397fdd8c327 -r 4a2ca0e20006 pkg/imports/sr.go --- a/pkg/imports/sr.go Thu Oct 18 17:05:54 2018 +0200 +++ b/pkg/imports/sr.go Thu Oct 18 17:30:53 2018 +0200 @@ -42,6 +42,11 @@ ) const ( + contourStepWidth = 0.5 + contourTolerance = 0.1 +) + +const ( insertPointsSQL = ` INSERT INTO waterway.sounding_results ( bottleneck_id, @@ -80,6 +85,34 @@ $2, $3 )` + + insertContourSQL = ` +INSERT INTO waterway.sounding_results_contour_lines ( + sounding_result_id, + height, + lines +) +SELECT + $1, + $2, + ST_Transform( + ST_Multi( + ST_CollectionExtract( + ST_Intersection( + ST_Transform(sr.area::geometry, $3::integer), + ST_SimplifyPreserveTopology( + ST_GeomFromWKB($4, $3::integer), + $5 + ) + ), + 2 + ) + ), + 4326 + ) +FROM waterway.sounding_results sr +WHERE id = $1 +` ) func (srd *SoundingResultDate) UnmarshalJSON(data []byte) error { @@ -354,3 +387,22 @@ return tx.Commit() } + +func generateContours(tree *octree.Tree, tx *sql.Tx, id int64) error { + stmt, err := tx.Prepare(insertContourSQL) + if err != nil { + return err + } + defer stmt.Close() + + octree.DoContours(tree, contourStepWidth, func(res *octree.ContourResult) { + if err == nil { + _, err = stmt.Exec( + id, res.Height, tree.EPSG, + res.Lines.AsWKB2D(), + contourTolerance) + } + }) + + return err +} diff -r c397fdd8c327 -r 4a2ca0e20006 pkg/octree/contours.go --- a/pkg/octree/contours.go Thu Oct 18 17:05:54 2018 +0200 +++ b/pkg/octree/contours.go Thu Oct 18 17:30:53 2018 +0200 @@ -1,73 +1,18 @@ package octree import ( - "database/sql" "runtime" "sync" ) -const ( - contourStepWidth = 0.5 - contourTolerance = 0.1 -) - -type contourResult struct { - height float64 - lines MultiLineStringZ +type ContourResult struct { + Height float64 + Lines MultiLineStringZ } -const ( - insertContourSQL = ` -INSERT INTO waterway.sounding_results_contour_lines ( - sounding_result_id, - height, - lines -) -SELECT - $1, - $2, - ST_Transform( - ST_Multi( - ST_CollectionExtract( - ST_Intersection( - ST_Transform(sr.area::geometry, $3::integer), - ST_SimplifyPreserveTopology( - ST_GeomFromWKB($4, $3::integer), - $5 - ) - ), - 2 - ) - ), - 4326 - ) -FROM waterway.sounding_results sr -WHERE id = $1 -` -) +func DoContours(tree *Tree, step float64, store func(*ContourResult)) { -func generateContours(tree *Tree, tx *sql.Tx, id int64) error { - stmt, err := tx.Prepare(insertContourSQL) - if err != nil { - return err - } - defer stmt.Close() - - doContours(tree, contourStepWidth, func(res *contourResult) { - if err == nil { - _, err = stmt.Exec( - id, res.height, tree.EPSG, - res.lines.AsWKB2D(), - contourTolerance) - } - }) - - return err -} - -func doContours(tree *Tree, step float64, store func(*contourResult)) { - - results := make(chan *contourResult) + results := make(chan *ContourResult) done := make(chan struct{}) jobs := make(chan float64) @@ -98,7 +43,7 @@ func processLevels( tree *Tree, jobs <-chan float64, - results chan<- *contourResult, + results chan<- *ContourResult, wg *sync.WaitGroup, ) { defer wg.Done() @@ -111,6 +56,6 @@ } }) lines = lines.Merge() - results <- &contourResult{h, lines} + results <- &ContourResult{h, lines} } }