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:
With this done, I could now use the dbfdump utility to convert the dBASE file:
I now had a fixed-width ASCII file that looked like this:
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.
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
Which returns all of the addresses where the street number is 222.