POST
|
Appreciate the reply. However, my situation is a bit more complex. I'm querying a table that has over 200,000 records and shares relationship classes with more than a dozen feature classes. If I set up a query on that table the related records across all feature classes don't display.
... View more
10-22-2018
11:03 AM
|
0
|
0
|
2043
|
POST
|
I realize this is a year old but I've the same general question. I have a non-spatial table that shares relationship classes with numerous feature layers. Using the query widget against the table does awkwardly bring up the related records from the features in the Results panel. But nothing is highlighted. Has anyone developed a widget that properly highlights/selects/filters features based upon a query of a related table?
... View more
09-20-2018
06:03 AM
|
0
|
3
|
2043
|
POST
|
Yeah, so it looks like under the Search Widget's layer source for one of his layers, it's set to a service URL that isn't actually part of the underlying web map. I'm going to ask him to set it to the service URL that his web map actually points to and we'll see if that fixes it. I probably should have mentioned earlier that this is all hosted by AGOL. He's not using the developer edition or hosting locally. I'm not a full-time developer but given that, I'm not sure how I can browse config_search.json.
... View more
03-29-2017
07:45 AM
|
0
|
0
|
614
|
POST
|
Is that what the 'null' is referring to? yeah, I'll see if he'll let me have edit access to his app to go through it.... Thanks for your feedback and I'll write again after I inspect it closer.
... View more
03-29-2017
06:52 AM
|
0
|
2
|
614
|
POST
|
Absolutely. Keep in mind...this isn't my app. I didn't configure it. I see there's an error here specific to the search widget but at first glance, I'm not sure what is the issue. WebApp link (in dev). Try it logged in and logged out of AGOL.
... View more
03-29-2017
06:27 AM
|
0
|
4
|
614
|
POST
|
A colleague has put together a web app using Web AppBuilder and is simply configuring options (no coding.) His app has uses a bunch of hosted feature layers that are public. However, the Search widget is acting oddly. If the user is signed into AGOL, the widget shows up. If they aren't, the widget does not appear on the map. I've tried this in various browsers and that doesn't seem to matter. I can't find anything online suggesting a user needs to log into an account to use this tool. And the tool works fine (and appears) when logged into AGOL. Not sure what's what...
... View more
03-28-2017
11:12 AM
|
0
|
6
|
1206
|
POST
|
Actually, yeah. I've seen and used that code before. I should have started there. This would do, provided I add a for lyr in layers: line to it.
... View more
01-20-2016
08:41 AM
|
0
|
0
|
499
|
POST
|
I'm having a bit of trouble finding a more suitable way to handle a series of selections/queries based on a many-to-many relationship. The code below works, for the most part, but it's in the "def selectRelatedRecords" section where I know I'm probably unnecessarily repeating steps and could use some input. The basic idea: I have a table (linkTable) where the user selects a field and a value from that table that becomes sqlExp. I then get the value of the field "CR_ID" from the same linkTable where sqlExp is true. I then want to cycle through all the feature layers in the current mxd and get the related records in those layers (again, CR_ID is the same as the now selected records in linkTable.) But what I end up doing is reselecting the same records over and over in the linkTable each time I try to apply a SelectLayerByAtrribute to the available feature layers b/c I'm looping for lyr in layers: I'm really looking for some tweaks so I can maybe put the selected CR_IDs into a list, maybe, and then apply the selectlayerbyattribtue to the available layers. import arcpy, os, string
import arcpy.mapping as MAP
#Needed CR layers as well as Link table should be loaded into current mxd
mxd = MAP.MapDocument("CURRENT")
df = MAP.ListDataFrames(mxd)[0]
#Get Link tables from input
linkTable = arcpy.GetParameterAsText(0)
#Make lists of all feature layers in dataframe
layers = MAP.ListLayers(mxd, "", df)
#set Reg_Code value for regional data into a sql expression
fldName = arcpy.AddFieldDelimiters(arcpy.env.workspace, arcpy.GetParameterAsText(1))
sqlExp = fldName + " = " + " '{0}' ".format(arcpy.GetParameterAsText(2))
arcpy.AddMessage(sqlExp)
#set selection type
selectType = arcpy.GetParameterAsText(3)
#used in generating list of related CR_IDs for match Link table to CR Features.
linkKeyField = "CR_ID"
featureKeyField = "CR_ID"
#Main code to select all records in CR Feature Classes with matching Program ID in Link table
def buildWhereClauseFromList(linkTable, linkKeyField, valueList):
# Add DBMS-specific field delimiters
fieldDelimited = arcpy.AddFieldDelimiters(arcpy.Describe(linkTable).path, linkKeyField)
arcpy.AddMessage("fieldDelimited value: {}".format(fieldDelimited))
# Determine field type
fieldType = arcpy.ListFields(linkTable, linkKeyField)[0].type
# Add single-quotes for string field values
if str(fieldType) == 'String':
valueList = ["'%s'" % value for value in valueList]
# Format WHERE clause in the form of an IN statement
whereClause = "%s IN(%s)" % (fieldDelimited, ', '.join(map(str, valueList)))
return whereClause
arcpy.AddMessage("whereClause: {}".format(whereClause))
if len(layers) > 0:
for lyr in layers:
def selectRelatedRecords(linkTable, lyr, linkKeyField, featureKeyField):
# Defines the record selection from the record selection of the linkTable
# and applys it to the featureTable using a SQL WHERE clause built
# in the previous defintion"""
# Set the SearchCursor to look through the selection of the OriginTable
sourceIDs = set([row[0] for row in arcpy.da.SearchCursor(linkTable, linkKeyField, sqlExp)])
# Establishes the where clause used to select records from DestinationTable
whereClause = buildWhereClauseFromList(lyr, featureKeyField, sourceIDs)
arcpy.AddMessage("whereClause inside selectRelatedRecords: {} \n".format(whereClause))
arcpy.AddMessage("lyr: {0}, selectType: {1}".format(lyr, selectType))
# Process: Select Layer By Attribute
arcpy.SelectLayerByAttribute_management(lyr, selectType, whereClause)
# Process: Select related records between OriginTable and DestinationTable
arcpy.AddMessage("Selecting records in CR Feature Layers related to records in Link table...")
selectRelatedRecords(linkTable, lyr, linkKeyField, featureKeyField)
... View more
01-20-2016
07:49 AM
|
0
|
2
|
2168
|
POST
|
Thank you. I you a link yesterday through email to download some data. I appreciate this greatly. We are using SQL Server 2012.
... View more
12-07-2015
08:17 AM
|
0
|
0
|
461
|
POST
|
Thanks!! It's sql server 2012. Matt Stutts, GIS Specialist Cultural Resources GIS National Park Service Washington, DC 202-354-2149 www.nps.gov/crgis www.facebook.com/crgis
... View more
12-07-2015
08:16 AM
|
0
|
0
|
461
|
POST
|
One last thing... Quite interesting... I was in the process of exporting some data to shapefile. I used a subset of one layer and exported all of the two tables mentioned (catalog and link). I ran both versions of my code... the one that uses SQL and the code you pointed me to that I reconfigured for my needs. BOTH WORKED. So, what's different? Each code is getting hung up on the section where they try to get related records from the Link table based on what's selected in the Catalog table (REG_CODE = 'NER'). The tables are the same in my exported versions....except they are stand-alone .dbfs. My original tests were on live .sde tables. I have no idea how to resolve this but maybe something is going on w/some of the 'NER' related records in my sde database?
... View more
12-04-2015
03:39 PM
|
0
|
3
|
862
|
POST
|
I'll try to get some data but I don't think that's right. Again, with the new version I'm working on, I've already pre-selected all the records in the catalog table where REG_CODE = 'NER'. The code you pointed me to, doesn't rely on that at all. It uses OID, from what I understand. So, 'NER' is never being passed, looked at, or touched in any way. Instead, I'm wondering if there is some kind of odd typo going on with one of the CR_ID values in either table. I'm not sure.
... View more
12-04-2015
03:04 PM
|
0
|
0
|
862
|
POST
|
Also, that part of the code with the IN(%).... I'm not passing 'NER' there. The guid string values from my CR_ID field are being passed in there. I believe.
... View more
12-04-2015
03:01 PM
|
0
|
0
|
461
|
POST
|
I should point out.. .It bombs on this specifically... only when I pick 'NER' arcpy.SelectLayerByAttribute_management(linkTable,'NEW_SELECTION',whereClause)
... View more
12-04-2015
02:58 PM
|
0
|
6
|
862
|
POST
|
That'd make sense if it weren't for the fact that I've since been working w/the other script you pointed me to that doesn't use that whereClause. And again, it bombs out on NER. here's a portion of what I've been working on: # Process: Select Layer By Attribute to pre-select records in catalogTable where REG_CODE = <input> arcpy.SelectLayerByAttribute_management(catalogTable, selOption, sqlExp) # Environment arcpy.env.qualifiedFieldNames = False # Get the set of selected OIDs in the input desc = arcpy.Describe(linkTable) fidSet = desc.FIDSet if fidSet: fidList = fidSet.replace(' ','').split(';') oidSet = set([int(oid) for oid in fidList]) else: oidSet = set() # Get a set of key values arcpy.AddMessage('Finding unique key field values...\n') keyValues = set([row[0] for row in arcpy.da.SearchCursor(catalogTable,"CR_ID")]) # Extract all candidate target OIDs and their key field values # We operate on this set for later selection on ObjectID arcpy.AddMessage('Finding input table ObjectID and key field mapping...\n') sourcePath = os.path.join(desc.path,desc.name) tmpView = "tmpView" arcpy.MakeTableView_management(sourcePath,tmpView) oidKVDict = {row[0]:row[1] for row in arcpy.da.SearchCursor(tmpView, ['OID@',"CR_ID"])} #oidKVList = [(k, v) for (k, v) in oidKVDict.items()] oidKVList = [(k, v) for (k, v) in list(oidKVDict.items())] allSet = set([t[0] for t in oidKVList]) # Find OID values to select on arcpy.AddMessage('Finding selection set...\n') if selOption == 'NEW_SELECTION': # Adopt value set oidList = sorted([t[0] for t in oidKVList if t[1] in keyValues]) elif selOption == 'ADD_TO_SELECTION': # Add value set addSet = set([t[0] for t in oidKVList if t[1] in keyValues]) oidSet |= addSet oidList = sorted(list(oidSet)) elif selOption == 'REMOVE_FROM_SELECTION': # Common values removed remSet = set([t[0] for t in oidKVList if t[1] in keyValues and t[0] in oidSet]) oidSet -= remSet oidList = sorted(list(oidSet)) elif selOption == 'SUBSET_SELECTION': # Common values retained andSet = set([t[0] for t in oidKVList if t[1] in keyValues]) oidSet &= andSet oidList = sorted(list(oidSet)) else: arcpy.AddError('Unknown selection option\n') sys.exit(0) # Make the selection arcpy.AddMessage('Selecting...\n') compOIDList = sorted(list(allSet - set(oidList))) if len(compOIDList) == 0: # select all whereClause = '{} is not null'.format(desc.OIDFieldName) elif len(oidList) == 0: # select none whereClause = '{} < 0'.format(desc.OIDFieldName) elif len(oidList) <= len(compOIDList): inStatement = repr(tuple(oidList)).replace(',)',')') whereClause = '{} in {}'.format(desc.OIDFieldName,inStatement) else: inStatement = repr(tuple(compOIDList)).replace(',)',')') whereClause = '{} not in {}'.format(desc.OIDFieldName,inStatement) arcpy.SelectLayerByAttribute_management(linkTable,'NEW_SELECTION',whereClause) #arcpy.SetParameter(5,linkTable) arcpy.Delete_management(tmpView)
... View more
12-04-2015
02:57 PM
|
0
|
7
|
862
|
Online Status |
Offline
|
Date Last Visited |
11-11-2020
02:23 AM
|