|
POST
|
Hi SYM, Here's an example: import arcpy
from arcpy import env
env.workspace = r"C:\temp\python\test.gdb"
lstFCs = arcpy.ListFeatureClasses("*", "POLYGON")
arcpy.Union_analysis(lstFCs, "Union_FC") This script is creating a list of all the polygon feature classes, and then passing this list as the input for the Union GP tool.
... View more
08-02-2012
01:51 PM
|
0
|
0
|
1520
|
|
POST
|
Hi thanks very much for the reply. Could I use that script with the following folder references removed so that all folders in M:\Planning\ and F:\ are replaced or do I have to do it by individual folder? import arcpy, os from arcpy import env workspace = env.workspace = r"C:\Temp\Python" mxdList = arcpy.ListFiles("*.mxd") for mxd in mxdList: mxd2 = workspace + os.sep + mxd mapdoc = arcpy.mapping.MapDocument(mxd2) mapdoc.findAndReplaceWorkspacePaths(r"M:\Planning\", r"M:\Directorates\Planning\") mapdoc.findAndReplaceWorkspacePaths(r"F:\", r"M:\Directorates\Planning\") mapdoc.save() del mapdoc Also do I have to enter that script into all current .mxd files or can it be entered directly into ArcGIS just once? Thanks again Yes, this is possible, but takes a little bit more coding. Here's an example: import arcpy, os from arcpy import env from arcpy import mapping workspace = env.workspace = r"F:" mxdList = arcpy.ListFiles("*.mxd") for mxd in mxdList: mxd2 = workspace + os.sep + mxd mapdoc = arcpy.mapping.MapDocument(mxd2) for df in mapping.ListDataFrames(mapdoc): for layer in mapping.ListLayers(mxd, "", df): if "F:\\" in layer.dataSource: origPath = layer.dataSource.split("\\") origPath2 = "" for x in origPath[0:-1]: origPath2 += x + os.sep origPath2 = origPath2[0:-1] dataSource = layer.dataSource.strip("F:\\") dataSource = dataSource.split("\\") path = "" for y in dataSource[0:-1]: path += y + os.sep path = path[0:-1] mapdoc.findAndReplaceWorkspacePaths(origPath2, r"M:\Directorates\Planning" + os.sep + path) elif "M:\\Planning\\" in layer.dataSource: origPath = layer.dataSource.split("\\") origPath2 = "" for x in origPath[0:-1]: origPath2 += x + os.sep origPath2 = origPath2[0:-1] dataSource = layer.dataSource.strip("M:\\Planning\\") dataSource = dataSource.split("\\") path = "" for y in dataSource[0:-1]: path += y + os.sep path = path[0:-1] mapdoc.findAndReplaceWorkspacePaths(origPath2, r"M:\Directorates\Planning" + os.sep + path) mapdoc.save() del mapdoc I have not tested this extensively, but had a similar version of this script work successfully. Also, this will need to be only executed once. The script will loop through all MXDs in the workspace directory: workspace = env.workspace = r"F:" In the above example, it will find all the MXDs on the F drive. You can update this to the folder location where your MXDs are.
... View more
08-02-2012
07:41 AM
|
0
|
0
|
2075
|
|
POST
|
You can also you the Feature Class to Feature Class (conversion) tool. This allows you to use the field map option: You can add, rename, or delete output fields as well as set properties such as data type and merge rule.
... View more
08-02-2012
06:32 AM
|
0
|
0
|
2593
|
|
POST
|
You could use the findAndReplaceWorkspacePaths to accomplish this. Here is an example: import arcpy, os
from arcpy import env
workspace = env.workspace = r"C:\Temp\Python"
mxdList = arcpy.ListFiles("*.mxd")
for mxd in mxdList:
mxd2 = workspace + os.sep + mxd
mapdoc = arcpy.mapping.MapDocument(mxd2)
mapdoc.findAndReplaceWorkspacePaths(r"M:\Planning\Development Plan", r"M:\Directorates\Planning\Development Plan")
mapdoc.findAndReplaceWorkspacePaths(r"F:\Planning policy\Shapefiles", r"M:\Directorates\Planning\Planning Policy\Shapefiles")
mapdoc.findAndReplaceWorkspacePaths(r"M:\Directorates\Planning", r"M:\Directorates\Planning\08Plan")
mapdoc.save()
del mapdoc
... View more
08-02-2012
04:48 AM
|
0
|
0
|
2075
|
|
POST
|
Hi James, I would recommend using replication. With replication you can synchronize your edits to your parent SDE feature class. You can find more information on replication below: http://resources.arcgis.com/en/help/main/10.1/index.html#//003n000000v1000000 http://resources.arcgis.com/en/help/main/10.1/index.html#/Replication_types/003n000000t6000000/
... View more
08-01-2012
10:29 AM
|
0
|
0
|
701
|
|
POST
|
Yes, you are correct. The split method will return a list of values. For example: string = 'Saur_5'
string.split("_") will return: ['Saur', '5'] Specifying an index will return the value in the list. Ex: string.split("_")[0] will return: 'Saur'
... View more
07-30-2012
08:19 AM
|
0
|
0
|
2236
|
|
POST
|
Hi Numa, I'm not sure if you can use a wildcard with the replace method. The method will read everything within quotes as a string. Try the following instead: Pre-Logic Script Code: def replace(field): if "_" in field: return field.split("_")[0] else: return field Under the code block: replace(<fieldname>) Note: Be sure 'Python' is checked at the top of the Field Calculator
... View more
07-30-2012
05:46 AM
|
0
|
0
|
2236
|
|
POST
|
Hi Tim, You could accomplish this using Python. Here is an example: import arcpy from arcpy import env env.workspace = r"C:\temp\python\Test.sde" lstDatasets = arcpy.ListDatasets("*") for dataset in lstDatasets: lstFCs = arcpy.ListFeatureClasses("*", "", dataset) for fc in lstFCs: lstFields = arcpy.ListFields(fc) for field in lstFields: if field.domain: print fc, field.name, field.domain What this code does is loop through all feature classes in the 'Test' SDE geodatabase and, if a domain is present, prints out the feature class name, the field name that contains the domain, and the domain name.
... View more
07-20-2012
11:48 AM
|
0
|
0
|
821
|
|
POST
|
Try creating a Raster Dataset with the same name by right-clicking on the File Geodatabase > New > Raster Dataset. If it succeeds, right-click on the Raster Dataset > Delete.
... View more
07-19-2012
12:00 PM
|
0
|
0
|
4751
|
|
POST
|
Hi Kevin, You have tbl declared as a variable, and then you declare it as a string with the SearchCursor. Try the following: import arcpy d = {} tbl = r'E:\gis\forestry\20120711_forestryWebApp\temp.gdb\wholeCity' with arcpy.da.SearchCursor(tbl, ['rangeClass', 'count']) as c: for r in c: print r[0], r[1] #d[r[0]] = r[1] print d
... View more
07-19-2012
11:26 AM
|
0
|
0
|
623
|
|
POST
|
Unfotunately, I don't receive this error. What is your Editor set to under Geoprocessing > Geoprocessing Options > Script Tool Editor/Debugger? Clear this so that it is blank, and test to see if you get the error. The editor should default to notepad when this is empty. Let me know if you still receive the same error.
... View more
07-19-2012
10:12 AM
|
0
|
0
|
913
|
|
POST
|
Hi Roger, Looks like the error is stating that you do not have the 'numpy' module installed. Can you open your Python editor and try to import this module: import numpy Do you receive an error when you run this?
... View more
07-19-2012
08:40 AM
|
0
|
0
|
913
|
|
POST
|
That was my mistake, the code should have been: def update(field):
if field[0] in str(range(0, 10)) or field[0] == '#':
pass
else:
return field What this code is doing is checking the first character of each value. If the first character is a number within the range of 0 - 10, or if the character is a '#' sign it will pass this row. If the character is a letter, it will update the row in the new field with that value.
... View more
07-19-2012
04:35 AM
|
0
|
0
|
1576
|
|
POST
|
You will want to specify the field that has the current values in the update() function. So, change: update(!Label_Field!) to: update(!TAG!) This will calculate the values, that begin with a character, from the TAG field to the LABEL_FIELD.
... View more
07-19-2012
04:12 AM
|
0
|
0
|
1576
|
|
POST
|
Thank you, that worked partially, this is what is left: Can you send a screen shot of what you entered in the Field Calculator. It looks like the code did the opposite of what you are looking to accomplish. It calculated all the text values that begin with a number and '#' sign, and not the values that begin with a character.
... View more
07-19-2012
03:49 AM
|
0
|
0
|
6065
|
| Title | Kudos | Posted |
|---|---|---|
| 1 | 3 weeks ago | |
| 4 | 05-07-2020 05:14 PM | |
| 1 | 03-25-2026 04:16 AM | |
| 1 | 03-16-2026 01:00 PM | |
| 1 | 12-22-2025 10:39 AM |
| Online Status |
Online
|
| Date Last Visited |
35m ago
|