Thursday, March 25, 2010

Visual Studios 2010 Release Date

The release date for Visual Studios 2010 is set for:

Monday, 12 April 2010

Mark it down

Tuesday, March 23, 2010

Reinstalling VS 2008

Here's what I think of the stupid people images on the VS 2008 install:
I put the I love Microsoft because apparently it makes some people warm and fuzzy.  Maybe they should improve the installer so it doesn't take 1/2 your work day.

Using Kernel Density

Has anyone ever been able to get the kernel density function to work in a python script?  It appears that the function does not honor the inputs, but I could be mistaken.  Post some code if you got it working.

The script I'm using is published to ArcGIS Server, and the kernel density if performed from the ArcToolbox, it returns the proper image, while the python call returns a black or blank tile, depending on how ArcGIS Server want to behave that minute. 

It's very frustrating because no errors are returned, and both the script and arctoolbox function work in desktop.

Wednesday, March 10, 2010

ArcGIS Explorer 1200 Released

A new version of ArcGIS Explorer (build 1200) is now available for download at:

If you've not installed ArcGIS Explorer before, you can run the system check utility or review the platform requirements before you install. If you are already using ArcGIS Explorer on the same machine as ArcGIS Desktop, please note that the uninstall may take a few minutes...

Find the Official Announcement Here.

Friday, March 5, 2010

What the Heck is *args and **kwargs in my Function?

Take the following code example:

Let's call this function:
c = Child()
You'll notice that method3() will not be called because our super() is passing in a variable gp, and it is expecting all classes to accept one parameter in the __init__(). 
A small change to your program can be done to fix this problem by using *args and **kwargs.
The *args is used to pass a variable-length argument list, and the **kwargs form is used to pass a dictionary object of variable length.
By modifying the class SomeClass' __init__() by adding *args and **kwargs, you can now have functions that doesn't need variables to just ignore the variables being passed for this function.

In the other Classes you should use either the *args or **kwargs for your parameters too.  You can check if the len() of the list is correct, and if so, assign the values.

Thursday, March 4, 2010

Singleton Exmple

Building off of my last post, I am going to post a singleton example that performs geographic functions.

1) Create your Singleton classHere there is a singleton class that will return the same instance of the object every time a specific class is called.
2) Create your class and have it inherit from Singleton

Now to use this, simply create a __main__ declaration, and create the object GeometryObject()

This gives you the output of:

Notice that GO and GO2 are the same exact object. This is what you want if you create a Singleton, only one instance of the object.

Singleton Pattern Design for Python

There are three categoris of OO Patterns:
  1. Creational - patterns that can be used to create objects
  2. Structural - patterns that are used to combine object and classes in order to build structured objects
  3. Behavioral - patterns that can be used to build computation and control the flow of data
Creational Example:

A Singleton is a way to ensure that you cannot create more than one instance of a class. A class attribute could be used to check the number of instantiations of the class.
The singleton patter requires a mechanism to access the singleton class member without creating a class object and a mechanism to persist the value of class members among class objects. The singleton pattern is implemented by creating a class with a method that creates a new instance of the class if one does not exist. If an instance already exists, it simply returns a reference to that object. To make sure that the object cannot be instantiated any other way, the constructor is made protected.
As a note: "The singleton pattern must be carefully constructed in multi-threaded applications. If two threads are to execute the creation method at the same time when a singleton does not yet exist, they both must check for an instance of the singleton and then only one should create the new one. If the programming language has concurrent processing capabilities the method should be constructed to execute as a mutually exclusive operation." ~From

Here are two examples of Singleton Patterns:

This will produce an output of:
Here is a second singleton implementation that returns the same instance of the singleton instead of throwing an error:

I would recommend starting to use Design Patterns in your ArcGIS Python code. With the coming of 10, it will be more important than ever to have code that conforms to standard coding practices.

The goal of any OO programming is the following:
  1. Genericity - is a technique to define parameters for a module exactly as you define parameters for a function thus making the module more general
  2. Flexibility - very difficult to achieve, but functions should be written as general as possible to allow for multiple data types
  3. Inheritance - is the ability in OO Programming to derive a class from another, either by extending it or specialize it
  4. Overloading - refers to the possibility for an operator or method to behave differently according to the actual data types of their arguments
  5. Polymorphism - is the possibility for something to have several forms.