2

I have been asked to create a custom script to reproject shapefiles (different projections) from a folder, but can't contain values such as filenames and path names to access them.

I have started with Batch Project script and tried to set the input parameter as 'folder' but get the error 000840: The value is not a dataset, because the input values needs to be feature class or dataset.

I have also searched the forum and found:

How do I use python to batch process the reprojection of a group of shapefiles?

But obviously this answer contains values. I have also tried setting;

Set workspace environment;

arcpy.env.workspace = arcpy.GetParameterAsText(0)

Doesn't appear to work.


It is now working after I changed my code from:

arcpy.env.workspace = arcpy.GetParameterAsText(0)

to:

arcpy.env.workspace = arcpy.ListFeatureClasses()
asked Apr 3, 2015 at 22:06

2 Answers 2

3

There's one important modification you would need to make to the script that is in the link you posted. In that code there is the variable input_features which is a list of feature classes that exist within the geodatabase that has been set as the workspace. You are on the right track by using arcpy.env.workspace = arcpy.GetParameterAsText(0) to feed the folder path to the script, but you need to change the input_features variable.

Try:

input_features = arcpy.ListFeatureClasses()

now the input_features variable is a list of all the feature classes (shapefiles, in this case) that are in the workspace. Here's a little more about arcpy.ListFeatureClasses().

answered Apr 3, 2015 at 22:14
2

The arcpy functions, classes, etc., are designed to be used. Once you set the workspace, you can use any arcpy functions your license level allows on any appropriate shapefiles, tables, feature classes, coverages, etc. in that workspace.

Sometimes you can just give the full path to the feature on disk, but often you have to use a layer file. This depends on the specific function. In python, you often have to create a layer file from the data on disk before working with it.

When you add a shapefile or feature class to ArcMap, it's actually a layer file as far as ArcMap is concerned. So you don't need to specifically create it.

Essentially, in many/most (?) cases, you're working with a copy of the data which is then written back to the primary data.

PolyGeo
65.5k29 gold badges115 silver badges350 bronze badges
answered Apr 3, 2015 at 23:38
2
  • @PolyGeo, not sure why the edit. It was a reference to the OP's post, giving encouragement. Apologize if this isn't the place to bring this up, clicking your name just brought up your profile. Commented Apr 4, 2015 at 17:29
  • I always try to upvote words of encouragement when made as comments but, as per the Tour, for Qs&As no chit-chat applies. The desirability of that has been most eloquently put in a Meta SE paragraph headed You gotta get this to get us. Also, the term the asker and then you used is one that I would always edit out or re-word. It is a relatively minor issue. Commented Apr 4, 2015 at 22:48

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.