Mercurial > gemma
annotate pkg/imports/stsh.go @ 4855:01b593ea2311
Added missing doc strings for the STR tree in the mesh package.
author | Sascha L. Teichmann <sascha.teichmann@intevation.de> |
---|---|
date | Tue, 19 Nov 2019 17:48:02 +0100 |
parents | 046a07a33b19 |
children | e4ab338e7ba9 |
rev | line source |
---|---|
4311
f9bb06f2dbe3
Added stub for a shape upload stretch import. POST /api/imports/stsh
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
1 // This is Free Software under GNU Affero General Public License v >= 3.0 |
f9bb06f2dbe3
Added stub for a shape upload stretch import. POST /api/imports/stsh
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
2 // without warranty, see README.md and license for details. |
f9bb06f2dbe3
Added stub for a shape upload stretch import. POST /api/imports/stsh
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
3 // |
f9bb06f2dbe3
Added stub for a shape upload stretch import. POST /api/imports/stsh
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
4 // SPDX-License-Identifier: AGPL-3.0-or-later |
f9bb06f2dbe3
Added stub for a shape upload stretch import. POST /api/imports/stsh
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
5 // License-Filename: LICENSES/AGPL-3.0.txt |
f9bb06f2dbe3
Added stub for a shape upload stretch import. POST /api/imports/stsh
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
6 // |
f9bb06f2dbe3
Added stub for a shape upload stretch import. POST /api/imports/stsh
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
7 // Copyright (C) 2019 by via donau |
f9bb06f2dbe3
Added stub for a shape upload stretch import. POST /api/imports/stsh
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
8 // – Österreichische Wasserstraßen-Gesellschaft mbH |
f9bb06f2dbe3
Added stub for a shape upload stretch import. POST /api/imports/stsh
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
9 // Software engineering by Intevation GmbH |
f9bb06f2dbe3
Added stub for a shape upload stretch import. POST /api/imports/stsh
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
10 // |
f9bb06f2dbe3
Added stub for a shape upload stretch import. POST /api/imports/stsh
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
11 // Author(s): |
f9bb06f2dbe3
Added stub for a shape upload stretch import. POST /api/imports/stsh
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
12 // * Sascha L. Teichmann <sascha.teichmann@intevation.de> |
f9bb06f2dbe3
Added stub for a shape upload stretch import. POST /api/imports/stsh
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
13 |
f9bb06f2dbe3
Added stub for a shape upload stretch import. POST /api/imports/stsh
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
14 package imports |
f9bb06f2dbe3
Added stub for a shape upload stretch import. POST /api/imports/stsh
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
15 |
f9bb06f2dbe3
Added stub for a shape upload stretch import. POST /api/imports/stsh
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
16 import ( |
4313
5da02dcc51f6
shape upload stretch import: Started to decode geometries and attributes from uploaded shape file.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4311
diff
changeset
|
17 "archive/zip" |
4311
f9bb06f2dbe3
Added stub for a shape upload stretch import. POST /api/imports/stsh
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
18 "context" |
f9bb06f2dbe3
Added stub for a shape upload stretch import. POST /api/imports/stsh
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
19 "database/sql" |
4313
5da02dcc51f6
shape upload stretch import: Started to decode geometries and attributes from uploaded shape file.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4311
diff
changeset
|
20 "errors" |
5da02dcc51f6
shape upload stretch import: Started to decode geometries and attributes from uploaded shape file.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4311
diff
changeset
|
21 "fmt" |
4311
f9bb06f2dbe3
Added stub for a shape upload stretch import. POST /api/imports/stsh
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
22 "os" |
4313
5da02dcc51f6
shape upload stretch import: Started to decode geometries and attributes from uploaded shape file.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4311
diff
changeset
|
23 "path" |
5da02dcc51f6
shape upload stretch import: Started to decode geometries and attributes from uploaded shape file.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4311
diff
changeset
|
24 "path/filepath" |
5da02dcc51f6
shape upload stretch import: Started to decode geometries and attributes from uploaded shape file.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4311
diff
changeset
|
25 "strings" |
4316
3d6a2c6b436c
shape upload stretch import: Store features in database. Still broken [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4314
diff
changeset
|
26 "time" |
4313
5da02dcc51f6
shape upload stretch import: Started to decode geometries and attributes from uploaded shape file.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4311
diff
changeset
|
27 |
5da02dcc51f6
shape upload stretch import: Started to decode geometries and attributes from uploaded shape file.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4311
diff
changeset
|
28 shp "github.com/jonas-p/go-shp" |
5da02dcc51f6
shape upload stretch import: Started to decode geometries and attributes from uploaded shape file.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4311
diff
changeset
|
29 |
5da02dcc51f6
shape upload stretch import: Started to decode geometries and attributes from uploaded shape file.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4311
diff
changeset
|
30 "gemma.intevation.de/gemma/pkg/common" |
4332
8080007d3c06
shape upload stretch import: Finished implementation (staging, summary).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4316
diff
changeset
|
31 "gemma.intevation.de/gemma/pkg/models" |
4311
f9bb06f2dbe3
Added stub for a shape upload stretch import. POST /api/imports/stsh
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
32 ) |
f9bb06f2dbe3
Added stub for a shape upload stretch import. POST /api/imports/stsh
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
33 |
4852
046a07a33b19
Fixed the golint issues of the imports package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4506
diff
changeset
|
34 // StretchShape imports stretches from an uploaded shape file. |
4311
f9bb06f2dbe3
Added stub for a shape upload stretch import. POST /api/imports/stsh
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
35 type StretchShape struct { |
f9bb06f2dbe3
Added stub for a shape upload stretch import. POST /api/imports/stsh
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
36 Dir string `json:"dir"` |
f9bb06f2dbe3
Added stub for a shape upload stretch import. POST /api/imports/stsh
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
37 } |
f9bb06f2dbe3
Added stub for a shape upload stretch import. POST /api/imports/stsh
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
38 |
4852
046a07a33b19
Fixed the golint issues of the imports package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4506
diff
changeset
|
39 // STSHJobKind is the import queue type identifier. |
4311
f9bb06f2dbe3
Added stub for a shape upload stretch import. POST /api/imports/stsh
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
40 const STSHJobKind JobKind = "stsh" |
f9bb06f2dbe3
Added stub for a shape upload stretch import. POST /api/imports/stsh
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
41 |
f9bb06f2dbe3
Added stub for a shape upload stretch import. POST /api/imports/stsh
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
42 type stshJobCreator struct{} |
f9bb06f2dbe3
Added stub for a shape upload stretch import. POST /api/imports/stsh
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
43 |
f9bb06f2dbe3
Added stub for a shape upload stretch import. POST /api/imports/stsh
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
44 func init() { RegisterJobCreator(STSHJobKind, stshJobCreator{}) } |
f9bb06f2dbe3
Added stub for a shape upload stretch import. POST /api/imports/stsh
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
45 |
f9bb06f2dbe3
Added stub for a shape upload stretch import. POST /api/imports/stsh
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
46 func (stshJobCreator) Description() string { return "stretch from shape" } |
f9bb06f2dbe3
Added stub for a shape upload stretch import. POST /api/imports/stsh
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
47 |
f9bb06f2dbe3
Added stub for a shape upload stretch import. POST /api/imports/stsh
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
48 func (stshJobCreator) AutoAccept() bool { return false } |
f9bb06f2dbe3
Added stub for a shape upload stretch import. POST /api/imports/stsh
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
49 |
f9bb06f2dbe3
Added stub for a shape upload stretch import. POST /api/imports/stsh
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
50 func (stshJobCreator) Create() Job { return new(StretchShape) } |
f9bb06f2dbe3
Added stub for a shape upload stretch import. POST /api/imports/stsh
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
51 |
f9bb06f2dbe3
Added stub for a shape upload stretch import. POST /api/imports/stsh
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
52 func (stshJobCreator) Depends() [2][]string { |
f9bb06f2dbe3
Added stub for a shape upload stretch import. POST /api/imports/stsh
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
53 return [2][]string{ |
f9bb06f2dbe3
Added stub for a shape upload stretch import. POST /api/imports/stsh
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
54 {"stretches", "stretch_countries"}, |
f9bb06f2dbe3
Added stub for a shape upload stretch import. POST /api/imports/stsh
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
55 {}, |
f9bb06f2dbe3
Added stub for a shape upload stretch import. POST /api/imports/stsh
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
56 } |
f9bb06f2dbe3
Added stub for a shape upload stretch import. POST /api/imports/stsh
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
57 } |
f9bb06f2dbe3
Added stub for a shape upload stretch import. POST /api/imports/stsh
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
58 |
4316
3d6a2c6b436c
shape upload stretch import: Store features in database. Still broken [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4314
diff
changeset
|
59 const ( |
3d6a2c6b436c
shape upload stretch import: Store features in database. Still broken [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4314
diff
changeset
|
60 stshInsertSQL = ` |
4389
5e38667f740c
Use stretches as areas of responsibility.
Sascha Wilde <wilde@intevation.de>
parents:
4332
diff
changeset
|
61 INSERT INTO users.stretches ( |
4316
3d6a2c6b436c
shape upload stretch import: Store features in database. Still broken [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4314
diff
changeset
|
62 name, |
3d6a2c6b436c
shape upload stretch import: Store features in database. Still broken [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4314
diff
changeset
|
63 stretch, |
3d6a2c6b436c
shape upload stretch import: Store features in database. Still broken [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4314
diff
changeset
|
64 area, |
3d6a2c6b436c
shape upload stretch import: Store features in database. Still broken [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4314
diff
changeset
|
65 objnam, |
3d6a2c6b436c
shape upload stretch import: Store features in database. Still broken [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4314
diff
changeset
|
66 nobjnam, |
3d6a2c6b436c
shape upload stretch import: Store features in database. Still broken [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4314
diff
changeset
|
67 date_info, |
3d6a2c6b436c
shape upload stretch import: Store features in database. Still broken [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4314
diff
changeset
|
68 source_organization |
3d6a2c6b436c
shape upload stretch import: Store features in database. Still broken [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4314
diff
changeset
|
69 ) VALUES ( |
3d6a2c6b436c
shape upload stretch import: Store features in database. Still broken [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4314
diff
changeset
|
70 $1, |
3d6a2c6b436c
shape upload stretch import: Store features in database. Still broken [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4314
diff
changeset
|
71 isrsrange(isrs_fromText($2), isrs_fromText($3)), |
3d6a2c6b436c
shape upload stretch import: Store features in database. Still broken [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4314
diff
changeset
|
72 ST_GeomFromWKB($4, 4326), |
3d6a2c6b436c
shape upload stretch import: Store features in database. Still broken [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4314
diff
changeset
|
73 $5, |
3d6a2c6b436c
shape upload stretch import: Store features in database. Still broken [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4314
diff
changeset
|
74 $6, |
3d6a2c6b436c
shape upload stretch import: Store features in database. Still broken [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4314
diff
changeset
|
75 $7, |
3d6a2c6b436c
shape upload stretch import: Store features in database. Still broken [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4314
diff
changeset
|
76 $8) |
3d6a2c6b436c
shape upload stretch import: Store features in database. Still broken [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4314
diff
changeset
|
77 RETURNING id` |
3d6a2c6b436c
shape upload stretch import: Store features in database. Still broken [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4314
diff
changeset
|
78 ) |
3d6a2c6b436c
shape upload stretch import: Store features in database. Still broken [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4314
diff
changeset
|
79 |
4332
8080007d3c06
shape upload stretch import: Finished implementation (staging, summary).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4316
diff
changeset
|
80 // StageDone is merely the same as for the normal stretch import. |
4311
f9bb06f2dbe3
Added stub for a shape upload stretch import. POST /api/imports/stsh
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
81 func (stshJobCreator) StageDone( |
f9bb06f2dbe3
Added stub for a shape upload stretch import. POST /api/imports/stsh
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
82 ctx context.Context, |
f9bb06f2dbe3
Added stub for a shape upload stretch import. POST /api/imports/stsh
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
83 tx *sql.Tx, |
f9bb06f2dbe3
Added stub for a shape upload stretch import. POST /api/imports/stsh
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
84 id int64, |
f9bb06f2dbe3
Added stub for a shape upload stretch import. POST /api/imports/stsh
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
85 ) error { |
4332
8080007d3c06
shape upload stretch import: Finished implementation (staging, summary).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4316
diff
changeset
|
86 return stJobCreator{}.StageDone(ctx, tx, id) |
4311
f9bb06f2dbe3
Added stub for a shape upload stretch import. POST /api/imports/stsh
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
87 } |
f9bb06f2dbe3
Added stub for a shape upload stretch import. POST /api/imports/stsh
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
88 |
4852
046a07a33b19
Fixed the golint issues of the imports package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4506
diff
changeset
|
89 // CleanUp removes the folder with the uploaded shape file. |
4311
f9bb06f2dbe3
Added stub for a shape upload stretch import. POST /api/imports/stsh
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
90 func (stsh *StretchShape) CleanUp() error { |
f9bb06f2dbe3
Added stub for a shape upload stretch import. POST /api/imports/stsh
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
91 return os.RemoveAll(stsh.Dir) |
f9bb06f2dbe3
Added stub for a shape upload stretch import. POST /api/imports/stsh
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
92 } |
f9bb06f2dbe3
Added stub for a shape upload stretch import. POST /api/imports/stsh
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
93 |
4316
3d6a2c6b436c
shape upload stretch import: Store features in database. Still broken [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4314
diff
changeset
|
94 func fixAttribute(s string) string { |
3d6a2c6b436c
shape upload stretch import: Store features in database. Still broken [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4314
diff
changeset
|
95 return strings.TrimRight(s, "\x00") |
3d6a2c6b436c
shape upload stretch import: Store features in database. Still broken [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4314
diff
changeset
|
96 } |
3d6a2c6b436c
shape upload stretch import: Store features in database. Still broken [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4314
diff
changeset
|
97 |
4332
8080007d3c06
shape upload stretch import: Finished implementation (staging, summary).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4316
diff
changeset
|
98 type stretchSummary struct { |
8080007d3c06
shape upload stretch import: Finished implementation (staging, summary).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4316
diff
changeset
|
99 ID int64 `json:"id"` |
8080007d3c06
shape upload stretch import: Finished implementation (staging, summary).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4316
diff
changeset
|
100 Name string `json:"name"` |
8080007d3c06
shape upload stretch import: Finished implementation (staging, summary).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4316
diff
changeset
|
101 From string `json:"from"` |
8080007d3c06
shape upload stretch import: Finished implementation (staging, summary).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4316
diff
changeset
|
102 To string `json:"to"` |
8080007d3c06
shape upload stretch import: Finished implementation (staging, summary).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4316
diff
changeset
|
103 ObjNam string `json:"objnam"` |
8080007d3c06
shape upload stretch import: Finished implementation (staging, summary).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4316
diff
changeset
|
104 NObjNam *string `json:"nobjnam"` |
8080007d3c06
shape upload stretch import: Finished implementation (staging, summary).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4316
diff
changeset
|
105 Date models.Date `json:"date-info"` |
8080007d3c06
shape upload stretch import: Finished implementation (staging, summary).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4316
diff
changeset
|
106 Countries models.UniqueCountries `json:"countries"` |
8080007d3c06
shape upload stretch import: Finished implementation (staging, summary).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4316
diff
changeset
|
107 } |
8080007d3c06
shape upload stretch import: Finished implementation (staging, summary).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4316
diff
changeset
|
108 |
8080007d3c06
shape upload stretch import: Finished implementation (staging, summary).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4316
diff
changeset
|
109 func parseUniqueCountries(s string) (models.UniqueCountries, error) { |
8080007d3c06
shape upload stretch import: Finished implementation (staging, summary).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4316
diff
changeset
|
110 unique := map[models.Country]struct{}{} |
8080007d3c06
shape upload stretch import: Finished implementation (staging, summary).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4316
diff
changeset
|
111 var countries models.UniqueCountries |
8080007d3c06
shape upload stretch import: Finished implementation (staging, summary).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4316
diff
changeset
|
112 for _, c := range strings.Split(s, ",") { |
8080007d3c06
shape upload stretch import: Finished implementation (staging, summary).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4316
diff
changeset
|
113 if c = strings.ToUpper(strings.TrimSpace(c)); c == "" { |
8080007d3c06
shape upload stretch import: Finished implementation (staging, summary).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4316
diff
changeset
|
114 continue |
8080007d3c06
shape upload stretch import: Finished implementation (staging, summary).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4316
diff
changeset
|
115 } |
8080007d3c06
shape upload stretch import: Finished implementation (staging, summary).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4316
diff
changeset
|
116 n := models.Country(c) |
8080007d3c06
shape upload stretch import: Finished implementation (staging, summary).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4316
diff
changeset
|
117 if !n.Valid() { |
8080007d3c06
shape upload stretch import: Finished implementation (staging, summary).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4316
diff
changeset
|
118 return nil, fmt.Errorf("'%s' is not a valid country code", c) |
8080007d3c06
shape upload stretch import: Finished implementation (staging, summary).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4316
diff
changeset
|
119 } |
8080007d3c06
shape upload stretch import: Finished implementation (staging, summary).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4316
diff
changeset
|
120 if _, found := unique[n]; found { |
8080007d3c06
shape upload stretch import: Finished implementation (staging, summary).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4316
diff
changeset
|
121 return nil, fmt.Errorf("'%s' is not a unique country code", c) |
8080007d3c06
shape upload stretch import: Finished implementation (staging, summary).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4316
diff
changeset
|
122 } |
8080007d3c06
shape upload stretch import: Finished implementation (staging, summary).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4316
diff
changeset
|
123 countries = append(countries, n) |
8080007d3c06
shape upload stretch import: Finished implementation (staging, summary).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4316
diff
changeset
|
124 unique[n] = struct{}{} |
8080007d3c06
shape upload stretch import: Finished implementation (staging, summary).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4316
diff
changeset
|
125 } |
8080007d3c06
shape upload stretch import: Finished implementation (staging, summary).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4316
diff
changeset
|
126 return countries, nil |
8080007d3c06
shape upload stretch import: Finished implementation (staging, summary).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4316
diff
changeset
|
127 } |
8080007d3c06
shape upload stretch import: Finished implementation (staging, summary).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4316
diff
changeset
|
128 |
4852
046a07a33b19
Fixed the golint issues of the imports package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4506
diff
changeset
|
129 // Do executes the actual stretch import from the shape file. |
4311
f9bb06f2dbe3
Added stub for a shape upload stretch import. POST /api/imports/stsh
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
130 func (stsh *StretchShape) Do( |
f9bb06f2dbe3
Added stub for a shape upload stretch import. POST /api/imports/stsh
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
131 ctx context.Context, |
f9bb06f2dbe3
Added stub for a shape upload stretch import. POST /api/imports/stsh
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
132 importID int64, |
f9bb06f2dbe3
Added stub for a shape upload stretch import. POST /api/imports/stsh
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
133 conn *sql.Conn, |
f9bb06f2dbe3
Added stub for a shape upload stretch import. POST /api/imports/stsh
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
134 feedback Feedback, |
f9bb06f2dbe3
Added stub for a shape upload stretch import. POST /api/imports/stsh
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
135 ) (interface{}, error) { |
4313
5da02dcc51f6
shape upload stretch import: Started to decode geometries and attributes from uploaded shape file.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4311
diff
changeset
|
136 |
4316
3d6a2c6b436c
shape upload stretch import: Store features in database. Still broken [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4314
diff
changeset
|
137 start := time.Now() |
3d6a2c6b436c
shape upload stretch import: Store features in database. Still broken [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4314
diff
changeset
|
138 defer func() { |
3d6a2c6b436c
shape upload stretch import: Store features in database. Still broken [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4314
diff
changeset
|
139 feedback.Info("Storing stretches from shape file took %v.", |
3d6a2c6b436c
shape upload stretch import: Store features in database. Still broken [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4314
diff
changeset
|
140 time.Since(start)) |
3d6a2c6b436c
shape upload stretch import: Store features in database. Still broken [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4314
diff
changeset
|
141 }() |
3d6a2c6b436c
shape upload stretch import: Store features in database. Still broken [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4314
diff
changeset
|
142 |
4313
5da02dcc51f6
shape upload stretch import: Started to decode geometries and attributes from uploaded shape file.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4311
diff
changeset
|
143 zpath := filepath.Join(stsh.Dir, "stretch.zip") |
5da02dcc51f6
shape upload stretch import: Started to decode geometries and attributes from uploaded shape file.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4311
diff
changeset
|
144 |
5da02dcc51f6
shape upload stretch import: Started to decode geometries and attributes from uploaded shape file.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4311
diff
changeset
|
145 z, err := zip.OpenReader(zpath) |
5da02dcc51f6
shape upload stretch import: Started to decode geometries and attributes from uploaded shape file.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4311
diff
changeset
|
146 if err != nil { |
5da02dcc51f6
shape upload stretch import: Started to decode geometries and attributes from uploaded shape file.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4311
diff
changeset
|
147 return nil, err |
5da02dcc51f6
shape upload stretch import: Started to decode geometries and attributes from uploaded shape file.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4311
diff
changeset
|
148 } |
5da02dcc51f6
shape upload stretch import: Started to decode geometries and attributes from uploaded shape file.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4311
diff
changeset
|
149 defer z.Close() |
5da02dcc51f6
shape upload stretch import: Started to decode geometries and attributes from uploaded shape file.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4311
diff
changeset
|
150 |
5da02dcc51f6
shape upload stretch import: Started to decode geometries and attributes from uploaded shape file.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4311
diff
changeset
|
151 shpF := common.FindInZIP(z, ".shp") |
5da02dcc51f6
shape upload stretch import: Started to decode geometries and attributes from uploaded shape file.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4311
diff
changeset
|
152 if shpF == nil { |
5da02dcc51f6
shape upload stretch import: Started to decode geometries and attributes from uploaded shape file.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4311
diff
changeset
|
153 return nil, errors.New("no SHP file found in ZIP") |
5da02dcc51f6
shape upload stretch import: Started to decode geometries and attributes from uploaded shape file.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4311
diff
changeset
|
154 } |
5da02dcc51f6
shape upload stretch import: Started to decode geometries and attributes from uploaded shape file.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4311
diff
changeset
|
155 prefix := strings.TrimSuffix(shpF.Name, path.Ext(shpF.Name)) |
5da02dcc51f6
shape upload stretch import: Started to decode geometries and attributes from uploaded shape file.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4311
diff
changeset
|
156 dbfF := common.FindInZIP(z, prefix+".dbf") |
5da02dcc51f6
shape upload stretch import: Started to decode geometries and attributes from uploaded shape file.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4311
diff
changeset
|
157 if dbfF == nil { |
5da02dcc51f6
shape upload stretch import: Started to decode geometries and attributes from uploaded shape file.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4311
diff
changeset
|
158 return nil, fmt.Errorf("no DBF file found for %s", shpF.Name) |
5da02dcc51f6
shape upload stretch import: Started to decode geometries and attributes from uploaded shape file.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4311
diff
changeset
|
159 } |
5da02dcc51f6
shape upload stretch import: Started to decode geometries and attributes from uploaded shape file.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4311
diff
changeset
|
160 |
5da02dcc51f6
shape upload stretch import: Started to decode geometries and attributes from uploaded shape file.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4311
diff
changeset
|
161 shpR, err := shpF.Open() |
5da02dcc51f6
shape upload stretch import: Started to decode geometries and attributes from uploaded shape file.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4311
diff
changeset
|
162 if err != nil { |
5da02dcc51f6
shape upload stretch import: Started to decode geometries and attributes from uploaded shape file.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4311
diff
changeset
|
163 return nil, err |
5da02dcc51f6
shape upload stretch import: Started to decode geometries and attributes from uploaded shape file.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4311
diff
changeset
|
164 } |
5da02dcc51f6
shape upload stretch import: Started to decode geometries and attributes from uploaded shape file.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4311
diff
changeset
|
165 |
5da02dcc51f6
shape upload stretch import: Started to decode geometries and attributes from uploaded shape file.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4311
diff
changeset
|
166 dbfR, err := dbfF.Open() |
5da02dcc51f6
shape upload stretch import: Started to decode geometries and attributes from uploaded shape file.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4311
diff
changeset
|
167 if err != nil { |
5da02dcc51f6
shape upload stretch import: Started to decode geometries and attributes from uploaded shape file.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4311
diff
changeset
|
168 shpR.Close() |
5da02dcc51f6
shape upload stretch import: Started to decode geometries and attributes from uploaded shape file.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4311
diff
changeset
|
169 return nil, err |
5da02dcc51f6
shape upload stretch import: Started to decode geometries and attributes from uploaded shape file.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4311
diff
changeset
|
170 } |
5da02dcc51f6
shape upload stretch import: Started to decode geometries and attributes from uploaded shape file.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4311
diff
changeset
|
171 sr := shp.SequentialReaderFromExt(shpR, dbfR) |
5da02dcc51f6
shape upload stretch import: Started to decode geometries and attributes from uploaded shape file.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4311
diff
changeset
|
172 defer sr.Close() |
5da02dcc51f6
shape upload stretch import: Started to decode geometries and attributes from uploaded shape file.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4311
diff
changeset
|
173 |
5da02dcc51f6
shape upload stretch import: Started to decode geometries and attributes from uploaded shape file.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4311
diff
changeset
|
174 fields := sr.Fields() |
5da02dcc51f6
shape upload stretch import: Started to decode geometries and attributes from uploaded shape file.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4311
diff
changeset
|
175 |
4316
3d6a2c6b436c
shape upload stretch import: Store features in database. Still broken [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4314
diff
changeset
|
176 // Map the attribute column indices. |
3d6a2c6b436c
shape upload stretch import: Store features in database. Still broken [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4314
diff
changeset
|
177 |
3d6a2c6b436c
shape upload stretch import: Store features in database. Still broken [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4314
diff
changeset
|
178 var ( |
3d6a2c6b436c
shape upload stretch import: Store features in database. Still broken [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4314
diff
changeset
|
179 nameIdx = -1 |
3d6a2c6b436c
shape upload stretch import: Store features in database. Still broken [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4314
diff
changeset
|
180 objnamIdx = -1 |
3d6a2c6b436c
shape upload stretch import: Store features in database. Still broken [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4314
diff
changeset
|
181 nobjnamIdx = -1 |
3d6a2c6b436c
shape upload stretch import: Store features in database. Still broken [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4314
diff
changeset
|
182 lowerIdx = -1 |
3d6a2c6b436c
shape upload stretch import: Store features in database. Still broken [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4314
diff
changeset
|
183 upperIdx = -1 |
3d6a2c6b436c
shape upload stretch import: Store features in database. Still broken [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4314
diff
changeset
|
184 sourceIdx = -1 |
3d6a2c6b436c
shape upload stretch import: Store features in database. Still broken [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4314
diff
changeset
|
185 dateInfoIdx = -1 |
3d6a2c6b436c
shape upload stretch import: Store features in database. Still broken [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4314
diff
changeset
|
186 countriesIdx = -1 |
3d6a2c6b436c
shape upload stretch import: Store features in database. Still broken [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4314
diff
changeset
|
187 ) |
3d6a2c6b436c
shape upload stretch import: Store features in database. Still broken [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4314
diff
changeset
|
188 |
3d6a2c6b436c
shape upload stretch import: Store features in database. Still broken [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4314
diff
changeset
|
189 type index struct { |
3d6a2c6b436c
shape upload stretch import: Store features in database. Still broken [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4314
diff
changeset
|
190 name string |
3d6a2c6b436c
shape upload stretch import: Store features in database. Still broken [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4314
diff
changeset
|
191 idx *int |
3d6a2c6b436c
shape upload stretch import: Store features in database. Still broken [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4314
diff
changeset
|
192 } |
3d6a2c6b436c
shape upload stretch import: Store features in database. Still broken [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4314
diff
changeset
|
193 |
3d6a2c6b436c
shape upload stretch import: Store features in database. Still broken [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4314
diff
changeset
|
194 indices := []index{ |
3d6a2c6b436c
shape upload stretch import: Store features in database. Still broken [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4314
diff
changeset
|
195 {"name", &nameIdx}, |
3d6a2c6b436c
shape upload stretch import: Store features in database. Still broken [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4314
diff
changeset
|
196 {"objnam", &objnamIdx}, |
3d6a2c6b436c
shape upload stretch import: Store features in database. Still broken [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4314
diff
changeset
|
197 {"nobjnam", &nobjnamIdx}, |
3d6a2c6b436c
shape upload stretch import: Store features in database. Still broken [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4314
diff
changeset
|
198 {"lower", &lowerIdx}, |
3d6a2c6b436c
shape upload stretch import: Store features in database. Still broken [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4314
diff
changeset
|
199 {"upper", &upperIdx}, |
3d6a2c6b436c
shape upload stretch import: Store features in database. Still broken [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4314
diff
changeset
|
200 {"source", &sourceIdx}, |
3d6a2c6b436c
shape upload stretch import: Store features in database. Still broken [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4314
diff
changeset
|
201 {"source", &sourceIdx}, |
3d6a2c6b436c
shape upload stretch import: Store features in database. Still broken [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4314
diff
changeset
|
202 {"dateinfo", &dateInfoIdx}, |
3d6a2c6b436c
shape upload stretch import: Store features in database. Still broken [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4314
diff
changeset
|
203 {"countries", &countriesIdx}, |
3d6a2c6b436c
shape upload stretch import: Store features in database. Still broken [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4314
diff
changeset
|
204 } |
3d6a2c6b436c
shape upload stretch import: Store features in database. Still broken [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4314
diff
changeset
|
205 |
3d6a2c6b436c
shape upload stretch import: Store features in database. Still broken [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4314
diff
changeset
|
206 nextField: |
3d6a2c6b436c
shape upload stretch import: Store features in database. Still broken [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4314
diff
changeset
|
207 for i := range fields { |
3d6a2c6b436c
shape upload stretch import: Store features in database. Still broken [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4314
diff
changeset
|
208 name := strings.ToLower(fields[i].String()) |
3d6a2c6b436c
shape upload stretch import: Store features in database. Still broken [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4314
diff
changeset
|
209 for j := range indices { |
3d6a2c6b436c
shape upload stretch import: Store features in database. Still broken [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4314
diff
changeset
|
210 if name == indices[j].name { |
3d6a2c6b436c
shape upload stretch import: Store features in database. Still broken [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4314
diff
changeset
|
211 *indices[j].idx = i |
3d6a2c6b436c
shape upload stretch import: Store features in database. Still broken [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4314
diff
changeset
|
212 continue nextField |
3d6a2c6b436c
shape upload stretch import: Store features in database. Still broken [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4314
diff
changeset
|
213 } |
3d6a2c6b436c
shape upload stretch import: Store features in database. Still broken [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4314
diff
changeset
|
214 } |
3d6a2c6b436c
shape upload stretch import: Store features in database. Still broken [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4314
diff
changeset
|
215 } |
3d6a2c6b436c
shape upload stretch import: Store features in database. Still broken [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4314
diff
changeset
|
216 |
3d6a2c6b436c
shape upload stretch import: Store features in database. Still broken [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4314
diff
changeset
|
217 var missingFields []string |
3d6a2c6b436c
shape upload stretch import: Store features in database. Still broken [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4314
diff
changeset
|
218 |
3d6a2c6b436c
shape upload stretch import: Store features in database. Still broken [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4314
diff
changeset
|
219 for i := range indices { |
3d6a2c6b436c
shape upload stretch import: Store features in database. Still broken [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4314
diff
changeset
|
220 if *indices[i].idx == -1 { |
3d6a2c6b436c
shape upload stretch import: Store features in database. Still broken [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4314
diff
changeset
|
221 missingFields = append(missingFields, indices[i].name) |
3d6a2c6b436c
shape upload stretch import: Store features in database. Still broken [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4314
diff
changeset
|
222 } |
3d6a2c6b436c
shape upload stretch import: Store features in database. Still broken [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4314
diff
changeset
|
223 } |
3d6a2c6b436c
shape upload stretch import: Store features in database. Still broken [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4314
diff
changeset
|
224 |
3d6a2c6b436c
shape upload stretch import: Store features in database. Still broken [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4314
diff
changeset
|
225 if len(missingFields) > 0 { |
3d6a2c6b436c
shape upload stretch import: Store features in database. Still broken [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4314
diff
changeset
|
226 return nil, fmt.Errorf("missing fields in attributes: %s", |
3d6a2c6b436c
shape upload stretch import: Store features in database. Still broken [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4314
diff
changeset
|
227 strings.Join(missingFields, ", ")) |
3d6a2c6b436c
shape upload stretch import: Store features in database. Still broken [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4314
diff
changeset
|
228 } |
3d6a2c6b436c
shape upload stretch import: Store features in database. Still broken [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4314
diff
changeset
|
229 |
3d6a2c6b436c
shape upload stretch import: Store features in database. Still broken [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4314
diff
changeset
|
230 // Now we have ensured that all columns are in place |
3d6a2c6b436c
shape upload stretch import: Store features in database. Still broken [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4314
diff
changeset
|
231 // so start extracting data from the shape file. |
3d6a2c6b436c
shape upload stretch import: Store features in database. Still broken [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4314
diff
changeset
|
232 |
3d6a2c6b436c
shape upload stretch import: Store features in database. Still broken [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4314
diff
changeset
|
233 tx, err := conn.BeginTx(ctx, nil) |
3d6a2c6b436c
shape upload stretch import: Store features in database. Still broken [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4314
diff
changeset
|
234 if err != nil { |
3d6a2c6b436c
shape upload stretch import: Store features in database. Still broken [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4314
diff
changeset
|
235 return nil, err |
3d6a2c6b436c
shape upload stretch import: Store features in database. Still broken [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4314
diff
changeset
|
236 } |
3d6a2c6b436c
shape upload stretch import: Store features in database. Still broken [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4314
diff
changeset
|
237 defer tx.Rollback() |
3d6a2c6b436c
shape upload stretch import: Store features in database. Still broken [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4314
diff
changeset
|
238 |
3d6a2c6b436c
shape upload stretch import: Store features in database. Still broken [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4314
diff
changeset
|
239 insStmt, err := tx.PrepareContext(ctx, stshInsertSQL) |
3d6a2c6b436c
shape upload stretch import: Store features in database. Still broken [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4314
diff
changeset
|
240 if err != nil { |
3d6a2c6b436c
shape upload stretch import: Store features in database. Still broken [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4314
diff
changeset
|
241 return nil, err |
3d6a2c6b436c
shape upload stretch import: Store features in database. Still broken [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4314
diff
changeset
|
242 } |
3d6a2c6b436c
shape upload stretch import: Store features in database. Still broken [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4314
diff
changeset
|
243 defer insStmt.Close() |
3d6a2c6b436c
shape upload stretch import: Store features in database. Still broken [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4314
diff
changeset
|
244 |
3d6a2c6b436c
shape upload stretch import: Store features in database. Still broken [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4314
diff
changeset
|
245 insCountryStmt, err := tx.PrepareContext(ctx, stInsertCountrySQL) |
3d6a2c6b436c
shape upload stretch import: Store features in database. Still broken [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4314
diff
changeset
|
246 if err != nil { |
3d6a2c6b436c
shape upload stretch import: Store features in database. Still broken [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4314
diff
changeset
|
247 return nil, err |
3d6a2c6b436c
shape upload stretch import: Store features in database. Still broken [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4314
diff
changeset
|
248 } |
3d6a2c6b436c
shape upload stretch import: Store features in database. Still broken [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4314
diff
changeset
|
249 defer insCountryStmt.Close() |
3d6a2c6b436c
shape upload stretch import: Store features in database. Still broken [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4314
diff
changeset
|
250 |
4332
8080007d3c06
shape upload stretch import: Finished implementation (staging, summary).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4316
diff
changeset
|
251 trackStmt, err := tx.PrepareContext(ctx, trackImportSQL) |
8080007d3c06
shape upload stretch import: Finished implementation (staging, summary).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4316
diff
changeset
|
252 if err != nil { |
8080007d3c06
shape upload stretch import: Finished implementation (staging, summary).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4316
diff
changeset
|
253 return nil, err |
8080007d3c06
shape upload stretch import: Finished implementation (staging, summary).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4316
diff
changeset
|
254 } |
8080007d3c06
shape upload stretch import: Finished implementation (staging, summary).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4316
diff
changeset
|
255 defer trackStmt.Close() |
8080007d3c06
shape upload stretch import: Finished implementation (staging, summary).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4316
diff
changeset
|
256 |
8080007d3c06
shape upload stretch import: Finished implementation (staging, summary).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4316
diff
changeset
|
257 var stretches []*stretchSummary |
8080007d3c06
shape upload stretch import: Finished implementation (staging, summary).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4316
diff
changeset
|
258 |
4313
5da02dcc51f6
shape upload stretch import: Started to decode geometries and attributes from uploaded shape file.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4311
diff
changeset
|
259 for sr.Next() { |
5da02dcc51f6
shape upload stretch import: Started to decode geometries and attributes from uploaded shape file.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4311
diff
changeset
|
260 |
5da02dcc51f6
shape upload stretch import: Started to decode geometries and attributes from uploaded shape file.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4311
diff
changeset
|
261 _, p := sr.Shape() |
5da02dcc51f6
shape upload stretch import: Started to decode geometries and attributes from uploaded shape file.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4311
diff
changeset
|
262 if p == nil { |
5da02dcc51f6
shape upload stretch import: Started to decode geometries and attributes from uploaded shape file.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4311
diff
changeset
|
263 feedback.Warn("Invalid NULL geometry found.") |
5da02dcc51f6
shape upload stretch import: Started to decode geometries and attributes from uploaded shape file.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4311
diff
changeset
|
264 continue |
5da02dcc51f6
shape upload stretch import: Started to decode geometries and attributes from uploaded shape file.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4311
diff
changeset
|
265 } |
5da02dcc51f6
shape upload stretch import: Started to decode geometries and attributes from uploaded shape file.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4311
diff
changeset
|
266 poly, err := shapeToPolygon(p) |
5da02dcc51f6
shape upload stretch import: Started to decode geometries and attributes from uploaded shape file.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4311
diff
changeset
|
267 if err != nil { |
5da02dcc51f6
shape upload stretch import: Started to decode geometries and attributes from uploaded shape file.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4311
diff
changeset
|
268 feedback.Warn("Invalid geometry found: %v.", err) |
5da02dcc51f6
shape upload stretch import: Started to decode geometries and attributes from uploaded shape file.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4311
diff
changeset
|
269 continue |
5da02dcc51f6
shape upload stretch import: Started to decode geometries and attributes from uploaded shape file.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4311
diff
changeset
|
270 } |
5da02dcc51f6
shape upload stretch import: Started to decode geometries and attributes from uploaded shape file.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4311
diff
changeset
|
271 |
4316
3d6a2c6b436c
shape upload stretch import: Store features in database. Still broken [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4314
diff
changeset
|
272 var ( |
4332
8080007d3c06
shape upload stretch import: Finished implementation (staging, summary).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4316
diff
changeset
|
273 name = fixAttribute(sr.Attribute(nameIdx)) |
8080007d3c06
shape upload stretch import: Finished implementation (staging, summary).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4316
diff
changeset
|
274 objnam = fixAttribute(sr.Attribute(objnamIdx)) |
8080007d3c06
shape upload stretch import: Finished implementation (staging, summary).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4316
diff
changeset
|
275 nobjnam = fixAttribute(sr.Attribute(nobjnamIdx)) |
8080007d3c06
shape upload stretch import: Finished implementation (staging, summary).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4316
diff
changeset
|
276 lower = fixAttribute(sr.Attribute(lowerIdx)) |
8080007d3c06
shape upload stretch import: Finished implementation (staging, summary).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4316
diff
changeset
|
277 upper = fixAttribute(sr.Attribute(upperIdx)) |
8080007d3c06
shape upload stretch import: Finished implementation (staging, summary).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4316
diff
changeset
|
278 dateInfo = fixAttribute(sr.Attribute(dateInfoIdx)) |
8080007d3c06
shape upload stretch import: Finished implementation (staging, summary).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4316
diff
changeset
|
279 source = fixAttribute(sr.Attribute(sourceIdx)) |
8080007d3c06
shape upload stretch import: Finished implementation (staging, summary).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4316
diff
changeset
|
280 cnts = fixAttribute(sr.Attribute(countriesIdx)) |
4316
3d6a2c6b436c
shape upload stretch import: Store features in database. Still broken [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4314
diff
changeset
|
281 ) |
4313
5da02dcc51f6
shape upload stretch import: Started to decode geometries and attributes from uploaded shape file.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4311
diff
changeset
|
282 |
4332
8080007d3c06
shape upload stretch import: Finished implementation (staging, summary).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4316
diff
changeset
|
283 feedback.Info("Importing stretch %s (%s - %s).", |
8080007d3c06
shape upload stretch import: Finished implementation (staging, summary).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4316
diff
changeset
|
284 name, lower, upper) |
4316
3d6a2c6b436c
shape upload stretch import: Store features in database. Still broken [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4314
diff
changeset
|
285 |
3d6a2c6b436c
shape upload stretch import: Store features in database. Still broken [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4314
diff
changeset
|
286 date, err := common.ParseTime(dateInfo) |
3d6a2c6b436c
shape upload stretch import: Store features in database. Still broken [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4314
diff
changeset
|
287 if err != nil { |
3d6a2c6b436c
shape upload stretch import: Store features in database. Still broken [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4314
diff
changeset
|
288 feedback.Warn("Invalid time value: %v.", err) |
3d6a2c6b436c
shape upload stretch import: Store features in database. Still broken [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4314
diff
changeset
|
289 continue |
3d6a2c6b436c
shape upload stretch import: Store features in database. Still broken [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4314
diff
changeset
|
290 } |
4314
c3b5cf2f200a
shape upload stretch import: Converted multi polygon to WKB.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4313
diff
changeset
|
291 |
4332
8080007d3c06
shape upload stretch import: Finished implementation (staging, summary).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4316
diff
changeset
|
292 countries, err := parseUniqueCountries(cnts) |
8080007d3c06
shape upload stretch import: Finished implementation (staging, summary).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4316
diff
changeset
|
293 if err != nil { |
8080007d3c06
shape upload stretch import: Finished implementation (staging, summary).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4316
diff
changeset
|
294 feedback.Warn("Countries: %v.", err) |
8080007d3c06
shape upload stretch import: Finished implementation (staging, summary).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4316
diff
changeset
|
295 continue |
8080007d3c06
shape upload stretch import: Finished implementation (staging, summary).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4316
diff
changeset
|
296 } |
8080007d3c06
shape upload stretch import: Finished implementation (staging, summary).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4316
diff
changeset
|
297 |
4316
3d6a2c6b436c
shape upload stretch import: Store features in database. Still broken [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4314
diff
changeset
|
298 var nobjnamNull sql.NullString |
3d6a2c6b436c
shape upload stretch import: Store features in database. Still broken [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4314
diff
changeset
|
299 if nobjnam != "" { |
3d6a2c6b436c
shape upload stretch import: Store features in database. Still broken [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4314
diff
changeset
|
300 nobjnamNull = sql.NullString{ |
3d6a2c6b436c
shape upload stretch import: Store features in database. Still broken [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4314
diff
changeset
|
301 String: nobjnam, |
3d6a2c6b436c
shape upload stretch import: Store features in database. Still broken [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4314
diff
changeset
|
302 Valid: true, |
3d6a2c6b436c
shape upload stretch import: Store features in database. Still broken [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4314
diff
changeset
|
303 } |
3d6a2c6b436c
shape upload stretch import: Store features in database. Still broken [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4314
diff
changeset
|
304 } |
3d6a2c6b436c
shape upload stretch import: Store features in database. Still broken [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4314
diff
changeset
|
305 |
3d6a2c6b436c
shape upload stretch import: Store features in database. Still broken [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4314
diff
changeset
|
306 // Convert to a multi polygon. |
3d6a2c6b436c
shape upload stretch import: Store features in database. Still broken [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4314
diff
changeset
|
307 area := poly.MultiPolygonGeom().AsWKB() |
3d6a2c6b436c
shape upload stretch import: Store features in database. Still broken [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4314
diff
changeset
|
308 |
3d6a2c6b436c
shape upload stretch import: Store features in database. Still broken [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4314
diff
changeset
|
309 var id int64 |
4313
5da02dcc51f6
shape upload stretch import: Started to decode geometries and attributes from uploaded shape file.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4311
diff
changeset
|
310 |
4316
3d6a2c6b436c
shape upload stretch import: Store features in database. Still broken [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4314
diff
changeset
|
311 if err := insStmt.QueryRowContext( |
3d6a2c6b436c
shape upload stretch import: Store features in database. Still broken [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4314
diff
changeset
|
312 ctx, |
3d6a2c6b436c
shape upload stretch import: Store features in database. Still broken [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4314
diff
changeset
|
313 name, |
3d6a2c6b436c
shape upload stretch import: Store features in database. Still broken [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4314
diff
changeset
|
314 lower, upper, |
3d6a2c6b436c
shape upload stretch import: Store features in database. Still broken [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4314
diff
changeset
|
315 area, |
3d6a2c6b436c
shape upload stretch import: Store features in database. Still broken [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4314
diff
changeset
|
316 objnam, |
3d6a2c6b436c
shape upload stretch import: Store features in database. Still broken [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4314
diff
changeset
|
317 nobjnamNull, |
3d6a2c6b436c
shape upload stretch import: Store features in database. Still broken [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4314
diff
changeset
|
318 date, |
3d6a2c6b436c
shape upload stretch import: Store features in database. Still broken [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4314
diff
changeset
|
319 source, |
3d6a2c6b436c
shape upload stretch import: Store features in database. Still broken [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4314
diff
changeset
|
320 ).Scan(&id); err != nil { |
3d6a2c6b436c
shape upload stretch import: Store features in database. Still broken [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4314
diff
changeset
|
321 return nil, err |
3d6a2c6b436c
shape upload stretch import: Store features in database. Still broken [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4314
diff
changeset
|
322 } |
3d6a2c6b436c
shape upload stretch import: Store features in database. Still broken [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4314
diff
changeset
|
323 |
4332
8080007d3c06
shape upload stretch import: Finished implementation (staging, summary).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4316
diff
changeset
|
324 // Store the countries |
8080007d3c06
shape upload stretch import: Finished implementation (staging, summary).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4316
diff
changeset
|
325 for _, country := range countries { |
4388
eca3afe766d7
stretch shape import: Fixed db insert of countries.
Sascha Wilde <wilde@intevation.de>
parents:
4332
diff
changeset
|
326 if _, err := insCountryStmt.ExecContext(ctx, id, country); err != nil { |
4316
3d6a2c6b436c
shape upload stretch import: Store features in database. Still broken [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4314
diff
changeset
|
327 return nil, err |
3d6a2c6b436c
shape upload stretch import: Store features in database. Still broken [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4314
diff
changeset
|
328 } |
4313
5da02dcc51f6
shape upload stretch import: Started to decode geometries and attributes from uploaded shape file.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4311
diff
changeset
|
329 } |
5da02dcc51f6
shape upload stretch import: Started to decode geometries and attributes from uploaded shape file.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4311
diff
changeset
|
330 |
4332
8080007d3c06
shape upload stretch import: Finished implementation (staging, summary).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4316
diff
changeset
|
331 // Finally track the stretch |
8080007d3c06
shape upload stretch import: Finished implementation (staging, summary).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4316
diff
changeset
|
332 |
8080007d3c06
shape upload stretch import: Finished implementation (staging, summary).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4316
diff
changeset
|
333 if _, err := trackStmt.ExecContext( |
8080007d3c06
shape upload stretch import: Finished implementation (staging, summary).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4316
diff
changeset
|
334 ctx, |
8080007d3c06
shape upload stretch import: Finished implementation (staging, summary).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4316
diff
changeset
|
335 importID, |
4389
5e38667f740c
Use stretches as areas of responsibility.
Sascha Wilde <wilde@intevation.de>
parents:
4332
diff
changeset
|
336 "users.stretches", |
4332
8080007d3c06
shape upload stretch import: Finished implementation (staging, summary).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4316
diff
changeset
|
337 id, |
8080007d3c06
shape upload stretch import: Finished implementation (staging, summary).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4316
diff
changeset
|
338 ); err != nil { |
8080007d3c06
shape upload stretch import: Finished implementation (staging, summary).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4316
diff
changeset
|
339 return nil, err |
8080007d3c06
shape upload stretch import: Finished implementation (staging, summary).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4316
diff
changeset
|
340 } |
8080007d3c06
shape upload stretch import: Finished implementation (staging, summary).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4316
diff
changeset
|
341 |
8080007d3c06
shape upload stretch import: Finished implementation (staging, summary).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4316
diff
changeset
|
342 stretch := &stretchSummary{ |
8080007d3c06
shape upload stretch import: Finished implementation (staging, summary).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4316
diff
changeset
|
343 ID: id, |
8080007d3c06
shape upload stretch import: Finished implementation (staging, summary).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4316
diff
changeset
|
344 Name: name, |
8080007d3c06
shape upload stretch import: Finished implementation (staging, summary).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4316
diff
changeset
|
345 From: lower, |
8080007d3c06
shape upload stretch import: Finished implementation (staging, summary).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4316
diff
changeset
|
346 To: upper, |
8080007d3c06
shape upload stretch import: Finished implementation (staging, summary).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4316
diff
changeset
|
347 ObjNam: objnam, |
4506
e020e6e34ad7
Made 'go vet' happy again.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4390
diff
changeset
|
348 Date: models.Date{Time: date}, |
4332
8080007d3c06
shape upload stretch import: Finished implementation (staging, summary).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4316
diff
changeset
|
349 Countries: countries, |
8080007d3c06
shape upload stretch import: Finished implementation (staging, summary).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4316
diff
changeset
|
350 } |
8080007d3c06
shape upload stretch import: Finished implementation (staging, summary).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4316
diff
changeset
|
351 |
8080007d3c06
shape upload stretch import: Finished implementation (staging, summary).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4316
diff
changeset
|
352 if nobjnamNull.Valid { |
8080007d3c06
shape upload stretch import: Finished implementation (staging, summary).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4316
diff
changeset
|
353 stretch.NObjNam = &nobjnamNull.String |
8080007d3c06
shape upload stretch import: Finished implementation (staging, summary).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4316
diff
changeset
|
354 } |
8080007d3c06
shape upload stretch import: Finished implementation (staging, summary).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4316
diff
changeset
|
355 |
8080007d3c06
shape upload stretch import: Finished implementation (staging, summary).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4316
diff
changeset
|
356 stretches = append(stretches, stretch) |
4313
5da02dcc51f6
shape upload stretch import: Started to decode geometries and attributes from uploaded shape file.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4311
diff
changeset
|
357 } |
5da02dcc51f6
shape upload stretch import: Started to decode geometries and attributes from uploaded shape file.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4311
diff
changeset
|
358 |
5da02dcc51f6
shape upload stretch import: Started to decode geometries and attributes from uploaded shape file.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4311
diff
changeset
|
359 if err := sr.Err(); err != nil { |
5da02dcc51f6
shape upload stretch import: Started to decode geometries and attributes from uploaded shape file.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4311
diff
changeset
|
360 return nil, err |
5da02dcc51f6
shape upload stretch import: Started to decode geometries and attributes from uploaded shape file.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4311
diff
changeset
|
361 } |
5da02dcc51f6
shape upload stretch import: Started to decode geometries and attributes from uploaded shape file.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4311
diff
changeset
|
362 |
4332
8080007d3c06
shape upload stretch import: Finished implementation (staging, summary).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4316
diff
changeset
|
363 if len(stretches) == 0 { |
8080007d3c06
shape upload stretch import: Finished implementation (staging, summary).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4316
diff
changeset
|
364 return nil, UnchangedError("No stretches written.") |
8080007d3c06
shape upload stretch import: Finished implementation (staging, summary).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4316
diff
changeset
|
365 } |
8080007d3c06
shape upload stretch import: Finished implementation (staging, summary).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4316
diff
changeset
|
366 |
8080007d3c06
shape upload stretch import: Finished implementation (staging, summary).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4316
diff
changeset
|
367 if err := tx.Commit(); err != nil { |
8080007d3c06
shape upload stretch import: Finished implementation (staging, summary).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4316
diff
changeset
|
368 return nil, err |
8080007d3c06
shape upload stretch import: Finished implementation (staging, summary).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4316
diff
changeset
|
369 } |
8080007d3c06
shape upload stretch import: Finished implementation (staging, summary).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4316
diff
changeset
|
370 |
8080007d3c06
shape upload stretch import: Finished implementation (staging, summary).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4316
diff
changeset
|
371 return stretches, nil |
4311
f9bb06f2dbe3
Added stub for a shape upload stretch import. POST /api/imports/stsh
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
372 } |