comparison pkg/imports/sr.go @ 4566:2c49a293f275 iso-areas

Fixed access problem for waterway_admins and sys_admins.
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Thu, 03 Oct 2019 22:27:11 +0200
parents 6b107d4e6810
children 4b3a298b94f8
comparison
equal deleted inserted replaced
4565:25898dabd4af 4566:2c49a293f275
22 "database/sql" 22 "database/sql"
23 "encoding/hex" 23 "encoding/hex"
24 "errors" 24 "errors"
25 "fmt" 25 "fmt"
26 "io" 26 "io"
27 "log"
28 "math" 27 "math"
29 "os" 28 "os"
30 "path" 29 "path"
31 "path/filepath" 30 "path/filepath"
32 "runtime" 31 "runtime"
191 4326 190 4326
192 ) 191 )
193 FROM waterway.sounding_results sr 192 FROM waterway.sounding_results sr
194 WHERE id = $1 193 WHERE id = $1
195 ` 194 `
195
196 insertIsoAreasSQL = ` 196 insertIsoAreasSQL = `
197 INSERT INTO waterway.sounding_results_iso_areas ( 197 INSERT INTO waterway.sounding_results_iso_areas (
198 sounding_result_id, 198 sounding_result_id,
199 height, 199 height,
200 areas 200 areas
1010 1010
1011 // We need to bring it back to the 1011 // We need to bring it back to the
1012 // none raster coordinate system. 1012 // none raster coordinate system.
1013 a := make(wkb.MultiPolygonGeom, len(c)) 1013 a := make(wkb.MultiPolygonGeom, len(c))
1014 1014
1015 rXMin, rXMax := math.MaxFloat64, -math.MaxFloat64
1016 rYMin, rYMax := math.MaxFloat64, -math.MaxFloat64
1017
1018 for i, pl := range c { 1015 for i, pl := range c {
1019 shell := make(wkb.LinearRingGeom, len(pl)) 1016 shell := make(wkb.LinearRingGeom, len(pl))
1020 for j, pt := range pl { 1017 for j, pt := range pl {
1021 x := reprojX(pt.X)
1022 y := reprojY(pt.Y)
1023
1024 if x < rXMin {
1025 rXMin = x
1026 }
1027 if y < rYMin {
1028 rYMin = y
1029 }
1030 if x > rXMax {
1031 rXMax = x
1032 }
1033 if y > rYMax {
1034 rYMax = y
1035 }
1036
1037 shell[j] = wkb.PointGeom{ 1018 shell[j] = wkb.PointGeom{
1038 X: x, 1019 X: reprojX(pt.X),
1039 Y: y, 1020 Y: reprojY(pt.Y),
1040 } 1021 }
1041 } 1022 }
1042 a[i] = wkb.PolygonGeom{shell} 1023 a[i] = wkb.PolygonGeom{shell}
1043 } 1024 }
1044 log.Printf("(%.2f, %.2f) - (%.2f, %.2f)\n",
1045 rXMin, rYMin, rXMax, rYMax)
1046 log.Printf("%.2f / %.2f\n", rXMax-rXMin, rYMax-rYMin)
1047 1025
1048 areas[hIdx] = a 1026 areas[hIdx] = a
1049 } 1027 }
1050 } 1028 }
1051
1052 log.Printf("[%.2f, %.2f] - [%.2f, %.2f]\n",
1053 min.X, min.Y, max.X, max.Y)
1054 1029
1055 for n := runtime.NumCPU(); n >= 1; n-- { 1030 for n := runtime.NumCPU(); n >= 1; n-- {
1056 wg.Add(1) 1031 wg.Add(1)
1057 go doContours() 1032 go doContours()
1058 } 1033 }
1088 defer func() { 1063 defer func() {
1089 feedback.Info("Storing iso areas took %v.", 1064 feedback.Info("Storing iso areas took %v.",
1090 time.Since(total)) 1065 time.Since(total))
1091 }() 1066 }()
1092 1067
1093 log.Printf("EPSG: %d\n", epsg)
1094
1095 stmt, err := tx.PrepareContext(ctx, insertIsoAreasSQL) 1068 stmt, err := tx.PrepareContext(ctx, insertIsoAreasSQL)
1096 if err != nil { 1069 if err != nil {
1097 return err 1070 return err
1098 } 1071 }
1099 defer stmt.Close() 1072 defer stmt.Close()