|
POST
|
Well, since you ignored the post about being within ArcMap, I'm going to have to assume that when you say Field Calculator, you actually mean the calculateField python tool meaning that you want to do the entire thing in code without having to open ArcMap. One option would be to run the ConvertCoordinateNotation_management (in_table, out_featureclass, x_field, y_field, input_coordinate_format, output_coordinate_format, {id_field}, {spatial_reference}) tool using your OID (or other unique field in your data) as the id_field (which is specifically included to allow for joins back to the original table). As you said, this would create a new FC, but could be saved in_memory to increase speed. Then makeFeatureLayer on your original table so that you can do one of the following (won't work direclty on the FC): Now, if you want to add these new coordinates to the existing table, use the joinfield tool to add the new columns to the original table. Or, if you want to "update" some existing fields in the original FC, you would use addJoin to join the two together, then caclulateField and calculate the existing field(s) to the newly joined fields, then remove the join and you are done. R_
... View more
07-25-2013
03:44 PM
|
0
|
0
|
2397
|
|
POST
|
Ionara, This will do that for you. import arcpy, os from arcpy import da ws = r'D:\update\wch_updated2.gdb' arcpy.env.workspace = ws arcpy.env.overwriteOutput = True build_lyr = "build_lyr" field = "rec" maxValue = 14 arcpy.MakeFeatureLayer_management("buildings", "build_lyr") sqlFieldName = arcpy.AddFieldDelimiters("build_lyr", field) expr = sqlFieldName + " = " + str(maxValue) arcpy.SelectLayerByAttribute_management ("build_lyr", "NEW_SELECTION", expr) with da.SearchCursor(build_lyr,['rec']) as cursor: for row in cursor: print str(row[0]) Of course, the SearchCursor is just so that I could tell if it was working or not.... Have not tested with nulls as I have a script that removes all them, and sets the fields to not nullable as I got tired of issues with them. R_
... View more
07-25-2013
03:17 PM
|
0
|
0
|
1830
|
|
POST
|
not sure if you mean the Field Calculator or the calculateField tool. if you want to do it within arcmap, you can just right-click on the column header, pick calculate geometry, and select what coordinate system you want the values calculated from. R_
... View more
07-25-2013
02:46 PM
|
0
|
0
|
2397
|
|
POST
|
Hi Craig, You could accomplish this with the following code:
fc = "Parcels"
for field in arcpy.ListFields(fc, "*", "String"):
with arcpy.da.UpdateCursor(fc, field.name) as cursor:
for row in cursor:
value = row[0]
value = str(value).rstrip()
row[0] = value
cursor.updateRow(row)
del cursor Am I missing something in this code? It seems like this would just "strip" the whitespace from the ends and still leave all the internal spaces? R_
... View more
07-25-2013
02:36 PM
|
0
|
0
|
6344
|
|
POST
|
What version are you running? I have looked in 9.3, 10.0 and 10.1 and do not see an "Advanced" option for the label class expression so not sure what you are asking. Here are the available label options with arcpy.mapping http://resources.arcgis.com/en/help/main/10.1/index.html#/LabelClass/00s30000002t000000/ which lists nothing about an advanced option. Also, in the expression, using python parser, the following will add a new line between the values from my FAC_CODE and name fields.
[FAC_CODE] + "\n " + [name]
It appears as if you are trying to combine the lblClass.expression and lblClass.SQLquery into the expression box. If you want it to label things differently based on a query/filter, you set up different labelclass's (with a different name for each) So, you would create a labelclass named something like greaterthan with SQLquery= If [Residual] > 0 and the expression that tells it how to label the features that match the query. Then, you would create another labelclass named something like lessthan with SQLquery = If [Residual] < 0 and the expression that tells it how to label the matching features. So, basically, create a label class for each query and set the respective expressions to achieve what you are after. R_ personally, I go into ArcMap and create my labelClasses, make sure the query/expressions are working (make sure you use the python parser), then I figure out the syntax to get them to work with python.
... View more
07-25-2013
01:24 PM
|
0
|
0
|
939
|
|
POST
|
Hi Jake, Thanks for the quick response and script. I tried using this script that you provided by replacing "parcels" with the path to my feature class. I then added this script into ArcToolbox and ran it. The ran successfully, but when I opened the feature class, the extra spaces did not appear to get removed. Is there anything else that I am missing? Thanks again! You said that post 2 worked for you, but only on a single feature. You can combine the two and use that same coding on the entire FC if you want. something like this:
arcpy.MakeFeatureLayer_management("C:/data.gdb/parcels", "parcels_lyr")
for field in arcpy.ListFields("parcels_lyr", "*", "String"):
sqlFieldName = arcpy.AddFieldDelimiters("parcels_lyr", field)
calcSql= "' '.join( field.strip().split())"
arcpy.CalculateField_management("parcels_lyr",field,calcSql,"PYTHON_9.3","#")
This seems to do it for me. R_ If you wanted to use cursors, post 4 could be used, but use this calc function instead.
... View more
07-25-2013
11:21 AM
|
0
|
0
|
6344
|
|
POST
|
I am working with a large number of temporary rasters. Individually they can be saved simply and without issue like r1.save(outloc) However, if they are combined in any way -e.g. x = Raster(r1) + Raster(r2) and the result saved x.save(outloc) I receive the following error "RuntimeError: ERROR 010240: Could not save raster dataset to in_memory\times_ras1 with output format MEM." If I save -all- the temporary rasters before they are combined the final rasters save without issue. Any thoughts? What does print outloc give you? Might try the change in red and see if that fixes it for you. (documentation is unclear, you might need arcpy.env.workspace set an use quotes around r1 and r2. You will have to test. R_ http://resources.arcgis.com/en/help/main/10.1/index.html#//018z00000051000000
... View more
07-24-2013
03:42 PM
|
0
|
0
|
1661
|
|
POST
|
You might want to look into the Tkinter module as well. That will allow you to browse for file/folder using the windows explorer type interface. Not sure what your rasters are as it won't see inside FGDB's, but if they are stand alone files, you may be able to use Tkinter to browse to and select. R_
... View more
07-24-2013
03:33 PM
|
0
|
0
|
2162
|
|
POST
|
You need to look at listFields http://resources.arcgis.com/en/help/main/10.1/index.html#//018v00000012000000 using the wildcard to limit it to "NLCD*" fields. Then you can iterate through the list of fields that match your wildcard and perform what you need to do. A couple thoughts, if you know the number of grid cells that fall within the polygon (the count) and the grids are a set size per cell, then the count * size per cell is the area. Also, instead of creating/deleting fields, you can use internal references for your calculator expressions: (of course, you should work on copies of the data until you get it "right") I.e., if you want to take the value from field1 and multiply by something, you don't have to go to a new field, you can clobber the values. field1 = field1 * value works as long as the field1 type will support the resultant value. Also, keep in mind that you can go to the file menu of you model and export to a python script. This will at least give you the syntax for what you have set up in there already, as a starting point for the scripting. R_
... View more
07-24-2013
02:52 PM
|
0
|
0
|
3055
|
|
POST
|
Good to see you got it working. These get pretty difficult to debug the code when it's not the code causing the issue :rolleyes: You say it is exporting in 9.3 syntax? Do you mean that it is using the gp. instead of arcpy.? What version you exporting it from? I have not noticed this from my 10.0 and 10.1 box, but maybe I'm just not that familiar with the 9.3 syntax. All mine export with arcpy though. R_
... View more
07-24-2013
02:36 PM
|
0
|
0
|
2634
|
|
POST
|
It appears that maybe your list contains strings '999.332202045' Try this, might work for you, will make sure if string, converts to float, then int: Max= int(float(max(Quakesim_List)))
... View more
07-23-2013
04:11 PM
|
0
|
0
|
8849
|
|
POST
|
�?�Map layers can be used as Input Datasets. If a layer has a selection, only the selected records (features or table rows) are used by the Append tool. http://resources.arcgis.com/en/help/main/10.1/index.html#//001700000050000000 R_
... View more
07-23-2013
01:43 PM
|
0
|
0
|
2314
|
|
POST
|
that's too bad, was hoping that would solve your issue. Since it is working in the tool(s), I'm going to have assume you have seen this: http://resources.arcgis.com/en/help/main/10.1/index.html#//00vq0000000n010045 and ensured you data meets these requirements. Description The input that identifies those cells from which the least-cost path is determined does not contain any valid values. If the input is a raster, it should consist of cells that have valid values (zero is a valid value), and the remaining cells must be assigned NoData. Solution Ensure that the raster you specify as the destination dataset has some cells with a valid value (not NoData). Check the documentation for Cost Path for further information. You say it works "tool by tool", have you created a new model in ArcMap, then load each tool into that. Once you get it to run in the model, you can export to python script. Arc is not the "best" python code writer around, but you might see something in the exported code that gives a clue. R_
... View more
07-23-2013
08:24 AM
|
0
|
0
|
2634
|
|
POST
|
First, thanks to everybody for considering my issue. then: 1.- What I am trying to do is exporting into a PDF my Layout View using python. The scale of this map may be 1:20.000 (1:20000) 2.- Before executing the script: Data Frame Properties --> Extent : Automatic 3.- Before executing the script: The scale is set to 30000 (purposely) in order to see if the script works or not. 5.- OK, when I run the script, I look at the Map Scale (Data View) and the sequence I see with my own eyes is: ....1:30,000 (good).......1:20,000 (good!).....1:8,223..(not good). Result: PDF Scale --> 1:8,223 That is all I can say so far. Jose. So, understand the 1:30,000 as you set it manually in the mxd the 1:20,000 is what your script tells it to do Where is the 1:8223 coming from? you say you get all of them, but you only have one spot in the code that is making a change, why (or when) do you get three different values? Just to make sure, you do understand, that, unless you set Data Frame Properties --> Fixed Scale, you will likely "never" get the Layout scale to be exactly 1:20000 as long as you are also zooming to some extent in the dataframe? R_
... View more
07-23-2013
08:19 AM
|
0
|
0
|
7125
|
|
POST
|
Not sure what you mean by dynamically, but this thread shows how to move the scale bar. http://forums.arcgis.com/threads/59984-how-change-scalebar-position R_
... View more
07-22-2013
03:42 PM
|
0
|
0
|
1377
|
| Title | Kudos | Posted |
|---|---|---|
| 1 | 05-14-2026 04:00 PM | |
| 1 | 09-14-2022 07:53 AM | |
| 1 | 09-14-2022 08:23 AM | |
| 1 | 05-21-2026 08:53 AM | |
| 1 | 05-14-2026 04:28 PM |
| Online Status |
Online
|
| Date Last Visited |
2 weeks ago
|