Posts Tagged ‘nad 83’

Shapefiles, Actionscript 3.0, and Google Maps (Box Shaped World)

Monday, June 8th, 2009

[Editor's note: Tutorial for using the vanrikom classes to read in shapefiles in Flash and Flex AS3 and display them on a Google Maps mashup.]

Republished from the Box Shaped World blog. 28 April 2009.

I’m working an Adobe AIR application and I wanted to be able to have the user select a shapefile, and then parse it to create a KML file.  I didn’t want to have the user be responsible for creating a KML file.  I thought I might try and crack the shapefile enigma since it is a well documented format, but that would have taken time and I suddenly realized I’m not actually a developer :).  Instead, I found this set of Actionscript Classes to parse a shapefile in Flash.  Unfortunately, I didn’t find a very good tutorial on how to work with the classes.  The example is a little confusing (at least for me) and also uses a far file.  I’d never heard of far compressed files.  So I took the classes and created my own parser.  I thought I would post a tutorial on how to use these shapefile classes in conjunction with AIR and the Google Maps API for flash.  This technique would work with flex as well, I just didn’t want to have to write the code to upload a file.  I presume a few things with this.  The shapefile you are using for this should already have a geographic projection (e.g. latitude and longitude Geographic NAD 83).  In order to use the Google Maps API with AIR, you need a URL with a key associated with it.  Below are two zipfiles available for download.  The testfile.zip is the shapefile I was using.  The vanrikom.zip is the downloaded actionscript classes from the Google Code repository.  I had trouble downloading the using an svn so I did it manually.  I’ll save you the time by making it available here…unless the original author asks me to remove them.  There are parts that I find confusing with the way the reader was set up.  For some reason polyline inherits from polygon.  Intuitively to me it should be the other way around…but like I said, I’m not a developer.

This was all done using FlashDevelop and the Flex SDK 3.  There are 4 custom classes in addition to the mxml file.  Each are shown here.

Continue reading at Box Shaped World . . .