1

I have 8 shapefiles in a folder with shapefile 1 and 8 in the same projection and the others (shapefile 2-7) if different projections.

Is there a way to use python to use shapefile 1 as the projection template to project shapefiles 2-7 in a new folder but also to only copy shapefiles 1 and 8 in the output folder without reprojection them but also not using hard values to keep the script flexible?

I have been trying to use batch project, but am having trouble excluding shapefiles 1 and 8, or only including shapefiles 2-7. Should I be using the Describe.SpatialReference to filter out?

  • You should use the Desctibe.SpatialReference to test the projection of the shape file and project only the one that have not the same SpatialRef – S_TssG Apr 9 '15 at 9:05
  • S_TssG, have you an example code of how this is achieved? This is my code, it is saying achieved, but also projecting everything, but there are no shapefiles in the output folder. – Pete Apr 9 '15 at 10:03
1

this is how I identified different projections. Keep in mind that depending on different datum you need the right transformation. You would need elif for each transformation.

for lyr in lyrlist:
    if lyr.visible == True:
        desc = arcpy.Describe(lyr)
        Ref = desc.spatialreference.name
        if "ETRS" in Ref:
            arcpy.Copy_management(...)
        elif "DHDN" in Ref:
            arcpy.Project_management(lyr,desc.path+os.sep+ +desc.basename+"proj.shp","PROJCS['MV32_ETRS_1989_UTM_Zone_32N',GEOGCS['GCS_ETRS_1989',DATUM['D_ETRS_1989',SPHEROID['GRS_1980',6378137.0,298.257222101]],PRIMEM['Greenwich',0.0],UNIT['Degree',0.0174532925199433]],PROJECTION['Transverse_Mercator'],PARAMETER['False_Easting',32500000.0],PARAMETER['False_Northing',0.0],PARAMETER['Central_Meridian',9.0],PARAMETER['Scale_Factor',0.9996],PARAMETER['Latitude_Of_Origin',0.0],UNIT['Meter',1.0]]","DHDN_To_ETRS_1989_8_NTv2")
  • could you describe what "ETRS" and "DHDN" are? – mr.adam Apr 9 '15 at 13:56
  • These are parts of the name of the projection, just to identify the datum of the projection. The name of the datum is in most cases part of the name of the projection. Of course you have to adapt it to the projections you are using. Sadly the Describe() method does not support the .datumName with projected reference systems. help.arcgis.com/de/arcgisdesktop/10.0/help/index.html#//… – EikeMike Apr 9 '15 at 14:00
  • yeah, datumName would be nice. Thanks for the explanation. You might be able to simplify the elif situation by creating a dictionary like trans = {"ETRS":"transformation 1","DHDN":"transformation 2", etc.} and then looping through the keys and if key in Ref: do the Project_management using trans[key] for the transformation. – mr.adam Apr 9 '15 at 14:21
0

Trying to project first;

import arcpy

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

fcList = arcpy.ListFeatureClasses()

try:    

inFolder = arcpy.ListFeatureClasses()  
template = arcpy.GetParameteAsText(1)  
outFolder = arcpy.GetParameterAsText(2)


desc = arcpy.Describe(template).spatialReference


arcpy.BatchProject_management(inFolder, outFolder, desc)  

except:  
arcpy.AddMessage (arcpy.GetMessages ())

for fc in fcList:    
print fc
0

I see your code this way :

import arcpy

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

fcList = arcpy.ListFeatureClasses()

inFolder = arcpy.ListFeatureClasses()  
template = arcpy.GetParameteAsText(1)  
outFolder = arcpy.GetParameterAsText(2)


srf= arcpy.Describe(template).spatialReference

for fc in fcList:    
 if arcpy.Describe(fc).spatialReference.name != srf.name:
  arcpy.Project_management (fc, outFolder + "\\" + fc, desc, {transform_method}, {in_coor_system})
  • Thanks for your efforts S-TssG. For some reason I get an error in line 19 <module> desc = arcpy.Describe(template).spatialReference AttributeError: DescribeData: Method spatialReference does not exist. Do you know much about the error message? – Pete Apr 9 '15 at 12:20
  • What is your version of ArcGIS ? – S_TssG Apr 9 '15 at 12:27
  • I edited the code could you try again ? – S_TssG Apr 9 '15 at 12:33
  • I'm using 10.3, ahhh, now it doesn't like line 16. template = arcpy.GetParameteAsText(1) – Pete Apr 9 '15 at 12:42
  • I am using the script in a toolbox inArcGIS to run. I have set parameters as workspace, Feature Class and Folder. Is this correct? – Pete Apr 9 '15 at 12:43

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.