Thursday 31 August 2017

arcpy - Defining projections for multiple shapefiles in ArcMap?


I have over 100 shape files that don't have .prj file and thus when I bring them into ArcMap 10 they show the coordinate system as unknown. I know all of the shape files coordinate system is GCS WGS 1984. I also know I can use the Define Projection GP tool to individually assign the coordinate system to each file but that will take forever.


I was hoping there was a GP tool to batch define these but I don't see one. Next I was thinking maybe I could use python to do this so I looked in the help menu and found a script but it gives me an error.


Here is the python code I tried (this is for a single shp file so I would still have the pain of typing the name for each file:



import arcpy
infc = r"C:\Documents and Settings\User\My Documents\ArcGIS\shpfiles\Site_2.shp"
prjfile = r"\Coordinate Systems\Geographic Coordinate Systems\World\WGS 1984.prj"
arcpy.DefineProjection_management(infc, prjfile)

Answer



I think you guys are overthinking this one...



  1. Right-click on the "Define Projection" tool in toolbox,

  2. select "Batch",

  3. drag-and-drop your layers into the "Input Dataset" column,


  4. right-click in the first "Coordinate System" box to fill out the correct projection,

  5. then right-click on the projection you just selected and choose "Fill" which will fill out all of the rest of the projections for you.

  6. Hit "OK" and you are done.


alt text


No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...