|
POST
|
Just out of curiosity, try running mine. how many usually export before it fails? 1 or 2 or more like 90-100?
... View more
05-07-2015
04:00 PM
|
0
|
1
|
2949
|
|
POST
|
I've used this with 10.2.2 on several hundred maps, in single and multiple directories as well and have not had any issues. If you want continue with your code or if there are issues with mine, I would use either print or print > text file to at least know when or where it breaks. Like i said, mine has never had any problems
... View more
05-07-2015
01:24 PM
|
1
|
4
|
2949
|
|
POST
|
You're trying to export to pdf? Here's a script i wrote for jpg and pdf export of all mxd's in a directory. You can hard code the values if you want and just add a png option at the end if you need to import arcpy, os
inputPath = arcpy.GetParameterAsText(0)
outputPath = arcpy.GetParameterAsText(1)
outputType = arcpy.GetParameterAsText(2)
#Loop through each MXD file
for filename in os.listdir(inputPath):
fullpath = os.path.join(inputPath, filename)
if os.path.isfile(fullpath):
if filename.lower().endswith(".mxd"):
#Reference MXD and export
mxd = arcpy.mapping.MapDocument(fullpath)
fixedFilename = filename.strip( '.mxd' );
if outputType == "jpg":
arcpy.mapping.ExportToJPEG(mxd, outputPath + "//" + fixedFilename + ".jpg")
else:
arcpy.mapping.ExportToPDF(mxd, outputPath + "//" + fixedFilename + ".pdf")
... View more
05-07-2015
06:07 AM
|
1
|
6
|
2949
|
|
POST
|
To answer my own questions def calculateRadius(x1,y1,x2,y2):
radius = (( x2 - x1 )^2 + ( y2 - y1 )^2)^0.5
return radius
print calculateRadius(x1, y1, x2, y2)
... View more
05-06-2015
12:47 PM
|
0
|
1
|
476
|
|
POST
|
To calculate distance between two points, you could just do. import math
def calculateDistance(x1,y1,x2,y2):
dist = math.sqrt((x2 - x1)**2 + (y2 - y1)**2)
return dist
print calculateDistance(x1, y1, x2, y2) if it is along a line, you could just split the line with the points and use the length of the line for that
... View more
05-06-2015
11:46 AM
|
2
|
1
|
19261
|
|
POST
|
Well, are you struggling slightly(almost there, just something in your code is not right) or are you lost (nothing works like it should) Perhaps i can help you if you have something that just isn't quite working, if you are just lost,or not sure how to go about this. My script uses numpy, matplotlib, and scipy, so you would need to install those modules in python (not sure if numpy is installed with arcpy, but i think it is.) What my script does: 1. So you have a point feature class with a field that matches the DDP sheet number that it falls in 2. It then selects those features, and creates a graph, for that page generalizing for missing data to get rid of the jagged edges, as a png in the output folder 3. Then it inserts the graph onto the page and exports, and moves on to the next. So at the end, in the output folder there are the pdf's with the graph inserted on them and all of the png's in case you want them for something else. I really only use this as a function now to create the graphs, I have other functions in my tools that inserts graphs, graphics, pictures, labels, etc on the map. I tried to comment it to make it easier to understand, but let me know if you have any questions. import arcpy,os,glob
import matplotlib.pyplot as plt
import numpy as np
from scipy.interpolate import spline
mxd = arcpy.mapping.MapDocument(r"<MXD file with Data Driven Pages>")
outputFolder = "C:/<ouput location>/"
# there should be a picture element on your page at the location where you want the graph inserted
pictureElementName = "<Picture Element Name>"
eleFieldFeature = "<Elevation Point Feature Class>"
eleField = "<Elevation Field>"
# distField can be whatever field you want for the X axis
distField = "<Distance Field>"
df = arcpy.mapping.ListDataFrames(mxd, "Layers")[0]
pict = arcpy.mapping.ListLayoutElements(mxd, "PICTURE_ELEMENT", pictureElementName)[0]
lyr = arcpy.mapping.ListLayers(mxd, eleFieldFeature, df)[0]
for pageNum in range(1, mxd.dataDrivenPages.pageCount + 1):
mxd.dataDrivenPages.currentPageID = pageNum
# change this SeqId to match the field name that you have in the DDP featureclass
# this is redundant, but it works all the same and I didn't feel like changing it. :)
pageName = mxd.dataDrivenPages.pageRow.getValue("SeqId")
# change this SeqId to match the field name that you have in the Elevation featureclass
arcpy.SelectLayerByAttribute_management(lyr, "NEW_SELECTION", ' "SeqId" = '+ repr(pageName))
# create array of selected
arr = arcpy.da.FeatureClassToNumPyArray(lyr, (eleField, distField))
# set min and max for the graph from the array
mineleField = arr[eleField].min()
maxeleField = arr[eleField].max()
minStation = arr[distField].min()
maxStation = arr[distField].max()
# matplotlib stuff
x = []
y = []
elevPNG = outputFolder+"\elev"+repr(pageNum)+".png"
fig = plt.figure(figsize=(32, 2.8))
table = lyr
fields = [distField, eleField]
with arcpy.da.SearchCursor(table, fields) as rows:
for row in rows:
x.append(row[0])
y.append(row[1])
# the next 7 lines generalize, smooth the line in case of missing data
x_sm = np.array(x)
y_sm = np.array(y)
x_smooth = np.linspace(x_sm.min(), x_sm.max(),200)
y_smooth = spline(x,y,x_smooth)
# subtract/add 10 to the min max of the graph so elevation fits, can increase or decrease as you need
plt.ylim((mineleField-10,maxeleField+10))
plt.xlim((minStation,maxStation))
plt.plot(x_smooth,y_smooth, color='red', linewidth=3)
## the next 3 is your X label, Y Label, and Graph Title
plt.xlabel('Distance')
plt.ylabel('Elevation')
plt.title('Landscape Profile')
plt.grid(True)
fig.savefig(elevPNG, bbox_inches='tight', dpi=(100))
pict.sourceImage = elevPNG
# end of matplotlib stuff
print "Exporting page {0} of {1}".format(str(mxd.dataDrivenPages.currentPageID), str(mxd.dataDrivenPages.pageCount))
arcpy.mapping.ExportToPDF(mxd, outputFolder + str(pageName) + "_W_GRAPH.pdf", resolution=150, image_quality="NORMAL")
plt.clf()
plt.close()
del fig
del mxd
... View more
05-06-2015
10:10 AM
|
1
|
2
|
2064
|
|
POST
|
Ok, so to answer my own question, i figured it out. To do this, i stored the rotation value in a variable, then had to set the data frame rotation to 0. Calculate my page units XY from map units coordinates XY. Then I calculated the new XY and applied the rotation. Worked perfectly
... View more
04-22-2015
04:51 AM
|
0
|
0
|
514
|
|
POST
|
I have a known page unit XY. What i need to do is figure out the rotation matrix code to apply the data frame rotation to my element page unit XY. Example: At Data Frame rotation of 0 rotation my point is X = 10.5659" and Y = 7.0324" and at Data Frame rotation of 12.14, my point is X = 10.6832" and Y = 7.481". Although, I may have better luck posting this in a numpy or python specific forum.
... View more
04-08-2015
12:57 PM
|
0
|
1
|
2870
|
|
POST
|
here is a simple script to create a field and copy values from an existing field. import arcpy
fc = "<my Feature Class>"
fields = ('Length','mylength')
arcpy.AddField_management(fc,"myLength","LONG")
with arcpy.da.UpdateCursor(fc, fields) as cursor:
mySharedField = 0
print mySharedField
for row in cursor:
mySharedField = row[0]
print mySharedField
row[1]= mySharedField
cursor.updateRow(row)
del row
del cursor
... View more
04-01-2015
06:17 AM
|
1
|
0
|
3989
|
|
POST
|
here is a simple script i wrote to add points along line at distance that might help you import arcpy
from arcpy import env
env.workspace = arcpy.GetParameterAsText(0)
polylineFeature = arcpy.GetParameterAsText(1)
pointdistance = arcpy.GetParameterAsText(2)
pts = []
numPointDistance = repr(pointdistance)
with arcpy.da.SearchCursor(polylineFeature,"SHAPE@") as rows:
for row in rows:
# Skip First Point
#pts.append(row[0].positionAlongLine(0))
i = numPointDistance
while i < row[0].length:
pts.append(row[0].positionAlongLine(i))
i += numPointDistance
leng = row[0].length
# Skip Last Point
#pts.append(row[0].positionAlongLine(leng))
arcpy.CopyFeatures_management(pts, r"StationPoints")
del pts
... View more
03-31-2015
08:49 AM
|
2
|
1
|
2306
|
|
POST
|
does anyone know why when using arcpy to export or save a copy any inserted/embedded spreadsheets are not on the output? is there something i'm missing?
... View more
11-21-2013
04:29 AM
|
0
|
0
|
781
|
|
POST
|
Is it possible to use arcpy to give the properties of a curve?
... View more
04-18-2013
06:32 AM
|
0
|
2
|
4047
|
|
POST
|
How are you creating the graph? i have successfully done this with arcpy and matplotlib for data driven pages.
... View more
04-03-2013
01:20 PM
|
0
|
4
|
2064
|
| Title | Kudos | Posted |
|---|---|---|
| 1 | 09-12-2022 10:15 AM | |
| 1 | 05-11-2015 04:51 AM | |
| 1 | 04-01-2015 06:17 AM | |
| 1 | 05-07-2015 01:24 PM | |
| 1 | 05-07-2015 06:07 AM |
| Online Status |
Offline
|
| Date Last Visited |
03-05-2024
09:40 AM
|