|
POST
|
Since a regular dictionary does not track the insertion order, iterating over it produces the values in order based on how the keys are stored in the hash table. You need to use some sort of sorting when you iterate it. Or use an ordered dictionary where the insertion order is remembered. import collections
domDict = { 'ZA': 'First Option',
'AZ': 'Second Option',
'QA': 'Third Option',
'BT': 'Fourth Option',
'TC': 'Fifth Option'
}
print '\nunorderd dictionary'
for code in domDict:
print "{} : {}".format(code, domDict[code])
order = {
'ZA': 0,
'AZ': 1,
'QA': 2,
'BT': 3,
'TC': 4
}
print '\nsorted dictionary'
for code in sorted(order, key=order.get):
print "{} : {}".format(code, domDict[code])
od = collections.OrderedDict( [
('ZA','First Option'),
('AZ','Second Option'),
('QA','Third Option'),
('BT','Fourth Option'),
('TC','Fifth Option')
] )
print '\nordered dictionary'
for code in od:
print "{} : {}".format(code, od[code])
# for code in od:
# arcpy.AddCodedValueToDomain_management(gdb, domName, code, od ) Even using an ordered dictionary, you still may find your domain isn't in the order you want. This is why I would recommend using either codes or descriptions that can be sorted using the Sort Coded Domain tool (similar to suggestions in first post). Then you can add new domain entries and easily resort the domain.
... View more
07-18-2017
10:57 PM
|
2
|
4
|
4785
|
|
POST
|
Here's an idea: def sort_it(d, order):
return [d[k] for k in sorted(order, key=order.get)]
d = { 'QA': 'Third Option',
'BT': 'Fourth Option',
'AZ': 'Second Option',
'ZA': 'First Option',
'TC': 'Fifth Option'
}
order = {
'ZA': 0,
'AZ': 1,
'QA': 2,
'BT': 3,
'TC': 4
}
print sort_it(d, order)
# ['First Option', 'Second Option', 'Third Option', 'Fourth Option', 'Fifth Option']
... View more
07-17-2017
05:48 PM
|
0
|
6
|
4785
|
|
POST
|
The Sort Coded Value Domain tool will sort by either code or description in ascending or descending order. As Rebecca Strauch, GISP mentioned you can force the sort order, either using integers or text. For integers, I'll use a sequence like 1001, 2101, 2102, 2201 ... etc. that allows for insertion of new values at an appropriate place. I have increasingly used text strings for codes using 2 or three letters for a code that make an understandable abbreviation of the description. I also have used a combination of letters and numbers for codes, such as A01, A02, B01, C01, C05 ... etc. where the letter would be an abbreviation for the group and the number would be the order in the group. If you are using a python script, you might try creating a dictionary of domain codes and values for a custom sort. Just an idea...
... View more
07-17-2017
12:18 PM
|
1
|
8
|
4785
|
|
POST
|
Around line 115, change the query to: # build sql
sql = "{} <> '{}'".format(message['status field'], message['completed value'])
sql += " AND {}".format(message['query'])
I believe the SQL for AGOL uses "<>" instead of "!=" for not equals. Also, no single quotes around the field names.
... View more
07-17-2017
09:26 AM
|
1
|
1
|
3369
|
|
POST
|
I noticed a slash at the end of your service url around line 62. I don't think it should be there, so try removing it along with my previous suggestion. 'service url': 'https://services6.arcgis.com/ ... /Complaint/FeatureServer/0/' If that doesn't fix it , then I'd add a "print sql" around line 115, as indicated above, which should show you what the where query is. # build sql
sql = "{} != '{}'".format(message['status field'], message['completed value'])
sql += " AND {}".format(message['query'])
print sql # find out if sql is being properly formated
feature_layer = FeatureLayer(email_service['service url'], target)
features = _get_features(feature_layer, sql) From the code it looks like it should be: EMAIL != 'Completed' AND STATUS = 'Unassigned' Are the fields STATUS and EMAIL in the feature you are querying? Also, does the error message indicate which line it is happening on? It looks like the JSON response from the query is being printed out.
... View more
07-14-2017
02:54 PM
|
1
|
4
|
3369
|
|
POST
|
Around line 64, instead of: 'query': "'STATUS'= 'Unassigned'", Try it without single quotes around STATUS: 'query': "STATUS = 'Unassigned'",
... View more
07-14-2017
11:00 AM
|
0
|
6
|
3369
|
|
POST
|
When I create domains, I start with an Excel workbook with one domain per tab. I then run a python script to create a table in a file geodatabase for each domain and import the data from the spreadsheet. A second python script converts the table to a domain. I will use a third script, similar to the first, to create my feature layers. To create the tables: # Description: Add fields and datato a table
import xlrd
import arcpy
from arcpy import env
# name of geodatabase
geoDB = r"C:\Path\To\filedb.gdb"
# name of excel workbook
excelWB = r"C:\Path\To\workbook.xlsx"
# set environment settings
env.workspace = geoDB
# work happens here
def new_table(dbTable, dbFields, geoDB, excelWB):
# create the table
print "\nCreating table: " + dbTable
# set local variables
template = ""
config_keyword = ""
# Execute CreateTable
arcpy.CreateTable_management(geoDB, dbTable, template, config_keyword)
# add the fields
print "Adding fields: "
for new_field in dbFields:
# add new field
print "\t" + new_field[0]
# all fields using domains are non-nullable
if (new_field[4] == "#"):
nullable = "NULLABLE"
else:
nullable = "NON_NULLABLE"
# AddField_management (in_table, field_name, field_type, {field_precision}, {field_scale},
# {field_length}, {field_alias}, {field_is_nullable}, {field_is_required}, {field_domain})
arcpy.AddField_management(dbTable,new_field[0],new_field[1],"#","#",
new_field[2],new_field[3],nullable,"NON_REQUIRED",new_field[4])
# read Excel workbook
print "Adding data from Excel"
workbook = xlrd.open_workbook(excelWB)
worksheet = workbook.sheet_by_name(dbTable)
num_rows = worksheet.nrows - 1
fields = [t.encode('utf8') for t in worksheet.row_values(0)]
# Open an InsertCursor
# Since workspace defined as geoDB, should only need table name
cursor = arcpy.da.InsertCursor(dbTable, fields)
curr_row = 0
while curr_row < num_rows:
curr_row += 1
# use standard encoding, not Unicode
if (dbTable == "Domain2" ) :
# For issues with null fields in Excel, this seems to work
encoded = worksheet.row_values(curr_row)
else :
encoded = [t.encode('utf8') for t in worksheet.row_values(curr_row)]
cursor.insertRow(encoded)
# Delete cursor object
del cursor
if __name__ == "__main__":
# fields: [ 0:Name, 1:Type, 2:Size, 3:Alias, 4:Domain ] use "#" for blanks
# Use this for a simple domain
dbTable = "Domain1"
dbFields = [
["CODE", "TEXT", "1", "CODE", "#"],
["DESCRIPTION", "TEXT", "4", "DESCRIPTION", "#"]
]
new_table(dbTable,dbFields,geoDB,excelWB)
# Use this format to add other fields to table
dbTable = "Domain2"
dbFields = [
["CODE", "TEXT", "4", "CODE", "#"],
["DESCRIPTION", "TEXT", "8", "DESCRIPTION", "#"],
["MyInt", "SMALLINTEGER", "#", "My Int", "#"],
["MyDate", "DATE", "#", "My Date", "#"],
["MyLong", "INTEGER", "#", "My Long", "#"],
]
new_table(dbTable,dbFields,geoDB,excelWB)
# ISSUES with MyInt and MyDate fields being null in Excel
# [u'?', u'?', u'', u'', '', u'', '']
# [u'?', u'?', u'', u'', 0.0, u'', 36892.0]
print
print "Processing complete." And to convert the tables to domains: # Description: Convert tables to domains
import arcpy
from arcpy import env
# Set the current workspace
geoDB = r"C:\Path\To\filedb.gdb"
env.workspace = geoDB
domains = [ 'Domain1',
'Domain2' ]
# ONLY IF ALL TABLES ARE DOMAINS
# domains = arcpy.ListTables()
print "Processing Domains:"
for domain in domains:
print "\t" + domain
# create domain
# TableToDomain_management (in_table, code_field, description_field, in_workspace,
# domain_name, {domain_description}, {update_option REPLACE/APPEND})
arcpy.TableToDomain_management(domain,"CODE","DESCRIPTION",geoDB,domain,domain,"REPLACE")
# resort domain list by CODE not DESCRIPTION
# SortCodedValueDomain_management (in_workspace, domain_name, sort_by, sort_order)
arcpy.SortCodedValueDomain_management(geoDB,domain,"CODE","ASCENDING")
print "Done." Just another way among many, I suppose.
... View more
07-11-2017
10:39 AM
|
2
|
6
|
14337
|
|
POST
|
Regarding labels, here's some python snippets that I've been playing around with that may be of interest: mxd = arcpy.mapping.MapDocument("CURRENT")
for lyr in arcpy.mapping.ListLayers(mxd):
if lyr.supports("LABELCLASSES"):
print "\n\nLayer name: " + lyr.name
print " Show Labels: " + str(lyr.showLabels)
print " Data Set: " + lyr.datasetName
print "Data Source: " + lyr.dataSource
for lblClass in lyr.labelClasses:
print "\n Class Name: " + lblClass.className
print "Show Class Labels: " + str(lblClass.showClassLabels)
print " Expression: " + lblClass.expression
print " SQL Query: " + lblClass.SQLQuery
'''
Sample output:
Layer name: MyData
Show Labels: True
Data Set: FeatureTest
Data Source: C:\...\MyFeature.gdb\FeatureTest
Class Name: Default
Show Class Labels: True
Expression: def FindLabel ( [FeatureType] ):
if [FeatureType] == "Type One":
return "Type 1"
else:
return [FeatureType]
SQL Query: FeatureType = '1234'
''' mxd = arcpy.mapping.MapDocument("CURRENT")
for lyr in arcpy.mapping.ListLayers(mxd):
if lyr.supports("LABELCLASSES"):
for lblClass in lyr.labelClasses:
lblClass.SQLQuery = ""
arcpy.RefreshActiveView()
# removes query that was found in first snippet mxd = arcpy.mapping.MapDocument("CURRENT")
LayerList = ['Program']
for lyr in arcpy.mapping.ListLayers(mxd):
if lyr.supports("LABELCLASSES"):
if lyr.name in LayerList:
lyr.showLabels = True
else:
lyr.showLabels = False
arcpy.RefreshActiveView() I recommend checking the links that both bixb0012 and xander_bakker have mentioned.
... View more
07-10-2017
03:41 PM
|
2
|
0
|
6275
|
|
POST
|
Several lines in your script use r"P:\\GIS Public\\Projects\\... You do not need to escape your slashes by doubling them; the "r" indicates it is a raw string. # Instead of:
out_rasterdataset = r"P:\\GIS Public\\Projects\\Meter Zones\\route_polygons\\TIFF" + str(x) + ".tif"
# Use:
out_rasterdataset = r"P:\GIS Public\Projects\Meter Zones\route_polygons\TIFF" + str(x) + ".tif" In the discussion of String literals, see the paragraph about using the 'r' prefix.
... View more
07-07-2017
02:38 PM
|
1
|
0
|
2356
|
|
POST
|
Rather than being related to domains, the issue may be related to the field's nullability. If the field cannot be set to null, it is grayed out and visibility cannot be changed using Set View Definition >> Define Fields. The question remains, is there an issue to editing the view's json file to hide the field? The only issues I can think of would be if the layer data is editable through the view's permissions. Any thoughts or suggestions are appreciated.
... View more
07-07-2017
10:26 AM
|
0
|
0
|
2924
|
|
POST
|
I have been exploring how to Create hosted feature layer views. My goal is to use the view to hide certain fields while limiting editing (as discussed in other threads, such as: Restrict editing to authorized users while leaving the map viewable to the public). When using Set View Definition >> Define Fields for my feature layer, the fields using domains are checked and grayed out. Thus the “visibility can’t be changed”; these fields cannot be hidden. Does anyone know the reason for this limitation? However, it appears the json file for the layer can be edited to hide those fields using domains by setting “visible” : false. Is this a suitable workaround?
... View more
07-06-2017
02:55 PM
|
0
|
5
|
4032
|
|
IDEA
|
It is possible to access Trek2There from Collector. Do this by creating a feature that can Record GPS metadata; the fields you will specifically need are: ESRIGNSS_LATITUDE and ESRIGNSS_LONGITUDE. When you create the map, create a pop-up that uses a "Custom Attribute Display". This option allows you to create a link that will open Trek2There on your device with your destination set. The URL will be: arcgis-trek2there:///?stop={ESRIGNSS_LATITUDE},{ESRIGNSS_LONGITUDE} Collector for ArcGIS #trek2there
... View more
07-03-2017
10:44 PM
|
3
|
0
|
2247
|
|
POST
|
On Collector, under "Switch Account", there is an option menu (three dots) to the right of the account name which allows you to "Remove" the account. The user will then have to use the log-in procedure to access the account again.
... View more
07-03-2017
04:42 PM
|
0
|
1
|
980
|
|
POST
|
Although the question is an old one, it does relate to Collector, as well as online templates. Specifically , how can a crew using Collector follow-up on items submitted via a crowd-sourced geoform? In this case, a member of the public is submitting a report on a pot-hole, its location and a photo. A member of the street department would use Collector to verify the report by examining a photo attached by the citizen; this verification could involve a site visit. The basic question is: can Collector and the geoform share the same feature layer? From my experimenting, I believe they can.
... View more
07-03-2017
04:30 PM
|
0
|
0
|
1922
|
| 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
|