|
POST
|
Yea I picked that up and made the change in my testing yesterday....thanks So this is what I have right now...I get this error...thoughts? I assume a date format issue? Questions: I dont see how this query is looping through each Boat Ramp Name, The fc variable the query is running against might not even have the Boat Ramp in it ( in fact I know it does not have all the unique boat ramps in it). Thats why I created the LIST called "myBoatRampList". This contains all the unique Boat Ramp Names. I assumed I would loop through the LIST (myBoatRampList) reading each unique Boat Ramp name. On each pass through the loop verify if there has been a record created for that specific boat ramp in the last 30 days. If not then write that to a second LIST (notInspected). This will be the list of Boat Ramps that do not have inspection in the last 30 days. Traceback (most recent call last): File "E:\ArcGISProjects\BoatRampFacilities\PythonScripts\PythonSync\PythonScripts\~6_30days ago.py", line 44, in <module> for row in cursor: RuntimeError: Underlying DBMS error [[Microsoft][SQL Server Native Client 11.0][SQL Server]Operand type clash: datetime2 is incompatible with int] [DGIF_TEST.DBO.BRs_Boat_Ramp_Inspection_2]
arcpy.env.workspace = "C:\\Users\\xxx\\AppData\\Roaming\ESRI\\Desktop10.4\\ArcCatalog\\[email protected]"
fc = "xx"
var_additionalcomments = 'additionalcomments'
var_CreationDate = 'CreationDate'
var_Creator = 'Creator'
headers = ['comments','Creation Date','Creator']
QueryFields = [var_additionalcomments,var_CreationDate,var_Creator]
# Get Date 30 days ago
import datetime as DT
today = DT.date.today()
month_ago = today - DT.timedelta(days=30)
print month_ago
# Get list of all Boat Ramps
myLayer = "BoatRampsWGS"
myField = "SITENAME"
myBoatRampList = [row[0] for row in arcpy.da.SearchCursor(myLayer, myField)]
print myBoatRampList
# Loop through List of Boat Ramps and return those that dont have inspection within 30 days
notInspected = []
dateQry="""CreationDate > date{} AND CreationDate < date{}""".format(month_ago, today)
myField1 = "CreationDate"
#with arcpy.da.SearchCursor(myLayer, ['CreationDate', 'additionalcomments'], dateQry) as cursor:
with arcpy.da.SearchCursor(fc, myField1, dateQry) as cursor:
for row in cursor:
print(row)
CreatevalDate = str('{0},{1},{2}'.format(row[0],row[1],row[2]))
notInspected.append(CreatevalDate)
... View more
05-05-2017
06:25 AM
|
0
|
7
|
2086
|
|
POST
|
While writing the below I had a thought...where in that example is it taking the unique Boat Ramp Names from the Array and looping through each one to determine if that specific boat ramp has an inspection date in the last 30 days.... I then need a list of each boat ramp that does not have an inspection in the last 30 days....mind you each boat ramps has hundreds of existing inspections. Im really confused. It looks like that query is giving me the boat ramps that were inspected in the last 30 days...not the ones that have not been inspected... I try this: myLayer = "BoatRampsWGS"
myField = "SITENAME"
# Loop through List of Boat Ramps and return those that dont have inspection within 30 days
notInspected = []
dateQry="""CreationDate > date%s AND CreationDate < date%s"""%month_ago %today
with arcpy.da.SearchCursor(myLayer, ['CreationDate', 'additionalcomments'], dateQry) as cursor:
for row in cursor:
#print(row)
print('{} is in default of {}'.format(row[0], row[1]))
and get this error: Traceback (most recent call last):
File "E:\ArcGISProjects\xxxx\PythonScripts\PythonSync\PythonScripts\xxx.py", line 76, in <module>
dateQry="""CreationDate > date%s AND CreationDate < date%s"""%month_ago %today
TypeError: not enough arguments for format string
... View more
05-04-2017
05:24 PM
|
0
|
9
|
2086
|
|
POST
|
Is this saying : Greater than the month_ago variable and less than todays date? dateQry="""InspectionDate > date%s AND InspectionDate < date%s"""%month_ago %today
... View more
05-04-2017
05:11 PM
|
0
|
0
|
2086
|
|
POST
|
I know I am missing the ] at the end of this line....copy and paste issue QueryFields = [var_additionalcomments,var_CreationDate,var_Creator
... View more
05-04-2017
10:41 AM
|
0
|
0
|
2086
|
|
POST
|
I have list that contains all the Boat Ramps I want to validate. I want a query that loops through each boat ramp name and then determines which ones do not have a record in the last 30 days. I need that result to be written to a CSV file. I think I have the beginning and the end but not the part that loops and queries for Boat Ramps that do NOT have a record in the last 30 days I need to query the FC variable (my dataset that has all the records) "Ramp_1" is the field in the FC that has the Boat Ramp Name Using the List for Boat Ramp names (List) Loop through the List and find which records in the FC do not have a record in the last 30 days. import arcpy
import os, string
import smtplib, shutil
import email, time
import sys, csv
from email.MIMEMultipart import MIMEMultipart
from email.mime.text import MIMEText
#Variables==============================================
arcpy.env.workspace = "C:\\Users\\xxxx\\AppData\\Roaming\ESRI\\Desktop10.4\\ArcCatalog\\xxxx.sde"
fc = "xxxxx"
var_additionalcomments = 'additionalcomments'
var_CreationDate,var_Creator = 'CreationDate','Creator'
headers = ['comments','Creation Date','Creator']
QueryFields = [var_additionalcomments,var_CreationDate,var_Creator
# Get Date 30 days ago
import datetime as DT
today = DT.date.today()
month_ago = today - DT.timedelta(days=30)
print month_ago
# Get list of all Boat Ramps
myLayer = "BoatRampsWGS"
myField = "SITENAME"
myBoatRampList = [row[0] for row in arcpy.da.SearchCursor(myLayer, myField)]
print myBoatRampList
# Loop through List of Boat Ramps and return those that dont have inspection within 30 days
# I AM LOST HERE .... THIS IS WHERE THE LOOP AND QUERY SHOULD BE BUT DONT KNOW WHERE TO STATR
# Write the results to CSV file.
outFileRegionDate = open(r"E:\ArcGISProjects\xxxx\PythonScripts\PythonSync\PythonScripts\z_outFileRegionDate.csv", "w")
mylist=[]
with arcpy.da.SearchCursor(fc, QueryFields, where_clause=expressionDate) as cursorDate:
outFileRegionDate.write(','.join(headers) + '\n')
flagDate = False
for row in cursorDate:
flagDate = True
zvalDate = str('{0},{1},{2}'.format(row[0],row[1],row[2]))
outFileRegionDate.write(zvalDate + "%s\n")
mylist.append(zvalDate)
if not flagDate:
print "No rows found"
outFileRegionDate.close()
... View more
05-04-2017
10:40 AM
|
0
|
13
|
3509
|
|
POST
|
Trying to query records for older than 30 days from present.... Blowing up here...dont have to proper syntax,,,,I am trying to use two variables.. expDateMonthAgo = "CreationDate = [month_ago]" Thoughts? #Variables==============================================
arcpy.env.workspace = "C:\\Users\\xxxx\\AppData\\Roaming\ESRI\\Desktop10.4\\ArcCatalog\\xxxx_Admin.sde"
fc = "xxxxx"
var_additionalcomments = 'additionalcomments'
var_CreationDate,var_Creator = 'CreationDate','Creator'
headers = ['comments','Creation Date','Creator']
QueryFields = [var_additionalcomments,var_CreationDate,var_Creator]
import datetime as DT
today = DT.date.today()
month_ago = today - DT.timedelta(days=30)
print month_ago
expDateMonthAgo = "CreationDate = [month_ago]"
expDate = "({})".format(expDateMonthAgo)
expressionDate = expDate
outFileRegionDate = open(r"E:\ArcGISProjects\\PythonScripts\PythonSync\PythonScripts\z_outFileRegionDate.csv", "w")
mylist=[]
with arcpy.da.SearchCursor(fc, QueryFields, where_clause=expressionDate) as cursorDate:
outFileRegionDate.write(','.join(headers) + '\n')
flagDate = False
for row in cursorDate:
flagDate = True
zvalDate = str('{0},{1},{2}'.format(row[0],row[1],row[2]))
outFileRegionDate.write(zvalDate + "%s\n")
mylist.append(zvalDate)
if not flagDate:
print "No rows found"
outFileRegionDate.close()
... View more
05-04-2017
10:14 AM
|
0
|
5
|
3220
|
|
POST
|
I get totally different numbers for each...as you alluded to..not sure why UNION = 1275 records SPATIAL JOIN = 2076 records So trying to figure out whats up with all that.... The spatial join gives me the County Polygon...when I select a County I can see the records but they select with the WHOLE County boundary...I cant see their individual boundaries... Thoughts? Can I explode them out or something? Like the UNION gives me?
... View more
05-01-2017
12:30 PM
|
0
|
1
|
1743
|
|
POST
|
Am I doing a Union or a Spatial Join with Intersect?
... View more
05-01-2017
10:16 AM
|
0
|
4
|
1743
|
|
POST
|
I am trying to think of how to populate the County name (County Polygon shapefile) in my Zip Code shapefile (polygon). The challenge is that the Zip Code polygons sometimes cross 2 or three County Boundaries. I have a Zip code Poly and I want to populate a field (county) within the Zip Code shapefile with the County that it resides in. If the Zip crosses two Counties then I guess I would have to Split the County? Does that make sense? Any thoughts?
... View more
05-01-2017
10:04 AM
|
0
|
6
|
2082
|
|
POST
|
Dang that was it...thanks.... I have one more question sort of unrelated and might just post in another post... I have vehicle Laptops that have GPS...Can I tie this into the vehicles GPS...not on a phone?
... View more
04-26-2017
10:03 AM
|
0
|
1
|
1989
|
|
POST
|
I have a BasemapToggle, HomeButton and Search written in the same fashion and same location in the HTML, JS, and CSS files...Its just the LocateButton that dissapears
... View more
04-26-2017
09:07 AM
|
1
|
3
|
1989
|
|
POST
|
I have an app that I wan the Locate Button in. I have to code there, but when I refresh my screen the Locate Button FLASHES for a second and then dissapears. Any thoughts?
... View more
04-26-2017
09:06 AM
|
0
|
4
|
2460
|
|
POST
|
Yea that part I understand...just want to confirm...just gonna give this a test...and add the Fail safe another day. Thanks for your thoughts. Any examples of the code to do the testing? Creating the log file and then testing if it exists? I assume I do this in the python script and not in the Bat file.
... View more
04-19-2017
09:55 AM
|
0
|
0
|
18809
|
| Title | Kudos | Posted |
|---|---|---|
| 1 | 09-20-2018 11:09 AM | |
| 1 | 09-10-2018 06:26 AM | |
| 1 | 09-15-2022 11:02 AM | |
| 1 | 05-21-2021 07:35 AM | |
| 1 | 08-09-2022 12:39 PM |
| Online Status |
Offline
|
| Date Last Visited |
09-19-2022
09:23 PM
|