|
POST
|
You can move your select statement before creating the search cursor. Otherwise, you execute a select statement for each feature in the cursor. The cursor only considers selected features, so you don't need to filter with a where clause. The following selection where clause is hardcoded, but you can sub that out for GetParameterAsText. >>> import arcpy
... mxd = arcpy.mapping.MapDocument('CURRENT')
... df = arcpy.mapping.ListDataFrames(mxd, "Layers") [0]
... lyr = arcpy.mapping.ListLayers(mxd, "bc_geoname_albers")[0]
... whereClause = "GEONAME LIKE '%Fraser%' "
... arcpy.SelectLayerByAttribute_management(lyr, "NEW_SELECTION", whereClause )
... with arcpy.da.SearchCursor(lyr, ["SHAPE@","GEONAME"]) as cursor:
... for row in cursor:
... df.extent = row[0].extent
... df.scale = df.scale * 5
... arcpy.RefreshActiveView()
... View more
05-20-2015
02:38 PM
|
1
|
1
|
2403
|
|
POST
|
What type of feature class are you working with? Where clauses are data-specific (see the help for Make Feature Layer, where clause section). My example used a shapefile - fields are enclosed by double quotes. File GDB fields have no quotes. Personal GDB fields are enclosed by []. A nice way to figure it out is to run Make Feature Layer once through the normal tool dialog to figure out the syntax. Once you get it to work once, you can export the result from the results window to a Python snippet and inspect the syntax more fully in a text editor or IDE
... View more
05-20-2015
11:06 AM
|
0
|
1
|
10469
|
|
POST
|
No problem. Python requires proper indentation. The first line has no indentation - it is three '>' characters and one space. The next line is three '.' characters and one space. Both of these are at indentation level zero. Same with line three. Line 4 is indented by 4 spaces, to indicate it is inside the 'with' block. Line 5 is indented by 8 spaces, to indicate it is inside both the 'for' and 'with' blocks. Line 6 (rast=...) should be indented exactly the same as Line 5 - it should be inside both the 'for' and 'with' blocks.
... View more
05-20-2015
10:34 AM
|
0
|
4
|
8148
|
|
POST
|
There was a copy/paste error in there - I've updated above. The final line should end with this, not >>>: str(row[0])) rast = arcpy.sa.TabulateArea("tempFL","FID",raster,"Value",r"in_memory\outTable" + str(row[0]))
... View more
05-20-2015
10:12 AM
|
0
|
6
|
8148
|
|
POST
|
Here is how you can do it with Python. Requires Spatial Analyst. This example uses an overlapping zone feature class called "buffer_1000" (must have "FID" field), class raster called "raster" (must have "Value" field), and outputs one table for each feature in the zone feature class called "outTable1", "outTable2", etc. You can then run Merge to consolidate these output tables. Of course, change the feature class names to suit your data. >>> zoneFC = "buffer_1000"
... raster = "raster"
... with arcpy.da.SearchCursor(zoneFC,"OID@") as cursor:
... for row in cursor:
... arcpy.MakeFeatureLayer_management(zoneFC,"tempFL","\"FID\"=" + str(row[0]))
... rast = arcpy.sa.TabulateArea("tempFL","FID",raster,"Value",r"in_memory\outTable" + str(row[0]))
... View more
05-20-2015
09:23 AM
|
1
|
8
|
8148
|
|
POST
|
There are many ways to save yourself from repetition in ArcGIS, most of which rely on stringing together geoprocessing tools and clicking a "Go" button. You can do this using ArcObjects (personally, I wouldn't bother), Python script, ModelBuilder, or batch processing (listed in my order of most flexible/hardest to learn to least flexible/easiest to learn). You need to decide which road you feel like going down. The main tool(s) you're looking to repeat are Add Join or Join Field.
... View more
05-19-2015
02:35 PM
|
1
|
0
|
1364
|
|
POST
|
I think that used to be the case, but it's included out-of-the-box for all, now.
... View more
05-19-2015
02:27 PM
|
1
|
2
|
7250
|
|
POST
|
If you haven't turned on Maplex labeling, do so. Then, in Placement Properties, enable Place label at fixed position within polygon, and set Internal Zones to the centre zone = 1.
... View more
05-19-2015
02:16 PM
|
1
|
7
|
7248
|
|
POST
|
Please post the script you have so far. What are the "problems" you have trying top iterate?
... View more
05-18-2015
09:32 AM
|
0
|
2
|
2750
|
|
POST
|
In addition to Chris' comment about processing zones individually, it sounds like you may be more interested in the Tabulate Area tool (which will list the cells in each class), rather than Zonal Statistics (which performs some numerical summarization of your classes, like mean, range, etc.).
... View more
05-15-2015
10:32 AM
|
1
|
0
|
8148
|
|
POST
|
Sorry, just read the help and it looks like you only need the data frame name, not the data frame object. I hoped to have edited that in time.
... View more
05-15-2015
09:20 AM
|
2
|
0
|
2211
|
|
POST
|
Your dataFrame variable holds the name of the map, not the required data frame name, unless they happen to be the same.
... View more
05-15-2015
09:06 AM
|
0
|
4
|
2211
|
|
POST
|
Don't know if this is the whole problem, but "conversion" is spelled wrong.
... View more
05-14-2015
10:31 PM
|
2
|
5
|
2604
|
|
POST
|
As far as I can tell, your main problem with: arcpy.env.workspace = "folder1\folder2\folder3\" + mxd + "\folder4\folder5" is ending your string with \" which translates to an escaped quotation mark, or literally the symbol ". That part of the string never closes. For paths, you should use r"path\path", or "path/path" or "path\\path". Furthermore, the easy way to concatenate paths is by using os.path.join, which uses the system path separator to join path strings: >>> import os.path
... first_concat = os.path.join(r"C:\folder1\folder2\folder3","someMapName")
... print first_concat
... second_concat = os.path.join(first_concat,r"folder4\folder5")
... print second_concat
...
C:\folder1\folder2\folder3\someMapName
C:\folder1\folder2\folder3\someMapName\folder4\folder5
... View more
05-14-2015
02:09 PM
|
3
|
6
|
3322
|
|
POST
|
The following changes the length of the field. >>> inshp = "line"
... fms = arcpy.FieldMappings()
... fm = arcpy.FieldMap()
... fm.addInputField(inshp,"myField")
... newField = fm.outputField
... newField.length = 100
... fm.outputField = newField
... fms.addFieldMap(fm)
... arcpy.FeatureClassToFeatureClass_conversion(inshp, r'C:/junk', 'newshp', field_mapping=fms) Note that you must make your changes in a new field object ("newField") rather than fm.outputField. I won't say I understand why this is, it just is. For example, this will not change the output field length, although I would have guessed, like you, that it should: >>> inshp = "line"
... fms = arcpy.FieldMappings()
... fm = arcpy.FieldMap()
... fm.addInputField(inshp,"myField")
... fm.outputField.length = 100
... fms.addFieldMap(fm)
... arcpy.FeatureClassToFeatureClass_conversion(inshp, r'C:/junk', 'newshp2', field_mapping=fms)
... View more
05-14-2015
01:47 PM
|
1
|
3
|
5768
|
| Title | Kudos | Posted |
|---|---|---|
| 1 | 08-30-2013 02:22 PM | |
| 1 | 04-12-2011 11:19 AM | |
| 1 | 09-17-2021 09:43 AM | |
| 1 | 04-04-2012 12:05 PM | |
| 2 | 07-16-2020 11:31 AM |
| Online Status |
Offline
|
| Date Last Visited |
07-15-2023
12:11 AM
|