![Code Samples [page banner]](code3.gif)
|
This page is home to some ready-to-use sample Python code, some of it general, but most of it is related to GIS tasks involving USGS SDTS DEM files. It should be readily understood by experienced programmers and easily ported to other computer languages. Although all of these were written to be cross-platform, it was discovered in testing PullSDTS 1.3a on PowerMac that file path concatenation and time functions had to be changed to be compatible. While those changes have now been incorporated beginning with PullSDTS 1.4, they have not yet been made for any scripts listed on this page. Note: To use this code requires having the freeware Python 2.x language interpreter installed. Python comes with Linux (check to make sure you have Python 2.x) and is available for free download for most other platforms including Win95+/NT+ and Mac. See "Getting Started.
License: Although this entire page, accompanying pages, and their presentation are ©Copyright by Columbine, Inc., publisher of 3D Artist magazine, and thus are NOT in the public domain and may not be copied or mirrored (but please do link), permission is herewith granted to reuse the author's programming code on or directly attached to this page without any copyright or commercial restriction, and without need for further permission beyond this statement. The code on or attached to this page is itself is hereby placed in the public domain. If this Python code or a derivative is re-used in whole or in part in any manner publicly, it is not required that there be an acknowledgment and a link back, but such courtesy would be in the spirit of this contribution to the Python, GIS, and 3D graphics communities. This license does not incorporate any FSF/GNU General Public License restrictions. It does meet or exceed the definition of "open source" at |
PullSDTS Python Notes Tkinter Notes File Formats SDTS Notes Glossary Index |
Withdrawn: This original pre-GUI code for the PullSDTS script is has been withdrawn as obsolete. See the current PullSDTS utility.
tkDemo#1 1.1 code
Discussion: This is a minimal but complete demo script that puts up a Tkinter window with a basic menu. See "A basic Tkinter script" for an extensive explanation of the script and the issues involved in creating it.
ImageEmbedder 1.0 code
Discussion: Python programmers may find this script useful for creating PhotoImage statements with the GIF image in text-like base64 form embedded right in the script. It also shows a shortcut for putting a GUI interface on quick-and-dirty utilities, and incidentally illustrates how one script can write a new script and then boot it. See "A Tkinter shortcut" for more about how imageEmbedder works.
Withdrawn: This section, explaining how to open gzip .gz files natively in Python, has been withdrawnn along with its code. A revised explanation is now available on the "File Formats" page.
Withdrawn: This section, explaining how to parse TAR files (and deal with octal file attribute values), has been withdrawn along with its code. A revised explanation is now available on the "File Formats" page.
The following demo programs are taken from a section of the "SDTS Notes" page that deals with how to parse DDF files (more notes and code to come soon).
DDF Example 1 v1.0 code - D/DR leader viewer
See the "SDTS Notes" page where this script is used to show how easy it is to skim through a DDF file reading a DDF's most basic component - variable-length records called "data definition" (DDR) or "data" (DR) records.
DDF Example 2 v1.0 code - DEM DR reader
On the "SDTS Notes" page, this script demonstrates a shortcut for extracting elevations from the main DDF of an SDTS DEM transfer. In the process, it outputs the data to a .raw image file that Photoshop can read.
See also tarDump below.
tarOpen 1.1 code
Discussion: This is a basic utility for dumping out a wordprocessor-safe text file to let you inspect the innards of a TAR file and the files it contains. Version 1.1 adds the abilities to dump original Unix TAR files (version 1.0 only handled the USTAR header format), to deal with blocks of all nulls, and to skip over a user-specified excess number of blocks from long files of all kinds.
See "Data dumping" on the "SDTS Notes" page for more info.
30 May 2001: tkDemo#1 significantly revised.
4 May 2001: The information previously posted here about working with gzip and TAR files has been revised and posted on the new "File Formats" page.
6 April 2001: Page and code overhaul begun, and the tarball sections withdrawn, including the original pre-GUI PullSDTS utility.
27 Jan. 2001: Page first posted.
See also "What's New on the Project Site."