Mercurial > gemma
annotate pkg/imports/stsh.go @ 4316:3d6a2c6b436c
shape upload stretch import: Store features in database. Still broken [WIP].
author | Sascha L. Teichmann <sascha.teichmann@intevation.de> |
---|---|
date | Tue, 03 Sep 2019 19:01:51 +0200 |
parents | c3b5cf2f200a |
children | 8080007d3c06 |
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" |
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
|
22 "log" |
4311
f9bb06f2dbe3
Added stub for a shape upload stretch import. POST /api/imports/stsh
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
23 "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
|
24 "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
|
25 "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
|
26 "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
|
27 "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
|
28 |
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 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
|
30 |
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
|
31 "gemma.intevation.de/gemma/pkg/common" |
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 |
f9bb06f2dbe3
Added stub for a shape upload stretch import. POST /api/imports/stsh
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
34 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
|
35 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
|
36 } |
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 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
|
39 |
f9bb06f2dbe3
Added stub for a shape upload stretch import. POST /api/imports/stsh
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
40 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
|
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 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
|
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 (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
|
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) 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
|
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) 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
|
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) Depends() [2][]string { |
f9bb06f2dbe3
Added stub for a shape upload stretch import. POST /api/imports/stsh
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
51 return [2][]string{ |
f9bb06f2dbe3
Added stub for a shape upload stretch import. POST /api/imports/stsh
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
52 {"stretches", "stretch_countries"}, |
f9bb06f2dbe3
Added stub for a shape upload stretch import. POST /api/imports/stsh
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
53 {}, |
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 } |
f9bb06f2dbe3
Added stub for a shape upload stretch import. POST /api/imports/stsh
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
56 |
4316
3d6a2c6b436c
shape upload stretch import: Store features in database. Still broken [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4314
diff
changeset
|
57 const ( |
3d6a2c6b436c
shape upload stretch import: Store features in database. Still broken [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4314
diff
changeset
|
58 stshInsertSQL = ` |
3d6a2c6b436c
shape upload stretch import: Store features in database. Still broken [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4314
diff
changeset
|
59 INSERT INTO waterway.stretches ( |
3d6a2c6b436c
shape upload stretch import: Store features in database. Still broken [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4314
diff
changeset
|
60 name, |
3d6a2c6b436c
shape upload stretch import: Store features in database. Still broken [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4314
diff
changeset
|
61 stretch, |
3d6a2c6b436c
shape upload stretch import: Store features in database. Still broken [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4314
diff
changeset
|
62 area, |
3d6a2c6b436c
shape upload stretch import: Store features in database. Still broken [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4314
diff
changeset
|
63 objnam, |
3d6a2c6b436c
shape upload stretch import: Store features in database. Still broken [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4314
diff
changeset
|
64 nobjnam, |
3d6a2c6b436c
shape upload stretch import: Store features in database. Still broken [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4314
diff
changeset
|
65 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
|
66 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
|
67 ) VALUES ( |
3d6a2c6b436c
shape upload stretch import: Store features in database. Still broken [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4314
diff
changeset
|
68 $1, |
3d6a2c6b436c
shape upload stretch import: Store features in database. Still broken [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4314
diff
changeset
|
69 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
|
70 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
|
71 $5, |
3d6a2c6b436c
shape upload stretch import: Store features in database. Still broken [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4314
diff
changeset
|
72 $6, |
3d6a2c6b436c
shape upload stretch import: Store features in database. Still broken [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4314
diff
changeset
|
73 $7, |
3d6a2c6b436c
shape upload stretch import: Store features in database. Still broken [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4314
diff
changeset
|
74 $8) |
3d6a2c6b436c
shape upload stretch import: Store features in database. Still broken [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4314
diff
changeset
|
75 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
|
76 ) |
3d6a2c6b436c
shape upload stretch import: Store features in database. Still broken [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4314
diff
changeset
|
77 |
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 { |
f9bb06f2dbe3
Added stub for a shape upload stretch import. POST /api/imports/stsh
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
83 // TODO: Implement me! |
f9bb06f2dbe3
Added stub for a shape upload stretch import. POST /api/imports/stsh
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
84 return nil |
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 |
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 |
4311
f9bb06f2dbe3
Added stub for a shape upload stretch import. POST /api/imports/stsh
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
95 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
|
96 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
|
97 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
|
98 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
|
99 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
|
100 ) (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
|
101 |
4316
3d6a2c6b436c
shape upload stretch import: Store features in database. Still broken [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4314
diff
changeset
|
102 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
|
103 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
|
104 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
|
105 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
|
106 }() |
3d6a2c6b436c
shape upload stretch import: Store features in database. Still broken [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4314
diff
changeset
|
107 |
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
|
108 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
|
109 |
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
|
110 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
|
111 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
|
112 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
|
113 } |
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
|
114 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
|
115 |
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
|
116 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
|
117 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
|
118 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
|
119 } |
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
|
120 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
|
121 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
|
122 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
|
123 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
|
124 } |
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
|
125 |
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
|
126 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
|
127 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
|
128 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
|
129 } |
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
|
130 |
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
|
131 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
|
132 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
|
133 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
|
134 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
|
135 } |
5da02dcc51f6
shape upload stretch import: Started to decode geometries and attributes from uploaded shape file.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4311
diff
changeset
|
136 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
|
137 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
|
138 |
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
|
139 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
|
140 |
4316
3d6a2c6b436c
shape upload stretch import: Store features in database. Still broken [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4314
diff
changeset
|
141 // 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
|
142 |
3d6a2c6b436c
shape upload stretch import: Store features in database. Still broken [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4314
diff
changeset
|
143 var ( |
3d6a2c6b436c
shape upload stretch import: Store features in database. Still broken [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4314
diff
changeset
|
144 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
|
145 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
|
146 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
|
147 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
|
148 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
|
149 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
|
150 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
|
151 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
|
152 ) |
3d6a2c6b436c
shape upload stretch import: Store features in database. Still broken [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4314
diff
changeset
|
153 |
3d6a2c6b436c
shape upload stretch import: Store features in database. Still broken [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4314
diff
changeset
|
154 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
|
155 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
|
156 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
|
157 } |
3d6a2c6b436c
shape upload stretch import: Store features in database. Still broken [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4314
diff
changeset
|
158 |
3d6a2c6b436c
shape upload stretch import: Store features in database. Still broken [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4314
diff
changeset
|
159 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
|
160 {"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
|
161 {"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
|
162 {"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
|
163 {"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
|
164 {"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
|
165 {"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
|
166 {"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
|
167 {"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
|
168 {"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
|
169 } |
3d6a2c6b436c
shape upload stretch import: Store features in database. Still broken [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4314
diff
changeset
|
170 |
3d6a2c6b436c
shape upload stretch import: Store features in database. Still broken [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4314
diff
changeset
|
171 nextField: |
3d6a2c6b436c
shape upload stretch import: Store features in database. Still broken [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4314
diff
changeset
|
172 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
|
173 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
|
174 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
|
175 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
|
176 *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
|
177 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
|
178 } |
3d6a2c6b436c
shape upload stretch import: Store features in database. Still broken [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4314
diff
changeset
|
179 } |
3d6a2c6b436c
shape upload stretch import: Store features in database. Still broken [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4314
diff
changeset
|
180 } |
3d6a2c6b436c
shape upload stretch import: Store features in database. Still broken [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4314
diff
changeset
|
181 |
3d6a2c6b436c
shape upload stretch import: Store features in database. Still broken [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4314
diff
changeset
|
182 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
|
183 |
3d6a2c6b436c
shape upload stretch import: Store features in database. Still broken [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4314
diff
changeset
|
184 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
|
185 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
|
186 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
|
187 } |
3d6a2c6b436c
shape upload stretch import: Store features in database. Still broken [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4314
diff
changeset
|
188 } |
3d6a2c6b436c
shape upload stretch import: Store features in database. Still broken [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4314
diff
changeset
|
189 |
3d6a2c6b436c
shape upload stretch import: Store features in database. Still broken [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4314
diff
changeset
|
190 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
|
191 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
|
192 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
|
193 } |
3d6a2c6b436c
shape upload stretch import: Store features in database. Still broken [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4314
diff
changeset
|
194 |
3d6a2c6b436c
shape upload stretch import: Store features in database. Still broken [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4314
diff
changeset
|
195 // 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
|
196 // 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
|
197 |
3d6a2c6b436c
shape upload stretch import: Store features in database. Still broken [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4314
diff
changeset
|
198 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
|
199 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
|
200 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
|
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 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
|
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 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
|
205 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
|
206 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
|
207 } |
3d6a2c6b436c
shape upload stretch import: Store features in database. Still broken [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4314
diff
changeset
|
208 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
|
209 |
3d6a2c6b436c
shape upload stretch import: Store features in database. Still broken [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4314
diff
changeset
|
210 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
|
211 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
|
212 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
|
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 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
|
215 |
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
|
216 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
|
217 |
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
|
218 _, 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
|
219 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
|
220 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
|
221 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
|
222 } |
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
|
223 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
|
224 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
|
225 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
|
226 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
|
227 } |
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
|
228 |
4316
3d6a2c6b436c
shape upload stretch import: Store features in database. Still broken [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4314
diff
changeset
|
229 var ( |
3d6a2c6b436c
shape upload stretch import: Store features in database. Still broken [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4314
diff
changeset
|
230 name = fixAttribute(sr.Attribute(nameIdx)) |
3d6a2c6b436c
shape upload stretch import: Store features in database. Still broken [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4314
diff
changeset
|
231 objnam = fixAttribute(sr.Attribute(objnamIdx)) |
3d6a2c6b436c
shape upload stretch import: Store features in database. Still broken [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4314
diff
changeset
|
232 nobjnam = fixAttribute(sr.Attribute(nobjnamIdx)) |
3d6a2c6b436c
shape upload stretch import: Store features in database. Still broken [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4314
diff
changeset
|
233 lower = fixAttribute(sr.Attribute(lowerIdx)) |
3d6a2c6b436c
shape upload stretch import: Store features in database. Still broken [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4314
diff
changeset
|
234 upper = fixAttribute(sr.Attribute(upperIdx)) |
3d6a2c6b436c
shape upload stretch import: Store features in database. Still broken [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4314
diff
changeset
|
235 dateInfo = fixAttribute(sr.Attribute(dateInfoIdx)) |
3d6a2c6b436c
shape upload stretch import: Store features in database. Still broken [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4314
diff
changeset
|
236 source = fixAttribute(sr.Attribute(sourceIdx)) |
3d6a2c6b436c
shape upload stretch import: Store features in database. Still broken [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4314
diff
changeset
|
237 countries = fixAttribute(sr.Attribute(countriesIdx)) |
3d6a2c6b436c
shape upload stretch import: Store features in database. Still broken [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4314
diff
changeset
|
238 ) |
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
|
239 |
4316
3d6a2c6b436c
shape upload stretch import: Store features in database. Still broken [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4314
diff
changeset
|
240 log.Printf("name : %+q\n", name) |
3d6a2c6b436c
shape upload stretch import: Store features in database. Still broken [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4314
diff
changeset
|
241 log.Printf("objnam : %+q\n", objnam) |
3d6a2c6b436c
shape upload stretch import: Store features in database. Still broken [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4314
diff
changeset
|
242 log.Printf("nobjnam : %+q\n", nobjnam) |
3d6a2c6b436c
shape upload stretch import: Store features in database. Still broken [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4314
diff
changeset
|
243 log.Printf("lower : %+q\n", lower) |
3d6a2c6b436c
shape upload stretch import: Store features in database. Still broken [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4314
diff
changeset
|
244 log.Printf("upper : %+q\n", upper) |
3d6a2c6b436c
shape upload stretch import: Store features in database. Still broken [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4314
diff
changeset
|
245 log.Printf("dateinfo : %+q\n", dateInfo) |
3d6a2c6b436c
shape upload stretch import: Store features in database. Still broken [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4314
diff
changeset
|
246 log.Printf("source : %+q\n", source) |
3d6a2c6b436c
shape upload stretch import: Store features in database. Still broken [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4314
diff
changeset
|
247 log.Printf("countries: %+q\n", countries) |
3d6a2c6b436c
shape upload stretch import: Store features in database. Still broken [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4314
diff
changeset
|
248 |
3d6a2c6b436c
shape upload stretch import: Store features in database. Still broken [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4314
diff
changeset
|
249 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
|
250 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
|
251 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
|
252 continue |
3d6a2c6b436c
shape upload stretch import: Store features in database. Still broken [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4314
diff
changeset
|
253 } |
4314
c3b5cf2f200a
shape upload stretch import: Converted multi polygon to WKB.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4313
diff
changeset
|
254 |
4316
3d6a2c6b436c
shape upload stretch import: Store features in database. Still broken [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4314
diff
changeset
|
255 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
|
256 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
|
257 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
|
258 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
|
259 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
|
260 } |
3d6a2c6b436c
shape upload stretch import: Store features in database. Still broken [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4314
diff
changeset
|
261 } |
3d6a2c6b436c
shape upload stretch import: Store features in database. Still broken [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4314
diff
changeset
|
262 |
3d6a2c6b436c
shape upload stretch import: Store features in database. Still broken [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4314
diff
changeset
|
263 // 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
|
264 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
|
265 |
3d6a2c6b436c
shape upload stretch import: Store features in database. Still broken [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4314
diff
changeset
|
266 log.Printf("len geom: %d\n", len(area)) |
3d6a2c6b436c
shape upload stretch import: Store features in database. Still broken [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4314
diff
changeset
|
267 |
3d6a2c6b436c
shape upload stretch import: Store features in database. Still broken [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4314
diff
changeset
|
268 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
|
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 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
|
271 ctx, |
3d6a2c6b436c
shape upload stretch import: Store features in database. Still broken [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4314
diff
changeset
|
272 name, |
3d6a2c6b436c
shape upload stretch import: Store features in database. Still broken [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4314
diff
changeset
|
273 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
|
274 area, |
3d6a2c6b436c
shape upload stretch import: Store features in database. Still broken [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4314
diff
changeset
|
275 objnam, |
3d6a2c6b436c
shape upload stretch import: Store features in database. Still broken [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4314
diff
changeset
|
276 nobjnamNull, |
3d6a2c6b436c
shape upload stretch import: Store features in database. Still broken [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4314
diff
changeset
|
277 date, |
3d6a2c6b436c
shape upload stretch import: Store features in database. Still broken [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4314
diff
changeset
|
278 source, |
3d6a2c6b436c
shape upload stretch import: Store features in database. Still broken [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4314
diff
changeset
|
279 ).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
|
280 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
|
281 } |
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 log.Println("after insert") |
3d6a2c6b436c
shape upload stretch import: Store features in database. Still broken [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4314
diff
changeset
|
284 |
3d6a2c6b436c
shape upload stretch import: Store features in database. Still broken [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4314
diff
changeset
|
285 for _, country := range strings.Split(countries, ",") { |
3d6a2c6b436c
shape upload stretch import: Store features in database. Still broken [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4314
diff
changeset
|
286 if country = strings.TrimSpace(country); country == "" { |
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 } |
3d6a2c6b436c
shape upload stretch import: Store features in database. Still broken [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4314
diff
changeset
|
289 if _, err := insCountryStmt.ExecContext(ctx, country); 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
|
290 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
|
291 } |
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
|
292 } |
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
|
293 |
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
|
294 // TODO: Implement me! |
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
|
295 } |
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
|
296 |
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
|
297 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
|
298 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
|
299 } |
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
|
300 |
4316
3d6a2c6b436c
shape upload stretch import: Store features in database. Still broken [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4314
diff
changeset
|
301 return nil, errors.New("Not implemented, yet!") |
4311
f9bb06f2dbe3
Added stub for a shape upload stretch import. POST /api/imports/stsh
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
302 } |