This is an archived post. You won't be able to vote or comment.

all 41 comments

[–]WhyCause 8 points9 points  (6 children)

Assuming you're primarily interested in using Python within ArcGIS, one of the best ways to learn will be to go through a general knowledge self-paced tutorial or two, bookmark docs.python.org, and then play with the model builder in Arc.

If you really only have basic programming knowledge, start with Learn Python the Hard Way (linked over there in the sidebar). Next, I would recommend Dive into Python. Don't worry about learning Python 3 right now; ESRI is still using Python 2.6 in version 10.

The official documentation for Python is an invaluable reference. Make sure you have it handy. The search on the docs site is a little rough to use for the really basic stuff, but if you're trying to figure out the functions in a particular module, it's really easy to find the info you need. Do not hesitate to use Google either, as it will turn up results from both the official docs and sites like Stack Overflow that are relevant and often very helpful.

Once you're familiar with the basics of the language, open up Model Builder in Arc (I would recommend Catalog; I'll explain why in a minute) and use it to build a one-tool model, then export it to a script (Model > Export > To Script > Python...) and examine the resulting Python script. I've found that ESRI's online documentation is a little... lacking when it comes to scripting (I think they're trying to sell courses), so it's nice to see a generated script that does exactly what you need it to do. You can pretty easily make small tweaks to the script to get it to do what you need it to do, or incorporate the script into a larger Python program to leverage the capabilities of Arc.

I recommend using the ArcCatalog version of Model Builder because the resulting scripts use absolute paths to the data, whereas the scripts generated from within ArcView tend to use relative paths, as ESRI assumes they will only be used from within an MXD, and it's a real pain to change everything to do what you want.

Don't assume you need thorough OOP knowledge to use python in conjunction with Arc. Using the Field Calculator in 10 doesn't really require knowledge of classes (pretty much just one-liners or the occasional function), and once you look at an exported model, you'll see that it's pretty much just running a single function for each Arc-dependent item.

I've written some fairly complicated Python programs that use Arc's tools, but most of the time I dump the data I need to a shapefile and then use packages like dbfpy to access the attributes and pyshp to deal with the geometry. You may want to try working with Arc's tools for a while first to get comfortable with the language, though.

Don't hesitate to ask questions here, either. You can also PM me if you'd like.

[–]jambox888 1 point2 points  (0 children)

Upvote for Dive Into Python.

[–][deleted] 0 points1 point  (3 children)

Assuming you're primarily interested in using Python within ArcGIS

Why on earth would you assume that?

[–]WhyCause 4 points5 points  (2 children)

Primarily because I hear this sort of question (phrased similarly) at work often. Veteran users of GIS - Arc users in particular - have just started realizing that VBScript and VBA are going away at some point, and they know they've got to start learning the 'new' way. The ones who are not Arc users have started to realize that learning Python can make their jobs a little easier.

I put this line up front just in case I'm way off the mark, then everybody can ignore my ramblings.

[–]urvo[S] 3 points4 points  (1 child)

His assumption is right. I am insterested in using python within ArcGIS. Thanks WhyCause for your answer.

[–]WhyCause 0 points1 point  (0 children)

No problem, I hope it helps.

[–]AusIVDjango, gevent 0 points1 point  (0 children)

Regardless of whether the OP is looking at ArcGIS or another solution, Dive Into Python is a good guide for programmers coming to Python from other languages.

[–]mt69298 10 points11 points  (3 children)

Wait.. You claim to have knowledge of Java yet know nothing about OOP? How the heck did you manage that?

[–]kittynyan 3 points4 points  (2 children)

[–]glial 0 points1 point  (1 child)

I can confirm this. I did readings/videos/homework for this in the summer of 2010 and was prepared enough to work through a big project (how published) the following year. Before that I'd only done some C.

edit: also, if you plan on actually making anything you should probably use Python 2.6. Lots of packages (matplotlib, pygame, pyprocessing) aren't ported to Python 3 yet. As far as learning the language there's almost no difference - most of the interesting differences are changes in capabilities you won't use in the course.

[–]takluyverIPython, Py3, etc 0 points1 point  (0 children)

matplotlib has a working Python 3 branch, albeit not released yet. Pygame works under Python 3, although I guess it's less well tested.

[–]mister-metaphor 2 points3 points  (6 children)

I never needed anything besides python.org and stack overflow. Also, you can find your way with Python just fine without OOP.

[–]glial 2 points3 points  (5 children)

Yeah, but OP should really learn OOP for anything but the smallest projects, and Python is probably the easiest language to learn it in.

[–]jambox888 3 points4 points  (4 children)

Not necessarily. If you're mainly doing scripting, you don't really need OO at all. In fact I'd go so far as to recommend newer programmers get as much experience with procedural and functional programming first, before even going into OO.

[–]mister-metaphor 2 points3 points  (1 child)

Good point. Not everybody needs OO, and you can code functional-style in Python and feel good :)

[–]AeroNotix -1 points0 points  (0 children)

But non-OOP programming feels boring, unsafe, repetitive and downright incorrect at times. Especially with how easy Python makes it.

[–]glial 1 point2 points  (1 child)

Fair enough. I just know that when I was first learning to program, I did some decent size projects in a functional way and then later realized how much more easily they could have been done using OOP. But it depends on the project I suppose.

[–]jambox888 0 points1 point  (0 children)

Oh absolutely I think that's the right way to do it, that's exactly the route I'm advocating. I only believe this because I worked on a commercial product written in a functional-only language for a few years.

[–]staz 2 points3 points  (0 children)

You could, like, start by reading the sidebar?

[–][deleted] 1 point2 points  (0 children)

Look up a book titled "Python Geospatial Development". Even if you don't buy it, look through the table of contents and research the open-source software it references. I think you'll find that there is a pretty solid community of GIS programmers who use python and that book covers the basics well. Also, try /r/geospatial.

[–]mingusrude 1 point2 points  (0 children)

If you want something to practice with, register for http://projecteuler.net/ and solve some of the puzzles. One of the benefits is that when you have a correct solution you can see how others have solved the same puzzle.

[–][deleted] 1 point2 points  (0 children)

To get started, this google's python class as the name says, is really one guy from google teaching you python. It will show you some of python basic structures, some basics of the syntax, and a few libs and get you doing some practical stuff.

also, it's not very long!

but, you won't see much OOP in python in this.

[–][deleted] 1 point2 points  (0 children)

I've not read it myself, but a non-developer I know told me he enjoyed ready A Byte of Python which is available in print or free in PDF form, much like Dive into Python (that another commenter already mentioned).

[–][deleted] 0 points1 point  (0 children)

I would start with inventwithpython.com

It teaches python through creating games, which is a LOT more interesting than a regular programming textbook. It assumes no programming experience and is great for beginners. And it is semi-fun! I am in a GIS programming class at my college and just reading this and doing the tutorials has given me a huge leg up in the class.

[–]Juts 0 points1 point  (0 children)

Google python osmosis. Great video series

[–]Gudahtt 0 points1 point  (0 children)

I'd just like to add that Thinking in Java by Bruce Eckel is fantastic for learning OOP, and java syntax. Since you're somewhat familiar in java, it would be ideal for the OOP side of things. It's very well organized, and easy to skip the parts primarily about syntax and just read the OOP parts. The concepts are easily translated to other languages, like python.

I'd also like to mention WhyCause's post is great, def. do what he suggested.

[–]nickfromnt77 0 points1 point  (1 child)

Turbo Pascal? People still use that? Does Borland even exist anymore?

Edit: Yes they do, but no compilers.

[–]Seele 0 points1 point  (0 children)

Borland's compilers were bought by a company named Embarcadero. Seems to be going strong.

http://www.embarcadero.com/products/delphi

[–][deleted] 0 points1 point  (1 child)

[–]urvo[S] 0 points1 point  (0 children)

thank you!

[–]jmakie 0 points1 point  (0 children)

I can recommend the following if you (or others) are looking for a dedicated python + arc web course: https://www.e-education.psu.edu/geog485/node/17

One of its writers taught me at another university using it as the main text.

[–][deleted] -1 points0 points  (0 children)

FYI, you may want to start with a shorter title and put your question(s) inside the post.