Hi
I have created surface profiles at various locations with the help of the python script from Xander Bakker.
The script works perfect. Now i want to add/show the reference points in each profile (see attachment) . How can i do it? any sggestions?
Hi Xander,
Thank you for your response.
Yes the script is working perfect.
Yes, the reference values (points shapefile) located exactly on the lines.
The source for these points is the same raster (which used for lines )
You are right the "zp[ ] list need to be filled"
If you need more information dont hesitate ask.
Glad to hear the the script is working (at least for part of what you want to achieve). I assume that the zp list will need to be filled with data to be able to add it to the plot. Since zp will have only a few values, you will need to determine when the values have to be added.
Are the reference values located exactly on the lines? What is the source for these points? To plot the points to location (xy) need to be translated to a distance from start.
Hi Dan,
Thanks for your response.
Yes its Xander Bakker's script
The link to the script is: https://community.esri.com/docs/DOC-1973
I am a beginner to python/arcpy. I tried but i think i am missing things like ,extract values to points and position it along the profileline and plot the z values on the profile with looping.
i have ammended the script at:
line 11, 53, 75, and 86
and i got this error
zp.append() # want to append raster values with loop TypeError: append() takes exactly one argument (0 given)
ammended script is :
<SPAN class="keyword token">import</SPAN> arcpy <SPAN class="keyword token">import</SPAN> os <SPAN class="keyword token">import</SPAN> matplotlib<SPAN class="punctuation token">.</SPAN>pyplot <SPAN class="keyword token">as</SPAN> plt <SPAN class="keyword token">import</SPAN> numpy <SPAN class="keyword token">import</SPAN> math <SPAN class="comment token"># settings for datasources</SPAN> linesPath <SPAN class="operator token">=</SPAN> <SPAN class="string token">"lines"</SPAN> rasterPath <SPAN class="operator token">=</SPAN> <SPAN class="string token">"raster"</SPAN> pointPath <SPAN class="operator token">=</SPAN> <SPAN class="string token">"points"</SPAN> <SPAN class="comment token"># point shapefile</SPAN> <SPAN class="comment token"># settings for output profiles PNG's</SPAN> profileFolder <SPAN class="operator token">=</SPAN> r<SPAN class="string token">"\test_arcpy\profile"</SPAN> profilePrefix <SPAN class="operator token">=</SPAN> <SPAN class="string token">"ArcPy_"</SPAN> profilePostfix <SPAN class="operator token">=</SPAN> <SPAN class="string token">"_new.png"</SPAN> fldName <SPAN class="operator token">=</SPAN> <SPAN class="string token">"hm"</SPAN> <SPAN class="comment token"># standard NoData mapping</SPAN> NoDataValue <SPAN class="operator token">=</SPAN> <SPAN class="operator token">-</SPAN><SPAN class="number token">9999</SPAN> <SPAN class="comment token"># describe raster</SPAN> inDesc <SPAN class="operator token">=</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>Describe<SPAN class="punctuation token">(</SPAN>rasterPath<SPAN class="punctuation token">)</SPAN> rasMeanCellHeight <SPAN class="operator token">=</SPAN> inDesc<SPAN class="punctuation token">.</SPAN>MeanCellHeight rasMeanCellWidth <SPAN class="operator token">=</SPAN> inDesc<SPAN class="punctuation token">.</SPAN>MeanCellWidth <SPAN class="comment token"># search cursor</SPAN> fldShape <SPAN class="operator token">=</SPAN> <SPAN class="string token">"SHAPE@"</SPAN> flds <SPAN class="operator token">=</SPAN> <SPAN class="punctuation token">[</SPAN>fldShape<SPAN class="punctuation token">,</SPAN> fldName<SPAN class="punctuation token">]</SPAN> <SPAN class="keyword token">with</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>da<SPAN class="punctuation token">.</SPAN>SearchCursor<SPAN class="punctuation token">(</SPAN>linesPath<SPAN class="punctuation token">,</SPAN> flds<SPAN class="punctuation token">)</SPAN> <SPAN class="keyword token">as</SPAN> curs<SPAN class="punctuation token">:</SPAN> <SPAN class="keyword token">for</SPAN> row <SPAN class="keyword token">in</SPAN> curs<SPAN class="punctuation token">:</SPAN> feat <SPAN class="operator token">=</SPAN> row<SPAN class="punctuation token">[</SPAN><SPAN class="number token">0</SPAN><SPAN class="punctuation token">]</SPAN> profileName <SPAN class="operator token">=</SPAN> row<SPAN class="punctuation token">[</SPAN><SPAN class="number token">1</SPAN><SPAN class="punctuation token">]</SPAN> <SPAN class="comment token"># read extent of feature and create point for lower left corner</SPAN> extent <SPAN class="operator token">=</SPAN> feat<SPAN class="punctuation token">.</SPAN>extent <SPAN class="keyword token">print</SPAN> <SPAN class="string token">"Processing: {0}"</SPAN><SPAN class="punctuation token">.</SPAN>format<SPAN class="punctuation token">(</SPAN>profileName<SPAN class="punctuation token">)</SPAN> pntLL <SPAN class="operator token">=</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>Point<SPAN class="punctuation token">(</SPAN>extent<SPAN class="punctuation token">.</SPAN>XMin<SPAN class="punctuation token">,</SPAN> extent<SPAN class="punctuation token">.</SPAN>YMin<SPAN class="punctuation token">)</SPAN> <SPAN class="comment token"># determine number of rows and cols to extract from raster for this feature</SPAN> width <SPAN class="operator token">=</SPAN> extent<SPAN class="punctuation token">.</SPAN>width height <SPAN class="operator token">=</SPAN> extent<SPAN class="punctuation token">.</SPAN>height cols <SPAN class="operator token">=</SPAN> int<SPAN class="punctuation token">(</SPAN>width <SPAN class="operator token">/</SPAN> rasMeanCellWidth<SPAN class="punctuation token">)</SPAN> rows <SPAN class="operator token">=</SPAN> int<SPAN class="punctuation token">(</SPAN>height <SPAN class="operator token">/</SPAN> rasMeanCellHeight<SPAN class="punctuation token">)</SPAN> <SPAN class="comment token"># create Numpy array for extent of feature</SPAN> arrNP <SPAN class="operator token">=</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>RasterToNumPyArray<SPAN class="punctuation token">(</SPAN>rasterPath<SPAN class="punctuation token">,</SPAN> pntLL<SPAN class="punctuation token">,</SPAN> cols<SPAN class="punctuation token">,</SPAN> rows<SPAN class="punctuation token">,</SPAN> NoDataValue<SPAN class="punctuation token">)</SPAN> <SPAN class="comment token"># create empty arrays for distance (d) and altitude (z) and NAP line (zv)</SPAN> d <SPAN class="operator token">=</SPAN> <SPAN class="punctuation token">[</SPAN><SPAN class="punctuation token">]</SPAN> z <SPAN class="operator token">=</SPAN> <SPAN class="punctuation token">[</SPAN><SPAN class="punctuation token">]</SPAN> zv <SPAN class="operator token">=</SPAN> <SPAN class="punctuation token">[</SPAN><SPAN class="punctuation token">]</SPAN> zp <SPAN class="operator token">=</SPAN> <SPAN class="punctuation token">[</SPAN><SPAN class="punctuation token">]</SPAN> <SPAN class="comment token"># voor point shape</SPAN> <SPAN class="comment token"># loop through polyline and extract a point each meter</SPAN> <SPAN class="keyword token">for</SPAN> dist <SPAN class="keyword token">in</SPAN> range<SPAN class="punctuation token">(</SPAN><SPAN class="number token">0</SPAN><SPAN class="punctuation token">,</SPAN> int<SPAN class="punctuation token">(</SPAN>feat<SPAN class="punctuation token">.</SPAN>getLength<SPAN class="punctuation token">(</SPAN><SPAN class="string token">"PLANAR"</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">:</SPAN> XYpointGeom <SPAN class="operator token">=</SPAN> feat<SPAN class="punctuation token">.</SPAN>positionAlongLine<SPAN class="punctuation token">(</SPAN>dist<SPAN class="punctuation token">,</SPAN> <SPAN class="token boolean">False</SPAN><SPAN class="punctuation token">)</SPAN> XYpoint <SPAN class="operator token">=</SPAN> XYpointGeom<SPAN class="punctuation token">.</SPAN>firstPoint <SPAN class="comment token"># translate XYpoint to row, col (needs additional checking)</SPAN> c <SPAN class="operator token">=</SPAN> int<SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">(</SPAN>XYpoint<SPAN class="punctuation token">.</SPAN>X <SPAN class="operator token">-</SPAN> pntLL<SPAN class="punctuation token">.</SPAN>X<SPAN class="punctuation token">)</SPAN> <SPAN class="operator token">/</SPAN> rasMeanCellWidth<SPAN class="punctuation token">)</SPAN> r2 <SPAN class="operator token">=</SPAN> int<SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">(</SPAN>XYpoint<SPAN class="punctuation token">.</SPAN>Y <SPAN class="operator token">-</SPAN> pntLL<SPAN class="punctuation token">.</SPAN>Y<SPAN class="punctuation token">)</SPAN> <SPAN class="operator token">/</SPAN> rasMeanCellHeight<SPAN class="punctuation token">)</SPAN> r <SPAN class="operator token">=</SPAN> rows <SPAN class="operator token">-</SPAN> r2 <SPAN class="keyword token">if</SPAN> c <SPAN class="operator token">>=</SPAN> cols<SPAN class="punctuation token">:</SPAN> c <SPAN class="operator token">=</SPAN> cols<SPAN class="number token">-1</SPAN> <SPAN class="keyword token">if</SPAN> r <SPAN class="operator token">>=</SPAN> rows<SPAN class="punctuation token">:</SPAN> r <SPAN class="operator token">=</SPAN> rows<SPAN class="number token">-1</SPAN> <SPAN class="comment token"># extract value from raster and handle NoData</SPAN> zVal <SPAN class="operator token">=</SPAN> arrNP<SPAN class="punctuation token">[</SPAN>r<SPAN class="punctuation token">,</SPAN>c<SPAN class="punctuation token">]</SPAN> <SPAN class="keyword token">if</SPAN> <SPAN class="operator token">not</SPAN> zVal <SPAN class="operator token">==</SPAN> NoDataValue<SPAN class="punctuation token">:</SPAN> d<SPAN class="punctuation token">.</SPAN>append<SPAN class="punctuation token">(</SPAN>dist<SPAN class="punctuation token">)</SPAN> z<SPAN class="punctuation token">.</SPAN>append<SPAN class="punctuation token">(</SPAN>arrNP<SPAN class="punctuation token">[</SPAN>r<SPAN class="punctuation token">,</SPAN>c<SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">)</SPAN> zv<SPAN class="punctuation token">.</SPAN>append<SPAN class="punctuation token">(</SPAN><SPAN class="number token">0</SPAN><SPAN class="punctuation token">)</SPAN> zp<SPAN class="punctuation token">.</SPAN>append<SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="comment token"># want to append raster values with loop </SPAN> <SPAN class="comment token"># define output profile filename and figure size settings</SPAN> elevPNG <SPAN class="operator token">=</SPAN> profileFolder <SPAN class="operator token">+</SPAN> os<SPAN class="punctuation token">.</SPAN>sep <SPAN class="operator token">+</SPAN> profilePrefix <SPAN class="operator token">+</SPAN> profileName <SPAN class="operator token">+</SPAN> profilePostfix fig <SPAN class="operator token">=</SPAN> plt<SPAN class="punctuation token">.</SPAN>figure<SPAN class="punctuation token">(</SPAN>figsize<SPAN class="operator token">=</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="number token">10</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="number token">3.5</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="comment token"># inches</SPAN> <SPAN class="comment token"># plot profile, define styles</SPAN> plt<SPAN class="punctuation token">.</SPAN>plot<SPAN class="punctuation token">(</SPAN>d<SPAN class="punctuation token">,</SPAN>z<SPAN class="punctuation token">,</SPAN><SPAN class="string token">'r'</SPAN><SPAN class="punctuation token">,</SPAN>linewidth<SPAN class="operator token">=</SPAN><SPAN class="number token">0.75</SPAN><SPAN class="punctuation token">)</SPAN> plt<SPAN class="punctuation token">.</SPAN>plot<SPAN class="punctuation token">(</SPAN>d<SPAN class="punctuation token">,</SPAN>z<SPAN class="punctuation token">,</SPAN><SPAN class="string token">'ro'</SPAN><SPAN class="punctuation token">,</SPAN>alpha<SPAN class="operator token">=</SPAN><SPAN class="number token">0.3</SPAN><SPAN class="punctuation token">,</SPAN> markersize<SPAN class="operator token">=</SPAN><SPAN class="number token">3</SPAN><SPAN class="punctuation token">)</SPAN> plt<SPAN class="punctuation token">.</SPAN>plot<SPAN class="punctuation token">(</SPAN>d<SPAN class="punctuation token">,</SPAN>zv<SPAN class="punctuation token">,</SPAN><SPAN class="string token">'k--'</SPAN><SPAN class="punctuation token">,</SPAN>linewidth<SPAN class="operator token">=</SPAN><SPAN class="number token">0.5</SPAN><SPAN class="punctuation token">)</SPAN> plt<SPAN class="punctuation token">.</SPAN>plot<SPAN class="punctuation token">(</SPAN>d<SPAN class="punctuation token">,</SPAN>zp<SPAN class="punctuation token">,</SPAN><SPAN class="string token">'g'</SPAN><SPAN class="punctuation token">,</SPAN>alpha<SPAN class="operator token">=</SPAN><SPAN class="number token">0.3</SPAN><SPAN class="punctuation token">,</SPAN> markersize<SPAN class="operator token">=</SPAN><SPAN class="number token">3</SPAN><SPAN class="punctuation token">)</SPAN> plt<SPAN class="punctuation token">.</SPAN>xlabel<SPAN class="punctuation token">(</SPAN><SPAN class="string token">'Distance from start'</SPAN><SPAN class="punctuation token">)</SPAN> plt<SPAN class="punctuation token">.</SPAN>ylabel<SPAN class="punctuation token">(</SPAN><SPAN class="string token">'Elevation'</SPAN><SPAN class="punctuation token">)</SPAN> plt<SPAN class="punctuation token">.</SPAN>title<SPAN class="punctuation token">(</SPAN><SPAN class="string token">'Profile {0} using Python matplotlib'</SPAN><SPAN class="punctuation token">.</SPAN>format<SPAN class="punctuation token">(</SPAN>profileName<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="comment token"># change font size</SPAN> plt<SPAN class="punctuation token">.</SPAN>rcParams<SPAN class="punctuation token">.</SPAN>update<SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">{</SPAN><SPAN class="string token">'font.size'</SPAN><SPAN class="punctuation token">:</SPAN> <SPAN class="number token">8</SPAN><SPAN class="punctuation token">}</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="comment token"># save graph as PNG</SPAN> fig<SPAN class="punctuation token">.</SPAN>savefig<SPAN class="punctuation token">(</SPAN>elevPNG<SPAN class="punctuation token">,</SPAN> dpi<SPAN class="operator token">=</SPAN><SPAN class="number token">300</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="comment token"># delete some objects</SPAN> <SPAN class="keyword token">del</SPAN> arrNP<SPAN class="punctuation token">,</SPAN> XYpointGeom<SPAN class="punctuation token">,</SPAN> XYpoint <SPAN class="keyword token">print</SPAN> <SPAN class="string token">"PNGs stored in: {0}"</SPAN><SPAN class="punctuation token">.</SPAN>format<SPAN class="punctuation token">(</SPAN>profileFolder<SPAN class="punctuation token">)</SPAN> <SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN>
Is this Xander Bakker 's code?
If so a link, or proper formatting would be nice
/blogs/dan_patterson/2016/08/14/script-formatting
What were the results of the test?
What have you tried?
Přihlášení členové mohou přispívat, sledovat aktualizace a další. Jste tu noví? Zaregistrujte si bezplatný účet.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.