|
POST
|
I think you could use Richard Fairhurst's Turbo Charging Data Manipulation with Python Cursors and Dictionaries. Basically, read data from PRP17_dis into a dictionary using OBJECTID as the key and pr_id as the value. Then loop through the rows in 2106Q2_PRP17_adj and, where NEAR_FID equals the dictionary key, place the value into NEAREST_PRP. For code, see Richard's blog, Example 1.
... View more
11-16-2017
06:50 PM
|
1
|
0
|
1969
|
|
POST
|
Was editor tracking disabled before attempting to delete the table?
... View more
11-16-2017
01:41 PM
|
0
|
3
|
2397
|
|
POST
|
Since you are creating an SQL where clause, you may need the string in quotes for comparison. It may be helpful to use something like: >>> row = ( 123, "hello")
>>> sql = "RESID = {}".format(row[0]) # for numbers
>>> sql
'RESID = 123'
>>> sql = "RESID = '{}'".format(row[1]) # for strings
>>> sql
"RESID = 'hello'"
... View more
11-15-2017
11:25 AM
|
1
|
0
|
4237
|
|
POST
|
Posting code in a code block (use the syntax highlighter by clicking "More" when you create/edit your message) has a number of advantages. Convenience is probably the most important; people don't have to download and extract to see what you are attempting. Using the code block properly will add formatting and line numbering which will aid the discussion. A brief description of the project will help focus the discussion. Sometimes uploading sample of your data (and/or a picture of it) will assist in testing code. Regarding the AreaFieldName, you could check to see if the attribute exists, as in: if shapeType == "Polygon":
if hasattr(dscB, "AreaFieldName"):
areaField = dscB.AreaFieldName
attributesToCompare.append(areaField) With a SearchCursor you can use tokens in place of field names, so you wouldn't need to know the name of the area field. (Check out the field names in the syntax help section.) As an example, you can get the object ID using OID@ and the area using SHAPE@AREA. fc = r"C:\Path\To\shapefile.shp"
with arcpy.da.SearchCursor(fc,["OID@","SHAPE@AREA"]) as cursor:
for row in cursor:
print '{}, {}'.format(row[0],row[1])
'''
0, 24556814787.3
1, 28419119732.9
2, 12772853815.8
3, 46299780205.9
'''
... View more
11-14-2017
06:58 PM
|
1
|
1
|
661
|
|
POST
|
Try: SQL_statement = "MOD_DATE >= '"+yesterdaysDate+"'" And, noting Joshua Bixby's comment below, you may need to proceed your date with the word "date" (if using a file geodatabase, for example): SQL_statement = "MOD_DATE >= date '"+yesterdaysDate+"'"
... View more
11-13-2017
02:39 PM
|
1
|
1
|
1622
|
|
POST
|
You mention that a "bunch of analysis" is done. Would ArcMap be creating layers where the name changes with each run, and if so, is the script adapting to this change? Print statements would help identify this problem. This is a sample of the code that I use with ApplySymbologyFromLayer. import os
import arcpy # if outside ArcMap
# inside ArcMap, use "CURRENT" for document name
mxd = arcpy.mapping.MapDocument(r"C:\Path\To\map.mxd")
# layer file is in directory with mxd map document; this will be the workspace
arcpy.env.workspace = os.path.dirname(mxd.filePath)
# dictonary matches map layer with symbology layer file
symbols = {'SymbolTest':'LayerSymbology.lyr'}
for layer in arcpy.mapping.ListLayers(mxd):
if layer.name in symbols:
print "Applying symbology to layer '{}' using '{}'.".format(layer.name, symbols[layer.name])
arcpy.ApplySymbologyFromLayer_management(layer, symbols[layer.name])
else:
print "Layer '{}' not in map.".format(layer.name)
# may need to refresh map
# arcpy.RefreshTOC()
# arcpy.RefreshActiveView()
# save exported jpg in directory with mxd file using mxd name
arcpy.mapping.ExportToJPEG(mxd,os.path.splitext(os.path.basename(mxd.filePath))[0])
del mxd
... View more
11-11-2017
08:27 PM
|
1
|
0
|
1788
|
|
POST
|
The "AreaFieldName" is a property for a Geodatabase Feature Class. You are comparing shape files (.shp) which do not have this property - and thus the error at line 69. # String representing original feature class path
featureClassB = "J:/GIS/GIS_PROJ/parcels/Comparisons/2017_02-03/Data/03_DOIT_SOI.shp"
dscB = arcpy.Describe(featureClassB)
shapeType = str(dscB.ShapeType)
if shapeType == "Polygon":
areaField = dscB.AreaFieldName # line 69
attributesToCompare.append(areaField)
# AttributeError: DescribeData: Method AreaFieldName does not exist You may wish to post your code in a code block (see Code Formatting... the basics) to get more comments. Also, as Joshua Bixby suggested, you may want to provide a short description of what you are trying to accomplish. If I understand your code, you are trying to compare two shape files and write the differences to a third shape file.
... View more
11-09-2017
09:25 PM
|
1
|
3
|
3547
|
|
POST
|
Are you running the script in the Python window in ArcMap? If so, are you refreshing the view before exporting your jpeg? arcpy.RefreshTOC()
arcpy.RefreshActiveView()
... View more
11-07-2017
09:21 AM
|
1
|
2
|
1788
|
|
POST
|
An old question on Geonet: How to publish a feature service to ArcGIS Online from an mxd USING PYTHON? Which leads to this blog post (last comment suggests code -on GitHub- can be made to work with 10.5): Updating your hosted feature service for 10.2
... View more
11-01-2017
08:18 PM
|
2
|
0
|
1778
|
|
POST
|
It may be using UTC, and you may need to adjust to your local time zone.
... View more
10-31-2017
04:41 PM
|
1
|
0
|
803
|
|
POST
|
Try: def streetNUM(field):
if field == "Fourth":
return field.replace("Fourth","4th")
elif field == "Fifth":
return field.replace("Fifth","5th")
else:
return field
... View more
10-27-2017
02:40 PM
|
2
|
1
|
8220
|
|
POST
|
Perhaps something like: mxd = arcpy.mapping.MapDocument("CURRENT")
df = arcpy.mapping.ListDataFrames(mxd)[0]
for layer in arcpy.mapping.ListLayers(mxd):
if layer.isGroupLayer:
if layer.name == layer.longName:
refLayer = layer
# print "Reference layer: {}".format(refLayer.name)
else:
if layer.name != layer.longName:
moveLayer = layer
# print "Move layer: {}".format(moveLayer.name)
arcpy.mapping.MoveLayer(df,refLayer,moveLayer,"BEFORE")
# group layers should be empty, remove them
for layer in arcpy.mapping.ListLayers(mxd):
if layer.isGroupLayer:
arcpy.mapping.RemoveLayer(df, layer)
... View more
10-23-2017
03:41 PM
|
1
|
1
|
5694
|
|
POST
|
Some thoughts... ListLayoutElements may loop through TEXT_ELEMENTs in the same order. If so, you might be able to set values using this order. If you delete and add new elements, this order may change. Have your search text set to a certain default value ("Element1", "Element2", etc.). Have your script replace these values, print your PDF and then restore the text back to the default values (assuming you are resaving your map each time). Text Elements also have other properties, such as position (elementPositionX, elementPositionY), which may help identify the elements. See: TextElement Edit: Even better, name your text elements to identify them. On the "Size and Position" property tab for the text element, there is a box for "Element Name", or you can use Python: txtCount = 1
for elm in arcpy.mapping.ListLayoutElements(mxd,"TEXT_ELEMENT"):
elm.name = "TextBox_{}".format(txtCount)
txtCount += 1
for elm in arcpy.mapping.ListLayoutElements(mxd,"TEXT_ELEMENT"):
if elm.name == "TextBox_1":
elm.text = "new text"
... View more
10-23-2017
09:59 AM
|
3
|
2
|
5452
|
|
POST
|
Using ListLayoutElements you can search for a text element that contains a specific phrase (assuming the phrase will always be the same) and then change that text: mxd = arcpy.mapping.MapDocument("CURRENT")
for elm in arcpy.mapping.ListLayoutElements(mxd, "TEXT_ELEMENT"):
if elm.text == "Text":
print elm.text
elm.text = "new text"
arcpy.RefreshActiveView() But I would insert a map Title in Layout view as it uses dynamic text to access and display the title element from the document's properties. Then use python to edit the title property: mxd = arcpy.mapping.MapDocument("CURRENT")
print mxd.title
# prints map document property title
# found at File > Map Document Properties
# set map document title and refresh
mxd.title = "My Big Map"
arcpy.RefreshActiveView() See: Working with dynamic text If I understand your second question, something like this will rename a feature layer to a value found in a field in the feature's first row using SearchCursor. Line 1 causes this to loop through all layers, but if you have a specific layer name, you might be able to just use a modification of line 3. for layer in arcpy.mapping.ListLayers(mxd):
# change layer.name to value in found in FieldName of first row of SearchCursor
layer.name = arcpy.da.SearchCursor(layer, ("FieldName",)).next()[0]
arcpy.RefreshActiveView()
... View more
10-21-2017
08:28 PM
|
1
|
4
|
5452
|
| 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
|