Archive for April, 2012

April 18, 2012

Further Education (or, get yourself free university-level computing knowledge)

The notion of “Online distance learning” conjures up many different associations. The Open University, for example, is (rightly) regarded as a world-leading educational establishment, and has been offering distance-learning degree courses to students since 1971. OU Lectures, originally broadcast on BBC2 in the middle of the night, are now commonly distributed over the internet. At the other extreme, there’s the non-accredited American College of Holistic Nutrition – the institution from which disgraced TV nutritionist “Dr” Gillian McKeith claims to have received her PhD via the internet…

image

The first Open University lecture, broadcast on 3rd January 1971. Unusually, not hosted by a man with a beard.

Whereas the courses offered by the OU were always designed with distance-learning in mind, in recent years there has been growing momentum behind the idea of Open Courseware. Basically, this involves “regular” universities allowing their course materials to be downloaded by anyone over the internet, for free. And the idea has been taken up by some top-class (mostly American) institutions – M.I.T., Yale, and the University of Michigan, for example, offer a wide range of videos, downloadable lecture notes, and past exam questions that offer anybody access to the same material as if they were enrolled in that course in person. Click the links above to browse their course catalogues and learn something new today.

Whilst much of the OpenCourseware material is pretty amazing, it suffers from one problem, and that is that the courses are very one-directional. As an internet student, you sit and watch a pre-recorded hour long lecture video, but with no ability to interact with the lecturer. Although you can sit the exams, nobody will mark your paper (but you can get model answers and mark your own paper). And, even if you attend and “pass” all the required units, you won’t get any qualification at the end of it.

Or, will you?

Enter Udacity. Founded in January 2012 by Sebastian Thrun (Professor, Google Fellow, former director of the Stanford Artificial Intelligence Laboratory… amongst others), it offers free online computing courses. Where it differs from some Open Courseware courses is that the material has been explicitly designed to be studied over the internet. This means that the video clips are divided into nice short chunks, hosted on YouTube, and can easily be watched on a phone or tablet device, say. The Udacity courses use Python as their language of choice, but you don’t need to download any software to your computer – there’s an interactive, browser-hosted environment for you to write your code in. There’s a forum where you can discuss with other students enrolled on the course, and occasionally the lecturers will input there too. You don’t just sit and passively watch a video – there are plenty of interactive quizzes and homework assignments, and these are graded (albeit automatically). And, at the end of it all, you do get a certificate of completion of the course.

Sure, at the moment, a certificate from Udacity might not look so impressive as a degree from Stanford, but 5 years down the line I’m not so sure that will still be true. I’m enrolled on two courses at the moment, and I have to say that I think the quality of the material is fantastic.

If you have any interest in learning how to program, or learning to program better,  I highly recommend you look at the courses they have available – the introductory level 1 course requires no previous programming experience, while the level 3 courses include Applied Cryptography and how to build a robotic car.

image

These clever men want to teach you how to program. For free. Why not let them?

April 13, 2012

Gridding Geometries (or, “Creating patchwork animals in SQL Server”)

This is one of those things that I can’t imagine anybody would ever really want to do but, seeing as I haven’t posted anything for a while, I thought I’d write about it just in case it’s of use to someone…

First, suppose you had an arbitrary geometry. Here’s an example:

DECLARE @snake geometry = geometry::Parse('CIRCULARSTRING(0 0, 5 -5, 10 0, 15 5, 20 0, 25 -5, 29 -1)').STBuffer(2).STDifference(geometry::Parse('MULTIPOINT(28.5 -0.5, 29.75 -0.8)').STBuffer(0.6)).STUnion(geometry::Parse('MULTIPOINT(28.5 -0.5, 29.75 -0.8)').STBuffer(0.2)).STUnion(geometry::Parse('POLYGON((29.2 0.5, 29.5 2.7, 29.79 2.2, 30.22 2.75, 30 0.5, 29.2 0.5))'));
SELECT @snake;

In in the immortal words of Rolf Harris, “can you guess what it is yet?”.

Yes, that’s right – it’s a snake and it looks like this:

image

Now suppose that you wanted to divide that geometry up into a series of individual polygonal tiles on a regular-spaced grid. You could do so using the following T-SQL:

-- Determine the extent of the grid required to cover the geometry
DECLARE @grid geometry = @snake.STEnvelope();
DECLARE @gridwidth float = @grid.STPointN(3).STX - @grid.STPointN(1).STX;
DECLARE @gridheight float = @grid.STPointN(3).STY - @grid.STPointN(2).STY;

-- Work out the lower-left corner of the grid
DECLARE @xoffset float = @grid.STPointN(1).STX,
        @yoffset float = @grid.STPointN(1).STY;

-- Specify the number of columns and rows in the grid
DECLARE @numcolumns float = 80, @numrows float = 35;

-- Work out the height and width of each tile
DECLARE @cellwidth float = @gridwidth / @numcolumns;
DECLARE @cellheight float = @gridheight / @numrows;

-- Create a table variable to hold the tiles
DECLARE @gridcells table (id int, geom geometry)

-- Now, loop through and cut up the geometry into tiles
DECLARE @x int = 0, @y int = 0;
WHILE @y < @numrows
BEGIN
WHILE @x < @numcolumns
BEGIN
INSERT INTO @gridcells VALUES(
@y * @numcolumns + @x,
'POLYGON((' + cast(@xoffset + (@x * @cellwidth) AS varchar(32)) + ' ' + cast(@yoffset + (@y * @cellheight) AS varchar(32)) + ','
+ cast(@xoffset + ((@x + 1)  * @cellwidth) AS varchar(32)) + ' ' + cast(@yoffset + (@y * @cellheight) AS varchar(32)) + ','
+ cast(@xoffset + ((@x + 1)  * @cellwidth) AS varchar(32)) + ' ' + cast(@yoffset + ((@y + 1) * @cellheight) AS varchar(32)) + ','
+ cast(@xoffset + (@x * @cellwidth) AS varchar(32)) + ' ' + cast(@yoffset + ((@y + 1) * @cellheight) AS varchar(32)) + ','
+ cast(@xoffset + (@x * @cellwidth) AS varchar(32)) + ' ' + cast(@yoffset + (@y * @cellheight) AS varchar(32)) + '))'
)
SET @x = @x + 1;
END
SET @x = 0;
SET @y = @y + 1;
END

-- Finally, select the tiles from the table variable
SELECT geom.STIntersection(@snake) FROM @gridcells ORDER BY id;

My snake has now been chopped up into 800 little tiles, and here’s what the result looks like:

image

 

I wonder if this is how Elmer the Elephant was created?

image

Follow

Get every new post delivered to your Inbox.

Join 53 other followers