I've obtained a script which is meant to establish a point at every vertice within a (line) feature class. Despite my best efforts the script will not run, and returns "AttributeError: DescribeData: Method spatialReference does not exist" (line 19). Hoping someone can help. The script is attached.
I took the function out of the picture for testing and found two things. If you do use the function, you are assigning the outFc in two places...I would leave it in the function since that is the proper format (that is, you do need the \\ , but there are other ways to do this.
The other issue was the syntax for the CreateFeatureclass_Management, at least when I ran it with a sample line FC (with an Albers projection). Create Feature Class—Help | ArcGIS for Desktop
CreateFeatureclass_management (out_path, out_name, {geometry_type}, {template}, {has_m}, {has_z}, {spatial_reference}, {config_keyword}, {spatial_grid_1}, {spatial_grid_2}, {spatial_grid_3}
Try this: (the "#" in my CreateFeatureclass line mean, "use defaults")
import arcpy, os inFc = arcpy.GetParameterAsText(0) workspace = arcpy.GetParameterAsText(1) fcName = arcpy.GetParameterAsText(2) # Create Points at Vertices def VerticesToPoints(inFC, workspace, fcName): outFc = workspace + "\\" + fcName dsc = arcpy.Describe(inFC) sr = dsc.spatialReference #arcpy.CreateFeatureclass_management(workspace, fcName, "POINT", sr) arcpy.CreateFeatureclass_management(workspace, fcName,"POINT", "#", "#", "#", sr) with arcpy.da.InsertCursor(outFc, "SHAPE@") as iCurs: with arcpy.da.SearchCursor(inFc, "SHAPE@") as sCurs: for geom, in sCurs: for i in range(geom.partCount): part = geom.getPart(i) for pnt in part: if not pnt: continue row = (pnt,) iCurs.insertRow(row) del iCurs del sCurs return outFc #outFc = workspace + fcName #outFc = workspace + "\\" + fcName VerticesToPoints(inFc, workspace, fcName) arcpy.SetParameter(3, outFc)<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>
I'm not sure why you were getting and error with the spatial reference, but you don't mention the version of the software you are using, so maybe that is an issue. But if you still have issues, run the lines without the function first to make sure it is working with your inputs and outputs. Add a arcpy.Exists(<variable>) once in a while to make sure you don't have that issue (like if you used line 25 in the original script (that I posted for you). Also, sprinkle in plenty of print or arcpy.AddMessage to make sure the variables are what you expected. Those are all just good habits to get into when it comes to debugging in general (and of course...add comments. You may know what it does now...but years from now, you will appreciate the effort you put in now.)
Hope this works for you
something isn't getting passed or read because if works
<SPAN class="comment token"># arcpy imported already</SPAN> in_fc <SPAN class="operator token">=</SPAN> r<SPAN class="string token">"C:\some_path\testdata.gdb\polygon"</SPAN> desc <SPAN class="operator token">=</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>Describe<SPAN class="punctuation token">(</SPAN>in_fc<SPAN class="punctuation token">)</SPAN> sr <SPAN class="operator token">=</SPAN> desc<SPAN class="punctuation token">.</SPAN>spatialReference sr<SPAN class="punctuation token">.</SPAN>name <SPAN class="string token">'NAD_1983_CSRS_MTM_9'</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>
Dan Patterson the script is attached to a script tool - yes. It is also nested within a larger script, and as such the parameters are passed in through this larger script.
How are you providing the parameters to the script? Is it attached as the script to a tool in arctoolbox?
Are you trying to run this from a python IDE? Does just the line 'import arcpy' work if you are running it from an IDE?
PS, Sackville.... spelling.... SERSC, Sacvkille, NB
ahh..that would make a difference. Always good to mention that in you post. Also, much easier for others to respond it you try https://community.esri.com/people/curtvprice/blog/2014/09/25/posting-code-blocks-in-the-new-geonet?sr=search&searchId=c77d5699-3e07-4559-a6bb-266ef77a1eef&searchIndex=4 to they don't have to download, etc. I took the liberty of doing that here for you. It seems like a simple issue so someone will probably answer in short order (but I don't have time to look at it right now)
<SPAN class="comment token"># ---------------------------------------------------------------------------</SPAN> <SPAN class="comment token"># Creates points at each line vertice</SPAN> <SPAN class="comment token"># Tyler Searls, July 2017</SPAN> <SPAN class="comment token"># SERSC, Sacvkille, NB</SPAN> <SPAN class="comment token"># ---------------------------------------------------------------------------</SPAN> <SPAN class="comment token"># Import arcpy module</SPAN> <SPAN class="keyword token">import</SPAN> arcpy<SPAN class="punctuation token">,</SPAN> os inFc <SPAN class="operator token">=</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>GetParameterAsText<SPAN class="punctuation token">(</SPAN><SPAN class="number token">0</SPAN><SPAN class="punctuation token">)</SPAN> workspace <SPAN class="operator token">=</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>GetParameterAsText<SPAN class="punctuation token">(</SPAN><SPAN class="number token">1</SPAN><SPAN class="punctuation token">)</SPAN> fcName <SPAN class="operator token">=</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>GetParameterAsText<SPAN class="punctuation token">(</SPAN><SPAN class="number token">2</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="comment token"># Create Points at Vertices</SPAN> <SPAN class="keyword token">def</SPAN> <SPAN class="token function">VerticesToPoints</SPAN><SPAN class="punctuation token">(</SPAN>inFC<SPAN class="punctuation token">,</SPAN> workspace<SPAN class="punctuation token">,</SPAN> fcName<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">:</SPAN> outFc <SPAN class="operator token">=</SPAN> workspace <SPAN class="operator token">+</SPAN> <SPAN class="string token">"\\"</SPAN> <SPAN class="operator token">+</SPAN> fcName dsc <SPAN class="operator token">=</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>Describe<SPAN class="punctuation token">(</SPAN>inFC<SPAN class="punctuation token">)</SPAN> sr <SPAN class="operator token">=</SPAN> dsc<SPAN class="punctuation token">.</SPAN>spatialReference arcpy<SPAN class="punctuation token">.</SPAN>CreateFeatureclass_management<SPAN class="punctuation token">(</SPAN>workspace<SPAN class="punctuation token">,</SPAN> fcName<SPAN class="punctuation token">,</SPAN> <SPAN class="string token">"POINT"</SPAN><SPAN class="punctuation token">,</SPAN> sr<SPAN class="punctuation token">)</SPAN> <SPAN class="keyword token">with</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>da<SPAN class="punctuation token">.</SPAN>InsertCursor<SPAN class="punctuation token">(</SPAN>outFc<SPAN class="punctuation token">,</SPAN> <SPAN class="string token">"SHAPE@"</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="keyword token">as</SPAN> iCurs<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>inFc<SPAN class="punctuation token">,</SPAN> <SPAN class="string token">"SHAPE@"</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="keyword token">as</SPAN> sCurs<SPAN class="punctuation token">:</SPAN> <SPAN class="keyword token">for</SPAN> geom<SPAN class="punctuation token">,</SPAN> <SPAN class="keyword token">in</SPAN> sCurs<SPAN class="punctuation token">:</SPAN> <SPAN class="keyword token">for</SPAN> i <SPAN class="keyword token">in</SPAN> range<SPAN class="punctuation token">(</SPAN>geom<SPAN class="punctuation token">.</SPAN>partCount<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">:</SPAN> part <SPAN class="operator token">=</SPAN> geom<SPAN class="punctuation token">.</SPAN>getPart<SPAN class="punctuation token">(</SPAN>i<SPAN class="punctuation token">)</SPAN> <SPAN class="keyword token">for</SPAN> pnt <SPAN class="keyword token">in</SPAN> part<SPAN class="punctuation token">:</SPAN> <SPAN class="keyword token">if</SPAN> <SPAN class="operator token">not</SPAN> pnt<SPAN class="punctuation token">:</SPAN> <SPAN class="keyword token">continue</SPAN> row <SPAN class="operator token">=</SPAN> <SPAN class="punctuation token">(</SPAN>pnt<SPAN class="punctuation token">,</SPAN><SPAN class="punctuation token">)</SPAN> iCurs<SPAN class="punctuation token">.</SPAN>insertRow<SPAN class="punctuation token">(</SPAN>row<SPAN class="punctuation token">)</SPAN> <SPAN class="keyword token">del</SPAN> iCurs <SPAN class="keyword token">del</SPAN> sCurs <SPAN class="keyword token">return</SPAN> outFc outFc <SPAN class="operator token">=</SPAN> workspace <SPAN class="operator token">+</SPAN> fcName VerticesToPoints<SPAN class="punctuation token">(</SPAN>inFc<SPAN class="punctuation token">,</SPAN> workspace<SPAN class="punctuation token">,</SPAN> fcName<SPAN class="punctuation token">)</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>SetParameter<SPAN class="punctuation token">(</SPAN><SPAN class="number token">3</SPAN><SPAN class="punctuation token">,</SPAN> outFc<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>
Thanks Rebecca Strauch, GISP. I am solely trying to get points from vertices, however I don't have the appropriate license to run the Feature Vertices To Points—Help | ArcGIS for Desktop tool. This is a workaround.
I didn't take a look at the script, and understand that it may be doing other things you need, but just in case you are just trying to get the vertices to points, take a look at Feature Vertices To Points—Help | ArcGIS for Desktop
Creates a feature class containing points generated from specified vertices or locations of the input features
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.