Sunday, January 26, 2014

Arc GIS tool Development using Python (.Arcpy) Review, Tips

Arc GIS tool Development using Python (.Arcpy) Review, Tips


If you are new to Arcpy, or new to this ArcGIS tool development using python. This Blog is there for starter tips and contains the help material needed. I am writing this blog as when i was given a task to develop a python toolbox of ArcGIS i badly needed a blog like this. When i searched for the help i found the same results on Google i.e. ESRI help Resources page. They are Good but more detail was needed.

When i Started developing i faced two problems
1. Either i have to make it a .pyt toolbox
2. Or i have to make a .tbx toolbox

Now what are they ??
Well they are the two types of toolbox available in arctoolbox. i.e. i have to make one of these.
I then asked people a review about each and the difference between both of these.
I came to knew about that and i have written it in my previous blog also here.(click here to Open)
So i decided to go for .tbx.
I Read this book for the reference
Pimpler, E. 2013 Programming ArcGIS 10.1 with Python Cookbook.
Packt Publishing.


 
Few Things to Consider:
Python is a language that donot use brackets rather it is based upon indenting. You must be sure about its spacing, as with wrong spacing you would face such errors which will make you angry.

Environment to be used
Selecting Environment of development is based upon individual's ease and proficiency.
However, I used NotePad ++ for writing code and i tested it in ArcGIS through running it. I know some of you will think that if there is a built in utility in ArcGIS for python programming then why i used NotePad++ ?
Well there are certain pros and cons of this utility. I have discussed it in detail here in my previous blog.
you can check that by clicking here.




ArcGIS Python Window or PyScripter ?

ArcGIS Python Window or PyScripter ?

Developing a custom Geo-Processing tool / toolbox, Question arises that what software / environment to use??




Well Coding in Arcgis utility gives the advantage of telling the error at the runtime as you write code, it is good for those who are experts and write complete code in one go, but for starters i recommend using wither Pyscripter, IDLE, NotePad or NotePad++. You can write whole code in this and then check it in ArcGIS. How ?

You can create the toolbox by right clicking in folder where you want your toolbox to be created in Arc Catalog and then choose your required toolbox (pyt or tbx)
(for Difference in pyt and tbx click here)


After Creating the tool right click that and click on add script and Add the Script file which you previously created (Note Pad file containing code and saved as .py)
Now if the script file contains an error it will appear a red mark on tool icon in arc catalog.
Also you can check it by right clicking the tool and clicking Check Syntax It will tell the error and its line number.

Monday, January 20, 2014

Difference between pyt and tbx

Difference between pyt and tbx

.Pyt and .Tbx are the two types of ArcGIS tool box developed in python.


Difference of Both is written below. 
.tbx


  • It is the old version of toolbox.
  • There is a graphical interface for defining parameters 
  • Have to Manually Generate text file, i.e. manually have to write code in a text file and save it as .py format. Well I used NotePadd++ for this.
  • Have to write stand alone script.
.pyt
  • It is the new version of toolbox.
  • Even Parameters are defined by coding. there is a positive and negative side of this, positive side is that for the programmers Control is in your hand Define parameters the way you want. where as for newbies this might be difficult, as this is new version of toolbox so not much resources are there on web.
  • Less limitations are there.
  • Interface coding is done in the same file as part of the whole program.


Note: The upper description is not mentioned by any official website, I have learned this by working with both.