|
POST
|
Hi Dan, thanks for your last try. Main is obviously executed because I get the error message as defined in line 98.
... View more
05-02-2017
01:57 AM
|
0
|
3
|
4140
|
|
POST
|
Of course it is not meant to be without parameters but I was trying if it works with or without receiving the parameters through the tool. I was assuming that if the parameters are hard coded the script should just run as it is running in pyscripter, in cmd and in the python window in ArcGIS 10.4 - but it is not. That is why I was asking for help. My script as I posted it is taking the paths as parameters. But no matter if I take them as parameters or hard coded the script won't find any files in my directory when executed as Script Tool.
... View more
05-01-2017
11:58 PM
|
0
|
5
|
4140
|
|
POST
|
Hi Dan & Neil, ok, here comes the whole script. It might look in some parts familiar, still dealing with my profiles. But at least it's in general working fine....: That the _location variable had the underscore is only due to the programming habits of my colleague...(doesn't make a difference) import arcpy
import os
import numpy as np
import unicodedata
import codecs
import csv
#Workspace settings
arcpy.env.overwriteOutput= True
#input file
##location_for_tables = r"C:\data\2017\LakeKivu\Data\Python_testing\python\Pilot\source"
location_for_tables = arcpy.GetParameterAsText(0)
#output folder
##DirOutTables = r"C:\data\2017\LakeKivu\Data\Python_testing\python\Pilot\attachments"
DirOutTables= arcpy.GetParameterAsText(1)
def FindFiles(location):
arcpy.env.workspace = location
ListFiles=arcpy.ListFiles("*.txt")
return ListFiles
def unique_values(table, field):
with arcpy.da.SearchCursor(table, [field]) as cursor:
return sorted({row[0] for row in cursor})
def CreateTableView(location, filename):
arcpy.env.overwriteOutput = True
complete_filename = os.path.join(location, filename)
arcpy.MakeTableView_management(complete_filename, "kibu_tview")
return "kibu_tview"
def store_table(table):
arcpy.AddMessage("open "+table)
profile_nrs=unique_values(table, "Station")
arcpy.AddMessage(profile_nrs)
#get field names
desc = arcpy.Describe(table)
fieldnames=[field.name.encode("utf-8") for field in desc.fields]
#safe header line
tablefile=location_for_tables+"\\"+table #original table
# Select rows by station nr and save to txt file
for profile in profile_nrs:
if profile >0:
expression="Station="+str(profile)
print(expression)
with arcpy.da.SearchCursor(table,"*",expression) as sCursor:
for sRow in sCursor:
table_name=str(sRow[0])+"_"+str(sRow[1])+".txt"
filepath=DirOutTables +"\\"+ table_name #seperated tables
UIDvalue=str(sRow[0])+"_"+str(sRow[1])
break
if arcpy.Exists(filepath):
arcpy.AddMessage("Table "+table_name+" exists")
else:
with open(tablefile, 'r') as t:
with open(filepath, 'a') as f:
w = csv.writer(f, delimiter="\t", lineterminator='\n')
r = csv.reader(t, delimiter="\t")
all=[]
header=r.next()
header.append('UPI')
all.append(header)
##print(header)
for sRow in sCursor:
sRow=sRow + (UIDvalue,)
all.append(sRow)
w.writerows(all)
del sRow
arcpy.AddMessage("Table "+table_name+" created")
else:
print("empty line")
def main():
#input file
##location_for_tables = r"C:\data\2017\LakeKivu\Data\Python_testing\python\Pilot\source"
location_for_tables = arcpy.GetParameterAsText(0)
#output folder
##DirOutTables = r"C:\data\2017\LakeKivu\Data\Python_testing\python\Pilot\attachments"
DirOutTables= arcpy.GetParameterAsText(1)
# Step 1: find the source files to process
list_of_files = FindFiles(location_for_tables)
if len(list_of_files)==0:
arcpy.AddError("list empty")
sys.exit()
else:
arcpy.AddMessage(list_of_files)
# Step2: prozess each file to create a point in points
for each_file in list_of_files:
# create and save sub tables
store_table(each_file)
if __name__ == '__main__':
main() I don't see why the script should work in PyScripter, in the command window, in the python window in ArcGIS but not as a tool even if don't use any parameters. The difference I find between executing the tool and the same script in cmd is that in ArcGIS it does not put the paths in "path comes here" but in cmd they are required.
... View more
04-28-2017
07:45 AM
|
0
|
7
|
4140
|
|
POST
|
Hi Neil, thanks for your reply. In the script tool properties the data type for both folders is "folder", both are required, input and no multivalue. I don't have try / except blocks. I'm using Python 2.7 in ArcGIS 10.4.1, PyScripter 2.6, all running on Windows 10. Thank you! Here is my main() function: def main():
#input file
##_location_for_tables = r"C:\data\2017\LakeKivu\Data\Python_testing\python\Pilot\source"
_location_for_tables = arcpy.GetParameterAsText(0)
#output folder
##DirOutTables = r"C:\data\2017\LakeKivu\Data\Python_testing\python\Pilot\attachments"
DirOutTables= arcpy.GetParameterAsText(1)
# Step 1: find the source files to process
list_of_files = FindFiles(_location_for_tables)
if list_of_files==[]:
arcpy.AddError("list empty")
else:
arcpy.AddMessage(list_of_files)
# Step2: prozess each file to create a point in points
for each_file in list_of_files:
# create and save sub tables
store_table(each_file)
... View more
04-28-2017
06:01 AM
|
0
|
10
|
4140
|
|
POST
|
Hello friendly people, I have written a python script to split up text files. It has an input folder (and an output folder) that I refer to in the beginning: hardcoded version: _location_for_tables = r"C:\data\2017\LakeKivu\Data\Python_testing\python\Pilot\source" script tool version: _location_for_tables = arcpy.GetParameterAsText(0) When I execute the script in Pyscripter and in the command window, also in the python window in ArcGIS, everything runs as expected. But when I run it as a script tool it doesn't find my files. I tried it with the hardcoded path in the script and with an input field where I selected the (same) folder - no difference. I tried to put the path variables in my main() function and in the beginning of my script - no difference. The only error message I receive is my defined message when the list of files is empty. Has anyone an idea where the problem is? Please let me know if you need more details. Thanks in advance!
... View more
04-28-2017
05:05 AM
|
0
|
13
|
6362
|
|
POST
|
Hi Riyas Deen, I was looking for the possibility to replace the elevation widget by rscheitlin by the functionality of the elevation template and I think you are giving here the solution. Unfortunately I am not sure where to put what. Can you tell me which part (or the whole js folder?) of the js folder should go into my app's js folder? And where do I call it's functionality? I am using WAB2.4 and know how to add widgets like the elevation widget or enhanced search widget but this looks a bit different. Thanks in advance!
... View more
04-03-2017
02:35 AM
|
2
|
0
|
2307
|
|
DOC
|
Thank you Robert for the reply. Looks like I have to try a bit myself. But if it would be that easy then you would have done it already I guess....
... View more
04-02-2017
11:36 PM
|
1
|
0
|
14886
|
|
DOC
|
Hi Robert, Am I right that this is still not implemented? I was hoping to have the same functionality with your widget as I got with the Elevation template. I would like to select a route and see its profile.
... View more
03-31-2017
01:02 AM
|
0
|
0
|
14886
|
|
POST
|
Thank you Jonathan! Looks like I have to dig a bit deeper...
... View more
03-29-2017
12:07 AM
|
0
|
0
|
4948
|
|
POST
|
I would like to update a webmap through json with Python. I know that I could use the AGOL Assistant to change the json of a specific webmap but just as an example: If I want to change the same thing in all of my webmaps (e.g. changing a layer or a bookmark name or the bookmarks in general...) it would be more comfortable to "grab" all my webmaps from my AGOL content, make the changes (at the moment I'm just replacing for example "Berlin" as a bookmark name by "Berlin, Germany") and update my webmaps in AGOL. I have seen this ArcGIS REST API Update function but I don't understand how to use it. I have tried update-webmap-json at master · from GitHub but I don't see at which point I should apply my edits to the json in order to see if anything happened when doing the update. Did anyone manage to work with this? I learned thanks to this post Edit or update ArcGIS Online Web Map data using the REST API that I can pull the data with http://www.arcgis.com/sharing/rest/content/items/ITEMID/data and should be able to update with http://www.arcgis.com/sharing/rest/content/users/USER_ID/items/ITEM_ID/update. I attached my script in case someone feels like testing. Here is in brief what I do with my script: set username and password define (for testing) which webmap to take Read map(s) from Content and save to mxd and json Before updating I open the json, do my changes, save it to the same file. At the next step I am not sure which "stage" of the json I have to use to upload it and I don't really understand what lines from line 51 are actually doing. Maybe someone can point me where this actual update request is better described. The result is that my script runs smoothly showing all the prints, no errors, but when I check the bookmark in my webmap that I intended to change it is still the same. Thank you very much in advance!
... View more
03-28-2017
03:11 AM
|
0
|
3
|
6886
|
|
POST
|
Please vote here: https://community.esri.com/ideas/13270
... View more
03-23-2017
03:34 AM
|
0
|
0
|
1231
|
|
POST
|
Thank you Jonathan! Now it makes sense to me how to use the ConvertWebMapToMapDocument. My intention is to have a local copy of the map definition, that is what I call a Backup. Saving a second copy in the same location might help if someone is spoiling the original one by accident. But if for example my subscription expires I can't access my AGOL items anymore. I agree that I won't be able to restore my original webmap with this with one click but at least I can save the map composition.
... View more
03-16-2017
12:43 AM
|
0
|
0
|
1630
|
|
POST
|
I am trying to somehow backup WebMaps from AGOL and am thinking the ConvertWebMapToMapDocument function could be helpful with this. I thought of saving (1) the json file itself and (2) save it as mxd. While I think saving the json file itself shouldn't be that dificult, I'm struggeling finding a way to make ConvertWebMapToMapDocument work. Unfortunately, when looking through different examples in the documentation and through the web, I always find a WebMap_as_JSON variable (or similar named) that gets its value from a tool as it seems (getAttributeAsText(0)). I assume that it expects the json code of the WebMap which could be this one http://www.arcgis.com/sharing/rest/content/items/95562b6a24994641bbbaa3d1f2b7cf4f/data?f=pjson. I managed to read the content by adding jsonResponse = urllib.urlopen(webmap)
WebMap_as_JSON = json.loads(jsonResponse.read()) When I print now WebMap_as_JSON I get the same content as at the URL above though in a different order. But when I try to convert now my WebMap_as_JSON to a mapdocument with result = arcpy.mapping.ConvertWebMapToMapDocument(WebMap_as_JSON) I receive a Runtime Error: RuntimeError: Expected to find comma, colon or start of array; state : startOfObject; buffer : {u'authoringAppVersion': u'5.1', u'authoringApp': So I assume it's still not the right content as the input. I would highly appreciate if someone could give me a hint how to get the right input for ConvertWebMapToMapDocument. Thanks a lot! For you to try, this is what I have so far: import arcrest
import arcpy, urllib, urllib2, json
webmap="http://www.arcgis.com/sharing/rest/content/items/95562b6a24994641bbbaa3d1f2b7cf4f/data?f=pjson"
jsonResponse = urllib.urlopen(webmap)
WebMap_as_JSON = json.loads(jsonResponse.read())
print(WebMap_as_JSON)
result = arcpy.mapping.ConvertWebMapToMapDocument(WebMap_as_JSON)
mxd = result.mapDocument
mxd.saveACopy(r"<here is my path to the output mxd file>")
print("Map document saved")
... View more
03-14-2017
05:10 AM
|
0
|
2
|
2884
|
| Title | Kudos | Posted |
|---|---|---|
| 1 | 06-09-2023 03:26 AM | |
| 1 | 02-13-2019 01:51 AM | |
| 2 | 04-03-2025 11:07 AM | |
| 1 | 01-14-2024 01:34 PM | |
| 1 | 10-01-2018 10:23 PM |
| Online Status |
Offline
|
| Date Last Visited |
Friday
|