Mercurial > gemma
annotate pkg/imports/stsh.go @ 5560:f2204f91d286
Join the log lines of imports to the log exports to recover data from them.
Used in SR export to extract information that where in the meta json
but now are only found in the log.
author | Sascha L. Teichmann <sascha.teichmann@intevation.de> |
---|---|
date | Wed, 09 Feb 2022 18:34:40 +0100 |
parents | 59a99655f34d |
children | 6270951dda28 |
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, |
5034
59a99655f34d
Added feedback support for StageDone.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5020
diff
changeset
|
82 feedback Feedback, |
4311
f9bb06f2dbe3
Added stub for a shape upload stretch import. POST /api/imports/stsh
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
83 ) error { |
5034
59a99655f34d
Added feedback support for StageDone.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5020
diff
changeset
|
84 return stJobCreator{}.StageDone(ctx, tx, id, feedback) |
4311
f9bb06f2dbe3
Added stub for a shape upload stretch import. POST /api/imports/stsh
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
85 } |
f9bb06f2dbe3
Added stub for a shape upload stretch import. POST /api/imports/stsh
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
86 |
4852
046a07a33b19
Fixed the golint issues of the imports package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4506
diff
changeset
|
87 // 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
|
88 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
|
89 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
|
90 } |
f9bb06f2dbe3
Added stub for a shape upload stretch import. POST /api/imports/stsh
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
91 |
4316
3d6a2c6b436c
shape upload stretch import: Store features in database. Still broken [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4314
diff
changeset
|
92 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
|
93 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
|
94 } |
3d6a2c6b436c
shape upload stretch import: Store features in database. Still broken [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4314
diff
changeset
|
95 |
4332
8080007d3c06
shape upload stretch import: Finished implementation (staging, summary).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4316
diff
changeset
|
96 type stretchSummary struct { |
8080007d3c06
shape upload stretch import: Finished implementation (staging, summary).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4316
diff
changeset
|
97 ID int64 `json:"id"` |
8080007d3c06
shape upload stretch import: Finished implementation (staging, summary).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4316
diff
changeset
|
98 Name string `json:"name"` |
8080007d3c06
shape upload stretch import: Finished implementation (staging, summary).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4316
diff
changeset
|
99 From string `json:"from"` |
8080007d3c06
shape upload stretch import: Finished implementation (staging, summary).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4316
diff
changeset
|
100 To string `json:"to"` |
8080007d3c06
shape upload stretch import: Finished implementation (staging, summary).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4316
diff
changeset
|
101 ObjNam string `json:"objnam"` |
8080007d3c06
shape upload stretch import: Finished implementation (staging, summary).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4316
diff
changeset
|
102 NObjNam *string `json:"nobjnam"` |
8080007d3c06
shape upload stretch import: Finished implementation (staging, summary).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4316
diff
changeset
|
103 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
|
104 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
|
105 } |
8080007d3c06
shape upload stretch import: Finished implementation (staging, summary).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4316
diff
changeset
|
106 |
8080007d3c06
shape upload stretch import: Finished implementation (staging, summary).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4316
diff
changeset
|
107 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
|
108 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
|
109 var countries models.UniqueCountries |
8080007d3c06
shape upload stretch import: Finished implementation (staging, summary).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4316
diff
changeset
|
110 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
|
111 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
|
112 continue |
8080007d3c06
shape upload stretch import: Finished implementation (staging, summary).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4316
diff
changeset
|
113 } |
8080007d3c06
shape upload stretch import: Finished implementation (staging, summary).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4316
diff
changeset
|
114 n := models.Country(c) |
8080007d3c06
shape upload stretch import: Finished implementation (staging, summary).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4316
diff
changeset
|
115 if !n.Valid() { |
8080007d3c06
shape upload stretch import: Finished implementation (staging, summary).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4316
diff
changeset
|
116 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
|
117 } |
8080007d3c06
shape upload stretch import: Finished implementation (staging, summary).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4316
diff
changeset
|
118 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
|
119 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
|
120 } |
8080007d3c06
shape upload stretch import: Finished implementation (staging, summary).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4316
diff
changeset
|
121 countries = append(countries, n) |
8080007d3c06
shape upload stretch import: Finished implementation (staging, summary).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4316
diff
changeset
|
122 unique[n] = struct{}{} |
8080007d3c06
shape upload stretch import: Finished implementation (staging, summary).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4316
diff
changeset
|
123 } |
8080007d3c06
shape upload stretch import: Finished implementation (staging, summary).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4316
diff
changeset
|
124 return countries, nil |
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 |
4852
046a07a33b19
Fixed the golint issues of the imports package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4506
diff
changeset
|
127 // 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
|
128 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
|
129 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
|
130 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
|
131 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
|
132 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
|
133 ) (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
|
134 |
4316
3d6a2c6b436c
shape upload stretch import: Store features in database. Still broken [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4314
diff
changeset
|
135 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
|
136 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
|
137 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
|
138 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
|
139 }() |
3d6a2c6b436c
shape upload stretch import: Store features in database. Still broken [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4314
diff
changeset
|
140 |
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
|
141 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
|
142 |
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 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
|
144 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
|
145 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
|
146 } |
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 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
|
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 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
|
150 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
|
151 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
|
152 } |
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 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
|
154 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
|
155 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
|
156 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
|
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 |
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 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
|
160 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
|
161 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
|
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 |
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 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
|
165 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
|
166 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
|
167 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
|
168 } |
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 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
|
170 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
|
171 |
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 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
|
173 |
4316
3d6a2c6b436c
shape upload stretch import: Store features in database. Still broken [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4314
diff
changeset
|
174 // 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
|
175 |
3d6a2c6b436c
shape upload stretch import: Store features in database. Still broken [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4314
diff
changeset
|
176 var ( |
3d6a2c6b436c
shape upload stretch import: Store features in database. Still broken [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4314
diff
changeset
|
177 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
|
178 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
|
179 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
|
180 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
|
181 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
|
182 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
|
183 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
|
184 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
|
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 |
3d6a2c6b436c
shape upload stretch import: Store features in database. Still broken [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4314
diff
changeset
|
187 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
|
188 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
|
189 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
|
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 |
3d6a2c6b436c
shape upload stretch import: Store features in database. Still broken [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4314
diff
changeset
|
192 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
|
193 {"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
|
194 {"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
|
195 {"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
|
196 {"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
|
197 {"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
|
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 {"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
|
200 {"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
|
201 {"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
|
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 |
3d6a2c6b436c
shape upload stretch import: Store features in database. Still broken [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4314
diff
changeset
|
204 nextField: |
3d6a2c6b436c
shape upload stretch import: Store features in database. Still broken [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4314
diff
changeset
|
205 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
|
206 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
|
207 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
|
208 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
|
209 *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
|
210 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
|
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 |
3d6a2c6b436c
shape upload stretch import: Store features in database. Still broken [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4314
diff
changeset
|
215 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
|
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 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
|
218 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
|
219 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
|
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 |
3d6a2c6b436c
shape upload stretch import: Store features in database. Still broken [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4314
diff
changeset
|
223 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
|
224 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
|
225 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
|
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 |
3d6a2c6b436c
shape upload stretch import: Store features in database. Still broken [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4314
diff
changeset
|
228 // 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
|
229 // 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
|
230 |
3d6a2c6b436c
shape upload stretch import: Store features in database. Still broken [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4314
diff
changeset
|
231 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
|
232 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
|
233 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
|
234 } |
3d6a2c6b436c
shape upload stretch import: Store features in database. Still broken [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4314
diff
changeset
|
235 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
|
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 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
|
238 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
|
239 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
|
240 } |
3d6a2c6b436c
shape upload stretch import: Store features in database. Still broken [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4314
diff
changeset
|
241 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
|
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 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
|
244 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
|
245 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
|
246 } |
3d6a2c6b436c
shape upload stretch import: Store features in database. Still broken [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4314
diff
changeset
|
247 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
|
248 |
4332
8080007d3c06
shape upload stretch import: Finished implementation (staging, summary).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4316
diff
changeset
|
249 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
|
250 if err != nil { |
8080007d3c06
shape upload stretch import: Finished implementation (staging, summary).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4316
diff
changeset
|
251 return nil, err |
8080007d3c06
shape upload stretch import: Finished implementation (staging, summary).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4316
diff
changeset
|
252 } |
8080007d3c06
shape upload stretch import: Finished implementation (staging, summary).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4316
diff
changeset
|
253 defer trackStmt.Close() |
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 var stretches []*stretchSummary |
8080007d3c06
shape upload stretch import: Finished implementation (staging, summary).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4316
diff
changeset
|
256 |
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
|
257 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
|
258 |
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 _, 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
|
260 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
|
261 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
|
262 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
|
263 } |
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 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
|
265 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
|
266 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
|
267 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
|
268 } |
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 |
4316
3d6a2c6b436c
shape upload stretch import: Store features in database. Still broken [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4314
diff
changeset
|
270 var ( |
4332
8080007d3c06
shape upload stretch import: Finished implementation (staging, summary).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4316
diff
changeset
|
271 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
|
272 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
|
273 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
|
274 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
|
275 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
|
276 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
|
277 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
|
278 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
|
279 ) |
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
|
280 |
4332
8080007d3c06
shape upload stretch import: Finished implementation (staging, summary).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4316
diff
changeset
|
281 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
|
282 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
|
283 |
3d6a2c6b436c
shape upload stretch import: Store features in database. Still broken [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4314
diff
changeset
|
284 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
|
285 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
|
286 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
|
287 continue |
3d6a2c6b436c
shape upload stretch import: Store features in database. Still broken [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4314
diff
changeset
|
288 } |
4314
c3b5cf2f200a
shape upload stretch import: Converted multi polygon to WKB.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4313
diff
changeset
|
289 |
4332
8080007d3c06
shape upload stretch import: Finished implementation (staging, summary).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4316
diff
changeset
|
290 countries, err := parseUniqueCountries(cnts) |
8080007d3c06
shape upload stretch import: Finished implementation (staging, summary).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4316
diff
changeset
|
291 if err != nil { |
8080007d3c06
shape upload stretch import: Finished implementation (staging, summary).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4316
diff
changeset
|
292 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
|
293 continue |
8080007d3c06
shape upload stretch import: Finished implementation (staging, summary).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4316
diff
changeset
|
294 } |
8080007d3c06
shape upload stretch import: Finished implementation (staging, summary).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4316
diff
changeset
|
295 |
4316
3d6a2c6b436c
shape upload stretch import: Store features in database. Still broken [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4314
diff
changeset
|
296 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
|
297 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
|
298 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 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
|
300 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
|
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 |
3d6a2c6b436c
shape upload stretch import: Store features in database. Still broken [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4314
diff
changeset
|
304 // 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
|
305 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
|
306 |
3d6a2c6b436c
shape upload stretch import: Store features in database. Still broken [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4314
diff
changeset
|
307 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
|
308 |
4316
3d6a2c6b436c
shape upload stretch import: Store features in database. Still broken [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4314
diff
changeset
|
309 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
|
310 ctx, |
3d6a2c6b436c
shape upload stretch import: Store features in database. Still broken [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4314
diff
changeset
|
311 name, |
3d6a2c6b436c
shape upload stretch import: Store features in database. Still broken [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4314
diff
changeset
|
312 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
|
313 area, |
3d6a2c6b436c
shape upload stretch import: Store features in database. Still broken [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4314
diff
changeset
|
314 objnam, |
3d6a2c6b436c
shape upload stretch import: Store features in database. Still broken [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4314
diff
changeset
|
315 nobjnamNull, |
3d6a2c6b436c
shape upload stretch import: Store features in database. Still broken [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4314
diff
changeset
|
316 date, |
3d6a2c6b436c
shape upload stretch import: Store features in database. Still broken [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4314
diff
changeset
|
317 source, |
3d6a2c6b436c
shape upload stretch import: Store features in database. Still broken [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4314
diff
changeset
|
318 ).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
|
319 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
|
320 } |
3d6a2c6b436c
shape upload stretch import: Store features in database. Still broken [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4314
diff
changeset
|
321 |
4332
8080007d3c06
shape upload stretch import: Finished implementation (staging, summary).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4316
diff
changeset
|
322 // Store the countries |
8080007d3c06
shape upload stretch import: Finished implementation (staging, summary).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4316
diff
changeset
|
323 for _, country := range countries { |
4388
eca3afe766d7
stretch shape import: Fixed db insert of countries.
Sascha Wilde <wilde@intevation.de>
parents:
4332
diff
changeset
|
324 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
|
325 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
|
326 } |
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
|
327 } |
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
|
328 |
4332
8080007d3c06
shape upload stretch import: Finished implementation (staging, summary).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4316
diff
changeset
|
329 // Finally track the stretch |
8080007d3c06
shape upload stretch import: Finished implementation (staging, summary).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4316
diff
changeset
|
330 |
8080007d3c06
shape upload stretch import: Finished implementation (staging, summary).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4316
diff
changeset
|
331 if _, err := trackStmt.ExecContext( |
8080007d3c06
shape upload stretch import: Finished implementation (staging, summary).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4316
diff
changeset
|
332 ctx, |
8080007d3c06
shape upload stretch import: Finished implementation (staging, summary).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4316
diff
changeset
|
333 importID, |
4389
5e38667f740c
Use stretches as areas of responsibility.
Sascha Wilde <wilde@intevation.de>
parents:
4332
diff
changeset
|
334 "users.stretches", |
4332
8080007d3c06
shape upload stretch import: Finished implementation (staging, summary).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4316
diff
changeset
|
335 id, |
8080007d3c06
shape upload stretch import: Finished implementation (staging, summary).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4316
diff
changeset
|
336 ); err != nil { |
8080007d3c06
shape upload stretch import: Finished implementation (staging, summary).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4316
diff
changeset
|
337 return nil, err |
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 |
8080007d3c06
shape upload stretch import: Finished implementation (staging, summary).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4316
diff
changeset
|
340 stretch := &stretchSummary{ |
8080007d3c06
shape upload stretch import: Finished implementation (staging, summary).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4316
diff
changeset
|
341 ID: id, |
8080007d3c06
shape upload stretch import: Finished implementation (staging, summary).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4316
diff
changeset
|
342 Name: name, |
8080007d3c06
shape upload stretch import: Finished implementation (staging, summary).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4316
diff
changeset
|
343 From: lower, |
8080007d3c06
shape upload stretch import: Finished implementation (staging, summary).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4316
diff
changeset
|
344 To: upper, |
8080007d3c06
shape upload stretch import: Finished implementation (staging, summary).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4316
diff
changeset
|
345 ObjNam: objnam, |
4506
e020e6e34ad7
Made 'go vet' happy again.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4390
diff
changeset
|
346 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
|
347 Countries: countries, |
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 |
8080007d3c06
shape upload stretch import: Finished implementation (staging, summary).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4316
diff
changeset
|
350 if nobjnamNull.Valid { |
8080007d3c06
shape upload stretch import: Finished implementation (staging, summary).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4316
diff
changeset
|
351 stretch.NObjNam = &nobjnamNull.String |
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 |
8080007d3c06
shape upload stretch import: Finished implementation (staging, summary).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4316
diff
changeset
|
354 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
|
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 |
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 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
|
358 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
|
359 } |
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 |
4332
8080007d3c06
shape upload stretch import: Finished implementation (staging, summary).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4316
diff
changeset
|
361 if len(stretches) == 0 { |
8080007d3c06
shape upload stretch import: Finished implementation (staging, summary).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4316
diff
changeset
|
362 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
|
363 } |
8080007d3c06
shape upload stretch import: Finished implementation (staging, summary).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4316
diff
changeset
|
364 |
8080007d3c06
shape upload stretch import: Finished implementation (staging, summary).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4316
diff
changeset
|
365 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
|
366 return nil, err |
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 |
8080007d3c06
shape upload stretch import: Finished implementation (staging, summary).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4316
diff
changeset
|
369 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
|
370 } |