|
POST
|
One way would be to append date/time. import arcpy
from datetime import datetime
saveLayer = "{}_{}".format('observation_Layer',datetime.now().strftime('%y%m%d%H%M%S'))
# observation_Layer_180629093021
arcpy.MakeNetCDFFeatureLayer_md(
....
out_feature_layer = saveLayer,
.... )
... View more
06-29-2018
10:35 AM
|
1
|
0
|
1925
|
|
POST
|
In your script, are you using the full path to your target and join features (or an arcpy.env.workspace setting)? Are you receiving any error messages when using Pythonwin; if so, what are they? Can you share a bit more of your script so we can see how the target and join features are initialized before the SpatialJoin. Thanks.
... View more
06-28-2018
11:44 AM
|
0
|
8
|
3667
|
|
POST
|
Not sure I understand your question. Would something like this do what you want? data = ['xxx_9999TUNK10_',
'xxx_9999TUNK10_',
'xxx_9999TUNK10_',
'xxx_9999BANK12_',
'xxx_9999BANK17_',
'xxx_9999BANK1_',
'xxx_9999BANK20_',
'xxx_9999BANK20_',
'xxx_9999BANK20_',
'xxx_9999BANK30_' ]
d = {} # empty dictionary
cnt = 0 # counter
def seq_count(fname, val):
global d
global cnt
if val not in d.keys():
cnt += 1
d[val] = cnt
return "{}_{}{:04.0f}".format(fname, val, cnt)
else:
return "{}_{}{:04.0f}".format(fname, val, d[val])
fieldName = 'myField'
for item in data:
print seq_count(fieldName, item)
'''
Results:
myField_xxx_9999TUNK10_0001
myField_xxx_9999TUNK10_0001
myField_xxx_9999TUNK10_0001
myField_xxx_9999BANK12_0002
myField_xxx_9999BANK17_0003
myField_xxx_9999BANK1_0004
myField_xxx_9999BANK20_0005
myField_xxx_9999BANK20_0005
myField_xxx_9999BANK20_0005
myField_xxx_9999BANK30_0006
'''
... View more
06-28-2018
10:51 AM
|
2
|
1
|
2427
|
|
POST
|
Peeping in..... A dictionary solution could look like something like this: data = ['xxx_9999TUNK10_',
'xxx_9999TUNK10_',
'xxx_9999TUNK10_',
'xxx_9999BANK12_',
'xxx_9999BANK17_',
'xxx_9999BANK1_',
'xxx_9999BANK20_',
'xxx_9999BANK20_',
'xxx_9999BANK20_',
'xxx_9999BANK30_' ]
d = {}
cnt = 0
for row in data:
if row not in d.keys():
cnt += 1
d[row] = cnt
print "{}{:04.0f}".format(row, cnt)
else:
print "{}{:04.0f}".format(row, d[row])
'''
Results:
xxx_9999TUNK10_0001
xxx_9999TUNK10_0001
xxx_9999TUNK10_0001
xxx_9999BANK12_0002
xxx_9999BANK17_0003
xxx_9999BANK1_0004
xxx_9999BANK20_0005
xxx_9999BANK20_0005
xxx_9999BANK20_0005
xxx_9999BANK30_0006
''' Is the prefixed 'xxx_' always the same, or does it vary? If it varies, you will need to do some string splitting, etc. Is the postfixed '_' always present? If not, the formatting statement can be modified to include it. By making the dictionary 'd' and the counter 'cnt' global, you should be able to make it work for the field calculator. The code should also work with an update cursor, should you wish to go that route.
... View more
06-28-2018
10:18 AM
|
0
|
3
|
2427
|
|
POST
|
(an approximate translation to English) Good day friends, Thank you to accept me in the community. I have a problem. I'm trying to make a script, where the goal is to realize is a spatial union in my case. between target = Vias_Join_p (path point) and Join = via_ruta_a (path polygon) This is the line, it runs well in the command window in ArcMap, but when I try to run Pythonwin or run a script in the toolbox, it does not union appears, only fields of via_ruta_a with value 0 appear in the table of Vias_Join_p. arcpy.SpatialJoin_analysis("vias_l_p", "via_route_a", os.path.join (path, "IT_TRANSPORTE_TERRESTRE", "Vias_Join_p"), "JOIN_ONE_TO_ONE", "KEEP_ALL", "", "INTERSECT") The two coverages have domains in the field, I do not know if this is an inconvenience, I attach an image with the results table. Thanks for the answers!
... View more
06-28-2018
09:49 AM
|
0
|
1
|
3667
|
|
POST
|
This will get filename information from the master feature class and save an attachment in a related table. import arcpy
masterFC = r"C:\Path\to\file.gdb\masterFC"
masterFlds = ['GlobalID', 'Name']
# Use list comprehension to build a dictionary from a da SearchCursor
masterDict = {r[0]:(r[1:]) for r in arcpy.da.SearchCursor(masterFC, masterFlds)}
print masterDict
relatedTbl = r'C:\Path\to\file.gdb\related_ATTACH'
relatedFlds = ['REL_GLOBALID', 'ATT_NAME', 'DATA']
fileLocation = r'C:\Path\to\attachments'
with arcpy.da.SearchCursor(relatedTbl, relatedFlds) as cursor:
for item in cursor:
# item[0] is related GlobalID; take first item in masterDict tuple with that key
f1 = masterDict[item[0]][0].replace(" ","_") # replacing spaces
# assuming attachment name starts with "attachment", remove that part and keep rest
f2 = item[1][10:] # can use .split('.')[1:] or similar to get just extension
# make new filename
filename = "ATT_{}_{}".format(f1, f2)
print filename
open(fileLocation + os.sep + filename, 'wb').write(item[2].tobytes())
del cursor This assumes that the master feature class contains some attributes like: And the related attachments table is something like: The dictionary and filenames created are: # print masterDict
{u'{B0174984-E7EB-47EA-A49A-9D535CFD6125}': (u'State Office Building',), u'{43902175-71ED-47DB-BCC8-6C805D930D23}': (u'State Capitol',)}
# print filename
ATT_State_Capitol_1.jpg
ATT_State_Capitol_2.jpg
ATT_State_Office_Building_1.jpg Hope this helps.
... View more
06-15-2018
03:05 PM
|
2
|
1
|
4362
|
|
POST
|
The record for the attachment should contain the global ID of the linked/master record in one of the fields. As shown my example code, you can work it into the file name. If the master record can have multiple attachments, you will need to use some sort of count, perhaps the attachment ID, to make a unique filename. You will want to append a file extension which could be obtained from splitting the filename at the dot in your code or by using the data in the content type field to create an extension. If you want to create a filename using data from the master record other than the global/linking ID field, you should be able to do that by using some sort of join with the master table or creating a dictionary of the master record feature/table. I will work on a code sample later today or this weekend that illustrates this.
... View more
06-15-2018
09:45 AM
|
0
|
0
|
4362
|
|
POST
|
I have always found lastEditDate to be in the json file and a reliable method of knowing when updates have occured. I have only on a few rare occasions found this value to be None; however, it would quickly become a date once a record was added or edited. The only backup I could suggest would be with editor tracking and examine the EditDate field. My experience has been with AGOL. I assume server/portal would be much the same.
... View more
06-15-2018
09:18 AM
|
0
|
0
|
3920
|
|
POST
|
I really didn't find any major problems with your script. For testing, my script was similar: import arcpy, os
inTable = r'C:\Path\to\file.gdb\feature__ATTACH'
fileLocation = r'C:\Path\to\attachments'
with arcpy.da.SearchCursor(inTable, ['DATA', 'ATT_NAME', 'ATTACHMENTID']) as cursor:
for item in cursor:
print "ATT_NAME: {} - ATTACHMENTID: {}".format(item[1], item[2])
filename = "ATT_{}_{}".format(item[2], item[1])
print filename
open(fileLocation + os.sep + filename, 'wb').write(item[0].tobytes())
del cursor I would suggest testing with some print statements (or AddMessage), to see that your input table and file location strings are being interpreted correctly. For the filename, you might want to start with the attachment ID as the ATT_NAME field may include a file extension. If it does not contain an extension, you may need to look at the CONTENT_TYPE field so your code can append one if necessary.
... View more
06-14-2018
08:18 PM
|
1
|
0
|
4362
|
|
POST
|
Here's an old python script to get the "lastEditDate" of a feature from AGOL: Obtain last edit date from REST API using Python As I mentioned previously, I will also query the layer/table for the "EditDate" field (when edit tracking is enabled). If the layer definition was updated (adding/modifying a domain, for example), then lastEditDate would reflect these updates, even if it has been some time since a feature was added to the layer.
... View more
06-14-2018
02:48 PM
|
1
|
0
|
3920
|
|
POST
|
The json file that describes your feature has the "last edit date" as a UTC timestamp (assuming AGOL). The time is the date/time of the last item added to the feature/table OR when its definition was last changed/updated. "editingInfo" : {
"lastEditDate" : 1528926651042
},
If edit tracking is enabled, you can query the feature/table's "EditDate" field for the most recent update.
... View more
06-14-2018
01:07 PM
|
1
|
0
|
3920
|
|
POST
|
Try this: found = False
for domain in existingDomains:
if domain.name == 'DOM_YES_NO_UNK_NPS2016':
found = True
if found:
print "Domain exists"
else:
print "Domain does not exist"
... View more
06-14-2018
09:18 AM
|
2
|
2
|
1221
|
|
POST
|
You are looping through all domain names (around line 18 - for domain in existing...) and, since some of them will not match (at the next line), it will try to insert the new domain anyway. Try setting up your loop like this: gdb_name = r"C:\Path\To\file.gdb"
chkDomains = [
['DOM_YES_NO_UNK_NPS2016', {"Unknown":"Unknown", "Yes": "Yes", "No": "No"} ],
['DOM_ISEXTANT_NPS2016', {"Unknown":"Unknown", "True": "True", "False": "False", "Partial": "Partial", "Other": "Other"} ]
]
existingDomains = arcpy.da.ListDomains(gdb_name)
dn = []
for domain in existingDomains: # get list of domain names
dn.append(domain.name)
for chk in chkDomains:
if chk[0] in dn: # see if it is in list of domain names
print "Domain {} exists".format(chk[0])
else:
print "Adding domain {} using dictionary {}".format(chk[0], chk[1])
... View more
06-11-2018
04:58 PM
|
1
|
1
|
6072
|
|
POST
|
I haven't tested it, but try replacing line 16 in the previous code with an if/else to check count of features: import arcpy
arcpy.env.workspace = r'C:\Path\To\File.gdb'
for fds in arcpy.ListDatasets('','Feature'):
print "{}".format(fds)
features = 0
for fc in arcpy.ListFeatureClasses('','',fds):
count = int(arcpy.GetCount_management(fc).getOutput(0))
if count:
features += 1
print "\t{}: {} records".format(fc, count)
else:
print "\t{} records, deleting: {}".format(count, fc)
# arcpy.Delete_management(fc) # uncomment to delete fc
# line 16: print "{} has {} remaining features".format(fds, features)
if features == 0:
print "{} dataset is empty, deleting".format(fds)
arcpy.Delete_management(fds)
else:
print "{} has {} remaining features".format(fds, features) # previous line 16
... View more
06-11-2018
11:06 AM
|
2
|
2
|
4036
|
|
POST
|
One way is by using projectAs. # WGS 1984 : (4326) Lat/Lon
# WGS 1984 Web Mercator (auxiliary sphere) : (102100) or (3857)
ptGeometry = arcpy.PointGeometry(arcpy.Point(x,y),arcpy.SpatialReference(4326)).projectAs(arcpy.SpatialReference(3857))
print ptGeometry.firstPoint.X, ptGeometry.firstPoint.Y
... View more
06-11-2018
09:39 AM
|
1
|
0
|
1001
|
| 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
|