How To

How to do things

How to Convert TIFF image files to PDF for Easy Viewing

Recently a customer asked that we publish his scanned parcel maps to his Intranet. For those not up on decade old Internet lingo "an Intranet is a private computer network that uses Internet protocols". He wanted everyone in the office to be able to view and print the scanned TIFF parcel maps. Easy enough, just create share on the file server, or a virtual directory on his web server that points to the directory of scanned images.

Parcel MapThis was not exactly what he wanted. Windows XP provides a TIFF image viewer in the form of the “Windows Picture and Fax viewer”, however it’s slow, its zoom and pan capabilities are lacking (no zoom window) and printing is limited to “print to fit”. There’s also Irfanview , good for image batch conversion but I really don’t like the viewer.

Enter the Adobe PDF viewer. Adequate zoom and pan, fast, easy printing to original scanned size as well as other sizes, and you can zoom to an area and print just the zoomed area. I converted a few using tiff2pdf from the LibTiff utilities. Not too hard, install the LibTif windows binaries as well as the jpeg an zlib dll files. Add them to the PATH and go to work.

tiff2pdf -o map.pdf map.tif

Ok, so lets convert all 4000 of the TIFF files to PDF. Gosh there must be some way to batch this process. OK, there is. For each directory:

for %f in (*.tif) do; tiff2pdf -o %~nf.pdf %f

Notice the “%~nf”? It’s replaced by the base name for the file. Therefore %~nf.pdf is replaced by map100.pdf when the TIFF file is map100.tif. That’s better but the new PDF files landed in the dame directory. A small change fixes that:

for %f in (*.tif) do; tiff2pdf -o \\SERVER\\share\%~nf.pdf %f

or if you have mapped a drive:

for %f in (*.tif) do; tiff2pdf -o X:\dir\%~nf.pdf %f

Those who are fluent in shell scripting need not comment, I’m talking to the Windows guys who have lived their entire existence by clicking somewhere.

So far so good but I have 300 directories. We could use the /D and /R parameters of the for command to recurse a directory but I wanted more control. The following does not work:

>for /r %f in (*.tif) do tiff2pdf -o .\pdfdir%~pf%~nf.pdf %f

Since the directory does not exist tiff2pdf can’t create the output file. So what now?

Scripting to the Rescue

In a perfect world we would have a good UNIX/Linux shell (bash for instance) on our Windows PCs. And we can, just install Cygwin or if you need only the bash shell (unlikely) it’s available for Windows individually.

But we do have scripting. Windows Script Host provides VBScript and Javascript. We can also download and install a number of other scripting languages including Perl, Python, and others.

A few years ago I found a little VBScript program named span.vbs that does just this. I used it for a few tasks over the following months but soon found that I needed more flexibility.

I find writing in VB and VBscript a problem. Once I get my brain used to a language (I code in Java and C# regularly) I find it hard to switch to a language syntactically different as VBscript. Therefore I converted the VBS code to JavaScript then made my improvements.

The result is spanbase.js. With this program I can batch process an entire directory of files.

cscript [path/to]spanbase.js "[Command] [parameters]" [Regex] [NewExt] [NewBaseDir]

Command: Command string to pass to command interpreter

Regex: Regular expression pattern to match filename (e.g. tif$)

!!!! Make sure to place quotes around the command and parameters !!!!

The following substitutions will be made before execution

@File - the current filename
@Ext - the current file extension
@Base - the basename of the current file
@Newfile - a filename compose of the basename + NewExt

NewExt: The new extension to use for the new file
NewBase: New Base Directory for new file, this will be prepended to the file path.

this will be appended to the basename of the original filename (e.g. t.jpg)

The solution

cscript C:\wsh\spanbase.js "tiff2pdf -o @Newfile @File" tif$ pdf MyPdfDir

Run this script from the topmost directory containing your tiff images (e.g. C:\tiff) the new PDF files will be placed in the directory C:\tiff\MyPdfDir and the file C:\tiff\spanbase.log will contain each directory entered as well as program output and program error messages.

How to Create a PDF File of a Map or Drawing

Publish your work in a PDF file

Adobe PDF (Portable Document Format) provides a convient means for others to view maps, drawings or other documents. Here's how it's done.

Use Adobe Distiller or another commercial program. or... Use the free PDF995 printer driver.

Note: Be sure to use the correct sheet / paper size to insure that line weights and text display correctly.

You may also wish to download and install pdfEdit995, a configuration tool for pdf995 that gives you additional control over the PDF995 printer driver.

How to Install ArcObjects Developer Sample Programs

The ArcObjects Developer Kit contains numerous ArcGIS utility commands and routines that may find very useful.

Installing the samples is not as easy as ESRI makes to appear. Here's the lowdown on how it's done.

Install the ArcObjects Developer Kit from the ArcGIS install CD if you haven't already done so.

Click Start->Programs>ArcGIS->ArcObjects Developer Help and locate the sample that you wish to install. Read the install instructions.

Locate the sample on your hard drive using Windows Explorer (not always an easy task). You can use Windows Find/Search to search for the directory or one of the files to make the task a little easier.

First - the easy way (if only commands are implemented)

Right click on any toolbar.

Select Customize...

Click "Add from File"

Select the dll file containing the command, e.g. C:/arcgis/arcexe83/ArcObjects Developer Kit/Samples/ArcMap/Map Production/TextStamper/TextStamper.dll

The command will be added to the Developer Samples category. Drag and drop the command to any toolbar.

The hard way - for samples that implement other categories (e.g command bars)

Open an MSDOS (CMD) window and CD to that directory.

COGO:

CD "C:/arcgis/arcexe83/ArcObjects Developer Kit/Samples/Editing/Coordinate Geometry"

Parcel Split and Combine Wizard:

CD "C:/arcgis/arcexe83/ArcObjects Developer Kit/Samples/Editing/Edit Commands/Parcel Split and Combine"

If a file named _INSTALL.BAT exists: Run it in the CMD window and note any error messages.

Note: many of the _INSTALL.BAT scripts assume that your windows directory is C:/WINNT. You may need to edit _INSTALL.BAT and replace C:/WINNT with C:/WINDOWS if you are running Windows 2000 or XP.

Re-run _INSTALL.BAT and again to be sure that there are no error messages. It doesn't hurt to run it more than once.

If a file named _INSTALL.BAT does NOT exist:

Register all DLLs in the directory e.g. regsvr32 parcelngprj.dll Run C:/arcgis/arcexe83/Bin/categories.exe (I suggest creating a shortcut in a convenient place if you wish to install several examples) Follow the instructions in the ArcObjects help for that sample and register the component(s) of the sample. Click on and highlight the category where the compent should be added (e.g. ESRI Mx Commands) Click the Add Object Button. Find the dll that you wish to register and click open. Select the component(s) that you wish to register.

To add a command to a toolbar:

Right click on any toolbar.

Select Customize...

Optionally click on the New button to create a new toolbar. Name it and select save in normal.mxt (so that it will be available to all of your ArcMap maps.

The new toolbar will appear.

Click the Commands tab.

Click Developer Samples in Categories

Drag and drop and command(s) to your toolbar VBA macros (subroutines having no parameters) an also be added to toolbars, they are listed in the macros category. I suggest storing your commonly used macros in normat.mxt (or your custom template) to make them available for all maps.

Using Google Maps in a Web Mapping Application

One of the most tedious parts of creating any web mapping application is the creation of the base map. The application map data is in many occasions relatively simple points or polygons. Maps are much more useful when we can see not only our map data but also rivers, streams, roads, and aerial photos on our map. Google Maps provides worldwide maps as well as aerial photos utilizing an easy to use interface. All that you need is a web browser and an internet connection. In addition Google provides an API where we can utilize these maps in our own mapping application. We can add our data to the Google maps in a number of forms:

  1. KML/KMZ - The data file format used by Google Earth. You can use points, polygons, as well as lines.
  2. Tab delimited or comma delimited text files - good for simple point data.
  3. A WMS (Web Mapping Server): a conventional web mapping server that delivers layer(s) in the WMS image format. I’ve used MapServer and ArcIMS for this purpose.

Google Maps Site Locator: (click to launch application)
Mountain CAD Site Locator

This application demonstrates the use of Google Maps as the base map overlaid from West Virginia State and county lines from a KML file and point locations from a tab delimited text file. It also demonstrates the addition of a user interface that allows users to select a site either by clicking on the marker symbol or the list links in the right column. Once a site is selected the location address is shown in a popup windows and one can then click a link to get driving directions.