|
POST
|
In case someone is still following up on this: I tried the ArcGIS Online Assistant and was able to copy a feature service between two subscriptions but I had to redo the map and the two apps to be linked to this new copied feature service and not the original one. This makes somehow sense since the links are all "absolute" but it is still a pain. This means I still have to reconfigure the style and popups in my map. For the apps it was a bit strange. I can put the new map for the app but the save button is not active. When I just close it is still saved and then I can reconfigure the other settings. At least this worked for one simple app now. But if I want to move lets say 20 apps it gets really time consuming. And if I have to do the whole map (or maybe 100) again this gets really annoying.
... View more
03-09-2017
11:34 PM
|
0
|
2
|
1226
|
|
POST
|
Thank you Joshua, understanding what the script is doing was the intention of my last comment.
... View more
02-15-2017
10:29 PM
|
0
|
0
|
783
|
|
POST
|
I'm trying now to combine my scripts but I fail to understand what you are doing Richard Let me try to explain what I understand (or what I think to understand) and where I am struggling... line 15: fieldnames = ["Station"] + [field.name for field in fields if field.name != dsc.OIDFieldName] plus line 19: with arcpy.da.SearchCursor(table, fieldnames) as cursor: Did you choose the additional field name "Station" by purpose because you saw in my pfieldnames that there is already a field called Station? Because, if I would choose a random name it would not find this column in my table when applying the SearchCursor, isn't it? lines 18-23: stationDict = {} with arcpy.da.SearchCursor(table, fieldnames) as cursor: for row in cursor: station = row[0] if not station in stationDict: stationDict[station] = str(row[1])+"_"+str(row[2]) This daSearchCursor goes through my input table including all fieldnames (including your defined "Station", excluding OID). The variable station gets the value of the attribute "Station" (because this is mentioned as the first field name). If the number does not exist yet the dictionary stationDict receives a new entry for the entry with the station x concatenating the values of the attributes 2 and 3 of the row of the current cursor. So, this dictionary contains only the concatenated name (the table_name) per row x. Right? When I try now to follow your description which lines to replace I have instead of lines 32-45: for station in sorted(stationDict):
table_name = stationDict[station]
with arcpy.da.SearchCursor(table_name, pfieldnames) as pCursor:
pfieldsvalues = next(pCursor)
ShapeVal = [pfieldsvalues[4], pfieldsvalues[5]]
fillValues = [ShapeVal] + list(pfieldsvalues)
print(fillValues)
newPoint.insertRow(fillValues)
print("point " + str(station) + " added to All_points") This goes through my sorted stationDict, retrieves the table_name, and "opens" the table_name with my pfieldnames. Then it should write all values from the first row into pfieldsvalues, adds the Shape and the pfieldsvalues to the fillValues and inserts a new row into my point feature. Unfortunately it gives me the error "StopIteration" at my line 4. # When I want to combine this part now with what I attempt to achieve with https://community.esri.com/thread/190087-nested-searchinsertcursors I get totally stranded. I will try to continue at this other posting to describe better what I want to do in consideration what I learned here.
... View more
02-15-2017
03:11 AM
|
0
|
2
|
2722
|
|
POST
|
Ok, it works! Great job! Thanks a lot! Just trying to get the differences now... Why did you put the "Station" additionally as a field into fieldnames? I don't have to delete the inputCursor in the end? Does this apply only for searchCursors (and UpdateCursors?) when NOT used with the "with"? As I said in my last comment the table_name tables in fact only contain one station each. Those were already extracted in a previous script from a bigger file (as I tried to explain here: Nested Search/InsertCursors). The optimum would be to combine these two steps, so this will be my next attempt... I tried to replace as you said "the last for loop and the last two if clauses can be replaced with pfieldvalues = next(pCursor)" but I am still confused about what is happening where so I just left it for now. As long as it's working 😉 Thanks to all of you!
... View more
02-13-2017
09:54 PM
|
0
|
0
|
2722
|
|
POST
|
Thank you very much Richard for taking so much effort to work through (and obviously improve) my script! I have to admit that I didn't take the time yet to read carefully through your blog posting Dan referred to before. Actually, each table_name contains only the data for one station while the point feature class is supposed to contain all points taken from the input table(s). Additionally each table (each table_name as well as the corresponding point feature class) should receive an UID (the same as the table_name, incorrectly named UPI before) to be able to relate them later again. At the moment the script doesn't write any points but I think I have to look through it again carefully... Thanks so far again! Will give you an update soon!
... View more
02-13-2017
11:57 AM
|
0
|
1
|
2722
|
|
POST
|
Thanks to both of your for taking your time to help me in this! Dan, dedenting this whole part would mean moving it out of the profile_nrs loop, isn't it? But would it then still make a point for each of the profiles? Joshua, in fact I had troubles exactly with this part. I didn't understand with the cursor, how to not copy the whole row but just a couple of attributes plus adding the shape somehow. I felt like having a knot in my head... Using your snipplet gives me an "TypeError: can only concatenate list (not "tuple") to list" in your line 5 when "adding up" the fillValues. I also tried already before with moving the insertCursor outside of the loop but it didn't make a difference in the result.
... View more
02-13-2017
06:47 AM
|
0
|
1
|
2722
|
|
POST
|
Didn't want to "overload" the code but here is the whole snipplet: import arcpy
import os
#Workspace settings
arcpy.env.workspace=r"C:\data\2017\LakeKivu\Kivu_python.gdb"
arcpy.env.overwriteOutput= True
def unique_values(table, field):
with arcpy.da.SearchCursor(table, [field]) as cursor:
return sorted({row[0] for row in cursor})
#input file
table = r"C:\data\2017\LakeKivu\Kivu_python.gdb\Test1"
#Output files
DirOutProfiles=r"C:\data\2017\LakeKivu\Kivu_python.gdb\Profiles"
DirOutCampaign=r"C:\data\2017\LakeKivu\Kivu_python.gdb\Campaigns"
DirOutTables=r"C:\data\2017\LakeKivu\Kivu_python.gdb"
points=r"C:\data\2017\LakeKivu\Kivu_python.gdb\Campaigns\All_points"
profile_nrs=unique_values(table, "Station")
print(profile_nrs)
dsc = arcpy.Describe(table)
fields = dsc.fields
# List all field names except the OID field
fieldnames = [field.name for field in fields if field.name != dsc.OIDFieldName]
pfields=arcpy.ListFields(points)
fillnames=[pfield.name for pfield in pfields if pfield.name != dsc.OIDFieldName] #names for point feature class
# get tables
for profile in profile_nrs:
expression="Station="+str(profile)
print(expression)
with arcpy.da.SearchCursor(table,fieldnames,expression) as sCursor:
for sRow in sCursor:
table_name=str(sRow[0])+"_"+str(sRow[1])
del sRow
# Create point feature
#Identify first OBJECTID used in new table
oid_nrs=unique_values(table_name, "OBJECTID")
FirstObject=oid_nrs[0]
print(FirstObject)
#Define expression to limit the extracted rows to the first row
pexpression="OBJECTID="+str(oid_nrs[0])
#Define field names used for point table
pfieldnames=['Cruise','Station', 'Type', 'Date', 'Longitude', 'Latitude','UPI']
print(pfieldnames)
#get values from table table_name
pfieldsvalues=[]
for pname in pfieldnames:
with arcpy.da.SearchCursor(table_name, pname, pexpression) as pCursor:
for pRow in pCursor:
fillvalue=pRow[0]
pfieldsvalues.append(fillvalue)
ShapeVal=[pfieldsvalues[4],pfieldsvalues[5]]
print(fillnames)
fillValues=[ShapeVal, pfieldsvalues[0],pfieldsvalues[1],pfieldsvalues[2],pfieldsvalues[3],pfieldsvalues[4],pfieldsvalues[5],pfieldsvalues[6],]
print(fillValues)
newPoint=arcpy.da.InsertCursor(points, fillnames)
newPoint.insertRow(fillValues)
station_nr=pfieldsvalues[1]
print("point "+str(station_nr) +" added to All_points")
del pRow
del pCursor
del sCursor I'm pretty sure that there is a better/simpler way of creating my points but I didn't find it yet. Maybe I miss somewhere a point in these Cursor methodologies. I couldn't figure out how to take only a certain number of attributes from the input table for my point feature PLUS adding somehow the shape values that's why it might look a bit irritating... In short what I do here: - profile_nrs takes all unique numbers in the attribute station (1-18) from input table Table1 (rows 21) - I created in a different script tables based on these unique numbers. This way I got 18 tables with the according names (concatenating attributes 1 and 2, resulting into something like bla_1, bla_2,...) (rows 33-39) - take only the first row of each table for creating the point (->pexpression, row 48+58) - write in pfieldvalues the values from the input table (in this case one of the new 18 tables).(rows 54-61) - fillnames includes the SHAPE attribute - fillvalues takes the created SHAPE attribute value (ShapeVal) plus the values written in pfieldvalues. (row 64) - then insert a row into points with fillvalues. (row 66/67). Let's hope this makes it somehow clearer...
... View more
02-11-2017
10:32 AM
|
0
|
4
|
3493
|
|
POST
|
Here we go... (I hope it works with just copy-paste...)
... View more
02-11-2017
10:02 AM
|
1
|
0
|
3493
|
|
POST
|
Yes, correct. Didn't want to mix up the issues. I separated now both parts - creating first the tables and then the points but now I am stuck here...
... View more
02-11-2017
09:59 AM
|
0
|
8
|
3493
|
|
POST
|
I have a problem with my for loop. In an array profile_nrs all the numbers are stored I want to create points for in an existing feature class. When I print these values I get the expected nr of values (and also the correct values). Now I am creating points with an insertCursor and print in the end which point nr was added. I get all the (in this case) 18 points printed. But when I look into my file I receive only 17 points. Any advise is highly appreciated. I don't see any potential cause for this "misbehavior". My feeling tells me that it must not be looping through the numbers itself but through the index but then I wouldn't get nr 18 printed, would I? Here the main part of the module: for profile in profile_nrs:
newPoint=arcpy.da.InsertCursor(points, fillnames)
newPoint.insertRow(fillValues)
print("point "+str(profile) +" added to All_points") Inside the for loop I have a couple of other loops to get the fillnames and fillvalues but I don't see anywhere how this could influence the output. Especially if it says it added nr 18 but obviously it didn't... Thanks in advance for helping me with this.
... View more
02-10-2017
01:02 PM
|
0
|
22
|
7833
|
|
POST
|
I think the problem is still somehow how the loops are nested. At which point would you suggest to delete the sCursor?
... View more
02-10-2017
05:03 AM
|
0
|
0
|
4170
|
|
POST
|
Thanks for the hint. I think I indented/detended them the way it should be (from my understanding I should delete them at the end of the according loop). okaaaaayyyyy, thinking through this I think the problem is, that it tries to create the table every time the sCursor reaches a new sRow. I guess this is why I had put an extra loop before for filling the table. Which still doesn't explain why the point is not created...
... View more
02-10-2017
03:56 AM
|
0
|
1
|
4170
|
|
POST
|
Thank you Neil for looking into this. Although your comment makes totally sense to me it seems like I created now an endless loop that doesn't allow the module to be finished. with arcpy.da.SearchCursor(table,fieldnames,expression) as sCursor:
for sRow in sCursor:
table_name=str(sRow[0])+"_"+str(sRow[1])+"_data1"
iCursor=arcpy.da.InsertCursor(table_name,fieldnames)
iCursor.insertRow(sRow)
del iCursor
del sRow
del sCursor
print("Table "+table_name+" filled") When I have the del sCursor in line 8 it says there is no sCursor, when I remove it and put it to the end then it runs without ending. It seems to establish the table_name correctly but only that. Any idea why my point is not created?
... View more
02-10-2017
02:09 AM
|
0
|
4
|
4170
|
|
POST
|
I need some help with some nested Search/Insert Cursors adding data to a table and to a point feature class. What I have: - I have one big table with stations 1-n with for example 10,000 rows for each station. - A point feature class in a file geodatabase. What I want: - I want to copy the rows for each station into a newly created table (all attributes). - AND I want to copy the first row from this new table into the point feature class but only with the relevant fields (5 attributes) adding its point to the geometry of course. What I get: I managed to create one new table and copy the table content into the new table. The script runs without giving an error but in the end I don't have a new point in my feature class. When I try to let it run for more than one station I get the RuntimeError: workspace already in transaction mode (below in Row 14). When I remove the part with creating the point I can create as many tables as I want. Printing the values that are supposed to be inserted into the point feature class (fillValues) they look good to me. What I also already tried: I just tried also with removing the table relevant part (since they are all created now). Now I get an IndexError: list index out of range pointing to my FirstObject. But it first runs through the whole script - but again without adding my point 😞 I also tried without adding the OBJECTID but with the same result. I would be very happy if someone could push me in the right direction to make this work. Here is simplified version of my module: table=input table
fieldnames = [field names from input table except OBJECTID]
pfields=arcpy.ListFields(points)
fillnames=[field names for point feature class, manually created, not OBJECTID, not SHAPE]
# Create cursors and insert new rows
for profile in profile_nrs:
expression="Station="+str(profile)
with arcpy.da.SearchCursor(table,fieldnames,expression) as sCursor:
for sRow in sCursor:
table_name=str(sRow[0])+"_"+str(sRow[1])+"_data1"
with arcpy.da.InsertCursor(table_name,fieldnames) as iCursor:
for sRow in sCursor: -> This is where I get the RuntimeError
iCursor.insertRow(sRow)
del iCursor
del sRow
del sCursor
print("Table "+table_name+" filled")
# From here starts the point feature creation
#Identify first OBJECTID used in new table
oid_nrs=unique_values(table_name, "OBJECTID")
FirstObject=oid_nrs[0]
#Define expression to limit the extracted rows to the first row
pexpression="OBJECTID="+str(oid_nrs[0])
#Define field names used for point table
pfieldnames=['Cruise','Station', 'Type', 'Date', 'Longitude', 'Latitude']
print(pfieldnames)
pfieldsvalues=[FirstObject]
for pname in pfieldnames:
with arcpy.da.SearchCursor(table_name, pname, pexpression) as pCursor:
for pRow in pCursor:
fillvalue=pRow[0]
print(fillvalue)
pfieldsvalues.append(fillvalue)
ShapeVal=[pfieldsvalues[5],pfieldsvalues[6]]
print(fillnames)
#take the values extracted from the first row in the new table and put
#them into a new array adding OBJECTID and Shape (Geometry)
fillValues=[pfieldsvalues[0], ShapeVal, pfieldsvalues[1], pfieldsvalues[2], pfieldsvalues[3], pfieldsvalues[4], pfieldsvalues[5], pfieldsvalues[6]]
print(fillValues)
newPoint=arcpy.da.InsertCursor(points, fillnames)
newPoint.insertRow(fillValues)
print("point added to All_points")
del pRow
del pCursor
... View more
02-10-2017
12:07 AM
|
0
|
8
|
5828
|
|
POST
|
Thank you! Very helpful. I don't have rasters but txt or dbf files but in theory that should work about the same. For the moment we decided to set the min and max manually. In the meanwhile I managed to print 5 subplots (Temperature, pH, Conductivity, Pressure...) in one figure, so I'm on a good way...
... View more
02-03-2017
01:50 AM
|
0
|
1
|
1661
|
| 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 |
17 hours ago
|