|
POST
|
Great points, Xander. I don't think I saw AddGeometryAttributes_management(). Or maybe I did but didn't see that you could specify the coordinate system. I'll do some testing with that! I have not needed to use a a specific transformation so have not tested it. What is a scenario I could use to test this? I don't understand what you mean when you say it "does not have a sr WGS 1984." For the lines, I agree, a midpoint would be better. I just didn't want to write extra code to check the geometry type and do different things. Point features are obviously preferred so anything else requires some compromise. That would be a good enhancement though, to do different calculations of feature to point conversion based on the geometry type. I also thought maybe instead of hard-coding the field name, I could just make a new field using the current date/time in the name. That would let me get rid of the field name and data type check and it would also hint that the field's values were calculated in a batch process separately from editing the geometry.
... View more
06-08-2015
04:39 PM
|
0
|
5
|
4141
|
|
POST
|
After getting a lot of requests to get latitude and longitude coordinates for features, I created a generic script that creates two new fields in the existing feature feature class and and calcs the latitude and longitude of the feature's "true centroid." The only problem is that you would have to run this script any time a feature's geometry was changed. I did some searching for something that already existed and didn't find anything that was simple and generic enough, so please let me know if you can do it better. import arcpy
fc = r"C:\temp\working.gdb\temp_fc"
# Define and create longitude/latitude fields
## Longitude is X, Latitude is Y
fieldsNew = ["GCS_WGS_1984_X", "GCS_WGS_1984_Y"]
fieldsExisting = {f.name: f.type for f in arcpy.ListFields(fc)}
for fNew in fieldsNew:
# Add field if it doens't already exist
if fNew not in fieldsExisting.keys():
arcpy.AddField_management(
fc, ## in_table
fNew, ## field_name
"DOUBLE", ## field_type
)
# If data type of existing field is not a Double, throw Exception
elif fieldsExisting[fNew] != "Double":
raise Exception(
"Existing {} field is type {}. Must be 'Double'".format(
fNew, fieldsExisting[fNew]
)
)
# Update fields with GCS_WGS_1984 lat/long
print("Updating Field values")
fieldsNew.append("SHAPE@")
GCS_WGS_1984 = arcpy.SpatialReference(4326)
with arcpy.da.UpdateCursor(fc, fieldsNew, "", GCS_WGS_1984) as u_cursor:
for row in u_cursor:
point = row[2].trueCentroid
row[0] = point.X
row[1] = point.Y
u_cursor.updateRow(row) python snippets
... View more
06-08-2015
12:03 PM
|
0
|
16
|
11355
|
|
POST
|
I created this script to help with some geodatabase house cleaning tasks. Maybe someone else will find it useful or have an idea to improve it. import arcpy
import os
# Set workspace
myGDB = r"C:\temp\working.gdb"
# Get domains that are assigned to a field
domains_used = []
for dirpath, dirnames, filenames in arcpy.da.Walk(myGDB, datatype=["FeatureClass", "Table"]):
for filename in filenames:
print "Checking {}".format(os.path.join(dirpath, filename))
try:
## Check for normal field domains
for field in arcpy.ListFields(os.path.join(dirpath, filename)):
if field.domain:
domains_used.append(field.domain)
## Check for domains used in a subtype field
subtypes = arcpy.da.ListSubtypes(os.path.join(dirpath, filename))
for stcode, stdict in subtypes.iteritems():
if stdict["SubtypeField"] != u'':
for field, fieldvals in stdict["FieldValues"].iteritems():
if not fieldvals[1] is None:
domains_used.append(fieldvals[1].name)
except Exception, err:
print "Error:", err
# Get domains that exist in the geodatabase
domains_existing = [dom.name for dom in arcpy.da.ListDomains(myGDB)]
# Find existing domains that are not assigned to a field
domains_unused = set(domains_existing) ^ set(domains_used)
print "{} unused domains in {}".format(len(domains_unused), myGDB)
for domain in domains_unused:
arcpy.DeleteDomain_management(myGDB, domain)
print "{} deleted".format(domain) python snippets
... View more
06-08-2015
11:50 AM
|
12
|
30
|
24698
|
|
POST
|
I hate to be a nitpicker, Richard, especially when you have all the answers, but you forgot a colon after your if statement on line 13 and are missing an extra right parenthesis at the end of lines 48 and 49. Great work though!
... View more
06-08-2015
08:48 AM
|
0
|
0
|
2552
|
|
POST
|
To download attachments, make sure you open the discussion up and are not viewing it in your Inbox or Activity Stream.
... View more
06-08-2015
08:42 AM
|
1
|
4
|
2873
|
|
POST
|
What do you have that is tying to you sdemon? Now might be a good time to start finding Alternatives to using SDE command line tools in ArcGIS. Use the Connections and Locks tab within the Geodatabase Administration tool instead of using sdemon –o info –I users/locks
... View more
06-04-2015
02:15 PM
|
0
|
0
|
1119
|
|
POST
|
Unfortunately, arcpy.ChangePrivileges_management() is just for database users in SDE, not ArcGIS Server.
... View more
06-04-2015
12:28 PM
|
1
|
0
|
2685
|
|
POST
|
Try manually geocoding the table your script fails on using ArcCatalog's built-in tools. That might give you more insight as to what is causing the geocoding process to fail. If it works sometimes, but not others, it's probably an issue with the table (or the data) you're trying to geocode.
... View more
06-04-2015
11:49 AM
|
0
|
0
|
2567
|
|
POST
|
It's still just an SDE connection file. You can either save your connection file to a local (or network) drive, or you can refer to the connection files with a relative path in ArcCatalog as simply "Database Connections\MyConnectionFile.sde" The ArcCatalog connection files are actually stored in a hidden folder at C:\Users\usernamehere\AppData\Roaming\ESRI\Desktop10.2\ArcCatalog I like to have an explicit location where the connection file is. If you had the ArcCatalog relative path, the connections available depend on the particular user logged in to the machine running the script.
... View more
06-04-2015
11:37 AM
|
0
|
0
|
1640
|
|
POST
|
In this case, I think the workspace variable is simply where to start the searching. You could also look into using arcpy.da.Walk().
... View more
06-03-2015
02:42 PM
|
0
|
0
|
1640
|
|
POST
|
Agreed, in_memory workspace can improve performance. How many points and lines do you have? Although it probably won't improve performance, opening your csv file using a with statement (like you do with the arcpy cursors) will automatically close the file if there is an error so you don't have to worry about adding f.close() everywhere.
... View more
06-03-2015
01:36 PM
|
2
|
1
|
9271
|
|
POST
|
The Dissolve should make one Destination polygon out of all Werne rows, with a single Commuter value of 1073.328 (which is the max value, belonging to Bergkamen). If you want to include the Origin (or better yet, the OriginID) for that Commuter value, try adding a second statistic field with the FIRST option (LAST would also give the same result).
... View more
06-03-2015
01:31 PM
|
0
|
17
|
4666
|
|
POST
|
I agree, I think a dissolve on the Destination field with statistics for maximum Commuter field sounds like the solution. If you want to keep the original shapes, you could always just join the result back to the original using the Destination field; e.g., all occurrences of Werne would have the same commuter statistic value from the dissolve output table. ArcGIS Help 10.1 - Dissolve (Data Management)
... View more
06-03-2015
12:05 PM
|
1
|
0
|
2027
|
|
POST
|
When you have WHERE OWNER LIKE 'GISADMN' without a % wildcard, you're essentially just saying equals. For the sake of clarity, you should change it to WHERE OWNER = 'GISADMN' unless you really do want a wildcard at the beginning or end.
... View more
06-02-2015
08:25 AM
|
2
|
0
|
824
|
|
POST
|
ArcGIS Help 10.1 - Make Query Table (Data Management) You may need to prefix the field names with the table name. Like MyFC.FieldName1 and MyTable.FieldName2
... View more
06-01-2015
02:50 PM
|
1
|
0
|
2696
|
| Title | Kudos | Posted |
|---|---|---|
| 1 | 10-23-2025 03:53 PM | |
| 1 | 04-28-2026 07:25 AM | |
| 1 | 03-19-2026 08:59 AM | |
| 1 | 02-12-2026 01:37 PM | |
| 1 | 12-01-2025 06:19 AM |