Mercurial > gemma
comparison pkg/imports/fm.go @ 4938:9f9d72a1d398 fairway-marks-import
Save some typos and wrong parameter counts when adding new fairway mark types
author | Tom Gottfried <tom@intevation.de> |
---|---|
date | Mon, 17 Feb 2020 14:47:54 +0100 |
parents | e41d42be0e13 |
children | 39b67b910204 |
comparison
equal
deleted
inserted
replaced
4937:40da1b8aba01 | 4938:9f9d72a1d398 |
---|---|
17 "context" | 17 "context" |
18 "database/sql" | 18 "database/sql" |
19 "encoding/json" | 19 "encoding/json" |
20 "fmt" | 20 "fmt" |
21 "io" | 21 "io" |
22 "strings" | |
22 "time" | 23 "time" |
23 | 24 |
24 "gemma.intevation.de/gemma/pkg/wfs" | 25 "gemma.intevation.de/gemma/pkg/wfs" |
25 ) | 26 ) |
26 | 27 |
54 Scamin *int `json:"hydro_scamin"` | 55 Scamin *int `json:"hydro_scamin"` |
55 Picrep *string `json:"hydro_picrep"` | 56 Picrep *string `json:"hydro_picrep"` |
56 Txtdsc *string `json:"hydro_txtdsc"` | 57 Txtdsc *string `json:"hydro_txtdsc"` |
57 Sordat *string `json:"hydro_sordat"` | 58 Sordat *string `json:"hydro_sordat"` |
58 Sorind *string `json:"hydro_sorind"` | 59 Sorind *string `json:"hydro_sorind"` |
60 } | |
61 | |
62 const ( | |
63 // Format string to be completed with type and additional attributes | |
64 insertFairwayMarkSQL = ` | |
65 WITH a AS ( | |
66 SELECT users.current_user_area_utm() AS a | |
67 ) | |
68 INSERT INTO waterway.fairway_marks_%s ( | |
69 geom, | |
70 datsta, | |
71 datend, | |
72 persta, | |
73 perend, | |
74 objnam, | |
75 nobjnm, | |
76 inform, | |
77 ninfom, | |
78 scamin, | |
79 picrep, | |
80 txtdsc, | |
81 sordat, | |
82 sorind, | |
83 %s | |
84 ) | |
85 SELECT newfm, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, | |
86 %s | |
87 FROM ST_Transform(ST_GeomFromWKB($1, $2::integer), 4326) AS newfm (newfm) | |
88 WHERE pg_has_role('sys_admin', 'MEMBER') | |
89 OR ST_Intersects((select a from a), | |
90 ST_Transform(newfm, (select ST_SRID(a) from a))) | |
91 ON CONFLICT ( | |
92 CAST((geom, | |
93 datsta, datend, persta, perend, objnam, nobjnm, inform, ninfom, | |
94 scamin, picrep, txtdsc, sordat, sorind, | |
95 0, %[2]s | |
96 ) AS waterway.fairway_marks_%[1]s) | |
97 ) | |
98 DO NOTHING | |
99 RETURNING id | |
100 ` | |
101 ) | |
102 | |
103 // Create INSERT statement for specific fairway marks type | |
104 func getFMInsertSQL(fmType string, attributes []string) string { | |
105 attNums := "$16" | |
106 for i := 1; i < len(attributes); i++ { | |
107 attNums += fmt.Sprintf(",$%d", 16+i) | |
108 } | |
109 | |
110 return fmt.Sprintf( | |
111 insertFairwayMarkSQL, | |
112 fmType, | |
113 strings.Join(attributes, ","), | |
114 attNums, | |
115 ) | |
59 } | 116 } |
60 | 117 |
61 // Common operation of FM imports to get features from WFS service | 118 // Common operation of FM imports to get features from WFS service |
62 func getFMFeatures( | 119 func getFMFeatures( |
63 ctx context.Context, | 120 ctx context.Context, |