|
POST
|
The thing that jumps out to me is that you start several cursors, never use one of them, and never delete them. You should use 'with' syntax, which cleans up your cursors even if they error out, and avoid seemingly random errors - which you seem to be experiencing.
... View more
08-04-2016
02:09 PM
|
0
|
0
|
3903
|
|
POST
|
Yes, this is the line that builds the dictionary. It uses some shorthand called a dictionary comprehension: features = {row[0]:[row[1],row[2]] for row in arcpy.da.SearchCursor(index,['ID','SHAPE@','Scale'])} This line is equivalent to: features = {}
with arcpy.da.SearchCursor(index,['ID','SHAPE@','Scale']) as cursor:
for row in rows:
features[row[0]] = [row[1],row[2]] # I think this is right, but may get key error, I can't remember And, yes, you're mostly right about which part specifies what in row. The first value ('ID') becomes the first item in row (row[0]), second value ('SHAPE@') goes into row[1], and third value ('Scale') goes into row[2]. If you listed more fields, they would go into row[3], row[4], etc.
... View more
08-04-2016
01:00 PM
|
2
|
0
|
2896
|
|
POST
|
You would need to add the scale value into the features dictionary. Before, the dictionary had the form: {ID1:SHAPE1, ID2:SHAPE2,...}. Below, I've changed it to be like: {ID1:[SHAPE1,SCALE1], ID2:[SHAPE2,SCALE2]...}. So, later on, you can reference by ID (features[pageNum]) and get either the shape ([0]), or scale ([1]).
import time
mxd = arcpy.mapping.MapDocument("CURRENT")
df1 = arcpy.mapping.ListDataFrames(mxd,"Layers")[0]
df2 = arcpy.mapping.ListDataFrames(mxd,"Layer02")[0]
fc = "D:\Practice\Arcpy\New_Shapefile.shp"
index = fc # my DDP index layer
features = {row[0]:[row[1],row[2]] for row in arcpy.da.SearchCursor
(index,['ID','SHAPE@','Scale'])} # all index features
for pageNum in range(1,mxd.dataDrivenPages.pageCount,2):
mxd.dataDrivenPages.currentPageID = pageNum
df1.extent = features[pageNum][0].extent
df1.scale = features[pageNum][1]
df2.extent = features[pageNum+1][0].extent
df2.scale = features[pageNum+1][1]
arcpy.RefreshActiveView
print ['ID']
arcpy.mapping.ExportToPDF(mxd, r"D:\Practice\Arcpy\Page_" + str(pageNum) + ".pdf")
time.sleep(2)
del mxd
... View more
08-04-2016
11:31 AM
|
2
|
2
|
2896
|
|
POST
|
It just doesn't actually read the available IDs. It assumes that every ID exists between 1 and the length of the list. If you happened to have IDs 1, 2, 3, 5 (missing 4), when the loop is on 3 it will look for value 4 (pageNum+1), but since it's not there, there will be an error. If all your IDs exist, there should be no problem.
... View more
08-04-2016
11:07 AM
|
2
|
4
|
2896
|
|
POST
|
This seems to work using a modern cursor. This works for 'nice' data, but you may have to do some work if you're missing IDs or something. >>> import time
... mxd = arcpy.mapping.MapDocument("CURRENT")
... df1 = arcpy.mapping.ListDataFrames(mxd,"Layers1")[0]
... df2 = arcpy.mapping.ListDataFrames(mxd,"Layers2")[0]
... index = 'buff' # my DDP index layer
... features = {row[0]:row[1] for row in arcpy.da.SearchCursor(index,['ID','SHAPE@'])} # all index features
... for pageNum in range(1,mxd.dataDrivenPages.pageCount,2):
... mxd.dataDrivenPages.currentPageID = pageNum
... df1.extent = features[pageNum].extent
... df2.extent = features[pageNum+1].extent
... arcpy.RefreshActiveView
... time.sleep(2)
... View more
08-04-2016
10:42 AM
|
2
|
6
|
2896
|
|
POST
|
I'll just point out that this type of script can be greatly simplified by using modern arcpy geometry objects: >>> fc = 'lines' # line feature layer
... bearing_field = 'BEARING' # bearing field
... sr = arcpy.Describe(fc).spatialReference # spatial reference of lines
... with arcpy.da.UpdateCursor(fc,['SHAPE@',bearing_field],spatial_reference=sr) as cursor: # create cursor
... for row in cursor: # loop through lines
... pt1 = arcpy.PointGeometry(row[0].firstPoint,sr) # first point geometry
... pt2 = arcpy.PointGeometry(row[0].lastPoint,sr) # last point geometry
... row[1] = pt1.angleAndDistanceTo(pt2)[0] # (angle, distance)[0] = angle
... if row[1] < 0: # if you want all positive angles
... row[1] += 360
... cursor.updateRow(row) # write value
... View more
08-03-2016
11:23 AM
|
0
|
0
|
2563
|
|
POST
|
You need to add all of the feature class paths to be merged into a list, which will be the first parameter in the Merge tool. So, something along the lines of (obviously, pseudocode): for ds... # loop datasets
mylist = [] # empty list for each dataset
for fc... # loop feature classes
mylist.append(os.path.join(...)) # add path to list
Merge(mylist,...) # merge list for each dataset
... View more
08-02-2016
03:26 PM
|
2
|
0
|
4491
|
|
POST
|
Forgive me for not wanting to dive back into the tedium of this math, but perhaps you can use something from this thread: Calculating angles using ArcGIS Desktop 10.2
... View more
08-02-2016
09:48 AM
|
1
|
0
|
5732
|
|
POST
|
Oh, if you're back at 10.0, the arcpy data access module didn't exist. Consult the help for reading and writing geometries at 10.0 with normal cursors.
... View more
08-02-2016
09:10 AM
|
1
|
1
|
3782
|
|
POST
|
What the heck... Parser = VB Script Expression: result Codeblock: result = 0
if [FY11] > 0 then
result = result + 1
end if
if [FY12] > 0 then
result = result + 1
end if
if [FY13] > 0 then
result = result + 1
end if
if [FY14] > 0 then
result = result + 1
end if
if [FY15] > 0 then
result = result + 1
end if
... View more
07-29-2016
03:02 PM
|
1
|
2
|
3465
|
|
POST
|
You can also use the field calculator: Parser = Python Expression: blah( !FY11! , !FY12! , !FY13! , !FY14! , !FY15! ) Codeblock: def blah(f1,f2,f3,f4,f5):
params = locals() # dictionary of all arguments in function
my_sum = 0 # cumulative total
for k,v in params.iteritems(): # loop through dictionary
if v>0: # inspect value
my_sum += 1 # add to cumulative total
return my_sum # return total
... View more
07-29-2016
02:53 PM
|
1
|
7
|
3465
|
|
POST
|
You can use an update cursor for this: >>> fc = 'points_test' # feature layer
... fields = ['FY11','FY12','FY13','FY14','FY15','Burns_5Yrs'] # your fields, with burns last
... with arcpy.da.UpdateCursor(fc,fields) as cursor: # create cursor
... for row in cursor: # loop through features
... row[-1] = sum(x > 0 for x in row[:-1]) # sum non-zeros, place in last position
... cursor.updateRow(row) # write new value, after changing burns value
... View more
07-29-2016
02:19 PM
|
0
|
8
|
3465
|
|
POST
|
It sounds like you've got lat/long coordinates (degrees) that are being assigned a coordinate reference system measured in some other unit (probably meters). Can you show the coordinate reference system you assign in the Display XY dialog box? It should be plain, old, geographic GCS_WGS_1984 (i.e. not projected).
... View more
07-28-2016
09:36 AM
|
2
|
0
|
3336
|
| 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
|