-
Notifications
You must be signed in to change notification settings - Fork 168
/
Copy pathhd.hdfs.in.vector.py
executable file
·77 lines (64 loc) · 1.71 KB
/
hd.hdfs.in.vector.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#!/usr/bin/env python3
############################################################################
#
# MODULE: hd.hdfs.in.vector
# AUTHOR(S): Matej Krejci ([email protected]
#
# COPYRIGHT: (C) 2016 by the GRASS Development Team
#
# This program is free software under the GNU General
# Public License (>=v2). Read the file COPYING that
# comes with GRASS for details.
#
#############################################################################
# %module
# % description: Module for export vector feature to hdfs(JSON)
# % keyword: database
# % keyword: hdfs
# %end
# %option
# % key: hdfs
# % type: string
# % answer: @grass_data_hdfs
# % required: yes
# % description: HDFS path or default grass dataset
# %end
# %option
# % key: driver
# % type: string
# % required: yes
# % options: webhdfs,hdfs
# % description: HDFS driver
# %end
# %option G_OPT_V_MAP
# % key: map
# % required: yes
# % label: Name of vector map to export to hdfs
# %end
# %option G_OPT_V_TYPE
# % key: type
# % required: yes
# %end
# %option G_OPT_V_FIELD
# % key: layer
# % required: yes
# %end
import grass.script as gs
from hdfsgrass.hdfs_grass_lib import JSONBuilder, GrassHdfs
def main():
transf = GrassHdfs(options["driver"])
if options["hdfs"] == "@grass_data_hdfs":
options["hdfs"] = transf.get_path_grass_dataset()
gs.message(options["hdfs"])
grass_map = {
"map": options["map"],
"layer": options["layer"],
"type": options["type"],
}
json = JSONBuilder(grass_map)
json = json.get_JSON()
gs.message("upload %s" % json)
transf.upload(json, options["hdfs"])
if __name__ == "__main__":
options, flags = gs.parser()
main()