If you spend any time working in oil and gas in this province then youâ€™re going to run into a situation where you need to put some stuff on a map. If youâ€™re like me that involves complaining about it on twitter
I don't know how I get myself into working with GIS data. I seriously have no idea.
â€” Simon Timms (@stimms) April 28, 2014
The problem is that GIS stuff is way harder than it looks on the surface. Maybe not timezone hard but still really hard. Most of it comes from the fact that we live on some sort of roughly spherical thing. If we live in flatland mapping would be trivial. As it stands we need to use crazy projections to map a 3D world onto a 2D piece of paper
There are literally hundreds of projections out there which stress different things. Add to that a variety of coordinate systems which can be layered on top of it. There is the latitude/longitude system with which weâ€™re all familiar but there are also a bunch of others. In Western CanadaÂ the important one is the Dominion Land Survey(well most of Western Canada, weâ€™ll get to that). The Dominion Land Survey was actually a series of surveys starting as far back as the 1870s. Bands of bearded men (there may have been bearded women too, everybody back then had beards) traveled around Canada plunking down lines to divide the land into 1sq mile sections called, well, sections. Why miles? Because of some guys calledÂ J. S. Dennis and William McDougall figured that a lot of people would be coming up from the states and would better understand miles. Thanks for screwing us over, again, with your stupid outdated measurement system, United States.
Anyway you can read a ton more about the system over atÂ wikipedia. The important thing to know is that Western Canada is divided into 6 mile by 6 mile blocks know as townships and that these are divided into 36 sections and each section is divided into 4 quarter sections. Sections can also be divided into 16 legal subdivisions commonly known as LSDs. The LSDsÂ are numbered in the stupidest way possible starting in the bottom right corner and counting up by going left and then up then pretending that weâ€™re a snake and just flipping back and forward
The company for which Iâ€™m working has most of its interests in Saskatchewan, Alberta and BC. I started with SaskatchewanÂ as I figured that I might as well get into thinking like a cartographer and working right to left straight off the bat(I hear that cartographers from Arabic countries work from left to right to maximize the confusion). The first step was to find some LSD data. Saskatchewan have an open data portal at Â http://opendatask.ca/data/Â which contains a link for LSD data. What you want in particular is theÂ SaskGrid2012. This file contains a lot of stuff but the four things you want are the various high level map structures: township, section, quarter section and legal sub division. We probably donâ€™t need quarter section as once we get to that level most people are interested in LSDs.Â Inside one of these zip files are a number of files which, as it turns out, are Esri shape files. Esri is a piece of GIS software. It is expensive. However there is a free alternative which has all the functionality we need along with 9000 pieces of functionality we donâ€™t:Â QGIS. If you download and install this software it will let you take a look at the shape files. You can add it by clicking on â€œAdd Vector Layerâ€ then pointing it at the .shp file.If you load the township file it will get you something which looks like very much likeÂ Saskatchewan. Whatâ€™s more is that if you click on the little identify featureÂ tool then on the map it will tell you the name of that township. Awesome!
For each township there are 36 section (6Ã—6) and for each section there are 16 (4Ã—4) LSDs. So for Saskatchewan there are something like 7000 townships, 250 000 section and a mind blowing 4 million LSDs. Â Quite a bit of data.
So now we have a map. But it only works inside of QGIS and Iâ€™m sure not going to go around supporting that. It would be really nice if this layer was available on a Google maps like thing.
Leaflet.js is a nifty library for manipulating maps. It can use any number of map backends but I usedÂ OpenStreeMap because it is awesome. Like really awesome. Start a new ASP.net project and then go and grab the latest leaflet from theirÂ site. Leaflet is in nuget but it is an older version which hasnâ€™t been updated for 6 months or so. Â Add the files to the site bundles in BundleConfig.cs. I also included my site files in this bundle for convenience
I created a typescript file for the home page based on the example on the lealflet home page
This can be used to select the intersecting polygons by doing
STIntersects will check the number of intersection points between the given polygon and the ones in the database. If there are any intersections then we have a match and we add that to the result set. Actually building the search area can be a pain as you actually build a geometry like so
This provides a set of data to return to the client.
Plotting the Data
Weâ€™re almost there, folks, thanks for staying with it. The last step is to get the returned data plotted on the map. This is simply done by adding the polygons to a multipolygon layer
Thatâ€™s it folks! You now have a map which looks like
The labels are a bit jaggedy right now as Iâ€™m just using the envelope center to calculate the position of the label. It doesnâ€™t take a whole lot to screw that up. Putting them in the top left corner helps with that a lot
P.S. I promised I would get back to BCâ€™s system. They donâ€™t use the DLS they use theÂ National Topographic System