Simple shapefile drawing in ActionScript 3 (Cartogrammar)

Shapefile + magic = map in Flash!

[Editor's note: Andy Woodruff explains how to use his quick and easy implementation of Edwin van Rijkom's AS3 classes for loading SHP files and their DBF attributes into Flash/Flex. This library DOES NOT PROJECT your shp files, you might consider doing that first.]

Recently I’ve heard two friends independently inquire about some sort of basic guide for loading and drawing a shapefile in Flash. The only real tutorial/example I can recall is here, dealing with Google Maps. But these guys are looking for something more bare-bones. Being a regular user of Edwin van Rijkom’s invaluable code libraries for reading shapefiles, and usually forgetting the process myself, I thought it would be a good idea to put together a very simple set of AS3 classes that load a shapefile and throw a map on screen.

So to get those jerks off my back, I wrote a little thing called ShpMap, which supplements van Rijkom’s classes by loading and drawing a shapefile. It’s nothing fancier than that. Sometimes all you need is to get your base map on screen. (Update: just to round it out a little more, I’ve added basic loading and parsing of a shapefile’s accompanying DBF file, which contains attribute data. This also uses classes by van Rijkom.)

I hope that this class (and the several associated classes) can both be directly usable for some projects and serve as a basic guide to using van Rijkom’s classes to load shapefiles.

Dig it:

  • An example that loads and displays a US states shapefile (and then puts a square on my house and colors the state of Wisconsin green). View the source code here.
  • Download the source code. (My classes plus van Rijkom’s, as well as a demo US States shapefile.)

Tags: , , , , , , , , ,

2 Responses to “Simple shapefile drawing in ActionScript 3 (Cartogrammar)”

  1. Mark Geddes says:

    Hi Andy,

    Great stuff! I’m wondering if it’s possible to extend the functionality of your classes to export the graphics layer from a geoprocessing service as a shapefile. If your classes aren’t built for such work, any idea on how to do this? Thanks a bunch,

    Mark Geddes
    GIS Tech
    GeoNet Technologies Inc.

  2. Mark Geddes says:

    Hello again,

    FYI, I’m looking to do all this in the Flex Sample Viewer. Thanks,