Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

In a toolbox of mine I want to add a function to add several shapefiles by assigning the datatype to shapefile and enabling the multi-value function.

I have noticed however that ArcMap parses this data as a long string deliminated by a ';' of which I have made into a list by the following.

def main(inputs,...)
    shp_files = inputs.split(';')

However these are still strings in a list and therefore when I run a geoprocessing task the error I receive is that the shapefile has no table 'C'. C being my directory C:. What I need is either a more elegant approach to my current step or a way to add r' ' to surrond each of my list strings.

I assume there must be a way to append each string in a list and add the r '' to indicate that is a pathname.

share|improve this question
add comment

1 Answer

up vote 1 down vote accepted

I will usually generate a feature layer before passing feature classes to geoprocessing functions. You shouldn't need to mess with path names, slashes, etc.

for i,shp_file in enumerate(shp_files):
    ftr_lyr = arcpy.MakeFeatureLayer_management(shp_file,'ftr_lyr_%d' % i)
    #pass ftr_lyr to geoprocessing tasks within the loop

Alternatively, generate a list of feature layers:

ftr_lyrs=[]
for i,shp_file in enumerate(shp_files):
    ftr_lyr = arcpy.MakeFeatureLayer_management(shp_file,'ftr_lyr_%d' % i)
    ftr_lyrs.append(ftr_lyr)

#use the list of feature layers in place of your list of shp_files
share|improve this answer
    
Thanks for your suggestion, I will definitely try that... im especially interested in how much longer it takes to create everything as a layer(yet alone space). I did find a temporary solution as well by using - shp_files = inputs.split(';') /n shp_files = [i.replace("'","") for i in shp_files] –  BJEBN Mar 10 '12 at 22:29
    
A feature layer is simply how Arcmap abstracts access to the underlying data source. The time and memory overhead is negligible. –  tharen Mar 11 '12 at 3:47
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.