POST
|
I have used this script in the past:
import arcpy, os, sys
arcpy.env.ovewriteOutput = True
arcpy.env.qualifiedFieldNames = False
def SelectRelatedRecords(in_ft, in_field, rel_table, rel_field, sql=''):
'''
Selects all features from input layer based on selection from another table. Acts like
a "relationship class". There must be a common field between the two tables.
in_ft = input features
in_field = field for the relate from input features
rel_table = related table
rel_field = related table field
sql = SQL Query for the related table (optional)
'''
# Check to make sure field types match, otherwise raise error and exit tool
in_ft_fields = arcpy.Describe(in_ft).fields
ftype1 = [f.type for f in in_ft_fields if f.name == in_field][0]
ftype2 = [f.type for f in arcpy.Describe(rel_table).fields if f.name == rel_field][0]
if ftype1 != ftype2:
arcpy.AddError('\nField type for "{0}" in "{1}" does not match field type for "{2}"' \
' in "{3}"!\n'.format(in_field,in_ft,rel_field,rel_table))
arcpy.AddError('Field type is "{0}", must be "{1}".\n'.format(ftype1,ftype2))
sys.exit()
# map doc
mxd = arcpy.mapping.MapDocument('CURRENT')
df = arcpy.mapping.ListDataFrames(mxd)[0]
# determine version for cursor type
ver = float(arcpy.GetInstallInfo()['Version'])
if ver > 10:
dataAccess = True
else:
dataAccess = False
# make feature layer if sql
if sql:
arcpy.SelectLayerByAttribute_management(rel_table, 'NEW_SELECTION', sql)
rel_count = int(arcpy.GetCount_management(rel_table).getOutput(0))
arcpy.AddMessage('\n{0} selected records from from "{1}"\n'.format(rel_count, rel_table))
# grab unique id's
if dataAccess:
with arcpy.da.SearchCursor(rel_table, [rel_field]) as rows:
if ftype2 == 'String':
recs = tuple(r[0].encode('utf-8') for r in rows)
else:
recs = tuple(r[0] for r in rows)
else:
rows = arcpy.SearchCursor(rel_table)
if ftype2 == 'String':
recs = tuple(r.getValue(rel_field).encode('utf-8') for r in rows)
else:
recs = tuple(r.getValue(rel_field) for r in rows)
del rows
# Select records in in_ft table
par_path = os.path.dirname(arcpy.Describe(in_ft).catalogPath)
where = ''' {0} in {1} '''.format(arcpy.AddFieldDelimiters(par_path, in_field), recs)
arcpy.SelectLayerByAttribute_management(in_ft, 'NEW_SELECTION', where)
sel_count = int(arcpy.GetCount_management(in_ft).getOutput(0))
arcpy.AddMessage('Selected {0} related records from "{1}"\n'.format(sel_count, in_ft))
return
if __name__ == '__main__':
# Get args
argv = tuple(str(arcpy.GetParameterAsText(i)) for i in range(arcpy.GetArgumentCount()))
# Run it
SelectRelatedRecords(*argv)
This should do the trick. I have a more complicated version where there is an option to export the selected records joined to the related table. You can download the attached toolbox if you want to try this one out. Thanks for the quick reply!
... View more
02-06-2014
08:21 AM
|
0
|
0
|
2830
|
POST
|
Is there any way to select related records using python? similar to the related records button within ArcMap. I like to include this operation as a script in a GP Model. Thanks in advanced. EC
... View more
02-06-2014
08:18 AM
|
0
|
0
|
2830
|
POST
|
Is there any way to select related records using python? similar to the related records button within ArcMap. I like to include this operation as a script in a GP Model. Thanks in advanced. EC
... View more
02-06-2014
08:06 AM
|
1
|
11
|
11575
|
POST
|
Ernesto, out of the box the query tool don't contain date-pickers. You will have to implement it yourself. The code for the add-in is available. That makes me think to implement a date-picker into the query tool myself. Hmmm, hopefully someone can modify/or create such tool.... My coding/programming skills are limited. 😞 Thanks for your input.
... View more
12-03-2013
09:23 AM
|
0
|
0
|
231
|
POST
|
Hi, just wondering if there is a query tool, such as an add-in, to query date data type fields. I am using a new query add-in, which is great but when I configured the Date field, the space provided to add the values only support text. Therefore, instead of appearing a calendar to select the date values, I have to type something like: date '2012-04-08' in order to select the records. Any ideas? I am using the most current ArcGIS Viewer for Silverlight. Thanks in advanced.
... View more
12-02-2013
03:20 AM
|
0
|
2
|
711
|
POST
|
Hi, I need to calculate the difference between two dates in days. I need it to work within the Model Builder since these are models that need to be published later as a GP service. I have two fields, one with the Inspection date and the other with the Current date. Something similar to the below VBscript: DateDiff("d", [date_field], Now()) Any advice will be appreciated. Thanks in advanced.
... View more
11-19-2013
10:51 AM
|
0
|
5
|
4842
|
POST
|
Hi Frank Yes, they are the same locators. Regards Bruce, isn't the world locator be part of the community project? Does the World Geocoding service contains more data contributed by other sources (local) other thank NAVTEQ and TomTom?
... View more
09-06-2013
05:25 AM
|
0
|
0
|
426
|
POST
|
Is there a way to configure popup windows to show only those fields that have populated values in them? In other words, disable empty or blank fields (which will vary across the dataset). I don???t want to turn off the field in the Configuration set up panel since some features have values and others do not.
... View more
09-06-2013
04:11 AM
|
0
|
0
|
1840
|
POST
|
In this, I am not speaking officially for Esri (hey, I handle map projections, not geocoding), but I used the Wayback Machine (web.archive.org) to check a random earlier version of the page. The rate was 80 credits per 1000 geocodes in April 2013. April 2013 version of the Geocoding page of ArcGIS Online Thanks everyone!!
... View more
08-06-2013
11:53 AM
|
0
|
0
|
372
|
POST
|
Mike, I just wanted to confirm they credits were adjusted to what was announcd during the past conference: "Geocoding costs have been reduced by 50 percent." http://www.esri.com/esri-news/releases/13-3qtr/get-more-with-arcgis-online I will appreciate if you can confirm this fact. Reagrds, Ernesto
... View more
08-06-2013
09:54 AM
|
0
|
0
|
372
|
POST
|
Is this page up-to-date? http://www.esri.com/software/arcgis/arcgisonline/credits/geocoding
... View more
08-03-2013
09:49 AM
|
0
|
0
|
372
|
POST
|
Is this page up-to-date? http://www.esri.com/software/arcgis/arcgisonline/credits/geocoding
... View more
08-03-2013
09:48 AM
|
0
|
5
|
853
|
POST
|
So you have an Advanced license, which is good, since that gives you the most options. What was the search radius setting that you used? Not specifying a radius would probably require eseentially perfect alignment of your points and lines, and nearly invisible imperfections in the alignment would result in lines not splitting. You may also want to make a copy of your data and run the Integrate tool first to ensure the lines and points are fully snapped before trying the Split Lina at Point tool. Will the tool actually split the line at every single location where it intersects with a point?
... View more
05-16-2013
08:58 AM
|
0
|
0
|
455
|
POST
|
Your post is completely vague. What did you expect that you did not get? A picture of what you got and comments on what you don't like would help a lot. Sorry for not been so clear. Basically I have two Feature Classes, one for points and one for liens. Some points intersect the lines. I want to run a script or tool that splits the line wherever the point intersects the lines (like valves on top of mains). I have tried the Split Lines at Points but it does not split the lines wherever the point intersect the lines.[ATTACH=CONFIG]24369[/ATTACH]
... View more
05-16-2013
05:03 AM
|
0
|
0
|
455
|
Title | Kudos | Posted |
---|---|---|
1 | 11-19-2014 07:02 AM | |
1 | 02-06-2014 08:06 AM | |
7 | 02-13-2016 08:12 AM | |
1 | 02-16-2015 08:10 AM |
Online Status |
Offline
|
Date Last Visited |
11-11-2020
02:24 AM
|