|
POST
|
Hello, I'm still working on my profiles with points etc. Now I am facing a problem with my da.SearchCursor. While it was working well with my original tables, it is not respecting my where_clause any longer since I reduced the tables to the attributes I actually need. def store_table(table):
arcpy.AddMessage("open "+table)
#get field names
desc = arcpy.Describe(table)
fieldnames=[field.name.encode("utf-8") for field in desc.fields]
#get profile numbers
profile_nrs=unique_values(table, "Profile No")
arcpy.AddMessage(profile_nrs)
tablefile=location_for_tables+"\\"+table #modified table
# Select rows by station nr and save to txt file
for profile in profile_nrs:
if profile is not None and profile!=0:
expression="'Profile No'='"+str(profile)+"'"
arcpy.AddMessage(expression)
with arcpy.da.SearchCursor(table,"*",where_clause=expression) as sCursor:
for sRow in sCursor:
table_name=str(sRow[2])+"_"+str(sRow[3])+"_.txt" #Campaign + Profile_No
arcpy.AddMessage("table_name="+table_name)
filepath=DirOutTables +"\\"+ table_name #seperated tables
UIDvalue=str(sRow[2])+"_"+str(sRow[3])
UIDGraphValue=UIDvalue+"_"
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")
allnewtable=[]
theader=r.next()
theader.append('UID')
theader.append('UIDGraph')
allnewtable.append(theader)
arcpy.AddMessage(theader)
for sRow in sCursor:
sRowNew=sRow + (UIDvalue,UIDGraphValue)
allnewtable.append(sRowNew)
w.writerows(allnewtable)
del sRow
print("Table "+table_name+" created")
arcpy.AddMessage("Table "+table_name+" created")
else:
print("empty line") In my test file I have 4 profiles in profile_nrs and with each loop through "for profile in profile_nrs" the expression is iterated correctly. But obviously the where_clause is not respected because sRow[3] is always 1. Also when I hard-code the expression with where_clause="'Profile_No'='4'" it still gives me back the whole table. I thought maybe I used the sCursor already in another part of the script but that's not the case. I tried the expression without putting the number in quotation marks but then it's not a valid sql expression it says. There is no error message and the script runs through up to the end, with the only mistake that it creates only one table instead of four. Do you have an idea what goes wrong? Thanks in advance!
... View more
10-05-2017
01:43 AM
|
0
|
7
|
1905
|
|
POST
|
One of our clients has following problem: He opens a survey from collector and fills automatically a couple of fields by pulldata. On Windows and iPhone this works like a charm but not when opening the survey on his Android tablet. Unfortunately I don't have an Android device at hand to test it myself. Is this a known issue? Is there a work around?
... View more
09-21-2017
06:26 AM
|
0
|
8
|
2644
|
|
POST
|
I'm not sure if it would really help to post the full 250 lines of my script...
... View more
09-16-2017
03:07 PM
|
0
|
0
|
1565
|
|
POST
|
Thanks Dan, I have to work with txt files. Both, the brackets and the word "Cruise" are only to find in the header of the txt file(s). I think I was trying it in the wrong place. Obviously I had the lines below already in a different position in my script (except of the Cruise line) which worked and the one I posted above didn't do anything. So when I added now the Cruise replacement it worked. with open(tablefile, 'r') as txtfile:
txtdata=txtfile.read()
txtdata=txtdata.replace("[","(")
txtdata=txtdata.replace("]",")")
txtdata=txtdata.replace("Cruise","Campaign")
with open(tablefile, 'w') as txtfile:
txtfile.write(txtdata) I knew it must have been my mistake...
... View more
09-16-2017
07:20 AM
|
0
|
2
|
1565
|
|
POST
|
I am replacing square brackets by round brackets with help of a python script - works perfectly. But I also want to replace a single word by another word (Cruise -> Campaign): nothing happens. Here is the part of the script: r = csv.reader(t, delimiter="\t")
all=[]
header=r.next()
#arcpy.AddMessage(header)
for fields in header:
fields.replace("Cruise","Campaign")##not working
fields.replace("[", "(")
fields.replace("]", ")")
Any idea why it replaces the brackets fine but not the word?
... View more
09-15-2017
11:43 AM
|
0
|
4
|
1738
|
|
POST
|
I didn't really know how to word my question in only a few words for the head line... Let me try to explain my problem: I have a script that attaches .png files to point features. The idea is to have those files matched to the point that have the same UID as the point. def AddAttachmentsToUid():
arcpy.GenerateAttachmentMatchTable_management(_location_for_points, _location_for_attachments,
_matchtable, "UID","*.png", "ABSOLUTE")
arcpy.AddAttachments_management(_location_for_points, "OBJECTID", _matchtable, "MatchID", "Filename") UIDs look e.g. like KivuWatt_151113_9 - the last number is ranging in this case from 1 to 16. While it works perfect for all other files I tested so far, I have a problem with the files KivuWatt_151113_1 and KivuWatt_151113_10 up to ..._16 which are all attached to the point with the UID KivuWatt_151113_1 (and then again to the correct point). For your information (in case it matters): The png files store also a specified range in the file name, e.g. KivuWatt_151113_1_0-400.png Edit: It is somehow understandable since the tool compares the uid with the file names and as long as they start with the same characters it matches them. So I think the best would be to compare the uid from the feature class with uid+_+*.png in the files, but how can a specify this within the GenerateAttachmentMatchTable_management tool?
... View more
09-05-2017
12:05 AM
|
0
|
0
|
851
|
|
POST
|
Sorry for the late reply, I was too busy on a different project. My colleague gave the advise not to use the app files from the server/apps directory but to download the app and then upload the unzipped download to the server (website). This seems to have solved the issue.
... View more
08-31-2017
12:02 AM
|
1
|
2
|
4599
|
|
POST
|
Thanks for your time Dan. It is a function: def FindFiles(location):
arcpy.env.workspace = location
listingFiles=arcpy.ListFiles("*.txt")
return listingFiles maybe the return value makes it get blocked somehow?
... View more
08-24-2017
05:41 AM
|
0
|
0
|
1193
|
|
POST
|
Update: I changed Step4 using new variable names for the list and its items. Now it works. Can someone maybe explain to me why I can't use the same loop/variables? # Step4: select points per campaign and create a polygon
list_of_campaigns = FindFiles(location_for_tables)
for each_campaign in list_of_campaigns:
arcpy.AddMessage(list_of_campaigns)
CreatePolygonFromCampaign(each_campaign)
... View more
08-24-2017
05:03 AM
|
0
|
2
|
1193
|
|
POST
|
It's me again with lots of cruises/campaigns, points and txt files but now I have additionally polygons to create. This is my main script: def main():
# Step 1: find the source files to process
list_of_files=[]
list_of_files = FindFiles(location_for_tables)
# Step2: prozess each file to data for points
for each_file in list_of_files:
# create and save sub tables
store_table(each_file)
# Step3: prozess each file to create a point in kivupoints
list_of_tables = FindFiles(DirOutTables)
for each_table in list_of_tables:
# create and store the point
tview = CreateTableView(DirOutTables, each_table)
pointInfo = ReadPointInfo(tview)
uid = LoadPointInfoToClass(pointInfo)
# Step4: select points per campaign and create a polygon
for each_campaign in list_of_files:
arcpy.AddMessage(list_of_files)
CreatePolygonFromCampaign(each_campaign) In Step2 and Step4 I am using the same files. But because I have to use the result from Step3 in Step4 I can't use the same for loop for Step2 and Step4. In both functions store_table(each_file) and CreatePolygonFromCampaign(each_campaign) I ask for the uniqueValues of one attribute of the current file. While this works perfectly with profile_nrs=unique_values(table, "Station") in the store_table(each_file) function (table receives the value from each_file), in the CreatePolygonFromCampaign(each_campaign) it tells me the correct file name but stops the script with the error message "cannot open 'KivuWatt_151120_Near-plant_CTM257 (2).txt'" (which is the correct txt file) while trying to retrieve the unique values for the Cruise attribute. I also tried other attributes and other files but with the same result. I wonder if the file is somehow "blocked" by the first loop or the first uniqueValues() method since it's using a SearchCursor. But it's using a "with arcpy.da.SearchCursor(table, [field]) as cursor" so I would assume it should release/delete the cursors afterwards again... Any help on this will be highly appreciated. I think I provided all necessary information and script snippets but please let me know if you need more details. Thanks in advance!
... View more
08-24-2017
04:36 AM
|
0
|
4
|
1347
|
|
POST
|
thanks! Will try to figure out where this is coming from... I am not aware of using a local version of the JS API...
... View more
06-22-2017
05:56 AM
|
0
|
4
|
4599
|
|
POST
|
Thanks Adrian, the link is updated now. I start the WAB with the start up bat file, yes. There the app works fine. But when I open it to the linked webpage it doesn't load the app beyond the loading screen. I already uploaded it twice because I thought there might have been an error during the upload I did yesterday.
... View more
06-22-2017
05:47 AM
|
0
|
0
|
4599
|
|
POST
|
Yes, thank you, that solved the issue! Looks like I just put my question into the wrong words 😉
... View more
06-22-2017
05:42 AM
|
1
|
0
|
750
|
|
POST
|
Hi all, I have created a webapp with WAB2.4 and uploaded my own animated gif to be showing while loading the app. While this was working without any problems on localhost it seems not be continuing loading the app and keeps showing my loading screen. You can see this here: Web App Any tips how to find out what causes the problem? Thanks in advance.
... View more
06-22-2017
05:18 AM
|
0
|
9
|
5606
|
| 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
|