2

I'm trying to reproject and copy some shapefile featureclasses to a file geodatabases and I'm having problems with the names imported. The code Im using is

# -*- coding: iso-8859-1 -*-
# -*- coding: latin-1 -*-

fcItem = "gsd_ap.shp"
outWorkspace = "database.gdb"
outCS = "1330"
fcList = arcpy.ListFeatureClasses() for fcItem in fcList:
    outFC = os.path.join(outWorkspace, fcItem.strip(".shp"))
    arcpy.Project_management(fcItem, outFC, outCS)

Unfortunately the outFC name in the file geodatabase becomes gsd_a, the last letter disappears. The same happens if the last letter is a "s". There are more letter combinations that don't work as well.

Why does this happens? CopyFeatures_management() does exactly the same.

Doing the above inside ArcGIS Desktop using toolbox, this does not happen, only when I try a standalone script.

  • Are you running the stand alone script directly from the command line (ie python myscript.py) or through the interpreter or other console (IDLE, IPython, etc.)? – Evil Genius Oct 21 '16 at 14:42
  • 1
    If you print outFC does the filename include the issue you described? Is the path sent to Project_management correct? – Matthew Snape Oct 21 '16 at 14:46
  • In the code you posted, the fcItem variable is getting overwritten with each iteration of the loop (so by the time it's passed to Project, it may not be gsd_ap.shp anymore). Also make sure your workspace is set to where your Shapefiles are stored (arcpy.env.workspace = '/path/to/shapefiles'), or else ListFeatureClasses won't list the right data. – roms Oct 21 '16 at 15:02
  • @roms - Workspace is set correctly, I just forgot to include that. – FishHead Oct 21 '16 at 18:53
  • 1
    This is a python issue, apparently strip removes all instances of the characters listed. stackoverflow.com/questions/7853914/… – Matthew Snape Oct 24 '16 at 11:39
1

Assuming you are referring to EPSG projection code 1330 then a spatial reference should be defined in the following manner:

sr = arcpy.SpatialReference(1330)

Then change the reference from the string outCS to the spatial reference

arcpy.Project_management(fcItem, outFC, sr)
  • The spatial reference isnt the problem, rather python stringhandling, se above :) – FishHead Oct 27 '16 at 6:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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