-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathimport-and-publish-hfl-target-layer-from-csv.py
More file actions
122 lines (63 loc) · 2.1 KB
/
import-and-publish-hfl-target-layer-from-csv.py
File metadata and controls
122 lines (63 loc) · 2.1 KB
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
#!/usr/bin/env python
# coding: utf-8
# In[1]:
## IMPORT A CSV FILE TO CREATE A NEW CSV ITEM IN ARCGIS ONLINE
## THEN PUBLISH THAT CSV ITEM AS A NEW HOSTED FEATURE LAYER
##
## CSV sample data at the bottom
import os
from arcgis.gis import GIS
from IPython.display import display
# In[2]:
# connect to your ArcGIS Online account
portal_name = 'xxxxx'
user_name = 'xxxxx'
pwd = 'xxxxx'
gis = GIS('https://' + portal_name + '.maps.arcgis.com', user_name, pwd)
# In[3]:
# assuming for now that the files to import are in the CWD
data_path = os.getcwd()
print(data_path)
# In[4]:
csv_path = os.path.join(data_path, "test9.csv")
# In[5]:
csv_properties={'title':'test9',
'description':'lorem ipsum',
'tags': 'lorem ipsum'}
# In[6]:
# optional: but helps if new items have thumbnail images (600x400px)
thumbnail_path = os.path.join(data_path, 'testcsv.png')
# In[7]:
# create the new CSV item
new_csv_item = gis.content.add(item_properties=csv_properties,
data=csv_path,
thumbnail=thumbnail_path)
# In[8]:
new_csv_item # just a check, you can remove this
# In[9]:
# publish the new CSV item as a new hosted feature layer
new_feature_layer_item = new_csv_item.publish()
# In[10]:
new_feature_layer_item # just a check, you can remove this
# In[11]:
# if you want, you can load up a map component
# to draw the new hosted feature layer info
map1 = gis.map()
map1.extent = new_feature_layer_item.extent
map1
# In[12]:
# don't fret if your layer doesn't appear right away
# often takes 10 seconds or so to show up
map1.add_layer(new_feature_layer_item)
# In[ ]:
# test9.csv
# ID,GREEK,PHON,LONG,LAT,VAL,NOTES
# 0,ALPHA,ALPHA,-74.1,40.4,0,First Letter
# 1,BETA,BRAVO,-74.1,40.5,1,Second Letter
# 2,GAMMA,CHARLIE,-74.1,40.6,2,Third Letter
# 3,DELTA,DELTA,-74.2,40.4,3,Fourth Letter
# 4,EPSILON,ECHO,-74.2,40.5,4,Fifth Letter
# 5,ZETA,FOXTROT,-74.2,40.6,5,Sixth Letter
# 6,ETA,GOLF,-74.3,40.4,6,Seventh Letter
# 7,THETA,HOTEL,-74.3,40.5,7,Eighth Letter
# 8,IOTA,INDIA,-74.3,40.6,8,Ninth Letter