Map places, people, and relationships inside a building with open source software

Meld buildings' directories and maps of their interiors to create ad-hoc maps of people, meeting spaces, and other assets

Google and MapQuest do a great job of creating maps of the outside world on the fly. But what about our workspaces? This article shows how to define and map places and people inside a building. Search, track, and plot individual cubicles, rooms, employees, or assets. Graph the location of individuals or groups of employees based on job function, or track unused office space visually.


Nathan Harrington, Programmer, EMC

Nathan Harrington is a programmer at IBM currently working with Linux and resource-locating technologies.

14 August 2007

Also available in Russian

The big names in geolocation have tools for mapping large-scale structures with near global coverage. Google, Yahoo! and Microsoft® all have mapping tools that brilliantly execute the delivery of cartographic data for land, borders, highways, and buildings. Moving inside the buildings to precisely locate rooms, people, and other trackable data is the focus of this article. Using The Gimp image-mapper plug-in, we'll define coordinates around trackable areas. Using simple text matching and ImageMagick annotation tools, we'll create maps of the interiors of buildings, showing useful information about content and relationships within a building.


Any modern PC manufactured after 2000 should provide plenty of horsepower for compiling and running the code in this article. If your building blueprint graphic is very large or you intend to map an enormous quantity of data points, you may require the latest multicore processor and several gigabytes of RAM. The typical computer used by developers reading this article should provide enough CPU cycles and memory to map a typical office environment in two shakes of a lamb's tail.

The ImageMagick tool suite, Perl, and The Gimp photo image-manipulation package are all required. Each are available for Windows®, Mac OS X, and various flavors of UNIX®, including Linux® (see Resources). You'll also need a simple and fast image viewer, which is usually bundled with modern desktop environments. For Linux users, I recommend feh, which was written by Tom Gilbert. Any image viewer will do, however.

The example code was written with a Linux environment in mind. However, with minor adjustments, it will operate on Mac OS X and Windows. This is an exercise we leave to the reader.

Building map image acquisition and defining coordinates

Finding a building image

The first step in creating a useful map of the interior of your building is to define coordinates around the interior structures. An easy way to do this is to use a blueprint image of the building itself. If you can't find a local site operations group that can provide a CAD image of the building, try taking a digital image of the building map diagrams posted near the entrances of your building. If a pre-rendered map of the building is unavailable, you can even sketch a diagram by hand and use that as your basis for a coordinate system. The building mapped as part of the example code in this article had an easily accessible CAD file, so I loaded it in a free CAD viewer program, and took a screen capture to acquire the building blueprint.

Defining areas with The Gimp

One of the easiest methods to define points or bounded shapes in a 2-D image is with The Gimp's ImageMap plug-in. Open your blueprint image in The Gimp, and select the Filters > Web > ImageMap option from the menubar. With the ImageMap tool, assigning identifiers to individual pixels in the image is as easy as specifying a rectangle in the appropriate area and entering a unique string in the input box that pops up. Figure 1 shows the ImageMap plug-in tool in action. Notice how you can create squares, polygons, and circles with names of your choice in the URL field. Using the ImageMap plug-in is a fast way to enter data about a pixel or area of pixels. You simply double-click on the image to define a shape, enter the identifying text, and press Enter. This technique will allow you to create coordinate maps of your building blueprint rapidly.

Figure 1. Building map blueprint
Building map blueprint

Extracting the coordinates and identifiers

After saving the created image map in The Gimp's ImageMap plug-in window, you'll have a file like that shown below.

Listing 1. Image map file
<img src="buildingMap1.png" width="570" height="666" border="0" usemap="#map" />

<map name="map">
<!-- #$-:Image Map file created by GIMP Imagemap Plugin -->
<!-- #$-:GIMP Imagemap Plugin by Maurits Rijk -->
<!-- #$-:Please do not edit lines starting with "#$" -->
<!-- #$VERSION:2.0 -->
<!-- #$AUTHOR:Unknown -->
<area shape="rect" coords="506,596,516,606" href="0a" />
<area shape="rect" coords="133,573,143,583" href="1a" />
<area shape="rect" coords="82,203,92,213" href="2a" />
<area shape="rect" coords="490,116,500,126" href="3a" />
<area shape="rect" coords="68,45,78,55" href="conference_room0" />
<area shape="rect" coords="188,131,198,141" href="conference_room1" />
<area shape="rect" coords="420,16,430,26" href="4b" />

For simplicity, we'll extract just the relevant coordinate and identifier portions with the one-liner shown below.

grep oo map |perl -lane 's/(coords|href|=|")//g;@F=split;print"@F[2,3]"'>coords

This command will change the default image map file into a format that's easier to use and redirect the output to the coords file. Listing 2 shows the example coords file.

Listing 2. Example coords file
506,596,516,606 0a
133,573,143,583 1a
82,203,92,213 2a
490,116,500,126 3a
68,45,78,55 conference_room0
188,131,198,141 conference_room1
420,16,430,26 4b

Now that the locations in the building are defined, data that specifies who or what is at a location needs to be built. In our organization, that means accessing the enterprise directory and performing a query to find all employees with a defined location in a particular building. Other areas of location occupancy data can be acquired from conference room reservation systems, as well as site planning and emergency planning databases. Listing 3 shows an example data file with individual names and assigned locations in the building.

Listing 3. Example nmLst name listing file
Franco 1a
Cliff 0a
Larry conference_room0
Melanie 2a
Michael 4b
Paul 7c.1
Chris conference_room1
Jeffrey 5b
Lisa 3a
Dave 7c.2

Note that this is a simplified example for development's sake. You can specify any number of identifiers in the name listing file. Define multiple people within the same cubicle, search by job title, number of years with the company, etc. Now we have a coordinates/office file and an attributes/office file. Let's combine the two with some shape identifiers to begin our image generation.

For this example, everyone with an "el" in their name will be drawn with a rectangle, and everyone with "is" in their name will be drawn with a circle. Use the commands as shown below for simple lookups based on their name attributes.

perl -ane 'if(/el/){print "rectangle " . `grep " $F[1]" coords`}' nmLst >  dots
perl -ane 'if(/is/){print "circle " . `grep " $F[1]" coords`}'    nmLst >> dots

The output stored in the dots file will look like that shown below. Although we are using one-liners and text files to generate our coordinates with attributes file, the general approach is applicable to any method of assigning and storing coordinate information. For example, you can store names and asset serial numbers in a DB2® database, and assign coordinates with assets in a separate table. Select the contents of both tables with a join and you can produce a shape and coordinate file like that shown below.

Listing 4. Example dots shape and coordinate file
rectangle 82,203,92,213 2a
rectangle 490,116,500,126 4b
circle 188,131,198,141 conference_room1
circle 420,16,430,26 3a

Creating a building interior map image

While the dots file provides basic shape and coordinate information, we need to use ImageMagick to draw the identifiers on the building blueprint image. In our first example, will draw red rectangles and green circles alpha-blended onto the image at the specified coordinates. Run the program with the command cat dots | perl buildingMap1.png output.png. Figure 2 shows an example output of the program.

Figure 2. Example building with mapped locations
Example building with mapped locations

Before we continue with a description of the program and further examples, some words are required about the rendering approach chosen for this implementation. There appears to be some limitation with both the C and Perl APIs to the gd package. No matter the options selected or the parameters specified, drawing an alpha-blended circle does not appear to be possible. The simplest method of removing this limitation is to draw all the geographic primitives on the command line using ImageMagick's convert command. The program simply builds a long chain of ImageMagick convert commands to be executed, and runs the commands in chunks to produce the desired output. program

The Perl commands comprising the program are shown below. The first task is to check for proper usage, followed by the definition of the variables used in the program. With a while loop set up to read from stdin, the various components of the dots file are extracted. For this example, only the first coordinate pair from the dots file is used to build the various drawing commands. For example, when drawing a circle, create decreasing radius and alpha-blended circles around the main point for a nice fade-out effect. After the alpha-blended draw command shapes have been created, check if the command buffer is approaching full and if so, run that portion of the command. Again, this iterative approach of building large convert syntax drawing commands is to get around a limitation (at writing time at least) of the GD C and Perl APIs not being able to draw alpha-blended circles.

Listing 5. part 1
#!/usr/bin/perl -w
# - build ImageMagick draw commands for building interiors
use strict;
die "usage: cat dots_file | input output" unless @ARGV==2;
my $lineCount = 1;    # line count for ImageMagick cmd
my ($inFile, $outFile) = @ARGV; # input, output files
my $cmd = qq( convert );

  my($type, $loc, $key) = split;
  my( $x, $y ) = split ",", $loc;
  my $count = 1;

  # building the ImageMagick draw commands
  while( $count < 10 )
    my $alpha = 255 - (20 * $count);  # decrease the alpha blending by 20 each pass
    if( $type =~ /circle/ )
      my $stopX = $x + (10 - $count);
      my $stopY = $y + (10 - $count);
$cmd .= qq( -fill "rgba(100,200,70,$alpha)" -draw 'circle $x,$y, $stopX,$stopY'  \\\n);
      my $tempX = ($x - 10) + $count;
      my $tempY = ($y - 10) + $count;
      my $stopX = ($x + 20) - $count;
      my $stopY = ($y + 20) - $count;
$cmd .= qq( -fill "rgba(200,100,50,$alpha)" 
-draw 'rectangle $tempX,$tempY, $stopX,$stopY' \\\n);
  }#while each 10 area

  # run the command in pieces 
  if( $lineCount % 50 == 0 )
    $cmd .= qq( $inFile $outFile );
    $cmd = `$cmd`;
    $inFile = "$outFile";
    $cmd = qq( convert );
  }#if command big enough to be executed


}#while stdin

$cmd .= qq( $inFile $outFile );
$cmd = `$cmd`;

Further examples

A common request where I work is visitors asking for the location of a conference room so that they know the closest place to park. To prevent your fellow colleagues from parking on the wrong side of the building and taking a long walk, consider the following command: cat dots | perl withParking_buildingMap1.png output.png. In this case, The Gimp was employed again to create an image with the former example blueprint image overlaid on overhead imagery of the facility. Figure 3 shows an example of what this can look like. Since the location of the various rooms in the building have already been defined, it's a very simple process to modify the program to show the location of managers in red and programmers in blue. Listing 6 shows the changes to the shape placement coordinates in

Listing 6. changes
  my($type, $loc, $key) = split;
  my( $x, $y ) = split ",", $loc;
  my $count = 1;
  $x += 85; #shift right 85
  $y += 90; #shift down 90
Figure 3. Example building with mapped locations and overhead imagery
Example building with mapped locations and overhead imagery


With these techniques, you now have the capability of utilizing the full power of ImageMagick for your building interior mapping needs. In our organization, providing the location of conference rooms ahead of time to business travelers increases efficiency and reduces aggravation. Site planners and resource managers will certainly benefit from custom interior plotting tools to help them visualize the usage of their buildings without expensive third-party software.


Sample scriptsos-gimpmap.buildingMap_01.zip918KB



  • Learn more about and download, The Gimp image manipulation software. Available for download for Windows, Mac OS X, and many flavors of UNIX.
  • ImageMagick is a software suite to create, edit, and compose bitmap images. Available for download for Windows, Mac OS X, and many flavors of UNIX.
  • If your system doesn't have Perl, grab it from This site also contains a wealth of knowledge about Perl. Available for download for Windows, Mac OS X, and many flavors of UNIX.
  • feh is a fast, lightweight image viewer for Linux.
  • To listen to interesting interviews and discussions for software developers, check out developerWorks podcasts.
  • Stay current with developerWorks' Technical events and webcasts.
  • Watch and learn about IBM and open source technologies and product functions with the no-cost developerWorks On demand demos.
  • Check out upcoming conferences, trade shows, webcasts, and other Events around the world that are of interest to IBM open source developers.
  • Visit the developerWorks Open source zone for extensive how-to information, tools, and project updates to help you develop with open source technologies and use them with IBM's products.

Get products and technologies

  • Download IBM product evaluation versions, and get your hands on application development tools and middleware products from DB2®, Lotus®, Rational®, Tivoli®, and WebSphere®.
  • Innovate your next open source development project with IBM trial software, available for download or on DVD.



developerWorks: Sign in

Required fields are indicated with an asterisk (*).

Need an IBM ID?
Forgot your IBM ID?

Forgot your password?
Change your password

By clicking Submit, you agree to the developerWorks terms of use.


The first time you sign into developerWorks, a profile is created for you. Information in your profile (your name, country/region, and company name) is displayed to the public and will accompany any content you post, unless you opt to hide your company name. You may update your IBM account at any time.

All information submitted is secure.

Choose your display name

The first time you sign in to developerWorks, a profile is created for you, so you need to choose a display name. Your display name accompanies the content you post on developerWorks.

Please choose a display name between 3-31 characters. Your display name must be unique in the developerWorks community and should not be your email address for privacy reasons.

Required fields are indicated with an asterisk (*).

(Must be between 3 – 31 characters.)

By clicking Submit, you agree to the developerWorks terms of use.


All information submitted is secure.

Dig deeper into Open source on developerWorks

Zone=Open source
ArticleTitle=Map places, people, and relationships inside a building with open source software