Mercurial > gemma
annotate pkg/imports/stsh.go @ 5020:e4ab338e7ba9
Removed unnecessary creatings of empty slices in expressing read dependencies in imports.
author | Sascha L. Teichmann <sascha.teichmann@intevation.de> |
---|---|
date | Sat, 14 Mar 2020 20:11:10 +0100 |
parents | 046a07a33b19 |
children | 59a99655f34d |
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 { |
5020
e4ab338e7ba9
Removed unnecessary creatings of empty slices in expressing read dependencies in imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4852
diff
changeset
|
53 return [2][]string{{"stretches", "stretch_countries"}} |
4311
f9bb06f2dbe3
Added stub for a shape upload stretch import. POST /api/imports/stsh
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
54 } |
f9bb06f2dbe3
Added stub for a shape upload stretch import. POST /api/imports/stsh
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
55 |
4316
3d6a2c6b436c
shape upload stretch import: Store features in database. Still broken [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4314
diff
changeset
|
56 const ( |
3d6a2c6b436c
shape upload stretch import: Store features in database. Still broken [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4314
diff
changeset
|
57 stshInsertSQL = ` |
4389
5e38667f740c
Use stretches as areas of responsibility.
Sascha Wilde <wilde@intevation.de>
parents:
4332
diff
changeset
|
58 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
|
59 name, |
3d6a2c6b436c
shape upload stretch import: Store features in database. Still broken [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4314
diff
changeset
|
60 stretch, |
3d6a2c6b436c
shape upload stretch import: Store features in database. Still broken [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4314
diff
changeset
|
61 area, |
3d6a2c6b436c
shape upload stretch import: Store features in database. Still broken [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4314
diff
changeset
|
62 objnam, |
3d6a2c6b436c
shape upload stretch import: Store features in database. Still broken [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4314
diff
changeset
|
63 nobjnam, |
3d6a2c6b436c
shape upload stretch import: Store features in database. Still broken [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4314
diff
changeset
|
64 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
|
65 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
|
66 ) VALUES ( |
3d6a2c6b436c
shape upload stretch import: Store features in database. Still broken [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4314
diff
changeset
|
67 $1, |
3d6a2c6b436c
shape upload stretch import: Store features in database. Still broken [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4314
diff
changeset
|
68 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
|
69 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
|
70 $5, |
3d6a2c6b436c
shape upload stretch import: Store features in database. Still broken [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4314
diff
changeset
|
71 $6, |
3d6a2c6b436c
shape upload stretch import: Store features in database. Still broken [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4314
diff
changeset
|
72 $7, |
3d6a2c6b436c
shape upload stretch import: Store features in database. Still broken [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4314
diff
changeset
|
73 $8) |
3d6a2c6b436c
shape upload stretch import: Store features in database. Still broken [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4314
diff
changeset
|
74 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
|
75 ) |
3d6a2c6b436c
shape upload stretch import: Store features in database. Still broken [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4314
diff
changeset
|
76 |
4332
8080007d3c06
shape upload stretch import: Finished implementation (staging, summary).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4316
diff
changeset
|
77 // 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
|
78 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
|
79 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
|
80 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
|
81 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
|
82 ) error { |
4332
8080007d3c06
shape upload stretch import: Finished implementation (staging, summary).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4316
diff
changeset
|
83 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
|
84 } |
f9bb06f2dbe3
Added stub for a shape upload stretch import. POST /api/imports/stsh
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
85 |
4852
046a07a33b19
Fixed the golint issues of the imports package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4506
diff
changeset
|
86 // 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
|
87 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
|
88 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
|
89 } |
f9bb06f2dbe3
Added stub for a shape upload stretch import. POST /api/imports/stsh
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
90 |
4316
3d6a2c6b436c
shape upload stretch import: Store features in database. Still broken [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4314
diff
changeset
|
91 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
|
92 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
|
93 } |
3d6a2c6b436c
shape upload stretch import: Store features in database. Still broken [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4314
diff
changeset
|
94 |
4332
8080007d3c06
shape upload stretch import: Finished implementation (staging, summary).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4316
diff
changeset
|
95 type stretchSummary struct { |
8080007d3c06
shape upload stretch import: Finished implementation (staging, summary).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4316
diff
changeset
|
96 ID int64 `json:"id"` |
8080007d3c06
shape upload stretch import: Finished implementation (staging, summary).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4316
diff
changeset
|
97 Name string `json:"name"` |
8080007d3c06
shape upload stretch import: Finished implementation (staging, summary).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4316
diff
changeset
|
98 From string `json:"from"` |
8080007d3c06
shape upload stretch import: Finished implementation (staging, summary).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4316
diff
changeset
|
99 To string `json:"to"` |
8080007d3c06
shape upload stretch import: Finished implementation (staging, summary).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4316
diff
changeset
|
100 ObjNam string `json:"objnam"` |
8080007d3c06
shape upload stretch import: Finished implementation (staging, summary).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4316
diff
changeset
|
101 NObjNam *string `json:"nobjnam"` |
8080007d3c06
shape upload stretch import: Finished implementation (staging, summary).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4316
diff
changeset
|
102 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
|
103 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
|
104 } |
8080007d3c06
shape upload stretch import: Finished implementation (staging, summary).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4316
diff
changeset
|
105 |
8080007d3c06
shape upload stretch import: Finished implementation (staging, summary).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4316
diff
changeset
|
106 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
|
107 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
|
108 var countries models.UniqueCountries |
8080007d3c06
shape upload stretch import: Finished implementation (staging, summary).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4316
diff
changeset
|
109 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
|
110 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
|
111 continue |
8080007d3c06
shape upload stretch import: Finished implementation (staging, summary).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4316
diff
changeset
|
112 } |
8080007d3c06
shape upload stretch import: Finished implementation (staging, summary).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4316
diff
changeset
|
113 n := models.Country(c) |
8080007d3c06
shape upload stretch import: Finished implementation (staging, summary).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4316
diff
changeset
|
114 if !n.Valid() { |
8080007d3c06
shape upload stretch import: Finished implementation (staging, summary).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4316
diff
changeset
|
115 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
|
116 } |
8080007d3c06
shape upload stretch import: Finished implementation (staging, summary).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4316
diff
changeset
|
117 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
|
118 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
|
119 } |
8080007d3c06
shape upload stretch import: Finished implementation (staging, summary).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4316
diff
changeset
|
120 countries = append(countries, n) |
8080007d3c06
shape upload stretch import: Finished implementation (staging, summary).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4316
diff
changeset
|
121 unique[n] = struct{}{} |
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 return countries, nil |
8080007d3c06
shape upload stretch import: Finished implementation (staging, summary).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4316
diff
changeset
|
124 } |
8080007d3c06
shape upload stretch import: Finished implementation (staging, summary).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4316
diff
changeset
|
125 |
4852
046a07a33b19
Fixed the golint issues of the imports package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4506
diff
changeset
|
126 // 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
|
127 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
|
128 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
|
129 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
|
130 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
|
131 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
|
132 ) (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
|
133 |
4316
3d6a2c6b436c
shape upload stretch import: Store features in database. Still broken [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4314
diff
changeset
|
134 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
|
135 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
|
136 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
|
137 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
|
138 }() |
3d6a2c6b436c
shape upload stretch import: Store features in database. Still broken [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4314
diff
changeset
|
139 |
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
|
140 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
|
141 |
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
|
142 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
|
143 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
|
144 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
|
145 } |
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 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
|
147 |
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 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
|
149 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
|
150 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
|
151 } |
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 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
|
153 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
|
154 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
|
155 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
|
156 } |
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 |
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 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
|
159 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
|
160 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
|
161 } |
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 |
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 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
|
164 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
|
165 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
|
166 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
|
167 } |
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 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
|
169 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
|
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 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
|
172 |
4316
3d6a2c6b436c
shape upload stretch import: Store features in database. Still broken [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4314
diff
changeset
|
173 // 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
|
174 |
3d6a2c6b436c
shape upload stretch import: Store features in database. Still broken [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4314
diff
changeset
|
175 var ( |
3d6a2c6b436c
shape upload stretch import: Store features in database. Still broken [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4314
diff
changeset
|
176 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
|
177 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
|
178 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
|
179 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
|
180 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
|
181 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
|
182 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
|
183 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
|
184 ) |
3d6a2c6b436c
shape upload stretch import: Store features in database. Still broken [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4314
diff
changeset
|
185 |
3d6a2c6b436c
shape upload stretch import: Store features in database. Still broken [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4314
diff
changeset
|
186 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
|
187 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
|
188 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
|
189 } |
3d6a2c6b436c
shape upload stretch import: Store features in database. Still broken [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4314
diff
changeset
|
190 |
3d6a2c6b436c
shape upload stretch import: Store features in database. Still broken [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4314
diff
changeset
|
191 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
|
192 {"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
|
193 {"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
|
194 {"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
|
195 {"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
|
196 {"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
|
197 {"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
|
198 {"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
|
199 {"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
|
200 {"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
|
201 } |
3d6a2c6b436c
shape upload stretch import: Store features in database. Still broken [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4314
diff
changeset
|
202 |
3d6a2c6b436c
shape upload stretch import: Store features in database. Still broken [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4314
diff
changeset
|
203 nextField: |
3d6a2c6b436c
shape upload stretch import: Store features in database. Still broken [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4314
diff
changeset
|
204 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
|
205 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
|
206 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
|
207 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
|
208 *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
|
209 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
|
210 } |
3d6a2c6b436c
shape upload stretch import: Store features in database. Still broken [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4314
diff
changeset
|
211 } |
3d6a2c6b436c
shape upload stretch import: Store features in database. Still broken [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4314
diff
changeset
|
212 } |
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 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
|
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 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
|
217 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
|
218 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
|
219 } |
3d6a2c6b436c
shape upload stretch import: Store features in database. Still broken [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4314
diff
changeset
|
220 } |
3d6a2c6b436c
shape upload stretch import: Store features in database. Still broken [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4314
diff
changeset
|
221 |
3d6a2c6b436c
shape upload stretch import: Store features in database. Still broken [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4314
diff
changeset
|
222 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
|
223 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
|
224 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
|
225 } |
3d6a2c6b436c
shape upload stretch import: Store features in database. Still broken [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4314
diff
changeset
|
226 |
3d6a2c6b436c
shape upload stretch import: Store features in database. Still broken [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4314
diff
changeset
|
227 // 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
|
228 // 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
|
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 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
|
231 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
|
232 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
|
233 } |
3d6a2c6b436c
shape upload stretch import: Store features in database. Still broken [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4314
diff
changeset
|
234 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
|
235 |
3d6a2c6b436c
shape upload stretch import: Store features in database. Still broken [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4314
diff
changeset
|
236 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
|
237 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
|
238 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
|
239 } |
3d6a2c6b436c
shape upload stretch import: Store features in database. Still broken [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4314
diff
changeset
|
240 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
|
241 |
3d6a2c6b436c
shape upload stretch import: Store features in database. Still broken [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4314
diff
changeset
|
242 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
|
243 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
|
244 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
|
245 } |
3d6a2c6b436c
shape upload stretch import: Store features in database. Still broken [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4314
diff
changeset
|
246 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
|
247 |
4332
8080007d3c06
shape upload stretch import: Finished implementation (staging, summary).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4316
diff
changeset
|
248 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
|
249 if err != nil { |
8080007d3c06
shape upload stretch import: Finished implementation (staging, summary).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4316
diff
changeset
|
250 return nil, err |
8080007d3c06
shape upload stretch import: Finished implementation (staging, summary).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4316
diff
changeset
|
251 } |
8080007d3c06
shape upload stretch import: Finished implementation (staging, summary).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4316
diff
changeset
|
252 defer trackStmt.Close() |
8080007d3c06
shape upload stretch import: Finished implementation (staging, summary).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4316
diff
changeset
|
253 |
8080007d3c06
shape upload stretch import: Finished implementation (staging, summary).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4316
diff
changeset
|
254 var stretches []*stretchSummary |
8080007d3c06
shape upload stretch import: Finished implementation (staging, summary).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4316
diff
changeset
|
255 |
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
|
256 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
|
257 |
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
|
258 _, 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
|
259 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
|
260 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
|
261 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
|
262 } |
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 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
|
264 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
|
265 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
|
266 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
|
267 } |
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 |
4316
3d6a2c6b436c
shape upload stretch import: Store features in database. Still broken [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4314
diff
changeset
|
269 var ( |
4332
8080007d3c06
shape upload stretch import: Finished implementation (staging, summary).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4316
diff
changeset
|
270 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
|
271 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
|
272 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
|
273 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
|
274 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
|
275 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
|
276 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
|
277 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
|
278 ) |
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
|
279 |
4332
8080007d3c06
shape upload stretch import: Finished implementation (staging, summary).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4316
diff
changeset
|
280 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
|
281 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
|
282 |
3d6a2c6b436c
shape upload stretch import: Store features in database. Still broken [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4314
diff
changeset
|
283 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
|
284 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
|
285 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
|
286 continue |
3d6a2c6b436c
shape upload stretch import: Store features in database. Still broken [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4314
diff
changeset
|
287 } |
4314
c3b5cf2f200a
shape upload stretch import: Converted multi polygon to WKB.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4313
diff
changeset
|
288 |
4332
8080007d3c06
shape upload stretch import: Finished implementation (staging, summary).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4316
diff
changeset
|
289 countries, err := parseUniqueCountries(cnts) |
8080007d3c06
shape upload stretch import: Finished implementation (staging, summary).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4316
diff
changeset
|
290 if err != nil { |
8080007d3c06
shape upload stretch import: Finished implementation (staging, summary).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4316
diff
changeset
|
291 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
|
292 continue |
8080007d3c06
shape upload stretch import: Finished implementation (staging, summary).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4316
diff
changeset
|
293 } |
8080007d3c06
shape upload stretch import: Finished implementation (staging, summary).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4316
diff
changeset
|
294 |
4316
3d6a2c6b436c
shape upload stretch import: Store features in database. Still broken [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4314
diff
changeset
|
295 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
|
296 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
|
297 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
|
298 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
|
299 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
|
300 } |
3d6a2c6b436c
shape upload stretch import: Store features in database. Still broken [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4314
diff
changeset
|
301 } |
3d6a2c6b436c
shape upload stretch import: Store features in database. Still broken [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4314
diff
changeset
|
302 |
3d6a2c6b436c
shape upload stretch import: Store features in database. Still broken [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4314
diff
changeset
|
303 // 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
|
304 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
|
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 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
|
307 |
4316
3d6a2c6b436c
shape upload stretch import: Store features in database. Still broken [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4314
diff
changeset
|
308 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
|
309 ctx, |
3d6a2c6b436c
shape upload stretch import: Store features in database. Still broken [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4314
diff
changeset
|
310 name, |
3d6a2c6b436c
shape upload stretch import: Store features in database. Still broken [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4314
diff
changeset
|
311 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
|
312 area, |
3d6a2c6b436c
shape upload stretch import: Store features in database. Still broken [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4314
diff
changeset
|
313 objnam, |
3d6a2c6b436c
shape upload stretch import: Store features in database. Still broken [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4314
diff
changeset
|
314 nobjnamNull, |
3d6a2c6b436c
shape upload stretch import: Store features in database. Still broken [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4314
diff
changeset
|
315 date, |
3d6a2c6b436c
shape upload stretch import: Store features in database. Still broken [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4314
diff
changeset
|
316 source, |
3d6a2c6b436c
shape upload stretch import: Store features in database. Still broken [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4314
diff
changeset
|
317 ).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
|
318 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
|
319 } |
3d6a2c6b436c
shape upload stretch import: Store features in database. Still broken [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4314
diff
changeset
|
320 |
4332
8080007d3c06
shape upload stretch import: Finished implementation (staging, summary).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4316
diff
changeset
|
321 // Store the countries |
8080007d3c06
shape upload stretch import: Finished implementation (staging, summary).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4316
diff
changeset
|
322 for _, country := range countries { |
4388
eca3afe766d7
stretch shape import: Fixed db insert of countries.
Sascha Wilde <wilde@intevation.de>
parents:
4332
diff
changeset
|
323 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
|
324 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
|
325 } |
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
|
326 } |
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
|
327 |
4332
8080007d3c06
shape upload stretch import: Finished implementation (staging, summary).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4316
diff
changeset
|
328 // Finally track the stretch |
8080007d3c06
shape upload stretch import: Finished implementation (staging, summary).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4316
diff
changeset
|
329 |
8080007d3c06
shape upload stretch import: Finished implementation (staging, summary).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4316
diff
changeset
|
330 if _, err := trackStmt.ExecContext( |
8080007d3c06
shape upload stretch import: Finished implementation (staging, summary).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4316
diff
changeset
|
331 ctx, |
8080007d3c06
shape upload stretch import: Finished implementation (staging, summary).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4316
diff
changeset
|
332 importID, |
4389
5e38667f740c
Use stretches as areas of responsibility.
Sascha Wilde <wilde@intevation.de>
parents:
4332
diff
changeset
|
333 "users.stretches", |
4332
8080007d3c06
shape upload stretch import: Finished implementation (staging, summary).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4316
diff
changeset
|
334 id, |
8080007d3c06
shape upload stretch import: Finished implementation (staging, summary).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4316
diff
changeset
|
335 ); err != nil { |
8080007d3c06
shape upload stretch import: Finished implementation (staging, summary).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4316
diff
changeset
|
336 return nil, err |
8080007d3c06
shape upload stretch import: Finished implementation (staging, summary).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4316
diff
changeset
|
337 } |
8080007d3c06
shape upload stretch import: Finished implementation (staging, summary).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4316
diff
changeset
|
338 |
8080007d3c06
shape upload stretch import: Finished implementation (staging, summary).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4316
diff
changeset
|
339 stretch := &stretchSummary{ |
8080007d3c06
shape upload stretch import: Finished implementation (staging, summary).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4316
diff
changeset
|
340 ID: id, |
8080007d3c06
shape upload stretch import: Finished implementation (staging, summary).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4316
diff
changeset
|
341 Name: name, |
8080007d3c06
shape upload stretch import: Finished implementation (staging, summary).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4316
diff
changeset
|
342 From: lower, |
8080007d3c06
shape upload stretch import: Finished implementation (staging, summary).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4316
diff
changeset
|
343 To: upper, |
8080007d3c06
shape upload stretch import: Finished implementation (staging, summary).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4316
diff
changeset
|
344 ObjNam: objnam, |
4506
e020e6e34ad7
Made 'go vet' happy again.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4390
diff
changeset
|
345 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
|
346 Countries: countries, |
8080007d3c06
shape upload stretch import: Finished implementation (staging, summary).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4316
diff
changeset
|
347 } |
8080007d3c06
shape upload stretch import: Finished implementation (staging, summary).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4316
diff
changeset
|
348 |
8080007d3c06
shape upload stretch import: Finished implementation (staging, summary).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4316
diff
changeset
|
349 if nobjnamNull.Valid { |
8080007d3c06
shape upload stretch import: Finished implementation (staging, summary).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4316
diff
changeset
|
350 stretch.NObjNam = &nobjnamNull.String |
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 |
8080007d3c06
shape upload stretch import: Finished implementation (staging, summary).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4316
diff
changeset
|
353 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
|
354 } |
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
|
355 |
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
|
356 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
|
357 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
|
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 |
4332
8080007d3c06
shape upload stretch import: Finished implementation (staging, summary).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4316
diff
changeset
|
360 if len(stretches) == 0 { |
8080007d3c06
shape upload stretch import: Finished implementation (staging, summary).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4316
diff
changeset
|
361 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
|
362 } |
8080007d3c06
shape upload stretch import: Finished implementation (staging, summary).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4316
diff
changeset
|
363 |
8080007d3c06
shape upload stretch import: Finished implementation (staging, summary).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4316
diff
changeset
|
364 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
|
365 return nil, err |
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 |
8080007d3c06
shape upload stretch import: Finished implementation (staging, summary).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4316
diff
changeset
|
368 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
|
369 } |