Introduction in Python


What is Python?

Python is a language that is used to automate computing tasks through programs called scripts. In the introduction to this lesson, you learned that automation makes work easier, faster, and more accurate. This applies to GIS and many other areas of computer science. Learning Python will make you a more effective GIS analyst, but Python programming is a technical skill that can be beneficial to you even outside the field of GIS.

Python is a good language for beginning programming. Python is a high-level language, meaning you don’t have to understand the “nuts and bolts” of how computers work in order to use it. Python syntax (how the code statements are constructed) is relatively simple to read and understand. Finally, Python requires very little overhead to get a program up and running.

Python is an open-source language and there is no fee to use it or deploy programs with it. Python can run on Windows, Linux, and Unix operating systems.

Python in ArcGis

In ArcGIS, Python can be used for coarse-grained programming, meaning that you can use it to easily run geoprocessing tools such as the Buffer tool that we just worked with. You could code all the buffer logic yourself, using more detailed, fine-grained programming with ArcObjects, but this would be time consuming and unnecessary in most scenarios; it’s easier just to call the Buffer tool from a Python script using one line of code.

Python syntax

Every programming language has rules about capitalization, white space, how to set apart lines of code and procedures, and so on. Here are some basic syntax rules to remember for Python:

Python is case-sensitive both in variable names and reserved words. That means it’s important whether you use upper or lower-case. The all lower-case “print” is a reserved word in Python that will print a value, while “Print” is unrecognized by Python and will return an error. Likewise arcpy is very sensitive about case and will return an error if you try to run a tool without capitalizing the tool name.

  • You end a Python statement by pressing Enter and literally beginning a new line. (In some other languages, a special character, such as a semicolon, denotes the end of a statement.) It’s okay to add empty lines to divide your code into logical sections.
  • If you have a long statement that you want to display on multiple lines for readability, you need to use a line continuation character, which in Python is a backslash (\). You can then continue typing on the line below and Python will interpret the line sequence as one statement. One exception is if you’re in the middle of parentheses () or brackets [], Python understands that you are continuing lines and no backslash is required.
  • Indentation is required in Python to logically group together certain lines, or blocks, of code. You should indent your code four spaces inside loops, if/then statements, and try/except statements. In most programming languages developers are encouraged to use indentation to logically group together blocks of code; however in Python, indentation of these language constructs is not only encouraged, but required. Though this requirement may seem burdensome, it does result in greater readability.
  • You can add a comment to your code by beginning the line with a pound (#) sign. Comments are lines that you include to explain what the code is doing. Comments are ignored by Python when it runs the script, so you can add them at any place in your code without worrying about their effect. Comments help others who may have to work with your code in the future; and they may even help you remember what the code does.


Training Seminar with Python


Esri uses the cloud today in several different ways. The currently available options include the following:

  • The ability to deploy ArcGIS Server on Amazon Web Services.
  •, a Web site offering tools and shared data for GIS applications.
  • ArcLogistics, a cloud application for optimizing routing, such as for delivery vehicles.
  • Business Analyst Online, a cloud application for geographic analysis of demographic, consumer, business, and other data.

These examples illustrate how cloud computing can make life better for GIS developers and users. Each one is worth a closer look.


ArcGIS Server is a platform for delivering GIS services to software on other systems. These capabilities are exposed as RESTful services, via SOAP, and in other ways, and they can be consumed by clients written using various technologies, including JavaScript, Adobe Flex, and Microsoft Silverlight.

Today, customers typically deploy ArcGIS Server on a computer running in their own data center. It’s also possible, however, to deploy ArcGIS Server in the cloud using AWS. As Figure 3 shows, ArcGIS Server itself can run in an EC2 VM running Windows, while a relational database holding GIS data runs in a second VM.


Deploying ArcGIS Server on AWS provides an alternative to deploying it solely in your own data center. But why would anybody do this? What are the advantages of choosing this option? There are several possible answers, including the following:

  • Easier deployment: Esri provides a preconfigured AMI containing ArcGIS Server. Rather than install and configure the product on a machine in your data center, you can just create an EC2 VM from this AMI.
  • Faster deployment: In many organizations, making a server machine available to run new software requires following a multi-step process, one that can take weeks or more. With AWS, by contrast, anybody with a valid credit card can get an EC2 VM deployed in a few minutes. If getting ArcGIS Server—and the application that uses it—up and running quickly is important, using the AWS option can make sense.
  • Lower cost: As mentioned earlier, AWS charges customers for each hour a VM is running. Depending on usage and costs in your own data center, running ArcGIS Server on AWS might be a less expensive option. This is especially true for applications with elastic (i.e., widely varying) demand. If, say, an application typically uses a single instance of ArcGIS Server, but needs ten instances for occasional peak loads, the AWS pay-as-you-go model lets you pay for this higher usage only when you need it.
  • Broad availability: Because software running on AWS can be accessed by anybody with an Internet connection, GIS services exposed by ArcGIS Server in an EC2 VM can be broadly available. While this raises the security bar, it can be an attractive approach for providing some kinds of information.
  • Better performance: ArcGIS Server allows running various kinds of analysis on GIS data. If you’re creating an application that performs complex data analysis, you might choose to deploy multiple instances of ArcGIS Server in multiple EC2 VMs, then use all of them in parallel to work on the same data. Applications running on AWS also have access to large amounts of bandwidth, which can significantly improve performance in some cases.
  • Simpler development and testing: Because the AWS environment can be essentially identical to an on-premises Windows environment, a development team can build and test an ArcGIS Server application in the cloud, then deploy it either in the cloud or on premises. Given that creating (and paying for) EC2 VMs can be more flexible than creating the same environment in your own data center, this can make the development process easier.

Running ArcGIS Server in the cloud isn’t always the right solution, of course. In many organizations, for instance, storing sensitive information outside the firewall is frowned upon. Still, this alternative deployment approach can sometimes be the best option.


Using the cloud to share GIS data and applications is an attractive idea., run by Esri, provides a good example of this. Figure 4 shows the site’s home screen.


As this screen shot suggests, provides a number of services, including the following:

  • Storage of publicly available maps and other GIS information. (Esri provides some of this data, including things such as layers and basemaps, but users of the site also contribute.)
  • Esri-created applications for examining and working with the site’s information, such as tools for creating maps.
  • A central site for finding and accessing GIS applications that use the data on, including applications that run on computers in non-Esri data centers.


Spatial Analysis in GIS

Geographic information systems uses spatial analysis in order to understand geographic questions.

This list is a work in progress.  If you would like to submit an article or GIS tutorial covering a theme in spatial analysis, visit the submissions page for guidelines.

Area Cartograms

Area cartogram maps are maps of non-absolute space where the areal extent is in proportion to some measured value.  More: Area Cartograms Explored.


Buffering in GIS creates a polygon layer that extends out or in from a set distance from a point, line, or polygon.  More: Buffers

Clip Analysis

Clip analysis is the function of using the extent of one geographic layer to clip the extent of another geographic layer.  More: Clip Analysis using ArcGIS Desktop.

Distance Decay

Distance decay is a phenomenon observed between locations or ethnic groups- the further apart they are, the less likely it is that they will interact very much. More: Distance Decay.


Geocoding is a way of georeferencing data by using a GIS data layer that has locational information.  More:Geocoding.

Heat Maps

Heat mapping, from a  geographic perspective, is a method of showing the geographic clustering of a phenomenon. More: Heat maps in GIS.

Line of Sight and Visibility Analysis

Light of sight measures the unimpeded view or access from one point to another point across a terrain or surface.  Visibility analysis is the end result, a line color coded to show which segments are visible and which segments have an obstructed view.  More: Light of Sight.


How to Import a Shapefile in CartoDB

The CartoDB platform is designed for maps of all shapes and sizes. While we appreciate linearity, we understand that many visualizations tell stories that don’t follow a straight path. The following tutorial will explain how to introduce complex shapes into your projects with shapefiles.

What are shapefiles and what do they contain?

A shapefile is a common format for transfering geographic data that you see online. Shapefiles are actually collections of three or more associated files that come together to represent vector features, such as points, lines, and polygons, each with descriptive attributes like “name” or “temperature”. When imported into CartoDB, those attributes will comprise your table.

Files extentions necessary for shapefile import:

  • .shp:
    This file contains the primary geographic reference data and records of various shape types included, such as points, polygons, or multipatches.
  • .dbf:
    The dBase format stores attributes for each shape, and its size cannot exceed 2GB.
  • .shx:
    The shapefile index format does what its name suggests, which is to organize the records of a shapefile for reference.
  • .prj:
    The projection format is essential because it contains coordinate system and projection information. As a plain text file, it describes your data using markup language, which allows it to sync with many applications.

How to import

The CartoDB interface requires the compression of shapefiles into a .zip file, all prefixed with the same name. For example, a file would containne_10m_populated_places.shp, ne_10m_populated_places.dbf, ne_10m_populated_places.shx, andne_10m_populated_places.prj.

There are different methods for zipping your shapefiles- some more complicated than others.

To streamline the process, you may consider downloading a plug-in (such as 7-Zip for Windows) that is compatible with your operating system. Otherwise, Mac allows you to Ctrl-click shapefiles inside Finder and select “Compress” [filename]. The .zip archive is created in the same location as the original file and is named [originalfilename].zip. You can also choose File → Compress. Your file is now ready to take shape on CartoDB via drag and drop to the window pictured below:


Regardless of your preferred zip method, you will need to be mindful of selecting the complete components of your shapefile from whichever folder they are stored.