|
POST
|
I looked at the blog post mentioned in your post. I believe you need to add an additional parameter for the name of the second field. The following code gives you an idea of what to add/modify in the validator section. Once you have the value of the first field, it will be used in a where clause to filter the results of the second field selection. Note that the code does not check for field types, so the where clause may not be properly formed. import arcpy
class ToolValidator(object):
"""Class for validating a tool's parameter values and controlling
the behavior of the tool's dialog."""
def __init__(self):
"""Setup arcpy and the list of tool parameters."""
self.params = arcpy.GetParameterInfo()
self.fcfld_1 = (None, None)
self.fcfld_2 = (None, None)
def initializeParameters(self):
"""Refine the properties of a tool's parameters. This method is
called when the tool is opened."""
return
def updateParameters(self):
"""Modify the values and properties of parameters before internal
validation is performed. This method is called whenever a parameter
has been changed."""
if self.params[0].value and self.params[1].value and self.params[2].value and self.params[3].value: # get second field and value list
fc, c_2 = str(self.params[0].value), str(self.params[3].value)
if self.fcfld_2 != (fc, c_2):
self.fcfld_2 = (fc, c_2)
wc = "{} = {}".format(self.params[1].value, str(self.params[2].value)) # where clause does not check field type
self.params[4].filter.list = [str(val) for val in sorted(set(row.getValue(c_2) for row in arcpy.SearchCursor(fc,fields=c_2, where_clause=wc)))]
if self.params[4].value not in self.params[4].filter.list:
self.params[4].value = self.params[4].filter.list[0]
elif self.params[0].value and self.params[1].value: # get first field and value list
fc, c_1 = str(self.params[0].value), str(self.params[1].value)
if self.fcfld_1 != (fc, c_1):
self.fcfld_1 = (fc, c_1)
self.params[2].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[2].value not in self.params[2].filter.list:
self.params[2].value = self.params[2].filter.list[0]
return
def updateMessages(self):
"""Modify the messages created by internal validation for each tool
parameter. This method is called after internal validation."""
return Hope this helps.
... View more
03-11-2018
06:40 PM
|
1
|
1
|
6618
|
|
POST
|
I believe the request should go to: https://www.arcgis.com/sharing/rest/generateToken (word "rest" between sharing and generateToken).
... View more
03-09-2018
12:55 PM
|
0
|
1
|
1793
|
|
POST
|
Xander Bakker has a blog post on this topic with a good code example: Implementing cascading drop down lists in a toolbox using validation with Python.
... View more
03-07-2018
07:34 PM
|
2
|
0
|
6618
|
|
POST
|
My recommendation would be to put a field in the feature table. I would also use a domain with values that would suggest what types of maintenance is required: "None, Inspection, Service, Replacement, etc." You can then symbolize on this field. When the crew has completed the inspection, they select "None" and the symbol changes to the default.
... View more
03-06-2018
04:59 PM
|
1
|
1
|
2486
|
|
POST
|
After you run a tool (like Points to line) in the ArcMap and get results you like, click on Geoprocessing >> Results and you should see the results of that tool. When you right click, you can "Copy as Python Snippet". This will show you the parameters used when the tool was run, and makes it easy to paste into a Python script.
... View more
03-05-2018
03:57 PM
|
1
|
1
|
5228
|
|
POST
|
Since you are using lat/lon, try "WGS 1984" as your spatial reference instead of "NAD 1983 2011 Contiguous US Albers".
... View more
03-05-2018
09:26 AM
|
1
|
0
|
1274
|
|
POST
|
Perhaps export hosted feature layer using python would be of interest.
... View more
02-26-2018
09:39 AM
|
0
|
0
|
1205
|
|
POST
|
See Dan Patterson's comment in this thread: numbering polygon in clockwise. Although the message doesn't have a code example, it gives a suggestion on how this problem might be approached.
... View more
02-25-2018
08:39 PM
|
0
|
1
|
5721
|
|
POST
|
Not knowing your intended use of feature2, I thought having an option to average x,y coordinates might be of interest although keeping the point of the matched community in the Mutual field would probably be your preferred choice. I agree with rfairhur24's comments on aggregating data. Creating the second feature can help you understand the data in feature1, it may help you find data errors, but it should not be a replacement. Hope this helps.
... View more
02-25-2018
08:26 PM
|
1
|
2
|
1594
|
|
POST
|
Here is another version that may give you some additional ideas. It populates an empty feature2, but you could add code to create an empty feature. I think it is simpler and probably more accurate to populate an empty feature. It groups on your "Mutual" field and ignores rows where the value is null. The "Mutual" field is also carried over to feature2, so it could be used for a label. Or the concatenated community names can be the label. An ordered dictionary is used so you can have the communities listed in order, or you can have the codes in order (see photo). By uncommenting/commenting some lines in the code you have the option to use a regular dictionary and omit the order by sql. The x,y point of the community in the "Mutual" field is used, although if desired, it can average the x,y coordinates and produce a point somewhere near the center of the group of points of the joined communities. Richard Fairhurst has given some good ideas regarding data rules, etc. For my part I have not provided any error checking should the data have issues. import arcpy
import itertools
from collections import OrderedDict as OD
mapData = OD([]) # empty ordered dictionary for cities and codes
# you can also use a regular dictionary if sort order is not an issue
# mapData = {} # empty dictionary
fields = ['Community', 'Ref_C_MOLG', 'Mutual', 'SHAPE@XY' ]
fc1 = r'C:\Path\To\Test.gdb\Feature1'
fc2 = r'C:\Path\To\Test.gdb\Feature2'
# read fc1 : an ordered dictionary and sql order by may be of interest
# for row in arcpy.da.SearchCursor(fc1,fields): # if using a regular dictionary and not using order by
# for row in arcpy.da.SearchCursor(fc1,fields,sql_clause=(None,"ORDER BY Ref_C_MOLG")): # to order by Code
for row in arcpy.da.SearchCursor(fc1,fields,sql_clause=(None,"ORDER BY Community")): # to order by Community
if row[2] is not None: # Mutual (for grouping) : ignore rows where this field is null
# mapData { governorate_mutual: [ 'city': 'cityname', 'code': 'numberCode', 'xy': (0.0, 0.0) ] }
item = ["".join(x) for _, x in itertools.groupby(str(row[1]), key=str.isdigit)]
dKey = "{}_{}".format(item[0],row[2])
if dKey in mapData:
mapData[dKey].append({'city': row[0], 'code': item[1], 'xy' : row[3] })
else:
mapData[dKey] = [{'city': row[0], 'code': item[1], 'xy' : row[3] }]
# insert cursor for "empty" fc2
cursor = arcpy.da.InsertCursor(fc2, fields)
for k1, v1 in mapData.iteritems():
city = []
cityCode = []
cityXY =[] # for averaging x,y option
for lst in v1:
city.append(lst['city'])
cityCode.append(lst['code'])
# if averaging x,y for new point
# cityXY.append(lst['xy'])
# if using city in Mutual field
if k1.split('_')[1] == lst['city']:
newXY = lst['xy']
# if averaging x,y for new point
# newXY = [sum(x) / len(x) for x in zip(*cityXY)]
# cursor.insertRow(( ", ".join(city), k1.split('_')[0]+"_".join(cityCode), k1.split('_')[1], tuple(newXY) ))
# if using city in Mutual field
cursor.insertRow(( ", ".join(city), k1.split('_')[0]+"_".join(cityCode), k1.split('_')[1], newXY ))
del cursor
print "Done."
... View more
02-23-2018
09:20 PM
|
1
|
5
|
2647
|
|
POST
|
And in my URL request (way back in my first code block) I like to add "outSR" : "4326" so that I get the geometry in latitude and longitude. I find this is more meaningful than meters when working with Collector and Survey123 data. query_dict = {
"where" : "EditDate >= DATE '2017-04-29 09:00:00'",
"outFields" : "*",
"orderByFields" : "EditDate",
"returnGeometry" : "true",
"outSR" : "4326", # get geometry in lat/lon
"f" : "json", "token" : token['token'] }
... View more
02-22-2018
02:22 PM
|
2
|
1
|
3703
|
|
POST
|
Here's a version of the stackoverflow code that will include the geometry. (Also changed it to tab delimited.) import csv
from datetime import datetime
def timestamp_to_date(t):
return datetime.fromtimestamp(t / 1e3).strftime('%Y-%m-%d %H:%M')
sheetname = 'test'
with open('{}.csv'.format(sheetname), 'wb') as outf:
dw = csv.DictWriter(
outf,
delimiter="\t", # for tab delimited; omit for csv
quotechar="|",
fieldnames=['objectid', 'globalid', 'SurveyDate', 'Ingress1Arrive', 'PointX', 'PointY']
)
dw.writeheader()
for row in gdata2:
row['attributes']['PointX'] = row['geometry']['x']
row['attributes']['PointY'] = row['geometry']['y']
current = row['attributes']
times = {
'Ingress1Arrive': timestamp_to_date(current['Ingress1Arrive']),
'SurveyDate': timestamp_to_date(current['SurveyDate'])
}
current.update(times)
dw.writerow(current)
... View more
02-22-2018
01:10 PM
|
2
|
3
|
3703
|
|
POST
|
Looks like this is best answer. You should mark it as correct.
... View more
02-22-2018
12:17 PM
|
0
|
5
|
3703
|
|
POST
|
I can see how DictWriter would be helpful with lots of columns. I suppose you could loop through gdata2 and edit u'SurveyDate': 1519102800000L so that it contains the time/date data in the desired format before passing it to DictWriter.
... View more
02-22-2018
11:36 AM
|
2
|
7
|
3703
|
| 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
|