I have a feature dataset, polygons,containing about 50 feature class. I need to convert them to lines. I was able to do it using PolygonToLine_management to perform the task for individual feature class in ArcMap 10.0 python window. Does "PolygonToLine_management" only work for individual feature class, or can work for the dataset at once? I tried to use for-in loop, it did not work.
Any advice appreciated!
Solved! Go to Solution.
In your code you are not naming the output. So I am not sure what it is calling the output but it is probably doing all 50 fc's but just overwriting them each time.
Try something like this :
import arcpy from arcpy import env env.workspace = "C:/Data/City of Oleander.gdb/FireBoxMaps" fcFireboxmaps = arcpy.ListFeatureClasses() for fc in fcFireboxmaps: lineout = str(fc) + "_line" arcpy.PolygonToLine_management(fc,"C:/Documents/ArcGIS/Default.gdb/" + lineout ,"IDENTIFY_NEIGHBORS")
What was your code? You have to cycle through the featuredataset to get the associated featureclasses. Some tips on setting up either a model or a script are here... Using geoprocessing options to control tool execution—Help | ArcGIS for Desktop and the arcpy structure and info is here... What is geoprocessing?—Help | ArcGIS for Desktop
import arcpy
from arcpy import env
env.workspace = "C:/Data/City of Oleander.gdb/FireBoxMaps"
fcFireboxmaps = arcpy.ListFeatureClasses()
for fc in fcFireboxmaps:
arcpy.PolygonToLine_management(fc,"C:/Documents/ArcGIS/Default.gdb","IDENTIFY_NEIGHBORS")
The above was code. FireBoxMaps is feature dataset, containing about 50 feature classes. I wasn't able to figure out the output feature for PolygonToLine_Management. The above code only output one feature class, not all feature classes.
Thanks, Dan
In your code you are not naming the output. So I am not sure what it is calling the output but it is probably doing all 50 fc's but just overwriting them each time.
Try something like this :
import arcpy from arcpy import env env.workspace = "C:/Data/City of Oleander.gdb/FireBoxMaps" fcFireboxmaps = arcpy.ListFeatureClasses() for fc in fcFireboxmaps: lineout = str(fc) + "_line" arcpy.PolygonToLine_management(fc,"C:/Documents/ArcGIS/Default.gdb/" + lineout ,"IDENTIFY_NEIGHBORS")
Many thanks, Neil! The code worked fine after a minor change. I am trying to make it clear for anybody who might have the same question in the future.
For the output, I had to remove .gdb from "Default.gdb" in order to make it work. So, the output would be "C:/Documents/ArcGIS/Default". I also noticed one interesting thing. All output files were shapefiles (ended with .shp), instead of feature class. Meanwhile, All output files fell outside .gdb. I would definitely like to find out while I get to know more about Python for GIS.
Again, thank Neil, thank Dan!
The .gdb part indicates a file geodatabase.
As you removed that part it must have put the outputs into a file system folder and made them shapefiles.
Rather than relying on the default, it is better to set up an output specifically for the task.
Make a fgdb using ArcCatalog in a project folder, so you know where everything is going.
Glad to have been of help.
Enjoy.
If you only have the 50, and it's a one time thing, you could do it old school and grab the python snippet in the "result" tab....and then do the for...loop for a list of file names. ArcGIS Desktop Is the 10.0 help. I'm not sure if the batch option was available back then or not.
edit. Might also want to look thru this PDF http://users.clas.ufl.edu/forrest/gis/lectures/2013-10-22%20-%20Data%20and%20Batch%20Geoprocessing%2...
Thanks, Rebecca.
Carol, if your question was answered, remember to mark any answers that were helpful, and mark the one that best resolved your question as answered. That will close this thread. of course, if you still have questions, check out Posting Code blocks in the new GeoNet (for future questions too).
Thanks for telling me, Rebecca. I already marked "best answer". I am new to this forum. Are there any restrictions or policies?