POST
|
hi rebecca thank you very much, but why del don't work here. Iuse it to clean the processus of running code
... View more
01-09-2016
01:35 PM
|
0
|
1
|
1495
|
POST
|
Hi all, when i run this code the message "local variable 'row' referenced before assignment" appear but i think the name o the variable and the indentation are correct. tb = table if tb is "RRAXERCL": fieldsToConcat_RRAXERCL = ["CODECAVA","CODCLASS","TYPERTCR","PROFILRC","ETATRTCR"] cursorup = arcpy.da.UpdateCursor(table,fieldsToConcat_RRAXERCL) for row in cursorup : row[0] = str(row[1]) + str(row[2]).rjust(2,'0') + str(row[3]).rjust(2,'0') + str(row[4]).rjust(2,'0') + str('00') cursorup.updateRow(row) del row del cursorup thank you
... View more
01-09-2016
12:13 PM
|
0
|
3
|
4552
|
POST
|
Hi rebecca, I solved the problem of "no module named arcpy" by the link given by you and i run the script in pyscripter with external run. The second "problem" of the class "does not exist" i solved it by re-writing the path of connection file in the script. Final thank you very much for your help
... View more
01-09-2016
03:02 AM
|
0
|
0
|
750
|
POST
|
Hi dan, I solved the problem of "no module named arcpy" by the link given by rebecca and i run the script in pyscripter with external run. The second "problem" of the class "does not exist" i solved it by re-writing the path of connection file in the script. Final thank you very muchforyour help
... View more
01-09-2016
03:00 AM
|
1
|
1
|
750
|
POST
|
hi rebecca, thank for the link. no the sccript run from pyscripter as external run. No the problem is the Access to the clasa. The class exist but the message is the class "does not exist"
... View more
01-08-2016
08:37 AM
|
0
|
0
|
750
|
POST
|
Hi dan, These are the python path illustrated with Pyscripter
... View more
01-07-2016
11:47 AM
|
0
|
6
|
750
|
POST
|
Hi Rebecca, thank tou I will do this or reinstall ArcGis!
... View more
01-07-2016
01:47 AM
|
0
|
0
|
294
|
POST
|
hi dan, thank you i use IDLE (python GUI) and Pyscripter. My code is correct and debugging.
... View more
01-07-2016
01:44 AM
|
0
|
8
|
750
|
POST
|
Hi, i have a problem with arcpy when i try to import it in a script with idle the message no "module named arcpy" appear. But when i run it directly in arcgis. The second problem is the no recognition of the feqtureclqss . the message that appearr is : the featureclass doesntexist. Remarque I use ArcSDE connection and ArcGIS 10.1 Thank you
... View more
01-06-2016
04:31 PM
|
0
|
12
|
3852
|
POST
|
hello, i find the mistake when i have this error message: "Objects in this class cannot be updated outside an edit session [TOP10_SIG.DBO.RHAXECEL]". So i edit the session with arcpy.da.Editor and the script run successfully. There is th good script:
try:
axeceau = "RHAXECEL"
fields = ['CODHYDRO', 'TYPECEAU']
edit = arcpy.da.Editor(arcpy.env.workspace)
with arcpy.da.Editor(arcpy.env.workspace) as edit:
cursor8 = arcpy.da.UpdateCursor(axeceau, fields)
#rows = arcpy.UpdateCursor(axeceau, fields)
for row in cursor8:
if row[0] == 3:
row[1] = 4
elif row[0] == 4:
row[1] = 1
elif row[0] == 5:
row[1] = 1
else:
row[1] = 1
cursor8.updateRow(row)
except arcpy.ExecuteError:
print(arcpy.GetMessages(2))
... View more
10-22-2013
07:11 AM
|
1
|
0
|
386
|
POST
|
What doesn't work? What error do you get. Have you already defined what subtypes 1 & 4 are? Cheers, Neil Thank you Neil Ayres, doesn't work = it mean there is no result, the script does nothing 🙂 What error do you get? : No i don't get an error. Have you already defined what subtypes 1 & 4 are? Yes,Subtypes are defined in the gdb. the subtypes are : 1 Cours d'eau naturel 2 Canal d'alimentation ou d'irrigation 3 Canal de drainage ou de collecte des eaux pluviales 4 Fossé d�??assèchement ou de drainage ou de collecte des eaux pluviales I use try and except to get error message but there is no message. the script with try is this:
try:
axeceau = "TOP10_SIG.DBO.RHAXECEL"
fields = ['CODHYDRO', 'TYPECEAU']
with arcpy.da.UpdateCursor(axeceau, fields) as cursor8:
#rows = arcpy.UpdateCursor(axeceau, fields)
for row in cursor8:
if row[0] == 3:
row[1] = 4
elif row[0] == 4:
row[1] = 1
elif row[0] == 5:
row[1] = 1
else:
row[1] = 1
cursor8.updateRow(row)
except arcpy.ExecuteError:
print(arcpy.GetMessages(2))
Thank you
... View more
10-22-2013
05:49 AM
|
0
|
0
|
386
|
POST
|
hello i try to update a subtype field (integer) from the value of an other field with arcpy.da.updateCursor() but dosen't work. please some idea axeceau = "RHAXECEL" # the feature class fields = ['CODHYDRO', 'TYPECEAU'] # TYPECEAU is the subtype field with arcpy.da.UpdateCursor(axeceau, fields) as cursor8: for row in cursor8: if row[0] == 3: row[1] = 4 elif row[0] == 4: row[1] = 1 elif row[0] == 5: row[1] = 1 else: row[1] = 1 cursor8.updateRow(row)
... View more
10-22-2013
02:33 AM
|
1
|
3
|
718
|
POST
|
Try this:
import arcpy
from arcpy import *
import sys
arcpy.env.workspace = r"c:\connectionFiles\conntop10sig.sde"
sql = "select * from TOP10_SIG.DBO.ABCBNIVL where TOP10_SIG.DBO.ABCBNIVL.TYPECBN = 3"
sdeConn = arcpy.ArcSDESQLExecute(r"c:\connectionFiles\conntop10sig.sde")
print "Execute SQL Statement: ", sql
print "connecting to dba"
sdeReturn = sdeConn.execute(sql)
if isinstance(sdeReturn, list):
print "Number of rows returned by query: ", len(sdeReturn), "rows"
for row in sdeReturn:
print row
else:
print "no selection made" If you are still getting errors, you need to confirm that there is a numeric field named TYPECBN in the table named TOP10_SIG.DBO.ABCBNIVL in the sde connection r"c:\connectionFiles\conntop10sig.sde". Look in ArcCatalog and make sure that TOP10_SIG.DBO.ABCBNIVL is listed as the table name there. If so, and still getting errors, you might try dropping the DBO from it ( TOP10_SIG.ABCBNIVL ) as I have seen in the FlexApp environment where links to DBO tables didn't work with that in the path. R_ hi rzufelt, you have reason the type of the field is SubtypeField, when i change the query to another field (integer) it works very good. thank you very much for the subtype field, have you please an idea how can select it.
>>> import arcpy
... from arcpy import *
... import sys
... arcpy.env.workspace = (r"c:\connectionFiles\conntop10sig.sde")
... try:
... SQLStatement = ("select * from TOP10_SIG.DBO.ABCBNIVL where TOP10_SIG.DBO.ABCBNIVL.ALTDCRNV = 50") # ALTDCRNV = the elevation
... sdeConn = arcpy.ArcSDESQLExecute(r"c:\connectionFiles\conntop10sig.sde") # vital part you are missing....
... print "Execute SQL Statement: ", SQLStatement
... try:
... # Pass the SQL statement to the database.
... #
... print "connecting to dba"
... sdeReturn = sdeConn.execute(SQLStatement)
... print "Number of rows returned by query: ", len(sdeReturn)
... except Exception, ErrorDesc:
... print "ErrorDesc",ErrorDesc ## added this to actually print what the error is
... sdeReturn = False
... # If the return value is a list (a list of lists), display each list as a row from the
... # table being queried.
... if isinstance(sdeReturn, list):
... print "Number of rows returned by query: ", len(sdeReturn), "rows"
... for row in sdeReturn:
... print "row"
... print "\n"
... else:
... # If the return value was not a list, the statement was most likely a DDL statment.
... # Check its status.
... if sdeReturn == True:
... print "SQL statement: ", SQLStatement , " ran sucessfully."
... print "\n"
... else:
... print "SQL statement: ",SQLStatement ," FAILED."
... print "\n"
... except:
... print "Problem executing SQL."
...
...
...
Execute SQL Statement: select * from TOP10_SIG.DBO.ABCBNIVL where TOP10_SIG.DBO.ABCBNIVL.ALTDCRNV = 50
connecting to dba
Number of rows returned by query: 38
Number of rows returned by query: 38 rows
row
row
.
.
... View more
08-01-2013
01:03 AM
|
0
|
0
|
168
|
POST
|
OIC, it's not actually running and generating that string, it is merely printing what you assigned it to. Did you try any of the changes I posted above, they are working for me just fine. I did notice that you have quite a few errors in your script, and, without the error reporting, it just errors out and doesn't tell you why. The code in my other post is working correctly, it is the "other" errors in your script that is throwing the exceptions. Notice the print statements, best to get away from using "+" in print statements as you were trying to concatenate (that's what the plus sign means) a number and a string. Gives an error, but without it reporting the error, just says Problem executing SQL. Use commas in print statements and you wont run into this problem. No need to iterate through a list of SQL statements as you are "splitting" your string by ";" as there are no semicolons in your string, so you end up with an empty list. Think you got this code from the example which is showing how to deal with the getParametersAsText() when passing from a script tool. In this case, if allow multiple inputs, they would come across as a semicolon separated string that would be parsed to the list. In this case, you are defining your "single" sql statement. Try this code, it is working. If it doesn't work for you, I'd suggest grabbing the snippet from the bottom of my earlier post and have it print the fields for you, and make sure fields in the SQL statement are correct (check CasE also, as that may sometimes matter). Anyway, cleaned out some of the error issues and the loop. Try this, get it to work, then add all the "other" stuff in there after it is working correctly. R_
import arcpy
from arcpy import *
import sys
arcpy.env.workspace = (r"c:\connectionFiles\conntop10sig.sde")
try:
SQLStatement = ("select * from TOP10_SIG.DBO.ABCBNIVL where TOP10_SIG.DBO.ABCBNIVL.TYPECBN = 3")
sdeConn = arcpy.ArcSDESQLExecute(r"c:\connectionFiles\conntop10sig.sde") # vital part you are missing....
print "Execute SQL Statement: ", SQLStatement
try:
# Pass the SQL statement to the database.
#
print "connecting to dba"
sdeReturn = sdeConn.execute(SQLStatement)
print "Number of rows returned by query: ", len(sdeReturn)
except Exception, ErrorDesc:
print "ErrorDesc",ErrorDesc ## added this to actually print what the error is
sdeReturn = False
# If the return value is a list (a list of lists), display each list as a row from the
# table being queried.
if isinstance(sdeReturn, list):
print "Number of rows returned by query: ", len(sdeReturn), "rows"
for row in sdeReturn:
print "row"
print "\n"
else:
# If the return value was not a list, the statement was most likely a DDL statment.
# Check its status.
if sdeReturn == True:
print "SQL statement: ", SQLStatement , " ran sucessfully."
print "\n"
else:
print "SQL statement: ",SQLStatement ," FAILED."
print "\n"
except:
print "Problem executing SQL."
This should work as long as the workspace.sde connection includes a table named "TOP10_SIG.DBO.ABCBNIVL", and that table has a numeric field named "TYPECBN" R_ hi rzufelt , this is the result of the script running in arcgis python window:
>>> import arcpy
... from arcpy import *
... import sys
... arcpy.env.workspace = (r"c:\connectionFiles\conntop10sig.sde")
... try:
... SQLStatement = ("select * from TOP10_SIG.DBO.ABCBNIVL where TOP10_SIG.DBO.ABCBNIVL.TYPECBN = 3")
... sdeConn = arcpy.ArcSDESQLExecute(r"c:\connectionFiles\conntop10sig.sde") # vital part you are missing....
... print "Execute SQL Statement: ", SQLStatement
... try:
... # Pass the SQL statement to the database.
... #
... print "connecting to dba"
... sdeReturn = sdeConn.execute(SQLStatement)
... print "Number of rows returned by query: ", len(sdeReturn)
... except Exception, ErrorDesc:
... print "ErrorDesc",ErrorDesc ## added this to actually print what the error is
... sdeReturn = False
... # If the return value is a list (a list of lists), display each list as a row from the
... # table being queried.
... if isinstance(sdeReturn, list):
... print "Number of rows returned by query: ", len(sdeReturn), "rows"
... for row in sdeReturn:
... print "row"
... print "\n"
... else:
... # If the return value was not a list, the statement was most likely a DDL statment.
... # Check its status.
... if sdeReturn == True:
... print "SQL statement: ", SQLStatement , " ran sucessfully."
... print "\n"
... else:
... print "SQL statement: ",SQLStatement ," FAILED."
... print "\n"
... except:
... print "Problem executing SQL."
...
Execute SQL Statement: select * from TOP10_SIG.DBO.ABCBNIVL where TOP10_SIG.DBO.ABCBNIVL.TYPECBN = 3
connecting to dba
ErrorDesc Problem executing SQL.
... View more
07-31-2013
12:56 AM
|
0
|
0
|
556
|
POST
|
This looks like what you "want" your sql to look like, but I can't figure any way you got that from the attached code. Are you running a different snippet than you posted? R_ hi rzuflet, this is the full script :
>>> import arcpy
... from arcpy import *
... import sys
... arcpy.env.workspace = (r"c:\connectionFiles\conntop10sig.sde")
... try:
...
... # Two ways to create the object, which also creates the connection to ArcSDE.
... # Using the first method, pass a set of strings containing the connection properties:
... # <serverName>,<portNumber>,<version>,<userName>,<password>
... # sdeConn = arcpy.ArcSDESQLExecute("gpserver3","5151","#","toolbox","toolbox")
... # Using the second method pass the path to a valid ArcSDE connection file
... #
...
... # Get the SQL statements, separated by ; from a text string.
... #
... SQLStatement = ("SELECT * FROM [TOP10_SIG].[dbo].[ABCBNIVL] WHERE [TOP10_SIG].[dbo].[ABCBNIVL].[TYPECBNV] = 3 ")
... SQLStatementList = SQLStatement.split(";")
...
...
... print "\n"
... # For each SQL statement passed in, execute it.
... #
... for sql in SQLStatementList:
... print "Execute SQL Statement: " + sql
... try:
... # Pass the SQL statement to the database.
... #
... sdeReturn = sdeConn.execute(sql)
... except Exception, ErrorDesc:
... print "ErrorDesc"
... sdeReturn = False
...
... # If the return value is a list (a list of lists), display each list as a row from the
... # table being queried.
... if isinstance(sdeReturn, list):
... print "Number of rows returned by query: " + len(sdeReturn), "rows"
... for row in sdeReturn:
... print "row"
... print "\n"
... else:
... # If the return value was not a list, the statement was most likely a DDL statment.
... # Check its status.
... if sdeReturn == True:
... print "SQL statement: " + sql + " ran sucessfully."
... print "\n"
... else:
... print "SQL statement: " + sql + " FAILED."
... print "\n"
...
... except Exception, ErrorDesc:
... print "Exception, ErrorDesc"
... except:
... print "Problem executing SQL."
...
the result is : Execute SQL Statement: SELECT * FROM [TOP10_SIG].[dbo].[ABCBNIVL] WHERE [TOP10_SIG].[dbo].[ABCBNIVL].[TYPECBNV] = 3 ErrorDesc SQL statement: SELECT * FROM [TOP10_SIG].[dbo].[ABCBNIVL] WHERE [TOP10_SIG].[dbo].[ABCBNIVL].[TYPECBNV] = 3 FAILED. thank you
... View more
07-30-2013
12:04 AM
|
0
|
0
|
556
|
Title | Kudos | Posted |
---|---|---|
1 | 01-09-2016 03:00 AM | |
1 | 10-22-2013 02:33 AM | |
1 | 10-22-2013 07:11 AM |
Online Status |
Offline
|
Date Last Visited |
11-11-2020
02:23 AM
|