Mercurial > gemma
comparison pkg/controllers/shapestretches.go @ 4309:78be85723eff
stretch shape export: Write attributes, too.
author | Sascha L. Teichmann <sascha.teichmann@intevation.de> |
---|---|
date | Mon, 02 Sep 2019 22:34:56 +0200 |
parents | 2c83d32bdd1b |
children | 5e38667f740c |
comparison
equal
deleted
inserted
replaced
4308:2c83d32bdd1b | 4309:78be85723eff |
---|---|
21 "io/ioutil" | 21 "io/ioutil" |
22 "log" | 22 "log" |
23 "net/http" | 23 "net/http" |
24 "os" | 24 "os" |
25 "path/filepath" | 25 "path/filepath" |
26 "strings" | |
26 "time" | 27 "time" |
27 | 28 |
28 "github.com/gorilla/mux" | 29 "github.com/gorilla/mux" |
29 "github.com/jonas-p/go-shp" | 30 "github.com/jonas-p/go-shp" |
30 | 31 |
212 if err != nil { | 213 if err != nil { |
213 return err | 214 return err |
214 } | 215 } |
215 defer writer.Close() | 216 defer writer.Close() |
216 | 217 |
217 // TODO: Write geometry | 218 fields := []shp.Field{ |
219 shp.StringField("NAME", 50), | |
220 shp.StringField("OBJNAM", 50), | |
221 shp.StringField("NOBJNAM", 50), | |
222 shp.StringField("LOWER", 25), | |
223 shp.StringField("UPPER", 25), | |
224 shp.StringField("SOURCE", 50), | |
225 shp.StringField("DATEINFO", 25), | |
226 shp.StringField("COUNTRIES", 50), | |
227 } | |
228 | |
229 writer.SetFields(fields) | |
230 | |
218 p := asShpPolygon(geom) | 231 p := asShpPolygon(geom) |
219 | 232 |
220 writer.Write(p) | 233 writer.Write(p) |
221 | 234 |
222 return nil | 235 write := func(field int, v interface{}) { |
236 if err == nil { | |
237 err = writer.WriteAttribute(0, field, v) | |
238 } | |
239 } | |
240 | |
241 write(0, name) | |
242 write(1, objnam) | |
243 if nobjnam.Valid { | |
244 write(2, nobjnam.String) | |
245 } | |
246 write(3, lower) | |
247 write(4, upper) | |
248 write(5, source) | |
249 write(6, dateInfo.Format(time.RFC3339)) | |
250 if len(countries) > 0 { | |
251 write(7, strings.Join(countries, ",")) | |
252 } | |
253 | |
254 return err | |
223 }(); err != nil { | 255 }(); err != nil { |
224 http.Error( | 256 http.Error( |
225 rw, fmt.Sprintf("creating shapefile failed: %v.", err), | 257 rw, fmt.Sprintf("creating shapefile failed: %v.", err), |
226 http.StatusInternalServerError) | 258 http.StatusInternalServerError) |
227 return | 259 return |