|
POST
|
def Reclass(FIELD1):
if FIELD1 == "H3010":
return "River"
elif FIELD1 == "ABC":
return "Something"
Hello, I am very new to Python scripting and I am trying to write one that will take values (they are always consistent), and based on their value enter a string into another field. I am working with data that is always coded the same (referenced below as field1, and I want to take those codes and automate a way to populate a different field based on those codes. I have been trying to play with this, but it hasn't worked so far: Expression: Reclass(!FIELD1!) Code block: def Reclass(FIELD1): if (FIELD1 == "H3010"): return "River" Ideally this is supposed to end up being an expression that the user can just load into the field calculator and it will grab the values from FIELD1 and place the desired values into FIELD2.
... View more
10-24-2013
12:14 PM
|
0
|
0
|
782
|
|
POST
|
Yup Jen. I think this saves you the time of creating and maintaining a code just for this task. You could work off from the SDE feature class of the parcels so that if that data is being updated, your ddp enabled mxd will get refreshed as well. But if you want to use the shapefiles for some valid reason, it would be best to merge them all in one dataset assuming their table schema are the same, before using them as a ddp index layer. And if all information you need to for your titles, subtitles etc are within the parcel data themselves then just simply use Data Driven Page Attribute (assuming your using 10.1). Cheers & Goodluck. I am using a large dataset out of SDE which has many shapefiles within it. It contains parcels of land for which I need to make a map for each parcel. I think datadriven pages would be adequate and am going to give that a try. Thank you.
... View more
10-24-2013
12:08 PM
|
0
|
0
|
747
|
|
POST
|
Do you mind sharing what other shapefiles you need to use and reference and what info you need from them in order complete your input for your "subtitle" text element? It sounds like DDP would be ideal for your property mapping, but you'll require a single parcel layer to use as an ddp index layer. Then you can add dynamic text element based on the attributes of your index layer to use for dynamic titles. But as you said you have several shapefiles, which we are not sure what they are or are they individual pproperty shapefiles? Perhaps you can clarify further. Cheers
... View more
10-17-2013
06:26 PM
|
0
|
0
|
747
|
|
POST
|
Cant you just use the layer name itself in the TOC as label in your Legend? If your using the layer name for a different purpose, you can also use it in tandem with a layer description as long as you set it up with a single unique symbol with a description. Seems a fairly simple approach without resorting to scripting. I'm trying to write a script to change the label next to the symbol in the TOC so it appears in the legend. Arcpy has a way to change the name of the layer, but I can't seem to find a way to change the text one level below that. They also have a way to change unique symbol texts and descriptions, but that's not what I need either. Am I just missing it in the tutorials/help pages? It's just the text box in the layer's Properties under the Symbology tab. There's a box that says "Legend" and then "Label appearing next to the symbol in table of contents." I've attached a picture of the box that I want to change. It's where it says "Positive CSC". Any help would be appreciated. Thanks
... View more
10-02-2013
12:12 AM
|
0
|
0
|
554
|
|
POST
|
try: arcpy.CalculateField_management("GISMainFabric_Line_Clip_0","Bear",str[NUM1] + '\xb0' + str[NUM2] + "'","PYTHON 9.3") I tried to populate a field by using the line below in my script but I got the error message below. Please how can I represent the degree (°) & Minute (') symbols in my Python Script. Any suggestions? arcpy.CalculateField_management("GISMainFabric_Line_Clip_0","Bear",'[NUM1] & "°" & [NUM2]',"VB")
File "C:\Users\Administrator\AppData\Local\ESRI\Desktop10.1\AssemblyCache\{7F12A0CE-D617-8330-5EBC-E045415D9345}\PlanTool_addin.py", line 105 SyntaxError: Non-ASCII character '\xb0'
... View more
10-01-2013
07:10 PM
|
0
|
0
|
3097
|
|
POST
|
I think it should just be arcpy.CalculateField_management(Selected_Features, "EditField", value, "VB", "") I figured that you can't really convert a model to a script and think everything is going to work. When I converted the model to script, the calculate field process was referencing Selected_features but selected features was a variable that was equal to Selecting Features which meant nothing. I added the Selected Features variable after the select layer by location and made it equal to the Input_points_layer, which was a real layer created before and already selected. Now I just need to figure out how to get the value for the second parameter, which is just showing %value% and not the value I entered for that parameter.
# Import arcpy module
import arcpy
# Script arguments
Selecting_Features = arcpy.GetParameterAsText(0)
if Selecting_Features == '#' or not Selecting_Features:
Selecting_Features = "in_memory\\{1CFDCCDD-5D8D-42F8-AEB2-E66ED4A51A44}" # provide a default value if unspecified
value = arcpy.GetParameterAsText(1)
# Local variables:
Input_Points = "D:\\ArcGISData\\ESRI_GEO_EX\\GDB.gdb\\SamplePoints"
Final_Output = value
Input_Points_Layer = "SamplePoints_Layer"
# Process: Make Feature Layer
arcpy.MakeFeatureLayer_management(Input_Points, Input_Points_Layer, "", "", "OBJECTID OBJECTID VISIBLE NONE;SymbologyField SymbologyField VISIBLE NONE;DomainField DomainField VISIBLE NONE;Shape Shape VISIBLE NONE;Subtype Subtype VISIBLE NONE;EditField EditField VISIBLE NONE")
# Process: Select Layer By Location
arcpy.SelectLayerByLocation_management(Input_Points_Layer, "INTERSECT", Selecting_Features, "", "NEW_SELECTION")
Selected_Features = Input_Points_Layer
# Process: Calculate Field
arcpy.CalculateField_management(Selected_Features, "EditField", "'%value%'", "PYTHON_9.3", "")
... View more
09-30-2013
01:21 PM
|
0
|
0
|
2128
|
|
POST
|
Thanks guys. Luckily my python labels were just a stop gap solution. Since my datasets have been updated I wont be needing such advanced label expressions. But it was good to know that this issue exist and the workarounds. Cheers Here is the nimbus for the support incident I logged with Esri regarding the issue: NIM091502: Labels written in advanced python are not displayed when exported to PDF outside of ArcMap. Just to echo what Richard already said, I think VB may be the best option if you are exporting PDF's programmatically. I have had successful exports with some 'advanced python' expressions I have tried, but VB never fails.
... View more
09-24-2013
03:51 PM
|
0
|
0
|
1554
|
|
POST
|
Yup Im currently using 10.1. I'm working with DDP enabled mxd's that has some layers having label expressions in them that I created using a python parser. what I did was I created another script to batch export a series of DDP maps and when I ran it and checked the output pdf's, those layers with python label expressions are missing labels.
... View more
09-23-2013
05:11 PM
|
0
|
0
|
1554
|
|
POST
|
Hi guys, ran into this problem yesterday. Is there any other way besides converting to VB expressions? Cheers
... View more
09-23-2013
02:06 PM
|
0
|
0
|
1554
|
|
POST
|
Hi guys, any solution to this problem? I tried this approach as well where each reclass row has 3 components. When I run my script, I get an erroneous raster data. when I check the xml file of the output raster, I saw that the remap string was changed from 3 component input to 2 components which would give that erroneous raster. Even if you export the tool within a model, the output exported script also will contain 3 component but when you run it, still same result.
... View more
09-22-2013
08:07 PM
|
0
|
0
|
541
|
|
POST
|
I've tried it like this, and its fine, import arcpy mxd = arcpy.mapping.MapDocument(mxd_path) df = arcpy.mapping.ListDataFrames(mxd, "Layers")[0] sourceLayer = arcpy.mapping.Layer(layerfile_path) for lyr in arcpy.mapping.ListLayers(mxd,'',df): if lyr.isRasterLayer == True: arcpy.mapping.UpdateLayer(df, lyr, sourceLayer, True) print lyr.name mxd.saveACopy(r"E:\Test2.mxd") del lyr, mxd
... View more
08-21-2013
06:36 PM
|
0
|
0
|
1113
|
|
POST
|
Hi Scott, Why not just create a LYR file from a raster with the alpha band already set and then create a short script to updated the other raster layers in your mxd. Look up this fucntion, "UpdateLayer (arcpy.mapping)". Cheers,
... View more
08-21-2013
04:00 PM
|
0
|
0
|
1113
|
|
POST
|
Yup your right. The difference of the code I put above is that you can make an input variable part of your where_clause which you said was your next step.:o Of course, it was even more simple than that. The reason it wasn't working is because I chose "String" for my input instead of "SQL statement" Once I changed the parameter it worked perfectly. Thanks anyway!
... View more
07-01-2013
01:01 PM
|
0
|
0
|
739
|
|
POST
|
try,
inputVariable = arcpy.GetParameterAsText(0)
arcpy.SelectLayerByAttribute_management ("Quakesim_lyr", "NEW_SELECTION", where_clause='"GRIDCODE"={0}'.format(inputVariable))
... View more
07-01-2013
12:36 PM
|
0
|
0
|
739
|
|
POST
|
Hi Daniel, I think your better off using arcpy.da.UpdateCursor(). So you can work directly with the data rather than call the CalculateFieldTool first from the script to do your field calculations. Thanos I'm trying to use the CalculateField tool in a script tool and part of this includes using the arcgis.rand function. I read somewhere that the calculate field tool has it's own globals and that I would need to use the import statement at the begining of the codeblock in order for the tool to work. If I don't import it in the codeblock, I receive an error "Name 'arcgis' is not defined". So, can anyone help in setting the syntax for the import statement. This is an example from the ESRI Resource site ... Expression:
MetersToFeet((float(!shape.area!)))
Expression Type:
PYTHON_9.3
Code Block:
import math
def MetersToFeet(area):
return math.pow(3.2808, 2) * area
This is what I have coded ... expression = "id_gen()"
codeblock = """def id_gen(size = 9, chars = string.ascii_uppercase + string.digits):
return ''.join(random.choice(chars) for x in range (size))"""
arcpy.CalculateField_management(sewer, fieldName, expression, "PYTHON", codeblock)
... View more
06-20-2013
02:31 PM
|
0
|
0
|
583
|
| Title | Kudos | Posted |
|---|---|---|
| 1 | 10-23-2014 12:00 PM | |
| 1 | 01-23-2013 05:05 PM | |
| 1 | 02-13-2018 05:55 PM | |
| 1 | 07-04-2017 02:01 PM | |
| 1 | 08-02-2017 01:57 AM |