GeoChalkboard

A “Spatial” Education Blog

Free Books!

Posted by epimpler on May 3, 2008

I’m cleaning out my library again and have some free books for anyone that is interested. All you have to do is pay for the shipping costs. Contact me at eric@geospatialtraining.com to let me know which books you’d like. Limit 2 please and I’m only shipping within the U.S.

Professional C#: 2nd Edition
Programming ASP.NET
Upgrading Visual Basic 6.0 to Visual Basic .NET
Active Server Pages 3.0
An Introduction to Database Systems
Project Management Best Practices for IT Professionals
Project Management Professional Study Guide
A Guide to the Project Management Body of Knowledge
Programming with Avenue
ArcView Developers Guide
ArcView/Avenue Programmer’s Reference

Posted in Uncategorized | No Comments »

Setting Google Maps Street View Orientation with GPov

Posted by epimpler on April 18, 2008

In our last post we introduced the new Google Maps API Street View objects which give developers the ability to enable Flash based street visualizations in select U.S. cities.  I described the functionality provided by the Street View objects as well as the capabilities of each object.  Finally, we took a look at a simple code sample that shows you how to use these objects to create a Street View Flash viewer. 

In this post we will examine how you can control the orientation of the Street View Flash viewer through the GPov class.  As we discussed last time, a Street View image consists of both a location, specified by a GLatLng object, as well as a particular orientation.  The orientation is specified through the GPov class.  Used together, these two parameters are used to construct the initial Street View object. 

Let’s examine the GPov class in greater detail.  GPov is an object literal which simply means that you do not create individual instances of a GPov through either a constructor or via other objects.  You simply use the properties and/or methods that are available to the literal class.  Let’s take a look at a code example to illustrate this point.

Example: Setting the GPov properties
myPOV = { yaw:90.00, pitch:-20, zoom:30 }

Properties of GPov
GPov has three optional properties that you can set, each of which are numeric values.

yaw – The camera yaw in degrees relative to true north.  True north is 0 degrees, east is 90 degrees, south is 180 degrees, and west is 270 degrees. 

pitch – The camera pitch in degrees, relative to the street view vehicle.  Values can range from 90 degrees (directly upwards) to -90 degrees (directly downwards)

zoom – The zoom level with 0 being fully zoomed-out, and values increased from there.

Note that I said all these parameters are optional.  In the event that you choose not to define any properties for GPov, they each default to 0 which defines a flat horizontal view directly north with the widest possible view.

Applying GPov to Street View
Once you’ve defined the parameters for GPov you will need to assign it to a GStreetviewPanorama object for the settings to take effect.  This can be done in two ways.  The first method is to assign GPov to an instance of GStreetviewPanoramaOptions which is then used in the constructor for GStreetviewPanorama.  Let’s take a closer look at how this is accomplished.  GStreetviewPanoramaOptions, like GPov, is an object literal.  This object literal has two properties that can be set: an instance of GLatLng, and an instance of GPov.  A code example can help reinforce this concept.

Example: Setting the GStreetviewPanoramaOptions properties and then using it in the constructor for GStreetviewPanorama
panoramaOptions = {  latlng:theAlamo, pov:myPOV }
myPano = new GStreetviewPanorama(document.getElementById(”pano”), panoramaOptions)

Click here to see the example in a web page.  Notice that we have set the yaw parameter to 90 which sets the direction to east.

The second method of assigning GPov to an instance of GStreetviewPanorama is through the setLocationAndPOV( ) method available on GStreetviewPanorama.  The setLocationAndPOV( ) method can be used to set the POV after an instance of GStreetviewPanorama has been created.  Once again, a code example is helpful to reinforce this concept. 

Example: Setting the POV through setLocationAndPOV
myPano = new GStreetviewPanorama(document.getElementById(”pano”));
var theAlamo = new GLatLng(29.425849,-98.486927);
myPOV = {yaw:90}myPano.setLocationAndPOV(theAlamo,myPOV) 

For more information on the Google Maps API please see our popular e-learning course “Google Maps For Your Apps!“.  This course has been in production since January 2006 and has been our best selling course since that time.  During the month of April you can save $15.00 on this course by entering a discount code of GISDiscount when purchasing this course through our website
 
This discount also applies to our “Google Earth and Google Maps Bundle” e-learning set which contains Google Maps For Your Apps along with several other Google Earth courses.
 
 

 

 

Posted in Google Maps | No Comments »

Add Google Maps Street Views To Your Apps

Posted by epimpler on April 6, 2008

Many Google Maps developers have been eagerly awaiting the inclusion of objects for controlling Street Views from the Google Maps API, and last week it became official!  A handful of new objects including GStreetviewPanorama, GStreetviewOverlay, GStreetviewClient, and GStreetviewLocation among others have been added to the Google Maps API that allow developers to include these Flash enabled street visualizations. 

What is StreetView?
For those of you who are not familiar with Google Maps Street View let me do a quick review.  In certain large metropolitan areas of the U.S. you can view and navigate within Google Maps via street-level imagery.  You’ll notice that when you go to the main Google Maps page a new button called Street View has been added to the display.

Clicking the Street View button will display a Camera for each city that has the capability of displaying Street Views.  You can click on an individual camera to zoom to your city of interest.

Streets that are capable of displaying a Street View will be outlined in blue and you will also see a human icon that can be used to display a Street View.  You can simply drag the icon onto the street you’d like to display or simply click on a street with your mouse.

This street-level imagery is provided through a Flash plugin so you should make sure that you have installed the latest version of Flash for your browser.  You’ll notice that a number of navigation and display controls are embedded in the Street View. 

Navigating the streets
Each street is labeled and contains arrows indicating direction.  You can click these arrows to navigate further in that direction. 

Zooming
There are a number of methods that you can use to control zooming in and out on the image.  Double-clicking the image, using your mouse wheel, or using the zoom control can all be used to zoom in on the image.  Once you’ve zoomed in a ‘Zoom Out’ button will then be provided or you can use the mouse wheel or zoom control to move back out on the image. 

Panning
Panning is accomplished either by dragging the image in the direction in which you’d like to pan or by clicking the pan buttons.  You can even tilt the image to see the sky or ground by dragging the mouse up or down. 

You can also use the arrow keys on your keyboard to control navigation along the street and to pan the image display.

New Classes in the Google Maps API
Let’s do a quick overview of the new classes for controlling Street View that have been added to the Google Maps API. 

GStreetviewPanorama – Holds an instance of the Flash® Street View Panorama viewer.  Normally embedded within a container object such as <div> and can be manipulated through its methods.

GStreetviewPanoramaOptions – Represents options that can be passed to the GStreetviewPanorama constructor.

GStreetviewOverlay – Tileset highlighting locations where Street View data is available.

 GStreetviewClient – Performs searches for Street View data based on parameters passed to its method.

GStreetviewData – Represents the data associated with a panorama.

GStreetviewLocation – Represents a street view location.

GStreetviewLink – Represents a link from one GStreetviewLocation to a neighboring GStreetviewLocation.

GPov – Repreesents the structure of a camera point of view used by street view.

A Simple Example
I’m going to do a series of posts that show you how to use these classes in your Google Maps application.  In this post we’ll start with a simple example.  Click here to see our first example and you can display the code for this example by right clicking the page and selecting View Source.  If you’ll click the right pan button twice you should see the Alamo in San Antonio, Texas.  Let’s review the code.

The new Street View classes that have been added to the Google Maps API are accessible through JavaScript just the same as any other class in the API.  Let’s first review the a line of HTML code near the bottom of the file. 

The <div> tag is used as a container for the Street View and you will need to assign an id to the div along with a height and width for the container.  Notice that we have assigned a value of ‘pano’ as our id.  You’ll see this value again inside the JavaScript when we assign our StreetViewPanorama to this container.  You’ll also notice in the code above that we have defined a JavaScript function that will be called in response to the onload event.  In this case, the initialize() function will be called when the page loads.  So, let’s take a look at the initialize() function since this is where we create our Street View.

Just above the initialize() function you’ll notice that we’ve declared a variable called myPano which will store the Street View Panorama that is created.  Inside the function we create a new GLatLng object from a pair of coordinates and store this object in a variable called theAlamo.  This value is then used in the panoramaOptions variable which will be passed into the constructor for GStreetviewPanorama in the next line.  Remember that we said the GStreetviewPanorama object holds an instance of the Flash® Street View Panorama viewer.  It is the primary object used for the Street Views in Google Maps.  The supporting GStreetviewPanoramaOptions is used in the constuctor for GStreetviewPanorama and defines various options that are used to control the display and functionality of the viewer.  In this case we’re only passing in a latitude/longitude coordinate value, but you can also pass in a GPov object that controls the camera orientation with which to open the Flash viewer.  The other parameter in the GStreetviewPanorama constructor controls where the Street View will appear.   This is where the <div> tag that we created in the HTML body comes into play.  When we pass in document.getElementById(”pano”) to the constuctor we are specifically stating that the Street View should be placed in this <div> tag container.  Finally, we add in an event listener for the Street View so that it can report browsers that are unable to support the Flash plugin. 

This was a very simple example that demonstrates how you can use the new Street View classes in the Google Maps API to add in Street Views to your Google Maps application.  In our new few posts we will take a look at more advanced Street View code examples. 

For more information on the Google Maps API please see our popular e-learning course “Google Maps For Your Apps!“.  This course has been in production since January 2006 and has been our best selling course since that time.  During the month of April you can save $15.00 on this course by entering a discount code of GISDiscount when purchasing this course through our website

This discount also applies to our “Google Earth and Google Maps Bundle” e-learning set which contains Google Maps For Your Apps along with several other Google Earth courses.

Posted in Google Maps | 1 Comment »

GeoSpatial Training Services - April 2008 Update

Posted by epimpler on April 6, 2008

GIS Programming 101 Course
Our  GIS Programming 101 course scheduled for May 12th - June 6th is beginning to fill up.  We still have six seats available though so if you’re interested please let us know ASAP. 

This is an instructor guided course taught in a Virtual GIS Classroom using the same technologies implemented by colleges and universities around the world to deliver Internet based courses. Our new Virtual GIS Classroom blends the best of instructor led and e-learning formats into a new instructor led web based format that allows for more interactivity between the instructor and student, and between students.

GIS Programming 101: Mastering Python for Geoprocessing in ArcGIS is designed to teach the fundamental programming constructs of the Python language and how it can be integrated with ArcGIS Desktop to automate geoprocessing tasks.  Course participants will be led through a series of 13 modules described below.
Module 1:  Getting Started with Python in ArcGIS
Module 2:  The Geoprocessor ArcObject
Module 3:  Basic Python Language Features
Module 4:  Obtaining Descriptive Information About ArcGIS Data
Module 5: Using Cursor Objects to Select, Edit, and Add Records to Tables and Feature Classes
Module 6:  Enumeration Objects for Listing ArcGIS Data
Module 7:  Miscellaneous Objects
Module 8:  Dynamic Scripts
Module 9:  Integrating Python Scripts with ArcToolbox
Module 10:  Geoprocessing Tools
Module 11: Scheduling Geoprocessing Tasks
Module 12:  Messaging and Error Handling
Module 13:  Final Project

April Sale - Save $15.00 on all GIS E-Learning Courses
You can save $15.00 on any and all GIS e-learning courses from GeoSpatial Training Services when you enter the code GISDiscount in the Discount Code box when ordering our courses on-line. 

As always we offer an additional 15% discount on any course to all educational, non-profit, local, state, and federal government organizations.  Please contact sales at geospatialtraining.com to take advantage of this discount.

Posted in Uncategorized | No Comments »

New Course Section: GIS Programming 101

Posted by epimpler on March 23, 2008

 Our GIS Programming 101 course scheduled for March 24th - April 18th is SOLD OUT.   Because the demand for this course has been so high we will be offering a second section of this course May 12th - June 6th. This is an instructor guided course taught in a Virtual GIS Classroom using the same technologies implemented by colleges and universities around the world to deliver Internet based courses. Our new Virtual GIS Classroom blends the best of instructor led and e-learning formats into a new instructor led web based format that allows for more interactivity between the instructor and student, and between students.

GIS Programming 101: Mastering Python for Geoprocessing in ArcGIS is designed to teach the fundamental programming constructs of the Python language and how it can be integrated with ArcGIS Desktop to automate geoprocessing tasks.  Course participants will be led through a series of 13 modules described below.
Module 1:  Getting Started with Python in ArcGIS
Module 2:  The Geoprocessor ArcObject
Module 3:  Basic Python Language Features
Module 4:  Obtaining Descriptive Information About ArcGIS Data
Module 5: Using Cursor Objects to Select, Edit, and Add Records to Tables and Feature Classes
Module 6:  Enumeration Objects for Listing ArcGIS Data
Module 7:  Miscellaneous Objects
Module 8:  Dynamic Scripts
Module 9:  Integrating Python Scripts with ArcToolbox
Module 10:  Geoprocessing Tools
Module 11: Scheduling Geoprocessing Tasks
Module 12:  Messaging and Error Handling
Module 13:  Final Project

Please click the link above for more information or to register.  If you have any questions please contact us at sales at geospatialtraining.com.

Posted in Uncategorized | No Comments »

Dynamic Geoprocessing Scripts

Posted by epimpler on March 18, 2008

Other posts in this series: 
Scripting Your ArcGIS Geoprocessing Tasks (Part 1)
Scripting Your ArcGIS Geoprocessing Tasks with Cursors (Part 2)
More ArcGIS Geoprocessing Concepts - Enumeration Objects (Part 3)
Obtaining Descriptive Information About GIS Datasets with ArcGIS Geoprocessing Objects (Part 4)
Executing ArcGIS Tools from Geoprocessing Scripts (Part 5)

Through the use of parameters, also known as arguments, you can pass data into your geoprocessing scripts.   The use of parameters makes your scripts more generic and flexible since they allow you to provide for the dynamic input of datasets, tool parameters, or to control the processing logic of a script.  For example, if you had a geoprocessing script that called the Buffer tool you would need to specify the input features, output feature class, and a buffer distance at a minimum.  To make your script more flexible you could take advantage of these dynamic features to input variable data sources and buffer distances depending upon the circumstance. 

In this post we will examine two methods for passing data into your scripts.  The first, GetParameterAsText( ) is a method on GpDispatch that allows you to pass parameters into your scripts through a tool dialog available through ArcToolbox.  We’ll also look at Python’s sys module which can also be used to pass data into a geoprocessing script.

GetParameterAsText( )

The GetParameterAsText method on the GpDispatch object can only be used with ArcToolbox. The advantage of using this method is that it provides for the use of a visual dialog that accepts input data from the user.  This input data is then retrieved inside your geoprocessing script through the GetParameterAsText method.  GetParameterAsText is zero based, with the first argument located at position zero, and each successive argument increments to the next largest integer (see figure below).

There are a number of advantages to running your scripts from ArcToolbox using GetParameterAsText. When you take this approach, the script becomes part of the geoprocessing framework which means that it can be run from a model, ArcGIS command line or another script. In addition, the script has access to ArcMap environment settings and help documentation. Other advantages include a nice user interface that is easier to use, and error prevention capabilities. Error prevention capabilities provided include a dialog box that informs the user of certain errors.

There are a couple negatives to using GetParameterAsText that I should point out.  As I mentioned above GetParameterAsText can only be used within ArcToolbox which means that you can’t execute a script using this method from PythonWin or a DOS prompt.  One additional negative to consider with GetParameterAsText is that it is more difficult to debug the scripts since they can’t be tested from PythonWin.

Python system Module
Python, like other scripting languages, provides a mechanism for accessing arguments passed into the script.  Python’s system, or sys, module is used to accomplish this task. Specifically, the sys.argv[] list contains the name of the script being executed along with any parameters being passed into the script.  As with any other list in Python you can access the parameters through an integer value.  This list, like GetParameterAsText, is zero based.  The difference is that the first item in the list references the script that is being run whereas with GetParameterAsText, the first item references an actual parameter value.  So, let’s take a look at a quick example. 

In this example we use Python from a command line prompt to start a script named PointDistance.py. In addition, we pass in three arguments to the script by including them on the same line, but separated by a space. The sys.argv[] function stores each of the arguments in a list which we can access. Notice that the first argument, referenced by the integer 0 contains the name of the script, PointDistance.py. The arguments that are passed into the script can then be referred to by each successive integer.  Each of these arguments can then be used in your script as necessary.

A similar script called from ArcToolbox:

More Information
We will be presenting a new Virtual GIS Classroom course, “GIS Programming 101: Mastering Python for Geoprocessing in ArcGIS” starting March 24th and ending April 18th.  We still have 1 seat available so hurry to reserve your seat now.  We do offer a 15% discount for government, educational, and non-profit entities.

We also offer an e-learning course entitled “Introduction to Geoprocessing with Python” which contains even more detailed information on ArcGIS geoprocessing with approximately 200 slides of audio and video lectures, visual software demonstrations, exercises and data. 

Posted in Uncategorized | No Comments »

Using Spreadsheet Mapper 2.0 with Google Earth & Google Maps

Posted by epimpler on March 11, 2008

Over the next few weeks I’m going to be writing a series of posts on some of the lesser know tools provided by Google for creating data layers in Google Earth and Google Maps.  The Google Earth Outreach program provides a number of these tools.  According to a press release from early last summer, Google Earth Outreach is “designed to help nonprofit organizations around the world leverage the power of Google Earth to illustrate and advocate the important work they do.”  The program includes comprehensive online guides, video tutorials, and case studies about using Google Earth specifically targeted to the needs of nonprofit organizations.  In addition, organizations can also apply for a Google Earth Pro grant ($400 value). 

In this initial post we’ll take a look at the Spreadsheet Mapper 2.0 tool created by the Outreach team for creating Google Earth and Google Maps placemark layers using Google Docs.  Google Docs is a great way to create, share and collaborate on documents, spreadsheets and presentations online.  Spreadsheet Mapper takes advantage of this online, collaborative environment by allowing you to create placemark layers for display in Google Earth and Google Maps through a spreadsheet created in Google Docs.  Because Google Docs is a collaborative tool, members of your team can simultaneously enter data and instantly publish updates to GE and GMaps.  So, let’s take a look at how this is done through a basic example.

In this example we’re going to create a placemark KML file containing existing Starbucks locations. The Starbucks data contains a unique identifer for each location along with the latitude, longitude coordinate pair and a physical address.  This data is contained within the “Starbucks No Linefeeds.csv” file which was last updated in January 2008. This file contains almost 9,000 Starbucks locations.  Since there are so many locations I’m only going to use a sample area for this example. The download also contains a Starbucks.bmp image which we’ll use in our next post in the series which covers Spreadsheet Mapper templates for styling icons and information balloons.  Let’s get started.  By default, Spreadsheet Mapper will use various templates to create some sample data.  We’ll do this first and then replace the sample data with our own Starbucks location data.

  1. Open the starter spreadsheet.  If you haven’t already done so you’ll need to login to your Google account or create one if necessary.
  2. Select File –> Rename and give you spreadsheet a name (”Starbucks Locations”).
  3. Fill in the “Author’s Information” and “About your KML Document” sections.
  4. Optional Parameters
    • Enable “Google Maps Compatibility” if you want the layer to work in Google Maps
    • Access the “Advanced/Optional Settings” by clicking the tab indicated on the left to un-hide rows
  5. Click the Publish tab and select Publish Now.  This step will publish the document to the web at the URL listed.
  6. Copy the publisher URL and paste it into the white cell provided under “Publish spreadsheet”.
  7. Copy the “Network Link KML” cell that you see below, open Google Earth, select My Places, then right-click and paste.
    Network Links capability in Google Earth provides for the delivery of dynamic data to your users.  We are using a Google Docs spreadsheet which can be edited by multiple users simultaneously.  Network Links in Google Earth are a perfect complement to a Google Docs spreadsheet since they can automatically refresh the Google Earth display to reflect updated data from a spreadsheet.  Get more information on Network Links in our “Mastering KML in Google Earth” e-learning course.So, at this point we’ve copied the sample data contained in the template into Google Earth.  You will notice a variety of folders, placemark icons and information balloons which have been created based on parameters found in the templates contained within Spreadsheet Mapper.

    The Spreadsheet Mapper comes with six templates that can be used to control icon and balloon styles.  Click any of the links at the bottom of the spreadsheet to get more information about each of these templates.  We’ll cover detailed information about the templates in a coming slide, but for now you can get an idea of how they are structured.
  8. At this point you’d want to prepare your template values.  However, as I mentioned above I’m going to save the details of altering the template values for another post since it really deserves a thorough explanation. 
  9. Now let’s add in the Starbucks data.  Open the “Starbucks No Linefeeds” Excel spreadsheet which contains the latitude,longitude, identification, and address values for each Starbucks location.  Due to the large size of the file I’m only going to add in Starbucks locations for my city, San Antonio.  Go to the PlacemarkData link at the bottom of the spreadsheet.
    • The Folder Name is optional, but in this case we’re going to define the folder name as “Starbucks” for each placemark instance.  What this will do is group the placemarks under the same Folder in Google Earth.  This would be helpful if you’d like to group Starbucks locations by city (i.e. San Antonio, Dallas, Houston, Austin). 
    • For the Placemark Name column I’m going to add in the unique identifier for each location based on the information pulled from the Excel spreadsheet we downloaded.  You should be able to copy and paste the data from MS Excel to the Google Docs spreadsheet to save time.
    • We’ll also enter the latitude, longitude values for each Starbucks location, also pulled from the Excel spreadsheet we downloaded.  If you don’t have coordinate values for each placemark you can enter an address which can be used to generate the placemark. 
    • Finally, we specify a template (#5 in this case) to define our icon and balloon styles.  The spreadsheet should look something like you see below.
  10.  Click Publish –> Re-publish document in your Google Docs spreadsheet.  Then refresh your network link in Google Earth by right clicking on “Link to - Spreadsheet” in the Places panel and selecting Refresh.  This should refresh the Google Earth display with the new Starbucks locations we entered in the Google Docs spreadsheet.
 
In our next post we’ll cover the templates provides by Spreadsheet Mapper and also take a look at how you can create your own templates.
March Sale on Google Earth and Google Maps E-Learning Courses
During the month of March we are offering a 15% discount on our “Google Earth and Google Maps Bundle” e-learning set.  Sale price is $170.00 (e-delivery), $210.00 (mail delivery).  This bundle is composed of 5 e-learning courses with over 450 pages of instruction.  Courses include:

Posted in Google Earth, Google Maps, Network Links | 2 Comments »

GeoSpatial Training Services - March 2008 Update

Posted by epimpler on March 3, 2008

GIS Programming 101 Course
Our GIS Programming 101 course scheduled for March 24th - April 18th is almost full.  We still have one seat available so if you’re interested please let us know ASAP.  Because the demand for this course has been so high we will be offering a second section of this course in the May-June timeframe.  The exact timing of the course has not been determined as of yet, but we will let everyone know as soon as we have the dates. 

This is an instructor guided course taught in a Virtual GIS Classroom using the same technologies implemented by colleges and universities around the world to deliver Internet based courses. Our new Virtual GIS Classroom blends the best of instructor led and e-learning formats into a new instructor led web based format that allows for more interactivity between the instructor and student, and between students.

GIS Programming 101: Mastering Python for Geoprocessing in ArcGIS is designed to teach the fundamental programming constructs of the Python language and how it can be integrated with ArcGIS Desktop to automate geoprocessing tasks.  Course participants will be led through a series of 13 modules described below.
Module 1:  Getting Started with Python in ArcGIS
Module 2:  The Geoprocessor ArcObject
Module 3:  Basic Python Language Features
Module 4:  Obtaining Descriptive Information About ArcGIS Data
Module 5: Using Cursor Objects to Select, Edit, and Add Records to Tables and Feature Classes
Module 6:  Enumeration Objects for Listing ArcGIS Data
Module 7:  Miscellaneous Objects
Module 8:  Dynamic Scripts
Module 9:  Integrating Python Scripts with ArcToolbox
Module 10:  Geoprocessing Tools
Module 11: Scheduling Geoprocessing Tasks
Module 12:  Messaging and Error Handling
Module 13:  Final Project

March Sale on Google Earth and Google Maps E-Learning Courses
During the month of March we are offering a 15% discount on our “Google Maps and Google Earth Bundle“.  Regular price is $200.00 (e-delivery), $250.00 (mail delivery), but during the month of March you can purchase this bundle for $170.00 (e-delivery), $210.00 (mail delivery). This bundle is composed of 5 e-learning courses with over 450 pages of instruction.  The five courses are as follows:

Mastering KML in Google Earth
Google Earth for ArcGIS Users
Google Maps for Your Apps!
Arc2Earth for ArcGIS Users
Dynamic Google Earth Applications (in development scheduled for March release)

See more information on these courses.

As always we offer an additional 15% discount on any course to all educational, non-profit, local, state, and federal government organizations.  Please contact sales at geospatialtraining.com to take advantage of this discount.

Posted in ESRI, GeoSpatial Training Services, Geoprocessing, Google Earth, Google Maps | No Comments »

Executing ArcGIS Tools from Geoprocessing Scripts (Part 5)

Posted by epimpler on February 28, 2008

Other posts in this series: 
Scripting Your ArcGIS Geoprocessing Tasks (Part 1)
Scripting Your ArcGIS Geoprocessing Tasks with Cursors (Part 2)
More ArcGIS Geoprocessing Concepts - Enumeration Objects (Part 3)
Obtaining Descriptive Information About GIS Datasets with ArcGIS Geoprocessing Objects (Part 4)

Introduction
In this final post in our five part series on scripting your geoprocessing tasks in ArcGIS we will take a look at how you can take advantage of the built in geoprocessing tools in ArcGIS through your scripts.  These are the tools available through ArcToolbox. 

Each of these tools is accessible from your Python scripts through dynamic methods on the Geoprocessor object.  We’ll take a look at the tools that are available, the syntax you need to use to access them, aliases for the toolboxes that you can use in referencing the tools, and some examples of how you can use these tools in your code. 

Dynamic Tools
The arcgisscripting/GpDispatch object on the Geoprocessor OMD contains a section called Dynamic Methods and Properties.  The Tool method seen below is a generic method meant to imply the existence of multiple tools. 

 

This generic “Tool” method can be a bit confusing until you understand some additional information.  There is a single “Tool” method on the OMD for two reasons.  First, there are simply too many geoprocessing tools to fit on the OMD.  Remember, if you have the ArcInfo license this would mean you’d have access to approximately 200 tools.  In addition, the tools available will depend upon the license level that you have.  Not only does this include the basic license level (ArcView, ArcEditor, ArcInfo), but also the ArcGIS extensions that you are licensing (3D Analyst, Spatial Analyst, many others).  So, as you can see it simply makes sense to group all these tools into a single generic “Tool” method.

Toolbox Names and Aliases
All system toolboxes have an alias property.  This alias is important because it is possible to have multiple tools with the same name.  For instance, a Buffer tool can be found in both the Analysis and Coverage toolboxes.  Therefore, to distinguish the correct tool in your code you’ll need to add the suffix “_<alias>” when calling a tool.  For example:

gp.buffer_analysis(”Roads.shp”,”Road_Buff.shp”, “150 feet”)

This specifically tells the geoprocessor to execute the buffer tool found in the analysis toolbox.  This is a bit inefficient though and most people prefer to set the Toolbox parameter in their code before calling the tool.  For example:

gp.toolbox = “analysis”
gp.buffer(”Roads.shp”,”Road_Buff.shp”, “150 feet”)

The alias for each toolbox can be found by right-clicking the toolbox in ArcToolbox and selecting Properties.

Tool Syntax
To run a tool from the geoprocessing library you need to know the correct syntax for doing so.  For example, the Buffer tool requires several inputs including the input features to buffer, an output feature class, and a buffer distance.  You must give Python the parameters it needs to run the tool correctly.  There are a number of ways that you can access syntax information for a tool, but perhaps the easiest is to use the online ArcGIS Desktop help system.   Here is the link to help information for the Buffer(Analysis) tool.  The help system contains an illustration, usage tips, command line syntax and examples, scripting syntax, and script examples for each tool.  For this post we’ll concentrate on the scripting syntax.  Scroll down near the bottom of the help page until you get to the Scripting syntax section.  In this case you should see the following:

Just below this you’ll see an explanation of each paramter including required or optional information, a descriptive explanation, and the data type.  Required parameters must be included when you call the tool while optional parameters are just that.  In some cases you may have a need to include these parameters and sometimes you won’t.   So, a very simple buffer script could look something like the figure below.

More Information
We will be presenting a new Virtual GIS Classroom course, “GIS Programming 101: Mastering Python for Geoprocessing in ArcGIS” starting March 24th and ending April 18th.  We still have 2 seats of available so hurry to reserve your seat now.  We do offer a 15% discount for government, educational, and non-profit entities.

We also offer an e-learning course entitled “Introduction to Geoprocessing with Python” which contains even more detailed information on ArcGIS geoprocessing with approximately 200 slides of audio and video lectures, visual software demonstrations, exercises and data. 

During our February sale when you purchase our “VBA & ArcObjects Bundle” you can receive a free copy of “Introduction to Geoprocessing with Python“.

Posted in ESRI, Geoprocessing | Tagged: , , , , | No Comments »

Obtaining Descriptive Information About GIS Datasets with ArcGIS Geoprocessing Objects (Part 4)

Posted by epimpler on February 17, 2008

Other posts in this series: 
Scripting Your ArcGIS Geoprocessing Tasks (Part 1)
Scripting Your ArcGIS Geoprocessing Tasks with Cursors (Part 2)
More ArcGIS Geoprocessing Concepts - Enumeration Objects (Part 3)

The arcgisscripting/GpDispatch object contains a Describe method that can be used to return an object that describes data.  The Describe method takes a single argument which is a pointer to a data source.  This method is intelligent enough to determine the type of data being referenced and return an object that describes the type of data.   Each descriptive object returned contains information about the particular dataset specified in the InputValue parameter passed into the Describe method.

 

For instance, if you use the Describe method with a  pointer to a feature class, a FeatureClass Properties object will be returned containing information about that dataset.  This object is often used to test for the type of data (either point, line, or polygon) before further processing.  Various read-only properties are available through this object including ShapeType which returns the basic data type such as point, line, or polygon, FeatureType, ShapeFieldName, and others. 

 This class also has access to two other classes in the Describe object model diagram.  These two classes are Table Properties and Dataset Properties.  The Table Properties object supplies a Fields object containing the Fields in the feature class as well as an Indexes property that returns an Indexes object containing all indexes on the feature class.    The Dataset Properties object contains properties for the spatial reference, extent, and dataset type.

Other Describe Objects
There are a number of other describe objects that can be returned by the Describe method including Tables, Datasets, Workspaces, Relationships, Raster Catalog, Raster Dataset, Raster Band, Coverages, and Layers.  For specific information about these objects please see the green colored objects on the OMD.

Common Describe Object Properties 
All objects returned by the Describe method on GpDispatch can access two additional properties.  These properties are DataType and CatalogPath.  DataType is used to distinguish between types of features classes such as shapefiles, coverages, personal geodatabases, CAD data, and others.  It is often used in if..elif..else decision statements to branch code based on the type of data.  CatalogPath can be used to obtain the full path to the data based on an ArcCatalog connection.  This information is identical to what you would find if you were viewing the data in ArcCatalog.

More Information
We will be presenting a new Virtual GIS Classroom course, “GIS Programming 101: Mastering Python for Geoprocessing in ArcGIS” starting March 24th and ending April 18th.  We still have 5 seats of available so hurry to reserve your seat now.  We do offer a 15% discount for government, educational, and non-profit entities.

We also offer an e-learning course entitled “Introduction to Geoprocessing with Python” which contains even more detailed information on ArcGIS geoprocessing with approximately 200 slides of audio and video lectures, visual software demonstrations, exercises and data. 

During our February sale when you purchase our “VBA & ArcObjects Bundle” you can receive a free copy of “Introduction to Geoprocessing with Python“.

Posted in ESRI, Geoprocessing | Tagged: , , , | No Comments »