POST
|
The quick and easy way to fix the issue I posted earlier was to fix my where clause. It was an invalid SQL statement so by altering it to what is below, I was able to fix the issue. whereclause = """{} IN (2, 3) """.format(arcpy.AddFieldDelimiters(fc, fieldname)) I was also able to further optimize my code and make it more streamline by using some of xander_bakker's suggestions. Thanks for your help Xander.
... View more
02-02-2018
11:34 AM
|
2
|
0
|
504
|
POST
|
Hey Xander thanks for the response and advice. Your assumptions were correct and my data is stored in a geodatabase. I'll give your suggestions a try and let you know how it goes!
... View more
02-01-2018
10:46 AM
|
1
|
0
|
504
|
POST
|
I have four markets 1-4, but I only want to do markets 2 and 3. I created a markets list only containing those two markets so that I could use the list in a "for" loop. However, when I try and run it, it still runs through all the markets. I think this has to do with my "whereclause" or "sqlclause" or both, but I can't figure out how to fix it. I've tried using a wildcard in the "whereclause" but that doesn't work. I've also tried getting rid of the "whereclause" but that also doesn't work. Could someone help me with this? - fc = 'Centers'
fields = ['market_id','Center_ID','Center_Name','Opening_Date']
fieldname = 'market_id'
#Define WHERE clause statement
#whereclause = """{} = '%000' """.format(arcpy.AddFieldDelimiters(fc, fieldname))
sqlclause = (None, 'Order By market_id, Center_ID')
# Set Markets to loop through
markets = [2,3]
# Set Years to loop through
years = [2016,2017]
# Set Months to loop through
months = [1, 2]
#returns last day of each month
def last_day_of_month(any_day):
next_month = any_day.replace(day=28) + datetime.timedelta(days=4)
return next_month - datetime.timedelta(days=next_month.day)
for market in markets:
sqlclause = (None, 'Order By market_id, Center_ID')
print (market)
for year in years:
print (year)
for month in months:
print (month)
with arcpy.da.SearchCursor(in_table = fc, field_names = fields, where_clause=whereclause, sql_clause=(None, 'ORDER BY market_id, Center_ID')) as cursor:
... View more
02-01-2018
09:03 AM
|
0
|
4
|
668
|
Title | Kudos | Posted |
---|---|---|
2 | 02-02-2018 11:34 AM | |
1 | 02-01-2018 10:46 AM |
Online Status |
Offline
|
Date Last Visited |
11-11-2020
02:24 AM
|