|
POST
|
It looks like your edit session is being set-up correctly. However, I do not think you are using the UpdateCursor correctly - specifically lines 14-18 in your code. I don't think you are actually changing anything. If the code is part of a custom script tool or Python toolbox, you may not be seeing any messages or errors generated by the update cursor. Since the AddMessage is working, you might try adding this code immediately using GetMessages following the update cursor to display any messages from the update cursor: arcpy.AddMessage(arcpy.GetMessages())
... View more
05-16-2019
11:57 AM
|
0
|
0
|
5441
|
|
POST
|
After a quick look at your functions, you might set and then pass the workspace to your function: def someFunction(ws):
workspace = ws
# more code
return something
workspace1 = r'C:\Some\Path\to\data1.gdb'
x = someFunction(workspace1)
workspace2 = r'C:\Some\Path\to\data2.gdb'
y = someFunction(workspace2)
Is this what you are looking for?
... View more
05-14-2019
04:30 PM
|
2
|
0
|
9868
|
|
POST
|
I suspect the issue is with the field name in line 11 of your code. (I assume this is the code/formatting you are using.) class OK(object):
"""Implementation for ok.button (Button)"""
def __init__(self):
self.enabled = True
self.checked = False
def onClick(self):
mxd = arcpy.mapping.MapDocument("CURRENT")
df = mxd.activeDataFrame
arcpy.MakeFeatureLayer_management(layer, "layerSel")
where_clause = "\"field\"= + '"+ valueS + "'"
arcpy.SelectLayerByAttribute_management("layerSel","NEW_SELECTION",where_clause)
df.zoomToSelectedFeatures()
arcpy.RefreshActiveView() You may need a input for the field you want: field = 'myField'
valueS = 'someValue'
where_clause = "\"{}\" = '{}'".format(field, valueS)
# result:
# "myField" = 'someValue'
... View more
05-13-2019
11:25 AM
|
1
|
0
|
1586
|
|
POST
|
I haven't worked a lot with add-ins, but I have experienced issues with script tools and Python toolboxes not working well with global variables. I think it has to do with how/where the global is declared and function calls. This link may give some insight, but won't directly answer your question: Python toolbox tool objects do not remember instance variables between function calls?
... View more
05-10-2019
02:36 PM
|
0
|
0
|
15678
|
|
POST
|
My initial guess would be that you are starting with an original feature table called "Field_Point" and that the linked attachment table is expected to be "Field_Point__ATTACH". Depending on your geodatabase type, it may be using a different naming system than what the code expects. Changes to lines 5-6 may be required. I would use Catalog to explore your database and verify the names of the feature and attachment tables.
... View more
05-08-2019
12:03 PM
|
2
|
0
|
6641
|
|
POST
|
You should be familiar with Python's datetime module and ArcGIS' Update Cursor tool. For a more specific answer, you should describe your work environment. What version of Python and ArcGIS are you using? What is the type of geodatabase?
... View more
05-08-2019
09:31 AM
|
1
|
3
|
2550
|
|
POST
|
The search cursor returns a tuple. Try taking the first element in the tuple: list1 = []
cursor = arcpy.da.SearchCursor("R:\Projects\MAP_Projects.gdb\MAP_INDEX","Map_No")
for row in cursor:
list1.append(row[0]) # take first element in row
list1.sort()
... View more
05-07-2019
10:17 AM
|
0
|
2
|
3470
|
|
POST
|
You can iterate through a dictionary, but some simple loops are easy. Just ideas.. months = {1:'jan',2:'feb',3:'mar',4:'apr',5:'may',6:'jun',7:'jul',8:'aug',9:'sep',10:'oct',11:'nov',12:'dec'}
for yr in range(2018,2019): # stop when 2019 is reached
for mo in months:
print yr, mo, months[mo]
print "Month = {} AND Year = {}".format(mo,yr)
print "{}_{}".format(months[mo], yr)
''' prints:
2018 1 jan
Month = 1 AND Year = 2018
jan_2018
... etc.
'''
for yr in range(2018, 2019): # stop when 2019 is reached
for mo in range(1,13): # stop when 2019 is reached
print yr, mo
''' prints
2018 1
2018 2
...
2018 11
2018 12
'''
... View more
05-06-2019
04:47 PM
|
1
|
0
|
5566
|
|
POST
|
# instead of OID@
with arcpy.da.SearchCursor(sel_lyr,"GNIS_Name",'OID@' = sel_oid) as cursor:
# try OBJECTID or the field's actual name instead of a token
# also note the quotes around the sql part
with arcpy.da.SearchCursor(sel_lyr,"GNIS_Name","OBJECTID = sel_oid") as cursor:
... View more
05-03-2019
10:04 AM
|
0
|
12
|
6808
|
|
POST
|
It looks like your friend is working with a custom script toolbox and not a Python toolbox. There's some differences in the coding and how they work. See Comparing custom and Python toolboxes. I am assuming you want to use arcpy.Select_analysis in your tool. This tool requires 2 parameters with an optional where clause. Select_analysis (in_features, out_feature_class, {where_clause}) In my sample script, there are three parameters: one for the in_features and two for use in the where clause. You will need to add another parameter which will be the out_feature_class. Replace lines 47-48 with something like: outFC = arcpy.Parameter(
displayName = "Feature to be saved",
name = "outFC",
datatype = "DEFeatureClass",
parameterType = "Required",
direction = "Output")
return [ feature, startDate, endDate, outFC ] The execute block also will need changes. Replace lines 65 to the end with something like: def execute(self, parameters, messages):
"""The source code of the tool."""
feature = parameters[0].valueAsText
startDate = parameters[1].value.strftime("%Y-%m-%d %H:%M:%S")
endDate = parameters[2].value.strftime("%Y-%m-%d %H:%M:%S")
outFC = parameters[3].valueAsText
where = "DateTime BETWEEN DATE '{}' AND DATE '{}'".format(startDate, endDate)
# messages.addMessage('Where: {}'.format(where))
arcpy.Select_analysis(feature, outFC, where)
for i in range(arcpy.GetMessageCount()):
messages.addMessage(arcpy.GetMessage(i))
return
You will need to watch the indentation as you edit your code. Lines 14-15 ( for i in range.... GetMessage ) will print the output of the Select_analysis tool, so you can see the parameters that are passed to it and any status messages it produces. As Joe Borgione pointed out in his comment will be the formatting of the time/date. You may need to investigate the SQL reference for your geodatabase. I am assuming that it is a file geodatabase (.gdb). Field names can be put inside double quotes, but this appears to be optional. Date/time strings go inside single quotes, and the DATE in front of the string might also be optional. Again, this depends on your geodatabase. As you finalize your project, you may want to add some code in the updateParameters section for validating your parameters.
... View more
05-01-2019
11:00 PM
|
1
|
0
|
686
|
|
POST
|
I was doing some experimenting with a Python toolbox and came up with the following code: import arcpy
import datetime
class Toolbox(object):
def __init__(self):
"""Define the toolbox (the name of the toolbox is the name of the
.pyt file)."""
self.label = "Toolbox"
self.alias = ""
# List of tool classes associated with this toolbox
self.tools = [Tool]
class Tool(object):
def __init__(self):
"""Define the tool (tool name is the name of the class)."""
self.label = "Tool"
self.description = ""
self.canRunInBackground = False
def getParameterInfo(self):
"""Define parameter definitions"""
feature = arcpy.Parameter(
displayName = "Feature layer to search",
name = "feature",
datatype = "GPFeatureLayer",
parameterType = "Required",
direction = "Input")
startDate = arcpy.Parameter(
displayName = "Select start date",
name = "startDate",
datatype = "GPDate",
parameterType = "Required",
direction = "Input")
endDate = arcpy.Parameter(
displayName = "Select ending date",
name = "endDate",
datatype = "GPDate",
parameterType = "Required",
direction = "Input")
params = None
return [ feature, startDate, endDate ]
def isLicensed(self):
"""Set whether tool is licensed to execute."""
return True
def updateParameters(self, parameters):
"""Modify the values and properties of parameters before internal
validation is performed. This method is called whenever a parameter
has been changed."""
return
def updateMessages(self, parameters):
"""Modify the messages created by internal validation for each tool
parameter. This method is called after internal validation."""
return
def execute(self, parameters, messages):
"""The source code of the tool."""
# the addMessages are for debugging and can be removed
messages.addMessage('Feature: {}'.format(parameters[0].valueAsText))
messages.addMessage('Start: {}'.format(parameters[1].valueAsText))
messages.addMessage('End: {}'.format(parameters[2].valueAsText))
messages.addMessage('Type: {}'.format(type(parameters[2].value)))
# one way to set the time portion
# startDate = '{} 00:00:00'.format(parameters[1].value.strftime("%Y-%m-%d"))
# endDate = '{} 23:59:59'.format(parameters[2].value.strftime("%Y-%m-%d"))
startDate = parameters[1].value.strftime("%Y-%m-%d %H:%M:%S")
endDate = parameters[2].value.strftime("%Y-%m-%d %H:%M:%S")
where = "DateTime BETWEEN DATE '{}' AND DATE '{}'".format(startDate, endDate)
messages.addMessage('Where: {}'.format(where))
arcpy.SelectLayerByAttribute_management(parameters[0].valueAsText, "NEW_SELECTION", where_clause=where)
return There are lots of addMessage() for debugging. At line 72, I used the type function to verify that the parameter being used was a datetime type. In addition I came across this topic: arcpy script tool - format parameter Date data type. It may provide some additional insight in how date/time works in a Python script or toolbox. Hope this helps.
... View more
04-30-2019
11:35 PM
|
2
|
1
|
5478
|
|
POST
|
'BETWEEN' will also work in date queries. For example with a file geodatabase: where = "DateTime BETWEEN DATE '2019-04-01 00:00:00' AND DATE '2019-04-30 23:59:59'"
with arcpy.da.SearchCursor(feature, ['DateTime'], where_clause=where) as cursor:
for row in cursor:
print row You will need to check the SQL documentation for the type of geodatabase you are working with. And the datetime module can also be very helpful. from datetime import datetime, timedelta
date_past = datetime.now() - timedelta(days=180)
wc = "DateField < DATE '{}'".format(date_past.strftime("%Y-%m-%d %H:%M:%S"))
print wc
... View more
04-30-2019
09:29 AM
|
3
|
1
|
5478
|
|
POST
|
Some things to try (assuming there is no space in the last name - that is not a name like Van Gogh): >>> name = 'Doe M Jane'
>>> ', '.join(name.split(" ", 1))
'Doe, M Jane'
>>> " ".join(name.split(" ", 1).__reversed__()).replace(',','')
'M Jane Doe'
>>> name = 'Doe, M Jane'
>>> if ',' not in name:
', '.join(name.split(" ", 1))
>>> name
'Doe, M Jane'
>>> name = 'Doe M Jane'
>>> if ',' not in name:
', '.join(name.split(" ", 1))
'Doe, M Jane'
... View more
04-19-2019
02:27 PM
|
2
|
0
|
3545
|
|
POST
|
You will also need to close the file before renaming it. Perhaps: for root, dirnames, filenames in os.walk(im): #iterate directory
for fname in filenames:
if fname.endswith('.JPG'):
with open(os.path.join(root, fname), 'rb') as image: #file path and name
exif = exifread.process_file(image)
dt = str(exif['EXIF DateTimeOriginal']) #get 'Date Taken' from JPG
ds = time.strptime(dt, '%Y:%m:%d %H:%M:%S')
nt = time.strftime("%Y-%m-%d",ds)
newname = fname[0:7] + "_" + nt + ".jpg"
image.close()
os.rename(os.path.join(root,fname), os.path.join(root,newname))
... View more
04-16-2019
02:12 PM
|
0
|
1
|
6000
|
|
POST
|
You need to change the slashes in the date to either dashes or underscore. Slashes are used to separate directories in the path, so they cannot be used in a file name. # change this
nt = time.strftime("%m/%d/%Y",ds)#variable with 'Date Taken'
# to
nt = time.strftime("%m-%d-%Y",ds)
# or
nt = time.strftime("%m_%d_%Y",ds)
... View more
04-16-2019
12:39 PM
|
1
|
3
|
6000
|
| Title | Kudos | Posted |
|---|---|---|
| 1 | 10-27-2016 02:23 PM | |
| 1 | 09-09-2017 08:27 PM | |
| 2 | 08-20-2020 06:15 PM | |
| 1 | 10-21-2021 09:15 PM | |
| 1 | 07-19-2018 12:33 PM |
| Online Status |
Offline
|
| Date Last Visited |
02-12-2026
07:13 PM
|