Extracting coordinates from single 60 bit hex numbers

Thanks to the wonderful people on Stackoverflow, I’m making some progress with figuring out how some geographic information is saved in a DB2 database that I’m working with.

it turns out that, rather than using the spatial functionality of DB2 (which would make sense, but considering the source of this database, I wouldn’t ask for too much), coordinate pairs are being stored as Morton codes in a 16-byte Character column.

So far, I’ve sorted out decoding the coordinate values, and can shuffle points predictably on my test map; now I’m just trying to figure out what grid that these coordinates are on. I’m fairly certain (not that I know anything about these things) that it’s somehow related to the MGA grid, because 0 east is at almost exactly 114°, which is where MGA zone 50 starts (the ‘almost’ comes from my point-and-click measurement technique).

But I don’t know where I’m going next; I’ll leave it till the morning.

* * *

My test code for this has been in PHP, and I needed something to convert big numbers between bases; hadn’t realised that the BC math library didn’t include base_convert(), so I found the one below.

/**
 * Convert an arbitrary-length number between arbitrary bases.
 * Copied, and very slightly translated, from
 * http://www.technischedaten.de/pmwiki2/pmwiki.php?n=Php.BaseConvert
 *
 * @param $value
 * @param $from_base
 * @param $to_base
 * @return string
 */
function bc_base_convert($value, $from_base, $to_base)
{
	$valid_digits = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
	if (min($from_base, $to_base) < 2)
	{
		trigger_error('Bad Format min: 2', E_USER_ERROR);
	}
	if (max($from_base, $to_base) > strlen($valid_digits))
	{
		trigger_error('Bad Format max: ' . strlen($valid_digits), E_USER_ERROR);
	}
	$dezi = '0';
	$level = 0;
	$result = '';
	$value = trim(strval($value), "\r\n\t +");
	$sign = ('-' === $value{0}) ? '-' : '';
	$value = ltrim($value, "-0");
	$len = strlen($value);
	for ($i = 0; $i < $len; $i++)
	{
		$wert = strpos($valid_digits, $value{$len - 1 - $i});
		if (FALSE === $wert)
		{
			trigger_error('Bad Char in input 1', E_USER_ERROR);
		}
		if ($wert >= $from_base)
		{
			trigger_error('Bad character in input 2', E_USER_ERROR);
		}
		$dezi = bcadd($dezi, bcmul(bcpow($from_base, $i), $wert));
	}
	if ($to_base == 10)
	{
		return $sign . $dezi; // Shortcut for base 10
	}
	while (1 !== bccomp(bcpow($to_base, $level++), $dezi));
	for ($i = $level - 2; $i >= 0; $i--)
	{
		$factor = bcpow($to_base, $i);
		$zahl = bcdiv($dezi, $factor, 0);
		$dezi = bcmod($dezi, $factor);
		$result .= $valid_digits{$zahl};
	}
	$result = empty($result) ? '0' : $result;
	return $sign . $result;
}

That on which the coding rests

Just to intersperse this stream of codeish posts with something a little more real

I rode part of the way to work today, and then put my bicycle on the bus for the remainder of the journey. (An odd feeling, looking through the bus’ windscreen and seeing my little bike all alone out there, bobbing up and down in the rush hour traffic; but I trust in these new yellow bike racks. Incidently, one of the recommendations from the Assembly’s inquiry into Action Buses was that passengers with bikes should travel for free — the argument being that putting the bike on the rack takes time, and so in order to keep the bus on schedule the putting of your card in the slot should be done away with. Hear hear!) Then at lunch time (oh, that sweet half of an hour!) I went and sat under one of my usual trees and sewed a button back on to a shirt. I’d planned to bring the real shirt that I’m actually sewing at the moment (completely by hand, I might add; no machine at all) but at the last minute thought this button would do. It wasn’t nearly enough: days like this were made for lounging under trees, enjoying the incrediblely beautiful calls of the birds above, and picking away at some little embroidery or other. Being quiet and being present, and certainly not locking one’s self up in an air-conditioned high-rise.

Bring on the recession, I must concur with Mr. Monbiot! Because (and I must appologise for the cliché) the Really Important Things have got nothing whatsoever to do with Economic Growth! But what I do, all this coding, is (it seems) very dependent upon this Growth, and so now I am sad…

Dispatches

I’ve just discovered the ABC’s blogs (blogs.abc.net.au) and I quite like what I’ve read so far. Maybe it’s just the idea of far-away correspondents filing these ‘letters home’ that appeals. A chap with a laptop (I’d like to think he’d be writing in longhand, on some favorite brand of Australian notepaper, but I realise the anachronism in that; he ain’t Bill Deedes) stopping his rental car by the side of a dirt road and pondering the economic future of the place he’s in, with Australian readers in mind. Postcards home, from people I’ll never know. (How odd the world is.)

I pulled up this editing window because I had to write something: I’ve been sitting here all afternoon slumping lower and lower in my chair, trying to focus on the magical world of Tivoli Storage Management Concepts. So magical. So engaging. Yes.

Oh, God, let me out of here! I really don’t know how I will manage being in this office over the remainder of this year, as the weather warms up, and all I want to do is stroll around enjoying spring! I’m not convinced of Tivoli’s ability to save me…

I’d thought to write no more on this blog, at least while employed at IBM. That being all day long at a computer would deter me from using a computer to express anything of myself — but that doesn’t work: sitting at this computer all day without using it to express something at least slightly human, has just dragged me down into a sort of mind-numbing ‘droid-like state, from which nothing looks worthwhile or interesting. Can’t have that. So I’ll keep spilling these poorly-thought-out thoughts onto this blog (in the fairly sure knowledge that very, very few people will ever read them).

Fake World DOES Contain Humans

All has gone well, since my last post, with my intra-office carlessness. My announcement (“I don’t go in cars; don’t ask me to.”) has been met with near universal acceptance (or silence), to my great relief. I had wondered whether the conversations in the tea-room about various cars’ power-ratings and other such motorcar trivia would mean some expression of distain towards one who rejects all that. But no, nothing has come of it. They’re nice chaps, and I needn’t have worried.

So, with that bit of excitement out of the way, I’m left pondering the far-off hills and wishing that I could be in the workshop, at my bench, and writing in ink and not at a keyboard. The computer-reality is basically two-dimensional: we, the IT people, strive to make everything the same. Documents can never show age; photos must be as bright forever as they day they were taken; we care only for content, and never for context or media. A rotten state of affairs! I want my pages to yellow and my photos to fade! A world in which nothing is old gives us nothing at all — despite what Wikipedia would have us believe.

But I wont go on about that. I can’t bear to think about it, not here, in this place.

This office has begun to pall my spirits, now the novelties of The Commute and Being A Man have worn thin. I just want to run! (Well, run for a little ways, and then sit and sew my shirt, or write in my Moleskine…). I can’t dream about my workshop.

From mud-and-straw to IBM

The chickenhouse must get finished! The chooks are growing up, and they’re in the shed with a little light to keep them warm — but we’ve got such a lovely house planned for them, and we just must finish it! It’s at the bottom of the garden, with two runs (summer and winter; nothing but the best for our chooks y’know), and is built (well, being built, at any rate) of mud and straw. I’ll post some photos soon, when Luke’s home and I can plug his camera in.

So it really needs to be finished soon… they’re growing up, and I’m starting full-time work in a week. No more dreaming idle days away for me, no Sir! No more getting up at nine thirty and spending an hour wandering what to have for breakfast (before breaking fast on exactly what I had the day before, it must be said): I am, as of next Monday, to be counted amongst those many souls employed by the International Business Machine (and I mean that in both senses: IBM, and the military-industrial complex).

It’s a far-flung thing, this job. Far in the south, in Tuggeranong, where I’d never been till the IBM interview. But on the bus each morning I’ll get, and shine my shoes and iron my shirts, and yes indeed, I’ll be a Good Little Geek, earning a crust and logging life (more on that latter, later).

Yet again, the Great Divide

Often, when I’m sitting in a lecture about concurrency, say, or sketching a possible design for some program, I actively love the fountain pen that I’m using at these times. Engaging with I.T., I find such great comfort in using such an old and ‘outdated’ technology. I usuallly don’t find this particularly interesting, becuase it seems to be a sensible reaction to being surrounded by and immersed in Modern Technology (oooh!). However, I’m blogging about this today becuase I’ve come back to a feeling that I was quite used to at one point a few years ago, at art school: I want out of all this computing, I want to get away from it all and not have my head spinning painfully with the unbearable complexity of it all. I want to get back to the workbench, and I want to blog about what I do there.

It seems that I can’t walk the line. I fall to one side of it, only to take pleasure in using the tools of the other side. I say I want to be completely with one branch of the dichotomy — technology these days — but can’t do so without yearning for the other. It rips me apart. I just wonder whether the divide is less consuming from one side or the other.

What I was going to say was that I want to get back to a workbench, and keep a journal of my work, probably on the web. Maybe even that I want to go and make furniture with my dad in WA, who knows?

In fact, fuck this!! I don’t want to be miserable about this! That’s not why I sat down to write. It’s too jolly cold here, that’s the problem, and I haven’t had my customary tipple of sherry yet.

I want to go home. I want to live with my friends in a nice house, and go to work in a furniture workshop with my dad. I’ve been away too long.

What’s the point?

Oh weary thing! Oh listless drudgery! Oh the stupid work we make for ourselves!! Oh!…

Here I sit, on a cool spring morning, with nothing at all to worry about; I am happy. So why-oh-why-oh-why should I sit down to work at some sloppy, good-for-nothing code that purports to “record, display and analyze genealogical data”?! Why?! This world certainly does not need me to be spending my time in meaningless work that helps no-one. Programming feels at times as though we’re just making up work for ourselves, work that doesn’t — in the Great Scheme Of Things — actually need to be done. Growing food, building houses, having sex, talking to old people: these are fundamental to living. Building Drupal modules is not.

It must be said also, that blogging is not. So I’ll stop now. I do not really think that I was making much sense anyway; sorry.