|
POST
|
Looks like just a missing parenthesis. Your current code: return !shape.length@kilometers! /40)*60 Should be: return (!shape.length@kilometers! / 40) * 60 (I'm guessing?)
... View more
03-09-2018
11:12 AM
|
1
|
4
|
1170
|
|
POST
|
You can use the workspace environment variable and ListFeatureClasses() to step through your classes: arcpy.env.workspace = r"Database Connections\YourConnection.sde"
for fc in arcpy.ListFeatureClasses():
arcpy.FeatureClassToFeatureClass_conversion(fc, targetFolder, fc) ListFeatureClasses has some optional parameters for filtering feature classes by name and type as well. Depending on your naming conventions it may not be a bad idea to look into ValidateTableName() as well, you can call it before calling FC to FC to make sure the table name is valid for the target (usually is but doesn't hurt to check).
... View more
03-02-2018
03:26 PM
|
1
|
0
|
3382
|
|
POST
|
You can get a list of versioned feature classes using something like this from the Python window: arcpy.env.workspace = r"Database Connections\YourConnFile.sde"
for fc in arcpy.ListFeatureClasses():
if arcpy.Describe(fc).isVersioned:
print(fc)
You could do that for each distinct connection you've got, or put the SDE file paths in a list and iterate through them all together. Edit: This will only work with standalone feature classes and would have to be extended to detect those inside of feature datasets...
... View more
03-02-2018
08:44 AM
|
1
|
0
|
5602
|
|
POST
|
Something like this should do it: fieldList = [ "ATTRB1", "ATTRB2", "ATTRB3", "ATTRB4" ]
with arcpy.da.InsertCursor(targetTable, fieldList) as insertCursor:
with arcpy.da.SearchCursor(sourceTable, fieldList) as searchCursor:
for row in searchCursor:
for attrbPart in row[3].split(","):
insertCursor.insertRow(( row[0], row[1], row[2], attrbPart )) I would throw in some null testing, empty string testing, error handling, etc.
... View more
02-28-2018
01:33 PM
|
1
|
1
|
2817
|
|
POST
|
Although I didn't build it for attribute tables, I've had some success with spellchecking using Microsoft Word through Python. The gist of my process was that I looped through a bunch of metadata files, grabbed a specific subset of metadata elements, wrote each element's text value to a new line in a text file, spellchecked the file in Word, then exported the errors out to a list. Upsides: Easy to setup Downsides: Not very fast when batch-processing a bunch of different metadata documents Occasionally Word would visibly pop-up and stall the process Obvious baked-in dependency I did this as a one-off though, so I didn't really worry about the downsides - if I were to use it frequently I'd really want to nail down the second downside in particular. Code looked something like this: import win32com.client
app = win32com.client.gencache.EnsureDispatch("Word.Application")
for metadataFile in metadataFiles:
# Extracted specific metadata elements here, put into list.
# ...
# Dump to text file
with io.open(tempDocPath, "w") as tempFile:
for elementText in elementTextBlocks:
tempFile.write(unicode(elementText))
tempFile.write(u"\n\n")
# Open the doc
doc = app.Documents.Open(tempDocPath)
for error in doc.SpellingErrors:
# Do stuff
# ...
doc.Close()
del doc
app.Quit()
Of course the Close()/del/Quit() stuff was handled in finally blocks and all that, and because I was getting a lot of recurring proper nouns flagged as errors I ended up building in an exclusion process where Line 18 would be, but basically I ended up dumping everything to a CSV with the filename and misspelled word.
... View more
02-28-2018
11:44 AM
|
1
|
1
|
1627
|
|
POST
|
Good point, another way would be to ditch MakeFeatureLayer and use arcpy.mapping.Layer instead.
... View more
02-28-2018
11:18 AM
|
0
|
0
|
1008
|
|
POST
|
Use the getOutput() method on the MakeFeatureLayer result: lyr = arcpy.MakeFeatureLayer_management(yourLayer).getOutput(0)
... View more
02-28-2018
08:35 AM
|
1
|
0
|
1008
|
|
POST
|
I usually stick with cursors as well but I've found using off-the-shelf tools and field mappings typically provide better performance than cursors... So if it's something I'm going to be running regularly and performance matters, I bite the bullet and get into mappings.
... View more
02-27-2018
03:21 PM
|
2
|
0
|
2887
|
|
POST
|
If that doesn't work, try adding this second line after your line 20: fms = arcpy.FieldMappings()
fms.addTable(in_file1)
... View more
02-27-2018
11:22 AM
|
0
|
0
|
2887
|
|
POST
|
I'm not sure if it's strictly necessary or if it's possible to achieve the equivalent result without it, but when creating the FieldMappings object in the past I've called the addTable method immediately after creation, passing in the input dataset(s).
... View more
02-27-2018
10:57 AM
|
0
|
2
|
2887
|
|
POST
|
Yes, you'll need to call it for each unique feature class name. You may also want to have a look at the "Validate Field Name" function, since you're using a template as part of your feature class creation. You could be pulling in a field that has a name that's valid in one type of workspace but invalid in another - for example, some field names may be valid in a File Geodatabase that aren't valid in SQL Server or in a Shapefile.
... View more
02-21-2018
01:19 PM
|
0
|
1
|
3617
|
|
POST
|
That error usually means there's whitespace, a hyphen, something like that in the table name - strange error in this case though since "Fiber" should be valid. Try using this function to validate your table name: (Edit: Posted the wrong link in my original post) ValidateTableName—Help | ArcGIS for Desktop
... View more
02-21-2018
12:47 PM
|
1
|
3
|
3617
|
|
POST
|
As that's a web map, it could be as simple as publishing a feature layer using ArcGIS Server or ArcGIS Online, creating a web map and applying a heat map renderer to your layer. How it turns out depends on what your point data look like though.
... View more
02-15-2018
08:34 AM
|
0
|
0
|
1401
|
|
POST
|
I'm not sure if there's a way to do it with standard tools, but I know of a way using Python given that in a polygon with holes, null point values (None in Python) separate the outer ring from inner rings: def findHoles(polygonLayerName):
# Get the layer from the current map document.
mxd = arcpy.mapping.MapDocument("CURRENT")
lyrList = arcpy.mapping.ListLayers(mxd, polygonLayerName)
if len(lyrList) == 0:
print("Layer not found")
return
layer = lyrList[0]
# Iterate through the layer's features.
oidList = []
with arcpy.da.SearchCursor(layer, ["OID@", "SHAPE@"]) as cursor:
for row in cursor:
polygon = row[1]
for partIdx in range(0, polygon.partCount):
if None in list(polygon.getPart(partIdx)):
oidList.append(row[0])
break
# Select the features and refresh the view.
layer.setSelectionSet("NEW", oidList)
arcpy.RefreshActiveView()
... View more
02-14-2018
02:22 PM
|
0
|
0
|
1127
|
|
POST
|
You need to fetch the first row from the cursor, then get the first value from the row. NZone = "12" # Default value in case no rows found
with arcpy.da.SearchCursor(ShpShp, ["UTM_Zone"]) as searchCursor:
for row in searchCursor:
NZone = row[0]
break
# Remainder of code down here...
UTMRef = r"Coordinate Systems\Projected Coordinate Systems\UTM\NAD 1983\NAD 1983 UTM Zone " + str(NZone) + "N.prj" There are more concise ways to create a cursor and fetch only its first row and first value, but I generally stick to this pattern of "with" on the first line and iteration on the second because it suits the majority of my use cases (may differ for others).
... View more
02-12-2018
03:07 PM
|
1
|
1
|
1070
|
| Title | Kudos | Posted |
|---|---|---|
| 1 | 03-02-2018 08:44 AM | |
| 1 | 02-02-2018 02:58 PM | |
| 1 | 04-17-2018 07:53 PM | |
| 1 | 05-01-2018 01:24 PM | |
| 1 | 02-05-2018 09:26 AM |
| Online Status |
Offline
|
| Date Last Visited |
11-11-2020
02:24 AM
|