|
POST
|
Thanks, Richard. I'll check out the blog post you mentioned. And I've noticed several other of your postings that I want to check out, too.
... View more
08-11-2017
11:51 AM
|
0
|
0
|
2946
|
|
POST
|
This code may get you close to what you need. The commented out print statements may help debug or understand the code. The first step was using Clinton Dow's suggestion of Excel To Table (this page has sample code that will add all worksheets into your geodatabase as tables. The second step was using code to loop through the feature classes in your feature datasets. This code is basically the code used in your previous question: How to Remove domain from field for gdb. The third step was including some code by Richard Fairhurst in his blog on Turbo Charging Data Manipulation with Python Cursors and Dictionaries. I've been wanting to explore Richard's code, and this question seemed to suitable. Here's the code. It may need some tweaking and clean-up. import arcpy
gdb = r'C:\Path\To\COBW_WS_FA_HVAC_SO_SW_FP\COBW_WS_FA_HVAC_SO_SW_FP.gdb'
arcpy.env.workspace = gdb
# tab names from Excel file - each tab is a feature dataset
# the sample code at http://desktop.arcgis.com/en/arcmap/latest/tools/conversion-toolbox/excel-to-table.htm
# will print a list of tabs names -- NOTE: they should match your feature dataset names
dsets = ['Audiovisual','Building','Communication','ConveyingSystem','DataSystem','Drianage','Fire_Alarm',
'Fire_Protection','Fuel','Gas_Air_Services','HVAC','Irrigation','Laboratory','Landbase','Lighting',
'lightning_Earthing','LPG','Master_Clock','MATV_IPTV','Power','Public_Address','Security','Solar',
'Steam_services','Storm_Water','Water_Supply','TSE','WaterResources','BMS' ]
for fds in arcpy.ListDatasets('','Feature'):
if fds in dsets:
print "DS: {}".format(fds)
# table (converted from Excel) to connect to for codes
sourceTbl = 'Asset_TypeCode_xlsx_' + fds # this matches default table name from the Excel conversion script
# print sourceTbl
# Use list comprehension to build a dictionary from a da SearchCursor where the key values are based on 3 separate feilds
# See https://community.esri.com/blogs/richard_fairhurst/2014/11/08/turbo-charging-data-manipulation-with-python-cursors-and-dictionaries
# Section: Creating a Multi-Field Python Dictionary Key to Replace a Concatenated Join Field
sourceFieldsList = [ "FeatureDataset", "FeatureClass", "SubtypeCode", "AssetTypeCode" ] # will match variables fds, fc and st_name
valueDict = {str(r[0]) + "," + str(r[1]) + "," + str(r[2]):(r[3:]) for r in arcpy.da.SearchCursor(sourceTbl, sourceFieldsList)}
# print valueDict
for fc in arcpy.ListFeatureClasses("*","",fds):
print "\tFC: {}".format(fc)
subtypes = arcpy.da.ListSubtypes(fc)
# print subtypes # print subtypes dictionary for debugging if needed
# loop through feature class' subtypes one at a time
for stcode, stdict in list(subtypes.items()):
for stkey in list(stdict.keys()):
# if there is a Subtype Field (that is, it is not an empty string)
if not stdict['SubtypeField'] == '':
st_name = stdict['SubtypeField']
else:
# default values in Excel table for missing subtype
st_name = "-" # no subtype found
if stkey == 'FieldValues':
fields = stdict[stkey]
if 'ASSET_TYPE_CODE' in fields:
fieldFound = 1
else:
fieldFound = 0
print("\t\tSubtype: {}".format(st_name))
if st_name == '-' and fieldFound:
# no subtype used
updateFieldsList = ["ASSET_TYPE_CODE"]
# print "\t\t{}".format(updateFieldsList)
with arcpy.da.UpdateCursor(fc, updateFieldsList) as updateRows:
for updateRow in updateRows:
# store the Join value by combining 3 values: fds, fc and st_name
keyValue = "{},{},{}".format(fds, fc, '01') # use 01 for SubtypeCode
# verify that the keyValue is in the Dictionary
if keyValue in valueDict:
# transfer the value stored under the keyValue from the dictionary to the updated field.
updateRow[0] = valueDict[keyValue][0]
updateRows.updateRow(updateRow)
# print valueDict[keyValue][0]
else:
print "NOT FOUND: {}".format(keyValue)
# print valueDict
elif fieldFound:
# subtype
updateFieldsList = [st_name, "ASSET_TYPE_CODE"]
# print "\t\t{}".format(updateFieldsList)
with arcpy.da.UpdateCursor(fc, updateFieldsList) as updateRows:
for updateRow in updateRows:
# store the Join value by combining 3 field values of the row being updated in a keyValue variable
keyValue = "{},{},{:02d}".format(fds, fc, updateRow[0] )
# verify that the keyValue is in the Dictionary
if keyValue in valueDict:
# transfer the value stored under the keyValue from the dictionary to the updated field.
updateRow[1] = valueDict[keyValue][0]
updateRows.updateRow(updateRow)
# print "{} {}".format(updateRow[0], valueDict[keyValue][0])
else:
print "NOT FOUND: {}".format(keyValue)
else:
print "\t\tSkipping {}".format(fc)
del valueDict
print "Done." It seems that your Asset Code Type is a combination of a numeric code for the dataset, feature and subtype code. It should be possible to create a dictionary of datasets and features that would provide the first two codes, then you could combine them with the subtype code in each row of the feature to calculate the Asset Code Type. In your Fire_Alarm worksheet, there wasn't a code for FA_Module with a subtype of 03. Also, the code above is expecting certain rules: tab names are same as dataset names, the feature class name is in the table, names are case sensitive, etc.
... View more
08-10-2017
11:15 PM
|
1
|
3
|
2946
|
|
POST
|
When you right-click and look at the properties, does the shortcut point to the right target?
... View more
08-10-2017
09:11 AM
|
1
|
1
|
3569
|
|
POST
|
Could the camera settings have the location tag turned off? This would not be a Collector setting.
... View more
08-09-2017
05:22 PM
|
1
|
0
|
852
|
|
POST
|
Add an else at the end of your script (match the indentation of your "if Point[0] ==...." for Point in Points:
arcpy.AddMessage( .... )
if Point[0] == orders[0] and Point[0] >= Minimum_Stream_Order_To_Delineate:
if arcpy.Exists(Final_PP_Layer + "_O" + Point[0]):
stuff
else:
more stuff
# add an else here to check if point[0], orders[0] and Min_Stream... meets criteria
else:
AddMessage ... "Failed"
... View more
08-09-2017
11:13 AM
|
1
|
0
|
3038
|
|
POST
|
Could you post a message that was printed at line 19-20? Point[0] == orders[0] and Point[0] >= Minimum_Stream_Order_To_Delineate
... View more
08-09-2017
10:59 AM
|
0
|
0
|
3038
|
|
POST
|
Are you seeing the message generated by arcpy.AddMessage in lines 19-20? And likewise, are you seeing the arcpy.AddWarning messages from lines 23, 26 and 31? You may need to use GetMessages. And what are some of those messages?
... View more
08-08-2017
03:14 PM
|
0
|
4
|
3038
|
|
POST
|
So if the field name is edited in line 4, how about this for line 9: query = fieldName + " LIKE '" + str(fieldValue) + "'"
... View more
08-04-2017
10:10 AM
|
1
|
1
|
7746
|
|
POST
|
Thanks for the image of the table. It was key to the answer. And, the tool acts differently outside ArcMap; it creates its own data map apparently ignoring the parameter (using version 10.2.1). *** EDIT: By inside ArcMap, I mean running the tool from ArcToolbox. By outside, I mean from a Python IDE with ArcMap closed, although running the results snippet in ArcMap's Python window showed similar issues. *** So, regarding the table (a tab delimited text file): ArcMap sees a column with a 0 (integer) in the first row and 22.32 (double) in the second as "text". My first recommendation is to change the numbers in the first row from this: 100 0 0 0 0 200 !!
101 10 22.32 67.58 5.12 200 !!
102 20 50.55 84.12 3.65 200 !! To this (so ArcMap will see them as doubles): 100 0 0.0 0.0 0.0 200 !!
101 10 22.32 67.58 5.12 200 !!
102 20 50.55 84.12 3.65 200 !!
Since there is no header row with field names, ArcMap will default to "Field1", "Field2", etc. So my second suggestion is to add a tab delimited header row, such as: IDCODE PARAM LON LAT VALUE REF_ID COMMENT
100 0 0.0 0.0 0.0 200 !!
101 10 22.32 67.58 5.12 200 !!
102 20 50.55 84.12 3.65 200 !!
This will name your fields with something meaningful. When I ran the tool outside ArcMap, I first used the following code with a data file without a header: import arcpy
TXT = r"C:/Path/To/data.txt"
GDB = r"C:/Path/To/Default.gdb"
TBL = "table2table"
arcpy.TableToTable_conversion(TXT,GDB,TBL,"#","""IDCODE "Field1" true true false 4 Long 0 0 ,First,#,TXT,Field1,-1,-1;PARAM "Field2" true true false 4 Long 0 0 ,First,#,TXT,Field2,-1,-1;LON "Field3" true true false 255 Double 0 0 ,First,#,TXT,Field3,-1,-1;LAT "Field4" true true false 255 Double 0 0 ,First,#,TXT,Field4,-1,-1;VALUE "Field5" true true false 255 Double 0 0 ,First,#,TXT,Field5,-1,-1;REF_ID "Field6" true true false 4 Long 0 0 ,First,#,TXT,Field6,-1,-1;COMMENT "Field7" true true false 255 Text 0 0 ,First,#,TXT,Field7,-1,-1""","#") Although the map contains the target field names ("IDCODE", etc.), when the table was created, "Field1"..."Field7" were used. I then used the version of the data table with the header (field names) and removed the field mapping, and it created the expected result. NOTE: This was tested with ArcMap version 10.2.1. import arcpy
TXT = r"C:/Path/To/data.txt"
GDB = r"C:/Path/To/Default.gdb"
TBL = "table2table"
# tested with ArcMap version 10.2.1
arcpy.TableToTable_conversion(TXT,GDB,TBL,"#","""#""","#") Hope this helps.
... View more
08-03-2017
03:18 PM
|
2
|
1
|
7291
|
|
POST
|
Perhaps you could provide a bit more description of: 1) the field you are symbolizing and the unique values allowed, and 2) the field and domain you are experiencing problems with. From your description so far, I am assuming these are two different fields. For the field that I symbolize, I use a domain that lists and limits the unique values allowed. I will also set the symbology up so that if any value not in the domain is used (in ArcMap <all other values>) the point feature will also display in Collector. The domain provides the field crew with a dropdown list of specific choices. Regarding "feature type", this does not refer to a subtype in this case. The feature type can be a residential building vs a commercial building. If the type is "residential", use a red dot; if "commercial", use a blue dot. If it happens to be anything else, use a yellow one. "Residential" and "commercial" (or their code value) would be unique value used in the field that you are using to symbolize. For the fields you are having trouble with, you might look at the default value that the field will be populated with. Also look at "allow nulls". Then compare these settings with other fields or features that are not causing issues.
... View more
08-02-2017
03:30 PM
|
0
|
0
|
1185
|
|
POST
|
Royce, I agree that manually doing changes is not a very productive workflow. I have not found a way to do this consistently in the mxd prep. Many of my features are similar; that is, they will have the same field definition and domain used for the symbology. For the ones that are alike, I will copy the types section of one feature and use it (just the types section) to update another feature. I will also use a python script to retrieve the types section from a hosted feature, sort the types based on ID and then update the feature. It seems that when I set up the symbology in ArcMap, the settings get lost in the publishing process. A python script could also set fields so the value would be inherited. This would assist in the workflow.
... View more
08-02-2017
12:36 PM
|
0
|
2
|
1185
|
|
POST
|
I am trying to understand where in the process you are. Are you still creating your feature in ArcMap? If so, it seems like the domain may not have been assigned to the field. I am attaching a some images that show some screen captures in ArcMap and ArcCatalog. The first shows properties of a created domain with the domain name circled. The second shows a field that uses the domain; you can see the domain that has been assigned to the field shown by the arrow. The third is the dropdown you should see when you are in the edit mode inside ArcMap. If you are at another stage in developing your feature, could you attach some images that show where in the process you are?
... View more
08-01-2017
09:51 AM
|
0
|
0
|
2938
|
|
POST
|
If you are using AGOL, I suggest editing the types section of the feature layer's json file using the REST API. Here's a sample of the layer's type section. {
"types": [
{
"id": "1",
"name": "Red",
"domains": {
"Color": {
"type": "inherited"
},
"Field2": {
"type": "inherited"
},
"Field3": {
"type": "inherited"
}
},
"templates": [{
"name": "Red",
"description": "",
"drawingTool": "esriFeatureEditToolPoint",
"prototype": {
"attributes": {
"Field2": 0,
"Color": "1",
"Notes": null,
"Field3": "AB"
}
}
}]
},
{
"id": "2",
"name": "Blue",
"domains": {
"Color": {
"type": "inherited"
},
"Field2": {
"type": "inherited"
},
"Field3": {
"type": "inherited"
}
},
"templates": [{
"name": "Blue",
"description": "",
"drawingTool": "esriFeatureEditToolPoint",
"prototype": {
"attributes": {
"Field2": 0,
"Color": "2",
"Notes": null,
"Field3": "CD"
}
}
}]
}]
} In this example there are two types, Red and Blue, which will be used to symbolize the layer. Setting the Color domain to "1" will set the symbol to a red dot; setting it to "2" will select a blue dot. The settings in the prototype section will also set Field2 and Field3's domain to the indicated default values. The "Notes" field is a text field and is set to null -- that is, if the field does not currently have a value. If it has a value, it will be inherited -- that is, it will remain unchanged. What you will need to do is to set Field2 and Field3 to null so they will also be inherited. For example: "attributes": {
"Field2": null,
"Color": "2",
"Notes": null,
"Field3": null
} The domain Color will retain its value, otherwise changing type would not change the symbol on the map. If Field3 had the value "XY", it would retain the value "XY" when the Color domain is changed. I do recommend that one type group retain all the default domain settings so that when new features are added, they will set domains properly. You do not want null values for your domain's codes. This setting should prevent the warning message about changing feature types, unless changing to the default per my recommendation. I also highly recommend that you work with a copy of layer and experiment with it. Back up your layer before making any changes. This blog Updating Hosted Feature Services in ArcGIS Online links to a PDF that explains the specifics of editing a json file.
... View more
07-31-2017
11:08 PM
|
0
|
4
|
1185
|
|
POST
|
Can you share the first few rows of the table you are trying to convert? Also a few more lines of code showing how TXT and GDB are being set?
... View more
07-31-2017
08:59 AM
|
0
|
3
|
2417
|
|
POST
|
I would start here: Prepare your data in ArcGIS Desktop. This is one of several tutorial pages for Collector that cover creating a feature, publishing it as a service and putting it in a map for Collector. (You do not want to zip the geodatabase or export it to a shapefile.)
... View more
07-28-2017
05:50 PM
|
2
|
0
|
2938
|
| 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
|