Buy Now

Working with Shapefiles in MapViewer 6

Introduction

The shapefile is a common format for geographic data that you may encounter if you transfer information from other programs or download spatial data from the Internet. This article describes the shapefile format and shows how to best use a shapefile in MapViewer 6.

The Shapefile Format

The shapefile is a vector data storage format introduced by ESRI's ArcView program for storing the location, shape, and attributes of geographic features. What is called a shapefile is actually a set of files with the same name, but with different three-letter extensions. Most commonly, a shapefile will consist of the following three component files:

SHP
The SHP file contains the coordinates of the geographic objects, either points, or curves, or areas. A shapefile will contain only one type of object.
DBF
The DBF file is a database format that contains the attribute table for the objects - an identifier and any related data.
SHX
The SHX file is an index that permits direct access to the data for a particular object.

Additionally, you may sometimes see the following files extensions, none of which are used by MapViewer:

PRJ
The PRJ file contains information about the projection of the shapefile. This is an ASCII text file that can be view with Notepad or another text editor. You might want to look in this file to get the projection info.
SHP.XML
The SHP.XML file contains metadata about the shapefile.
SBN/SBX
The SBN and SBX files are spatial indices for read/write shapefiles.

Importing a Shapefile

Before importing a shapefile, there are two things that are important to know - what projection is it in and what field in the attribute table should be used for a primary ID.

There are several ways you might determine the projection, if you don't already know it. You could look in the PRJ or SHP.XLM files, if present. The PRJ file will have info about the projection and the SHP.XML file might have. If you downloaded the shapefile from the Internet, look on that web site for information (often called metadata) that describes the shapefile. If you can't find any information, you can take a guess that the shapefile is in unprojected lat/long coordinates - they often are - and hope for the best.

You may be able to tell from the metadata or accompanying documentation what attribute field to use for the ID. If not, it's best to first open the DBF file and examine its contents to determine what data it contains and what field is appropriate for an ID. Usually, you will want the ID field to contain unique values for each record.

The DBF file is an old format that dates back to DOS days. The DBF definition specifies that the file name be in the 8.3 format, with only 8 characters in the name portion. The DBF import filter that MapViewer uses enforces this restriction. If your DBF file has a name longer than 8 characters, you will need to rename it before you can open it in MapViewer. You will probably want to rename the SHP file to match.

Once your DBF file has a name of 8 characters or less, you can open it in MapViewer. Switch to a worksheet window with File | Worksheet and open it using the File | Open command.


DBF file

Examine the DBF file to determine what data
it contains and what field to use for the PID.

I note in this DBF that there are several possible choices for an ID field - CITIES, CITIES_ID, ID, or even NAME. I decide to use CITIES_ID for the PID. I also decide that I will load the NAME field as the SID, as that might be handy for labelling the features. The data file I want to use is POPULATION. I won't load it as an attribute, but will instead access it from the linked data file.

Now that I know what fields in the DBF I want to use as attributes, I am ready to import the features from the SHP file using these steps:

  1. I switch back to the map window and go to File | Import.
  2. In the Import Boundary File dialog, I choose the SHP file, make sure the Append image and Specify import options are checked and click Open.
  3. In the ESRI Shape Import Options dialog, I do not check Areas to Curves and I click OK.
  4. In the Import Options dialog, I specify the projection as Unprojected Lat/Long.
     
    Specify projection

    Set the projection to Unprojected Lat/Long.

  5. I switch to the ID and Limits tab of the Import Options dialog, choose to create the PID from the CITIES_ID field, create the SID from the NAME field, and not create the other attributes.
     
    Loading the attributes

    Create the PID from CITIES_ID and the SID from NAME.
    Do not create Attribute 1, Attribute 2, or the Hyperlink.

  6. Once the IDs are specified, I click OK and the geographic objects are imported from the shapefile.

Making a Thematic Map

At this point, I have a data file loaded (the DBF from when I opened it to examine its contents), and I have boundary objects (from importing the SHP file). The boundary objects have a PID that came from the data file. I have everything I need to make a thematic map!

Since I am working with point objects and want to display the population, I decide to make a symbol map by going to Map | Thematic Maps | Symbol Map. I specify the PID as Column D: CITIES_ID, to match the boundary objects, and choose Column G: POPULATION as the variable. I choose the symbol type, color and sizes I want and click OK to create the symbol map.


Symbol Map settings

Choose the same column for the PID as was used when importing the SHP file.


Symbol Map

A symbol map made from the SHP and DBF files.

Converting a Shapefile to GSB + XLS Format

If you have a shapefile that you expect to use more than once, it is usually best to convert it to formats that are more native to MapViewer and that provide additional capabilities. Boundary files in MapViewer are typically stored in GSB format and data files are usually XLS or DAT files. GSB files retain the projection info and the IDs will load automatically. XLS and DAT files do not have the 8.3 naming restriction and can be modified by MapViewer.

Converting a shapefile to these other formats is easy. Import the SHP file as shown above, specifying the projection and how the attributes should be loaded. Then, just use File | Export to save it to the GSB format. Open the DBF as demonstrated, and then use the File | Save As command to save it to XLS or DAT format.


Back to Newsletter Index

 

Home * Products * Gallery * Support * About Us * Register * Order * Demos * Sitemap