Mercurial > gemma
annotate pkg/imports/stsh.go @ 4314:c3b5cf2f200a
shape upload stretch import: Converted multi polygon to WKB.
author | Sascha L. Teichmann <sascha.teichmann@intevation.de> |
---|---|
date | Tue, 03 Sep 2019 17:12:07 +0200 |
parents | 5da02dcc51f6 |
children | 3d6a2c6b436c |
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" |
5da02dcc51f6
shape 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" |
4311
f9bb06f2dbe3
Added stub for a shape upload stretch import. POST /api/imports/stsh
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
31 ) |
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 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
|
34 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
|
35 } |
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 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
|
38 |
f9bb06f2dbe3
Added stub for a shape upload stretch import. POST /api/imports/stsh
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
39 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
|
40 |
f9bb06f2dbe3
Added stub for a shape upload stretch import. POST /api/imports/stsh
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
41 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
|
42 |
f9bb06f2dbe3
Added stub for a shape upload stretch import. POST /api/imports/stsh
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
43 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
|
44 |
f9bb06f2dbe3
Added stub for a shape upload stretch import. POST /api/imports/stsh
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
45 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
|
46 |
f9bb06f2dbe3
Added stub for a shape upload stretch import. POST /api/imports/stsh
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
47 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
|
48 |
f9bb06f2dbe3
Added stub for a shape upload stretch import. POST /api/imports/stsh
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
49 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
|
50 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
|
51 {"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
|
52 {}, |
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 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
|
57 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
|
58 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
|
59 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
|
60 ) error { |
f9bb06f2dbe3
Added stub for a shape upload stretch import. POST /api/imports/stsh
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
61 // 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
|
62 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
|
63 } |
f9bb06f2dbe3
Added stub for a shape upload stretch import. POST /api/imports/stsh
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
64 |
f9bb06f2dbe3
Added stub for a shape upload stretch import. POST /api/imports/stsh
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
65 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
|
66 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
|
67 } |
f9bb06f2dbe3
Added stub for a shape upload stretch import. POST /api/imports/stsh
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
68 |
f9bb06f2dbe3
Added stub for a shape upload stretch import. POST /api/imports/stsh
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
69 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
|
70 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
|
71 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
|
72 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
|
73 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
|
74 ) (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
|
75 |
5da02dcc51f6
shape upload stretch import: Started to decode geometries and attributes from uploaded shape file.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4311
diff
changeset
|
76 //start := time.Now() |
5da02dcc51f6
shape upload stretch import: Started to decode geometries and attributes from uploaded shape file.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4311
diff
changeset
|
77 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
|
78 |
5da02dcc51f6
shape upload stretch import: Started to decode geometries and attributes from uploaded shape file.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4311
diff
changeset
|
79 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
|
80 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
|
81 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
|
82 } |
5da02dcc51f6
shape upload stretch import: Started to decode geometries and attributes from uploaded shape file.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4311
diff
changeset
|
83 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
|
84 |
5da02dcc51f6
shape upload stretch import: Started to decode geometries and attributes from uploaded shape file.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4311
diff
changeset
|
85 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
|
86 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
|
87 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
|
88 } |
5da02dcc51f6
shape upload stretch import: Started to decode geometries and attributes from uploaded shape file.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4311
diff
changeset
|
89 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
|
90 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
|
91 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
|
92 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
|
93 } |
5da02dcc51f6
shape upload stretch import: Started to decode geometries and attributes from uploaded shape file.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4311
diff
changeset
|
94 |
5da02dcc51f6
shape upload stretch import: Started to decode geometries and attributes from uploaded shape file.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4311
diff
changeset
|
95 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
|
96 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
|
97 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
|
98 } |
5da02dcc51f6
shape upload stretch import: Started to decode geometries and attributes from uploaded shape file.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4311
diff
changeset
|
99 |
5da02dcc51f6
shape upload stretch import: Started to decode geometries and attributes from uploaded shape file.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4311
diff
changeset
|
100 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
|
101 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
|
102 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
|
103 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
|
104 } |
5da02dcc51f6
shape upload stretch import: Started to decode geometries and attributes from uploaded shape file.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4311
diff
changeset
|
105 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
|
106 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
|
107 |
5da02dcc51f6
shape 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 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
|
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 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
|
111 |
5da02dcc51f6
shape 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 _, 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
|
113 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
|
114 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
|
115 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
|
116 } |
5da02dcc51f6
shape 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 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
|
118 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
|
119 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
|
120 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
|
121 } |
5da02dcc51f6
shape 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 |
5da02dcc51f6
shape 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 // Convert to a multi polygon. |
5da02dcc51f6
shape 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 mp := poly.MultiPolygonGeom() |
5da02dcc51f6
shape 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 |
4314
c3b5cf2f200a
shape upload stretch import: Converted multi polygon to WKB.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4313
diff
changeset
|
126 wkb := mp.AsWKB() |
c3b5cf2f200a
shape upload stretch import: Converted multi polygon to WKB.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4313
diff
changeset
|
127 |
c3b5cf2f200a
shape upload stretch import: Converted multi polygon to WKB.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4313
diff
changeset
|
128 _ = wkb |
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
|
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 for k, f := range 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
|
131 name := f.String() |
5da02dcc51f6
shape 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 val := sr.Attribute(k) |
5da02dcc51f6
shape 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 log.Printf("info: \t%s = %v\n", name, val) |
5da02dcc51f6
shape 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 } |
5da02dcc51f6
shape 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 // 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
|
137 } |
5da02dcc51f6
shape 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 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
|
140 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
|
141 } |
5da02dcc51f6
shape upload stretch import: Started to decode geometries and attributes from uploaded shape file.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4311
diff
changeset
|
142 |
4311
f9bb06f2dbe3
Added stub for a shape upload stretch import. POST /api/imports/stsh
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
143 return nil, nil |
f9bb06f2dbe3
Added stub for a shape upload stretch import. POST /api/imports/stsh
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
144 } |