16 Replies Latest reply on Mar 23, 2015 2:08 PM by shieldr

    Batch define projection

    fstadtschreiber
      hi everybody,

      i would really appreciate if anyone could help with the following problem:

      i have app. 100 rasterdataset which do not have any projection defined (anyway i know they are xxxx because of the coordinates...) There´s a tool "define projection" in the arctoolbox. is there a possiblity to define projection in one step for all of the rasterdatasets in my workspace (something like batch define projection) in ArcCatalog 10???

      FS
        • Re: Batch define projection
          mtgis
          Hi - There are several ways you can approach this.  This first way is to use the Batch option under ArcToolbox.  If you right click on the Define Projection toolbox you will see an option in the context menu that's called "Batch".  Here you can manually add the input dataset or feature class and it's appropriate Coordinate System.  However, as I'm sure you can imagine, doing this for all ~100 of your raster datasets would take a significant amount of time.  The second, and fastest method, is to use a Python script that will automate this for you.  Below is the script that I made that will read all of the raster datasets from a workspace and define the projection for each raster dataset.  Even if you are not too familiar with Python this script should be pretty straightforward but if you need any help please let me know.

          P.S.  You can use either IDLE or PythonWin for this script.
          • Re: Batch define projection
            fstadtschreiber
            please excuse, i´m quite new to using scripts... :-( moreover i´m using a german edition...

            so it would be a great help if you could tell me how to do this right: after donwloading des scriptfile i copied it into the .../arctoolbox/script folder. after that i made a new personal toolbox and added the script by right clicking -  add script. until here it worked fine. so far so good, now if i use the script, it says "this tool has no parameters"... ?? what does this mean?

            Thx you very much for your help!!!
            • Re: Batch define projection
              mtgis
              Hi Florian - Sorry, I should have been a little more clear in my initial post.  The reason you are getting "this tool has no parameters" is because the script that I sent is a standalone script.  In other words it is not meant to be used to build a new personal toolbox within Arc.  Instead you open this script with a program that's called IDLE.  With the install of ArcGIS 10 IDLE is the default Python IDE (Integrated Development Environment) that lets you load scripts like the one I had sent you and run them outside of the ArcGIS Desktop environment.  Below are directions that should get you where you need to go.

              1)  Open IDLE.  Either right-click on the Python script and select "Edit with IDLE" or navigate to the program's location which should be similar to the following "C:\Python26\ArcGIS10.0\Lib\idlelib\idlepyw

              2)Open your script if you haven't already done so.  In the script you will see two variables.  One called "prjfile" and another called "env.workspace".  The variable "prjfile" contains the location for the projection file.  I left the location of the projection file that I used to show you where the projections are located on your hard drive.  Change this to match that of the coordinate system you want to use for you own data. 
                  The "env.workspace" variable is the workspace where all of your raster datasets are located.  Change everything between the quotes to match the location of the folder on your hard drive with all of your raster datasets.  Note:  use forward slashes (/) instead of the usual back slash (\).  So instead of C:\Program Files\ArcGIS it will be C:/Program Files/ArcGIS.  Save your script.

              3)  In the menu bar of IDLE navigate to "Run" and select select "Run Module".  IDLE will sit for several seconds to gather all of the information that it needs.  A second window called the Python Shell should pop up and, if everything has been done correctly, IDLE should start printing out the names of your rasters and whether or not it has defined the projection.

              Hopefully those directions are clear enough to get you on your way but if you have any questions or the script errors out let me know and we can go from there.  Good luck.
              • Re: Batch define projection
                ashleydia
                Hi Florian, In addition to Matthew's great advice... There is an ESRI script that is the old batch define tool (attached). You can create your tool with the Add > Script... function that you mentioned. The attachment will be loaded in the "Script File" portion of the add script wizard. You can copy the parameters from the regular "Define Projection" tool (Input Dataset or Feature Class AND Coordinate System).

                Here is the walk-through: http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#//001500000006000000.htm
                • Re: Batch define projection
                  fstadtschreiber
                  i tried MTGIS script and it worked just fine the first time!! Tank you very much for your help, you´re great! :D

                  @AshleyDIA: can you give me some hint how to copy the "define projection" tool parameters to my new "batch define projection script"?

                  Ps: think i´m going to learn a bit more about using scripts in arcgis (i already learned there a standalone script´s an others within arc) :)
                  Thx a lot!
                  • Re: Batch define projection
                    ashleydia
                    Hi again Florian,
                    See attached for the parameters I have for my Batch Define Projection tool.

                    Good luck!
                    Ashley
                    • Re: Batch define projection
                      fstadtschreiber
                      @johns: wow, that´s easy :cool:
                      • Re: Batch define projection
                        osmanrc
                        Hi, could you help me please?, I tried to run your  script but does not work, tell me "invalid syntax" ... I follow all parameters that you said,  but still does not work, ... I'm using arcgis version 10 and I need to use this scrpy or the "BatchDefineSR.py" including in this version, or if you know how to works in the model builder,  I will to thank you a lot .... slds
                        • Re: Batch define projection
                          mtgis
                          Hi Osman - Just so I'm clear, are you using the script that I provided Florian in the beginning of this post?  I just wanted to make sure since there were several other scripts after mine that were provided as alternatives.  If you're referencing my script could you further explain the error?  Ideally, could you post the script that you tried to run when you got the error?  When it says "invalid syntax" it will usually provide the line of code that's the issue (it's usually found several lines about the "invalid syntax" error).  If you could provide those two pieces of information I can help you further.  Thanks!
                          • Re: Batch define projection
                            frankv3
                            hi everybody,

                            i would really appreciate if anyone could help with the following problem:

                            i have app. 100 rasterdataset which do not have any projection defined (anyway i know they are xxxx because of the coordinates...) There´s a tool "define projection" in the arctoolbox. is there a possiblity to define projection in one step for all of the rasterdatasets in my workspace (something like batch define projection) in ArcCatalog 10???

                            FS


                            you can do this easily with model builder
                            make a model that iterates the rasters in a workspace (directory) and applies a projection
                            • Re: Batch define projection
                              lyndy
                              This is an awesome, time saving tool! Thanks so much!

                              My only suggestion is that it would be good if a message could pop up that the process is completed. The window just closed so I wasn't sure if it worked or not at first.

                              Lyndy
                                • Re: Batch define projection
                                  GKishor

                                  Right click on workspace in model builder > model parameter

                                  Right click on define projection > make variable from parameter > coordinate system >right click >model parameter

                                  Then save & close model

                                  Double click on model. Now it will work like a tool.

                                  1 of 1 people found this helpful
                                    • Re: Batch define projection
                                      shieldr

                                      Thanks. I guess I am having a "special" case here? That is, I do NOT have a raster dataset, nor do I have a coverage. Could it be that ArcCatalog is calling them feature datasets, as they are .jpg files and is making assumptions?  What I do have is a folder with nearly 400 .jpg images that I converted, myself, from .tif files to .jpg files. And they are all "visble" and "selectable" in ArcCatalog. But to be clear: they are NOT currently Raster Datasets, per se. And I am not attempting to turn them into a mosaic. Specifically, what I am attempting to do is define the projection for each of approximately 4000 .jpg files (that already are projected and thus don't need to be) in an interative, batch process or fashion. But each time I attempt do do it, the script or the tool or the subroutine is expecting a sort of file that I do not have. Does this make sense?