Vector Shapes on Bing Maps

In addition to their obvious functional purpose, maps can be objects of great aesthetic beauty. On my bookshelf I have a book (The Map Book, by Peter Barber) full of beautiful illustrations of maps throughout history, such as these:

image image
image image

Perhaps it is unreasonable to compare a simple web-mapping tool such as Bing Maps to the art of a master cartographer, but one thing is certain; namely, this is not beautiful:

image

I try to convince myself that Microsoft chose these horrible default colours so that people would look at them, think “My God – those colours are awful – I must change them!”, and then look up how to set the FillColor, StrokeColor, and StrokeThickness properties of the Microsoft.Maps.Polygon object, but in practice this doesn’t always happen. Every time I see a default-coloured polygon like that above, I’m sure Marinus of Tyre must turn in his grave.

But it doesn’t have to be like this. Applying some simple style rules to change the fill and stroke properties can have a dramatic improvement on the appearance of your map. As an example, I took around 3,000 features from the OS Vector Map dataset in an area around Norwich and plotted them on Bing Maps as polylines and polygons. Every element contained an additional feature code property, which described the type of feature using the same numbering system as with the Ordnance Survey’s own dataset. For example, feature code 25710 is a motorway; code 25999 is an area of woodland, and 25301 is a single-track railway.

Then I created a set of “stylesheets” – simple arrays of different Microsoft.Maps.Color values that should be applied to features based on their type. For example:

[php]
var style1 = {
// Building
25014: {
strokeColour: new Microsoft.Maps.Color(alpha, 126, 119, 98),
strokeWidth: 1,
fillColour: new Microsoft.Maps.Color(alpha, 232, 214, 176)
},
// Glasshouse
25013: {
strokeColour: new Microsoft.Maps.Color(alpha, 232, 214, 176),
strokeWidth: 1,
fillColour: new Microsoft.Maps.Color(alpha, 255, 255, 255)
},
// Electricity Transmission Line
25102: {
strokeColour: new Microsoft.Maps.Color(alpha, 158, 170, 158),
strokeWidth: 1
},

}

[/php]

And finally, a simple function that looped through the elements on the map and applied the correct “style” to each element based on its feature code, using the setOptions() method. The results are shown below, or you can try a live demo here.

image
Default
image
Style 1
image
Style 2
image
Black and White
image
Random (very Mondrian-esque, I think!)

The Changes in Bing Maps

 

Microsoft have made some changes to the look and feel of the http://www.bing.com.maps site. So, it’s out with the old:

image

And in with the new:

image

The compass and zoom buttons are now overlaid as buttons on the map image rather than being in the toolbar header, and have been placed on the right hand side and made more prominent.

The breadcrumb trail has also been moved onto the map display itself, with a prominent target icon (displaying “World” in the screenshot above).

The streetside guy is still in the header although still doesn’t do anything yet (not if you’re in Europe, anyway).

However, the most interesting change for me is that the map styles themselves have been split into two separate dropdown categories – “road style” maps (Road, Ordnance Survey, Collins Bartholomew) and “aerial style” maps (Birds’ eye, Aerial). What’s more, the “show angled view” checkbox is gone, and the aerial map styles have reverted to their old names of aerial (for the top down imagery) and bird’s eye (for the oblique imagery).

This I think is a major improvement, and one which I hope feeds through into the Bing Maps AJAX v7 control soon. The problems with the old naming used on bing.com/maps (and still used the API) are many:

Firstly, there is terminology – when users say “birdseye” what they mean is the oblique, low level photographic imagery. They don’t say “birdseye angled” and “birdseye not angled” to refer to top down aerial imagery. This makes it hard to establish exactly what mode is being referred to.

Then, there are legal issues. In Microsoft’s own terms of use, there are specific restrictions placed on the use of “bird’s eye imagery” – http://www.microsoft.com/maps/product/terms.html – but what they really mean is “birdseye angled view” (i.e. true birdseye), not what you get when you just click the “birdseye” button, which gives you aerial view unless you checked the angled view button.

There are also technical differences – you can’t display custom tile layers over birdseye angled views, whereas you can display them over birdseye non-angled views (i.e. aerial) for example.

Birdseye and Aerial are two different map styles so it’s good to see they are being treated, and named as such on bing.com (as they always used to be!). So, when are these changes coming to the AJAX API?

OGR2OGR Importing Spatial Data to SQL Server

A few months back, I posted an article explaining how to import spatial data into SQL Server 2008 from any format supported by the OGR library (including ESRI shapefiles, GML, and TIGER data), using OGR2OGR. That article was written using OGR2OGR from v1.7 of the GDAL 1.7 library, which doesn’t support SQL Server 2008 directly, so I instead used OGR2OGR to create a CSV file containing spatial data in Well-Known Text format and then parsed that data in SQL Server using the STGeomFromText() method.

The good news is that things have become a bit easier since then, and version 1.8 of the GDAL library now has a MSSQLSpatial driver that can interface directly with geometry and geography data in SQL Server 2008.

The bad news is that most of the places that offer pre-compiled GDAL binaries for Windows have yet to update to the new version. FWTools, for example, still comes packaged only with v1.7. Likewise, the osgeo download site at http://download.osgeo.org/gdal/win32/ also lists GDAL versions up to v1.7.

So, if you want to get hold of the latest GDAL to import directly into SQL Server you’ll have to build it yourself from source, which can be downloaded from http://download.osgeo.org/gdal/gdal180.zip

Fortunately, the source has been very considerately packaged, and includes solution files that will build GDAL out-of-the-box in VS2005, 2008, and 2010. Simply load the .sln file, click build, and wait a few minutes:

Building GDAL 1.8 in VS2010

Then, if you look in the output directory (warmerdabldbin, by default) you should see a lovely collection of utilities for working with spatial data – GDAL (for working with raster data), and OGR (for its vector sibling).

Here’s the output of calling ogr2ogr –formats, which retrieves the list of supported vector spatial formats – note the MSSQLSpatial format supported for both read/write:

image

Example usage to load a shapefile to SQL Server as follows:

[php]
ogr2ogr -overwrite -f MSSQLSpatial "MSSQL:server=.\MSSQLSERVER2008;database=spatial;trusted_connection=yes" "TG20.shp"
[/php]