I'm currently using Arcmap 10.7 version. I'm guessing my error is in the where clause. Could anyone please help me to get rid from this problem?. I'm not able to print the cursor part i.e.,
Print (MEASUREDLENGTH_Risk_Score) # Not getting the value of MEASUREDLENGTH
Below is my code-:
import arcpy
arcpy.env.workspace = "D:\pipe\map.gdb"
featureClass_1 = "P_Pipes"
Table_Pipe = "Pipe_Risk"
fieldNames_1 = [ "Material" , "OPERATINGPRESSURE" , "MEASUREDLENGTH" , "INSTALLATIONDATE", "Risk_Score"]
fieldNames_Pipe = ["Material" , "OPERATINGPRESSURE" , "MEASUREDLENGTHLOWERLIMIT" ,"MEASUREDLENGTHUPPERLIMIT" , "INSTALLATIONDATELOWERLIMIT" , "INSTALLATIONDATEUPPERLIMIT" , "OVERALLRISKSCORE"]
def Pipe_Risk_Score(Material, OPERATINGPRESSURE, MEASUREDLENGTH, INSTALLATIONDATE):
ML_Out_fields = ["MEASUREDLENGTHLOWERLIMIT" ,"MEASUREDLENGTHUPPERLIMIT" , "OVERALLRISKSCORE"]
ML_where_Clause = "MEASUREDLENGTHLOWERLIMIT <= " + MEASUREDLENGTH + " and MEASUREDLENGTHUPPERLIMIT >= " + MEASUREDLENGTH
print(ML_where_Clause)
Table_Pipe_Cursor = arcpy.da.SearchCursor(Table_Pipe, ML_Out_fields, ML_where_Clause)
for row in Table_Pipe_Cursor:
lst.append(row[2])
MEASUREDLENGTH_Risk_Score = row[2]
print ((MEASUREDLENGTH_Risk_Score))
Pipe_Risk_Score("Material" , "OPERATINGPRESSURE" , "MEASUREDLENGTH" , "INSTALLATIONDATE")
Solved! Go to Solution.
Sir @Anonymous User . I'm getting my output for the same. But in case of Measured length & Installation Date, I'm getting the multiple values. See, in the case of Measured Length, I'm getting the 5 output values where as in case of Installation Date, I'm getting 2 values. So do i have to change the signs in the where clause? or something else.
Material: 5 OPERATINGPRESSURE: 40.0 MEASUREDLENGTH: 182.36985383 INSTALLATIONDATE: 1955-01-01 00:00:00
1.5
0.4
MEASUREDLENGTHUPPERLIMIT >= 182.36985383
0.1
0.2
0.3
0.4
1.0
INSTALLATIONDATELOWERLIMIT <= timestamp '1955-01-01 00:00:00' and INSTALLATIONDATEUPPERLIMIT >= timestamp '1955-01-01 00:00:00'
2.0
1.4
It looks like you are not using the right ML where clause again.
ML_where_Clause = "MEASUREDLENGTHLOWERLIMIT <= {0} and MEASUREDLENGTHUPPERLIMIT >= {0}".format(MEASUREDLENGTH)
For your date rage, maybe drop the = because it is including 01-01-1955 and 01-01-1935 as being valid so its selecting both.
So, my where clause for ID be like:
ID_where_Clause = "INSTALLATIONDATELOWERLIMIT < timestamp '{0}' and INSTALLATIONDATEUPPERLIMIT > timestamp '{0}'".format(INSTALLATIONDATE)
Is it??
try it
Thank you sir, It works. I just wanna ask that suppose if i have a string data type in "Material" case then what will be my where clause? like Material name is steel, plastic etc.
@broy06, how is this question different from one you posted yesterday? (https://community.esri.com/t5/python-questions/getting-error-in-arcpy-using-cursor/m-p/1087638#M6201...) . In the other post, @BlakeTerhune gave you a suggestion on handling dates, did you ever try it?
Yes sir. I tried But I wanna access only the domain value of Dates not the exact date & from this i'm getting Dates only.
Thank You!