|
POST
|
The date is returned as a Unix timestamp or epoch time, usually in UTC. I use something like this to convert to a locally formatted date string: def ts(t): # timestamp_to_date
# return time.strftime('%Y-%m-%d %H:%M:%S UTC', time.gmtime(t/1000)) if t is not None else '' # UTC time
if t is not None:
ts = time.strftime('%Y-%m-%d %H:%M:%S %Z', time.localtime(t/1000)) # epoch utc to local
return ts[:21]+re.sub('[^A-Z]','',ts[21:])
else:
return ''
... View more
05-08-2018
02:17 PM
|
2
|
0
|
1773
|
|
POST
|
Hello Michael, After reviewing you project, I think a script tool solution similar to one in Conditional Drop Down Lists - Tool Validator will work for you (see last code example in the discussion -- the ESRI forum you mentioned was also mentioned in this discussion). In this specific example, the tool takes an input feature and would populate 3 drop down lists with values from 3 fields in that feature. The work of populating the lists is done in the updateParameters section of the ToolValidator. As your needs call for using 7 fields, some blocks of code (such as this snippet) will need to be duplicated and modified to build the final where clause. Each block will drill down to get the user closer to the desired parcel, and the fields will need to be processed in proper sequence. fc, c_3 = str(self.params[0].value), 'Setting' # Check field 'Setting'
if fieldNames['HarvestArea'] == u'String':
wc3 = "{} AND HarvestArea = '{}'".format(wc2, str(self.params[2].value)) # field is string type
else:
wc3 = "{} AND HarvestArea = {}".format(wc2, str(self.params[2].value)) # field assumed to be a number field
self.params[3].filter.list = [str(val) for val in sorted(set(row.getValue(c_3) for row in arcpy.SearchCursor(fc,fields=c_3,where_clause=wc3)))]
if self.params[3].value not in self.params[3].filter.list:
self.params[3].value = self.params[3].filter.list[0] I'm not sure if the script tool really needs to be part of a model. If the tool's only goal is to select and zoom to a parcel, perhaps you wouldn't need a model. Regarding your tool, will users always be searching the same feature class for parcels? Or if they are searching several features, is the structure of the feature always the same -- that is, do the features always contain the same fields (same field name and type)? What are the field names that correspond to District, Town/Village, Quarter, Block, Sheet, Plan, and Parcel Number? In one of the photos above I see the fields: VILL_CCD, DIST_CODE, VIL_NM_E, VIL_MN_G, VIL_CODE. Are these the field names? If you are able to attach a few rows of sample data from your "parcels" layer, that would be helpful.
... View more
05-08-2018
12:48 PM
|
1
|
2
|
4027
|
|
POST
|
If you are using Pro, there's this: Create, modify, and delete subtypes With Desktop, I believe it is a Delete and Add instead of Modify.
... View more
04-27-2018
12:05 PM
|
0
|
1
|
3160
|
|
POST
|
Check out: An overview of the Domains toolset An overview of the Subtypes toolset You should be able to use these tools to do what you need.
... View more
04-26-2018
11:04 AM
|
1
|
1
|
3160
|
|
POST
|
Is it possible that the file's read-only attribute has been set?
... View more
04-24-2018
01:59 PM
|
2
|
0
|
1381
|
|
POST
|
I modified the code to do some error checking (basically to make sure the fields exist in the selected feature and to adjust for fields of either type string or number). I also added some messages in the updateMessages code. For the ToolValidator section: class ToolValidator(object):
def __init__(self):
import arcpy
self.params = arcpy.GetParameterInfo()
def initializeParameters(self):
# (initializeParameters code here)
return
def updateParameters(self):
if self.params[0].value: # feature has been selected
useFields = [u'Forest', u'HarvestArea', u'Setting'] # names of fields used by tool
desc = arcpy.Describe(self.params[0].value) # information about input feature
fieldNames = { f.name: f.type for f in desc.fields } # dictionary used to keep field names and types together
if set(useFields).issubset(fieldNames.keys()) : # all fields found in input feature
fc, c_1 = str(self.params[0].value), 'Forest' # Check field 'Forest'
self.params[1].filter.list = [str(val) for val in sorted(set(row.getValue(c_1) for row in arcpy.SearchCursor(fc,fields=c_1)))]
if self.params[1].value not in self.params[1].filter.list:
self.params[1].value = self.params[1].filter.list[0]
fc, c_2 = str(self.params[0].value), 'HarvestArea' # Check field 'HarvestArea'
if fieldNames['Forest'] == u'String':
wc2 = "Forest = '{}'".format(str(self.params[1].value)) # field is string type
else:
wc2 = "Forest = {}".format(str(self.params[1].value)) # field assumed to be a number field
self.params[2].filter.list = [str(val) for val in sorted(set(row.getValue(c_2) for row in arcpy.SearchCursor(fc,fields=c_2,where_clause=wc2)))]
if self.params[2].value not in self.params[2].filter.list:
self.params[2].value = self.params[2].filter.list[0]
fc, c_3 = str(self.params[0].value), 'Setting' # Check field 'Setting'
if fieldNames['HarvestArea'] == u'String':
wc3 = "{} AND HarvestArea = '{}'".format(wc2, str(self.params[2].value)) # field is string type
else:
wc3 = "{} AND HarvestArea = {}".format(wc2, str(self.params[2].value)) # field assumed to be a number field
self.params[3].filter.list = [str(val) for val in sorted(set(row.getValue(c_3) for row in arcpy.SearchCursor(fc,fields=c_3,where_clause=wc3)))]
if self.params[3].value not in self.params[3].filter.list:
self.params[3].value = self.params[3].filter.list[0]
# output set to completed whereClause
if fieldNames['Setting'] == u'String':
self.params[4].value = "{} AND Setting = '{}'".format(wc3, str(self.params[3].value)) # field is string type
else:
self.params[4].value = "{} AND Setting = {}".format(wc3, str(self.params[3].value)) # field assumed to be a number field
else: # at least one of the field names does not exist in feature; using the parameter to hold an error message
if u'Forest' not in fieldNames.keys():
self.params[1].value = "ERROR: Field 'Forest' not in selected feature class."
if u'HarvestArea' not in fieldNames.keys():
self.params[2].value = "ERROR: Field 'HarvestArea' not in selected feature class."
if u'Setting' not in fieldNames.keys():
self.params[3].value = "ERROR: Field 'Setting' not in selected feature class."
return
def updateMessages(self):
self.params[0].clearMessage()
self.params[1].clearMessage()
self.params[2].clearMessage()
self.params[3].clearMessage()
if self.params[0].value is not None: # set error message if field not in feature so user can correct problem
if self.params[3].value is not None:
if self.params[3].value.startswith("ERROR:"):
# self.params[3].value = None # clear error message in parameter value, if desired
self.params[0].setErrorMessage("Input FC '{}' does not contain field '{}'".format(self.params[0].value, 'Setting'))
self.params[3].setErrorMessage("Field '{}' is not in Input FC '{}'".format('Setting', self.params[0].value))
if self.params[2].value is not None:
if self.params[2].value.startswith("ERROR:"):
# self.params[2].value = None # clear error message in parameter value, if desired
self.params[0].setErrorMessage("Input FC '{}' does not contain field '{}'".format(self.params[0].value, 'HarvestArea'))
self.params[2].setErrorMessage("Field '{}' is not in Input FC '{}'".format('HarvestArea', self.params[0].value))
if self.params[1].value is not None:
if self.params[1].value.startswith("ERROR:"):
# self.params[1].value = None # clear error message in parameter value, if desired
self.params[0].setErrorMessage("Input FC '{}' does not contain field '{}'".format(self.params[0].value, 'Forest'))
self.params[1].setErrorMessage("Field '{}' is not in Input FC '{}'".format('Forest', self.params[0].value))
return
For the script tool, I used the following: import arcpy
inFC = arcpy.GetParameterAsText(0) # input feature class (Input, Data Type 'Feature Layer')
forestVal = arcpy.GetParameterAsText(1) # selected value of Forest field (Input, Data Type 'String')
harvestVal = arcpy.GetParameterAsText(2) # selected value of HarvestArea field (Input, Data Type 'String')
settingVal = arcpy.GetParameterAsText(3) # selected value of Setting field (Input, Data Type 'String')
whereClause = arcpy.GetParameterAsText(4) # set by ToolValidator updateParameters (Output, Derived, Data Type 'String')
arcpy.AddMessage("Where clause used: {}".format(whereClause))
arcpy.SelectLayerByAttribute_management(inFC, "NEW_SELECTION", where_clause=whereClause)
n = arcpy.GetCount_management(inFC)
arcpy.AddMessage("Number of records selected: {}".format(n))
... View more
04-23-2018
01:11 PM
|
1
|
9
|
6618
|
|
POST
|
We were using row0 so that for illustration purposes the variable name looks similar to row[0] , the first element in the SearchCursor row. This would be equal to the contents of the "STREET" field.
... View more
04-20-2018
10:11 AM
|
2
|
0
|
2496
|
|
POST
|
Building on Dan's idea, perhaps: vals = ["Xit","UPRR","Inpr Mp","Impr", "Rxr", "I 84"]
row0 = "I 84 Exit 21"
for v in vals:
if row0.startswith(v):
print "Delete row with {}".format(row0)
# prints: Delete row with I 84 Exit 21
#delete all attributes/Rows that start with Xit, UPRR,Inpr Mp, Impr Rxr, I 84
vals = ["Xit","UPRR","Inpr Mp","Impr", "Rxr", "I 84"]
with arcpy.da.UpdateCursor(lyr, 'STREET') as cursor:
for row in cursor:
for v in vals:
if row[0].startswith(v):
cursor.deleteRow()
... View more
04-20-2018
09:41 AM
|
2
|
0
|
2496
|
|
POST
|
As Debugging a ToolValidator class suggests, I placed the ToolValidator in a script that could be run inside an IDE where I could use print statements for testing purposes. There may be additional checks you will want to add to the code, such as a test that the 3 fields you are checking exist in the feature. I used the following code: # HELP at http://desktop.arcgis.com/en/arcmap/latest/analyze/creating-tools/debugging-a-toolvalidator-class.htm
import arcpy
# Load the toolbox and get the tool's parameters, using the tool
# name (not the tool label).
#
arcpy.ImportToolbox(r"C:\Path\To\Toolbox.tbx") # toolbox location
params = arcpy.GetParameterInfo("SelectAttributes") # name of script (not tool label)
# Set required parameters
#
params[0].value = r"C:\Path\To\geodatabase.gdb\Settings" # feature layer
# ToolValidator class block
# ----------------------------------------------------------------
class ToolValidator(object):
def __init__(self):
import arcpy
self.params = arcpy.GetParameterInfo()
def initializeParameters(self):
# (initializeParameters code here)
return
def updateParameters(self):
if self.params[0].value: # feature has been selected
# may want to insert some code to insure that selected feature has fields 'Forest', 'HarvestArea' and 'Setting'
fc, c_1 = str(self.params[0].value), 'Forest' # Check field 'Forest'
self.params[1].filter.list = [str(val) for val in sorted(set(row.getValue(c_1) for row in arcpy.SearchCursor(fc,fields=c_1)))]
if self.params[1].value not in self.params[1].filter.list:
self.params[1].value = self.params[1].filter.list[0]
print self.params[1].filter.list[0] ### Debug ###
print len(self.params[1].filter.list) ### Debug ###
fc, c_2 = str(self.params[0].value), 'HarvestArea' # Check field 'HarvestArea'
wc2 = "Forest = '{}'".format(str(self.params[1].value)) # where assumes string values for fields
self.params[2].filter.list = [str(val) for val in sorted(set(row.getValue(c_2) for row in arcpy.SearchCursor(fc,fields=c_2,where_clause=wc2)))]
if self.params[2].value not in self.params[2].filter.list:
self.params[2].value = self.params[2].filter.list[0]
print self.params[2].filter.list[0] ### Debug ###
print len(self.params[2].filter.list) ### Debug ###
fc, c_3 = str(self.params[0].value), 'Setting' # Check field 'Setting'
wc3 = "Forest = '{}' AND HarvestArea = '{}'".format(str(self.params[1].value), str(self.params[2].value)) # where assumes string values for fields
self.params[3].filter.list = [str(val) for val in sorted(set(row.getValue(c_3) for row in arcpy.SearchCursor(fc,fields=c_3,where_clause=wc3)))]
if self.params[3].value not in self.params[3].filter.list:
self.params[3].value = self.params[3].filter.list[0]
print self.params[3].filter.list[0] ### Debug ###
print len(self.params[3].filter.list) ### Debug ###
return
def updateMessages(self):
# (updateMessages code here)
return
# ----------------------------------------------------------------
# Call routine(s) to debug
#
validator = ToolValidator()
validator.updateParameters()
validator.updateMessages() Once the code tested without errors I pasted it (lines 17 to 59 minus the print lines 36, 37, 44, 45, 52 and 53) into the validation section of the script tool. As my testing environment may be a bit different from yours, my script tool code used was: import arcpy
inFC = arcpy.GetParameterAsText(0) # input feature class (Data Type 'Feature Layer')
forestVal = arcpy.GetParameterAsText(1) # selected value of Forest field (Data Type 'String')
harvestVal = arcpy.GetParameterAsText(2) # selected value of HarvestArea field (Data Type 'String')
settingVal = arcpy.GetParameterAsText(3) # selected value of Setting field (Data Type 'String')
forestFld = "Forest"
harvestFld = "HarvestArea"
settingFld = "Setting"
whereClause = "{} = '{}' AND {} = '{}' AND {} = '{}'".format(forestFld,forestVal,harvestFld,harvestVal,settingFld,settingVal)
arcpy.SelectLayerByAttribute_management(inFC, "NEW_SELECTION", where_clause=whereClause) Note in the where clauses, since we are using text values, the format used was: WHERE Field = 'some text' You my need to adjust this for your SQL version and/or to escape certain characters. Hope this helps and best of luck with your project.
... View more
04-19-2018
12:14 PM
|
1
|
0
|
6618
|
|
POST
|
The error message is suggesting that the string "203-001-01" is trying to be converted to an integer. Perhaps the tool's parameter has the wrong data type selection or perhaps the where clause in the validation section is changing it. I haven't had a chance to examine your validation code yet. But I do have a some questions so that I may understand what you are wanting to accomplish. It looks like you are trying to select rows from the feature class where Forest, HarvestArea and Setting contain specific values. Are these fields all text fields, or are some integer or other data types? Do all input feature classes contain these three fields (ie. they are always the same field names and data types)? Can you share a few rows of sample data from your feature?
... View more
04-16-2018
09:56 PM
|
1
|
1
|
6618
|
|
POST
|
As a test, do you get a count if you check just before the SelectByLocation? arcpy.MakeFeatureLayer_management('events', 'eventsLyr')
# check here to see if layer has a count
n = arcpy.GetCount_management('eventsLyr')
print n
arcpy.SelectLayerByLocation_management('eventsLyr', 'INTERSECT','selectLyr')
... View more
04-16-2018
09:08 AM
|
1
|
1
|
1275
|
|
POST
|
I've used something like the following: import arcpy
srcFeature = r'C:\Path\To\geodatabase.gdb\test1'
srcFields = ['SHAPE@X', 'SHAPE@Y', 'MyField'] # x & y plus additional fields as needed
srcSR = 3857 # Web Mercator - change as needed
destFeature = r'C:\Path\To\geodatabase.gdb\test2'
destFields = ['SHAPE@X', 'SHAPE@Y', 'MyField'] # x & y plus additional fields as needed
destSR = 4326 # WGS 1984 (Lat/Lon) - change as needed
whereClause = '1=1' # edit as needed
with arcpy.da.InsertCursor(destFeature, destFields) as destCursor: # destination - insert cursor
with arcpy.da.SearchCursor(srcFeature, srcFields, where_clause=whereClause) as srcCursor: # source - search cursor
for srcRow in srcCursor:
destRow = [None]* len(destFields) # initialize destRow for number of fields to be inserted
ptGeometry = arcpy.PointGeometry(arcpy.Point(srcRow[0], srcRow[1]), arcpy.SpatialReference(srcSR)).projectAs(arcpy.SpatialReference(destSR))
destRow[0] = ptGeometry.firstPoint.X # x coord
destRow[1] = ptGeometry.firstPoint.Y # y coord
destRow[2] = srcRow[2] # additional field(s)
destCursor.insertRow(destRow)
del destCursor, srcCursor For spatial reference, use WKID number. You can add additional fields, if you want them transferred. I've added a generic where clause which can be modified if you only have a specific group of points to transfer. Hope this helps.
... View more
04-11-2018
10:15 PM
|
1
|
1
|
4226
|
|
POST
|
If there is more than 1 match, you will get an index error. Also a bracket is missing. [0, 1][sum([True for i in [!a!, !b!, !c!, !d!] if i in [!e!, !f!]])] But it is a nice way to make multiple comparisons. a = 'a'
b = 'b'
c = 'c'
d = 'd'
e = 'd'
f = 'b'
print sum([True for i in [a, b, c, d] if i in [e, f]])
print "yes" if sum([True for i in [a, b, c, d] if i in [e, f]]) else "no"
# results
2
yes
... View more
04-11-2018
10:20 AM
|
1
|
0
|
2133
|
|
POST
|
Perhaps describe catalogPath: import arcpy
InputFeatureClass = arcpy.GetParameterAsText(0)
desc = arcpy.Describe(InputFeatureClass)
arcpy.AddMessage("{}".format(desc.catalogPath))
# or
arcpy.AddMessage("{}".format(desc.dataElement.catalogPath))
... View more
04-10-2018
10:38 PM
|
1
|
3
|
3768
|
|
POST
|
You can also use "in" if type(valName) in (str, unicode) else ...
... View more
04-10-2018
03:11 PM
|
2
|
0
|
1591
|
| 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
|