Feature to polygon in multiple folders
I have a few hundred folders, each with a set of shapefiles that are identical across folders (ie each folder has a 'lot.shp'). They are all supposed to be polygon features, but unfortunately many are line features.
I am trying to convert all line features to polygons using Feature to Polygon.
To do this I have tried the following code which should work through each folder converting the desired shapefiles and saving back into the same folder but with a '2' in the name:
import arcpy, glob, os
filelist = ['buildingpoly','lot', etc etc]
path = "C:/folder_containing_desired_subfolders/*/"
for x in filelist:
list = glob.glob(path + x + ".shp")
arcpy.FeatureToPolygon_management(in_features=list, out_feature_class=path + x + "2.shp", cluster_tolerance="", attributes="ATTRIBUTES", label_features="")
del list
But this gets the following error:
Runtime error Traceback (most recent call last): File "", line 10, in File "c:program files (x86)arcgisdesktop10.4arcpyarcpymanagement.py", line 2524, in FeatureToPolygon raise e ExecuteError: ERROR 000210: Cannot create output C:/folder_containing_desired_subfolders/*/buildingpoly2.shp Failed to execute (FeatureToPolygon).
Any ideas? I'm at a loss on this one.
An alternative that would also work is if I can have all the new polygon features saved in the same directory but this would require each getting a unique name.
arcpy error-000210
add a comment |
I have a few hundred folders, each with a set of shapefiles that are identical across folders (ie each folder has a 'lot.shp'). They are all supposed to be polygon features, but unfortunately many are line features.
I am trying to convert all line features to polygons using Feature to Polygon.
To do this I have tried the following code which should work through each folder converting the desired shapefiles and saving back into the same folder but with a '2' in the name:
import arcpy, glob, os
filelist = ['buildingpoly','lot', etc etc]
path = "C:/folder_containing_desired_subfolders/*/"
for x in filelist:
list = glob.glob(path + x + ".shp")
arcpy.FeatureToPolygon_management(in_features=list, out_feature_class=path + x + "2.shp", cluster_tolerance="", attributes="ATTRIBUTES", label_features="")
del list
But this gets the following error:
Runtime error Traceback (most recent call last): File "", line 10, in File "c:program files (x86)arcgisdesktop10.4arcpyarcpymanagement.py", line 2524, in FeatureToPolygon raise e ExecuteError: ERROR 000210: Cannot create output C:/folder_containing_desired_subfolders/*/buildingpoly2.shp Failed to execute (FeatureToPolygon).
Any ideas? I'm at a loss on this one.
An alternative that would also work is if I can have all the new polygon features saved in the same directory but this would require each getting a unique name.
arcpy error-000210
2
The asterisk shouldn't appear in your path, consider arcpy.da.Walk() to find the lot.shp in each subfolder and arcpy.Describe shapeType == 'Polyline' to find the line lot.shp files to polygonize.
– Michael Stimson
5 hours ago
add a comment |
I have a few hundred folders, each with a set of shapefiles that are identical across folders (ie each folder has a 'lot.shp'). They are all supposed to be polygon features, but unfortunately many are line features.
I am trying to convert all line features to polygons using Feature to Polygon.
To do this I have tried the following code which should work through each folder converting the desired shapefiles and saving back into the same folder but with a '2' in the name:
import arcpy, glob, os
filelist = ['buildingpoly','lot', etc etc]
path = "C:/folder_containing_desired_subfolders/*/"
for x in filelist:
list = glob.glob(path + x + ".shp")
arcpy.FeatureToPolygon_management(in_features=list, out_feature_class=path + x + "2.shp", cluster_tolerance="", attributes="ATTRIBUTES", label_features="")
del list
But this gets the following error:
Runtime error Traceback (most recent call last): File "", line 10, in File "c:program files (x86)arcgisdesktop10.4arcpyarcpymanagement.py", line 2524, in FeatureToPolygon raise e ExecuteError: ERROR 000210: Cannot create output C:/folder_containing_desired_subfolders/*/buildingpoly2.shp Failed to execute (FeatureToPolygon).
Any ideas? I'm at a loss on this one.
An alternative that would also work is if I can have all the new polygon features saved in the same directory but this would require each getting a unique name.
arcpy error-000210
I have a few hundred folders, each with a set of shapefiles that are identical across folders (ie each folder has a 'lot.shp'). They are all supposed to be polygon features, but unfortunately many are line features.
I am trying to convert all line features to polygons using Feature to Polygon.
To do this I have tried the following code which should work through each folder converting the desired shapefiles and saving back into the same folder but with a '2' in the name:
import arcpy, glob, os
filelist = ['buildingpoly','lot', etc etc]
path = "C:/folder_containing_desired_subfolders/*/"
for x in filelist:
list = glob.glob(path + x + ".shp")
arcpy.FeatureToPolygon_management(in_features=list, out_feature_class=path + x + "2.shp", cluster_tolerance="", attributes="ATTRIBUTES", label_features="")
del list
But this gets the following error:
Runtime error Traceback (most recent call last): File "", line 10, in File "c:program files (x86)arcgisdesktop10.4arcpyarcpymanagement.py", line 2524, in FeatureToPolygon raise e ExecuteError: ERROR 000210: Cannot create output C:/folder_containing_desired_subfolders/*/buildingpoly2.shp Failed to execute (FeatureToPolygon).
Any ideas? I'm at a loss on this one.
An alternative that would also work is if I can have all the new polygon features saved in the same directory but this would require each getting a unique name.
arcpy error-000210
arcpy error-000210
edited 4 hours ago
PolyGeo♦
53.6k1780240
53.6k1780240
asked 5 hours ago
VinceVince
785
785
2
The asterisk shouldn't appear in your path, consider arcpy.da.Walk() to find the lot.shp in each subfolder and arcpy.Describe shapeType == 'Polyline' to find the line lot.shp files to polygonize.
– Michael Stimson
5 hours ago
add a comment |
2
The asterisk shouldn't appear in your path, consider arcpy.da.Walk() to find the lot.shp in each subfolder and arcpy.Describe shapeType == 'Polyline' to find the line lot.shp files to polygonize.
– Michael Stimson
5 hours ago
2
2
The asterisk shouldn't appear in your path, consider arcpy.da.Walk() to find the lot.shp in each subfolder and arcpy.Describe shapeType == 'Polyline' to find the line lot.shp files to polygonize.
– Michael Stimson
5 hours ago
The asterisk shouldn't appear in your path, consider arcpy.da.Walk() to find the lot.shp in each subfolder and arcpy.Describe shapeType == 'Polyline' to find the line lot.shp files to polygonize.
– Michael Stimson
5 hours ago
add a comment |
1 Answer
1
active
oldest
votes
Have a try with this code:
import os, sys, arcpy
path = "C:/folder_containing_desired_subfolders"
filelist = ['buildingpoly','lot', etc etc]
for (Spath,Sfiles,Sdirs) in arcpy.da.Walk():
for ThisFile in Sfiles:
# break up the file name and extension
fName, fExt = os.path.splitext(ThisFile)
if fExt.upper() == '.SHP':
# only for .shp files
if fName.lower() in filelist:
# this fName is in the filelist of interest
# get some info about the shapefile
D = arcpy.Describe(os.path.join(Spath,ThisFile))
if D.shapeType == 'Polyline':
# do your polygonization here
elif D.shapeType == 'Polygon':
# do something for the already polygon feature classes
You say all your shapefiles are in subfolders so using arcpy.da.Walk() to traverse the folder tree, finding all Esri recognized feature classes and rasters then break up the file name and extension to filter by extension and then Describe to see if the feature class is a line or polygon.. this should get you a bit closer to where you're headed.
This works, except I can't get it to save the output file back into the same directory as the file it just worked on. So it will process the first one, save it to a location, then say it already exists and fails on the second one. Any suggestions for this?
– Vince
2 hours ago
1
os.path.join(Spath,'<your file name>') will save the output in the folder the input is being read from; if you need to find all of them at the end start with an empty list and append each save path as it is created. The value of Spath changes to the workspace path of the list of file names returned in Sfiles.
– Michael Stimson
2 hours ago
This also works. The one (big) issue now is that each newly created polygon feature is identical to whichever feature was first processed. It's naming them correctly and working through each folder correctly, but it's just processing the exact same feature over and over again and saving it as a different name + location each time. Is there some sort of cache that needs clearing between each process? I've tried arcpy.ClearWorkspaceCache_management() with no luck.
– Vince
37 mins ago
add a comment |
Your Answer
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "79"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fgis.stackexchange.com%2fquestions%2f313403%2ffeature-to-polygon-in-multiple-folders%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
Have a try with this code:
import os, sys, arcpy
path = "C:/folder_containing_desired_subfolders"
filelist = ['buildingpoly','lot', etc etc]
for (Spath,Sfiles,Sdirs) in arcpy.da.Walk():
for ThisFile in Sfiles:
# break up the file name and extension
fName, fExt = os.path.splitext(ThisFile)
if fExt.upper() == '.SHP':
# only for .shp files
if fName.lower() in filelist:
# this fName is in the filelist of interest
# get some info about the shapefile
D = arcpy.Describe(os.path.join(Spath,ThisFile))
if D.shapeType == 'Polyline':
# do your polygonization here
elif D.shapeType == 'Polygon':
# do something for the already polygon feature classes
You say all your shapefiles are in subfolders so using arcpy.da.Walk() to traverse the folder tree, finding all Esri recognized feature classes and rasters then break up the file name and extension to filter by extension and then Describe to see if the feature class is a line or polygon.. this should get you a bit closer to where you're headed.
This works, except I can't get it to save the output file back into the same directory as the file it just worked on. So it will process the first one, save it to a location, then say it already exists and fails on the second one. Any suggestions for this?
– Vince
2 hours ago
1
os.path.join(Spath,'<your file name>') will save the output in the folder the input is being read from; if you need to find all of them at the end start with an empty list and append each save path as it is created. The value of Spath changes to the workspace path of the list of file names returned in Sfiles.
– Michael Stimson
2 hours ago
This also works. The one (big) issue now is that each newly created polygon feature is identical to whichever feature was first processed. It's naming them correctly and working through each folder correctly, but it's just processing the exact same feature over and over again and saving it as a different name + location each time. Is there some sort of cache that needs clearing between each process? I've tried arcpy.ClearWorkspaceCache_management() with no luck.
– Vince
37 mins ago
add a comment |
Have a try with this code:
import os, sys, arcpy
path = "C:/folder_containing_desired_subfolders"
filelist = ['buildingpoly','lot', etc etc]
for (Spath,Sfiles,Sdirs) in arcpy.da.Walk():
for ThisFile in Sfiles:
# break up the file name and extension
fName, fExt = os.path.splitext(ThisFile)
if fExt.upper() == '.SHP':
# only for .shp files
if fName.lower() in filelist:
# this fName is in the filelist of interest
# get some info about the shapefile
D = arcpy.Describe(os.path.join(Spath,ThisFile))
if D.shapeType == 'Polyline':
# do your polygonization here
elif D.shapeType == 'Polygon':
# do something for the already polygon feature classes
You say all your shapefiles are in subfolders so using arcpy.da.Walk() to traverse the folder tree, finding all Esri recognized feature classes and rasters then break up the file name and extension to filter by extension and then Describe to see if the feature class is a line or polygon.. this should get you a bit closer to where you're headed.
This works, except I can't get it to save the output file back into the same directory as the file it just worked on. So it will process the first one, save it to a location, then say it already exists and fails on the second one. Any suggestions for this?
– Vince
2 hours ago
1
os.path.join(Spath,'<your file name>') will save the output in the folder the input is being read from; if you need to find all of them at the end start with an empty list and append each save path as it is created. The value of Spath changes to the workspace path of the list of file names returned in Sfiles.
– Michael Stimson
2 hours ago
This also works. The one (big) issue now is that each newly created polygon feature is identical to whichever feature was first processed. It's naming them correctly and working through each folder correctly, but it's just processing the exact same feature over and over again and saving it as a different name + location each time. Is there some sort of cache that needs clearing between each process? I've tried arcpy.ClearWorkspaceCache_management() with no luck.
– Vince
37 mins ago
add a comment |
Have a try with this code:
import os, sys, arcpy
path = "C:/folder_containing_desired_subfolders"
filelist = ['buildingpoly','lot', etc etc]
for (Spath,Sfiles,Sdirs) in arcpy.da.Walk():
for ThisFile in Sfiles:
# break up the file name and extension
fName, fExt = os.path.splitext(ThisFile)
if fExt.upper() == '.SHP':
# only for .shp files
if fName.lower() in filelist:
# this fName is in the filelist of interest
# get some info about the shapefile
D = arcpy.Describe(os.path.join(Spath,ThisFile))
if D.shapeType == 'Polyline':
# do your polygonization here
elif D.shapeType == 'Polygon':
# do something for the already polygon feature classes
You say all your shapefiles are in subfolders so using arcpy.da.Walk() to traverse the folder tree, finding all Esri recognized feature classes and rasters then break up the file name and extension to filter by extension and then Describe to see if the feature class is a line or polygon.. this should get you a bit closer to where you're headed.
Have a try with this code:
import os, sys, arcpy
path = "C:/folder_containing_desired_subfolders"
filelist = ['buildingpoly','lot', etc etc]
for (Spath,Sfiles,Sdirs) in arcpy.da.Walk():
for ThisFile in Sfiles:
# break up the file name and extension
fName, fExt = os.path.splitext(ThisFile)
if fExt.upper() == '.SHP':
# only for .shp files
if fName.lower() in filelist:
# this fName is in the filelist of interest
# get some info about the shapefile
D = arcpy.Describe(os.path.join(Spath,ThisFile))
if D.shapeType == 'Polyline':
# do your polygonization here
elif D.shapeType == 'Polygon':
# do something for the already polygon feature classes
You say all your shapefiles are in subfolders so using arcpy.da.Walk() to traverse the folder tree, finding all Esri recognized feature classes and rasters then break up the file name and extension to filter by extension and then Describe to see if the feature class is a line or polygon.. this should get you a bit closer to where you're headed.
answered 5 hours ago
Michael StimsonMichael Stimson
21.5k22360
21.5k22360
This works, except I can't get it to save the output file back into the same directory as the file it just worked on. So it will process the first one, save it to a location, then say it already exists and fails on the second one. Any suggestions for this?
– Vince
2 hours ago
1
os.path.join(Spath,'<your file name>') will save the output in the folder the input is being read from; if you need to find all of them at the end start with an empty list and append each save path as it is created. The value of Spath changes to the workspace path of the list of file names returned in Sfiles.
– Michael Stimson
2 hours ago
This also works. The one (big) issue now is that each newly created polygon feature is identical to whichever feature was first processed. It's naming them correctly and working through each folder correctly, but it's just processing the exact same feature over and over again and saving it as a different name + location each time. Is there some sort of cache that needs clearing between each process? I've tried arcpy.ClearWorkspaceCache_management() with no luck.
– Vince
37 mins ago
add a comment |
This works, except I can't get it to save the output file back into the same directory as the file it just worked on. So it will process the first one, save it to a location, then say it already exists and fails on the second one. Any suggestions for this?
– Vince
2 hours ago
1
os.path.join(Spath,'<your file name>') will save the output in the folder the input is being read from; if you need to find all of them at the end start with an empty list and append each save path as it is created. The value of Spath changes to the workspace path of the list of file names returned in Sfiles.
– Michael Stimson
2 hours ago
This also works. The one (big) issue now is that each newly created polygon feature is identical to whichever feature was first processed. It's naming them correctly and working through each folder correctly, but it's just processing the exact same feature over and over again and saving it as a different name + location each time. Is there some sort of cache that needs clearing between each process? I've tried arcpy.ClearWorkspaceCache_management() with no luck.
– Vince
37 mins ago
This works, except I can't get it to save the output file back into the same directory as the file it just worked on. So it will process the first one, save it to a location, then say it already exists and fails on the second one. Any suggestions for this?
– Vince
2 hours ago
This works, except I can't get it to save the output file back into the same directory as the file it just worked on. So it will process the first one, save it to a location, then say it already exists and fails on the second one. Any suggestions for this?
– Vince
2 hours ago
1
1
os.path.join(Spath,'<your file name>') will save the output in the folder the input is being read from; if you need to find all of them at the end start with an empty list and append each save path as it is created. The value of Spath changes to the workspace path of the list of file names returned in Sfiles.
– Michael Stimson
2 hours ago
os.path.join(Spath,'<your file name>') will save the output in the folder the input is being read from; if you need to find all of them at the end start with an empty list and append each save path as it is created. The value of Spath changes to the workspace path of the list of file names returned in Sfiles.
– Michael Stimson
2 hours ago
This also works. The one (big) issue now is that each newly created polygon feature is identical to whichever feature was first processed. It's naming them correctly and working through each folder correctly, but it's just processing the exact same feature over and over again and saving it as a different name + location each time. Is there some sort of cache that needs clearing between each process? I've tried arcpy.ClearWorkspaceCache_management() with no luck.
– Vince
37 mins ago
This also works. The one (big) issue now is that each newly created polygon feature is identical to whichever feature was first processed. It's naming them correctly and working through each folder correctly, but it's just processing the exact same feature over and over again and saving it as a different name + location each time. Is there some sort of cache that needs clearing between each process? I've tried arcpy.ClearWorkspaceCache_management() with no luck.
– Vince
37 mins ago
add a comment |
Thanks for contributing an answer to Geographic Information Systems Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fgis.stackexchange.com%2fquestions%2f313403%2ffeature-to-polygon-in-multiple-folders%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
2
The asterisk shouldn't appear in your path, consider arcpy.da.Walk() to find the lot.shp in each subfolder and arcpy.Describe shapeType == 'Polyline' to find the line lot.shp files to polygonize.
– Michael Stimson
5 hours ago