Making a Charlottetown Zoning Lookup

Since receiving a copy of the City of Charlottetown Zoning Map in digital form (as an ESRI shapefile), I’ve been thinking of various ways of using the data. An obvious one is to build a tool that allows a civic address to be entered and the current zoning designation to be returned; there’s no online tool that supports this sort of lookup right now (there’s this tool on the city’s website; it’s not pretty or particularly intuitive, but it will return the information), and, partly as a result, I think most city residents are ignorant of the zoning of their own property and those around them.

I decided that I wanted to build this as a standalone browser-based tool, which meant nothing on the server side (MySQL, PHP) would be required, and the tool wouldn’t need to rely on a data connection to be used, making it more suitable for mobile use. Here’s how I did it.

Convert the dBASE Database

The attribute data for ESRI shapefiles is stored in a dBASE-format database. To get this data out I needed a tool that would dump data out of dBASE files and into plain ASCII, and shapelib fit the bill. I downloaded the latest source code and then simply:

cd shapelib-1.3.0
make install

With this done, I could now use the dbfdump utility to convert the dBASE file:

wget -O City_Zoning_Apr-2012.dbf
dbfdump City_Zoning_Apr-2012.dbf > City_Zoning_Apr-2012.txt

I now had a fixed-width ASCII file that looked like this:

               PID        AREA_1   PERIMETER ZONING
134114.00000000000 1882636.72500 11146.96717 A
386524.00000000000  767652.65500  4243.97634 CDA
386128.00000000000  549478.99625  4015.56484 OS

Get the Civic Address Data

For the civic address data I was able to leverage some work I did many years ago that automates the download of the civic address data from the Province of PEI’s website, giving me a companion ASCII file, also containing the PID number, which I could then use to merge with the zoning information.

Merging Zoning with Civic Address

To ease the merging of the civic address and zoning data, I dump both datasets into SQLite3 tables; I chose SQLite3 because it’s pre-installed on my Mac and easily available otherwise.

Rolling all of the above and this together, I ended up with a PHP script to download and convert the civic address and zoning data, merge it together based on PID, and dump out the result to a JavaScript file. This JavaScript file looks like this:

var zoning = [{"pid":134023,
               "street_nm":"BRACKLEY POINT RD - RTE 15",

For each zoning designation that matches a civic address (there are 942 that don’t) this newly-defined zoning object holds information about the PID, the civic address and the zoning.

Making it Searchable

There are plenty of ways of searching through a JavaScript object; I opted for jSQL, a JavaScript library that offers some SQL-like features, allowing me to search for addresses in my zoning object as simply as this:

var db = new jSQL();
db.create('zoning',zoning).use('zoning');'*').where(function(o) {
    return (o.street_no == 222)
var data = db.listAll();

Which returns all of the addresses where the street number is 222.

I wrapped this all into a single HTML file (you can try the search out here at this live demo) that looks like this: