The Daily Parker

Politics, Weather, Photography, and the Dog

Chaining LINQ predicates

I've spent a good bit of free time lately working on migrating Weather Now to Azure. Part of this includes rewriting its Gazetteer, or catalog of places that it uses to find weather stations for users. For this version I'm using Entity Framework 5.0, which in turn allows me to use LINQ extensively.

I always try to avoid duplicating code, and I always try to write sufficient unit tests to prevent (and fix) any coding errors I make. (I also use ReSharper and Visual Studio Code Analysis to keep me honest.)

There are two methods in the Gazetteer's PlaceFinder class that search for places by distance. The prototypes are:

public static IEnumerable FindNearby(ILocatable center, Length radius)

and:

public static IEnumerable FindNearby(ILocatable center, Length radius, Expression<Func<Place, bool>> predicate)

But in order for the first method to work, it has to create a predicate of its own to draw a box around the center location. (The ILocatable interface requires Latitude and Longitude. Length is a class in the Inner Drive Extensible Architecture representing a measurable two-dimensional distance.) So in order for the second method to work, it has to chain predicates.

Fortunately, I found Joe and Ben Albahari's library of LINQ extensions. Here's the second method:

public static IEnumerable<PlaceDistance> FindNearby(
	ILocatable center,
	Length radius,
	Expression<Func<Place, bool>> predicate)
{
	var searchPredicate = 
		SearchDistancePredicate(center, radius)
		.And(predicate);

	var places = Find(searchPredicate);

	return SearchDistanceResults(places, center, radius);
}

This allows me to use a single Find method that takes a predicate, engages a retry policy, and returns exactly what I'm looking for. And it allows me to do this, which just blows my mind:

var results = PlaceFinder.FindNearby(TestNode, TestRadius, p => p.Feature.Name == "airport");

Compared with the way Weather Now works under the hood right now, and how much coding the existing code took to achieve the same results, I'm just stunned. And it will make migrating Weather Now a lot easier.

How Google builds its maps

This month's Atlantic explains:

"So you want to make a map," [former NASA engineer Michael] Weiss-Malik tells me as we sit down in front of a massive monitor. "There are a couple of steps. You acquire data through partners. You do a bunch of engineering on that data to get it into the right format and conflate it with other sources of data, and then you do a bunch of operations, which is what this tool is about, to hand massage the data. And out the other end pops something that is higher quality than the sum of its parts."

The sheer amount of human effort that goes into Google's maps is just mind-boggling. Every road that you see slightly askew in the top image has been hand-massaged by a human. The most telling moment for me came when we looked at couple of the several thousand user reports of problems with Google Maps that come in every day. The Geo team tries to address the majority of fixable problems within minutes. One complaint reported that Google did not show a new roundabout that had been built in a rural part of the country. The satellite imagery did not show the change, but a Street View car had recently driven down the street and its tracks showed the new road perfectly.

I've always been a map geek (which drove my Weather Now demo/application). The idea that Google will have a complete digital map of the entire world, and will presumably continue to maintain this map over the next several decades, warms my geeky heart. I wish some of this data had existed 50 years ago—or, alternately, that Google can integrate some of the existing photos and maps from earlier eras.

More Google Earth imagery released

They just launched high-resolution aerial photos of another batch of cities:

Improving the availability of more high quality imagery is one of the many ways we’re continuing to bring you the most comprehensive and accurate maps of the world. In this month’s update, you’ll find another extensive refresh to our high resolution aerial and satellite imagery (viewable in both Google Maps and Google Earth), as well as new 45 degree imagery in Google Maps spanning 30 new cities.

Google Maps and Earth now feature updated aerial imagery for more than 20 locations, and updated satellite imagery for more than 60 regions. Here are a few interesting locations included in our latest release.

Below is imagery of Mecca, Saudi Arabia where each year more than 15 million Muslims visit this important religious site. Here you can see Abraj Al Bait, one of the world largest clock towers, visible even from space!

Pretty soon they'll have photos of every square meter of the planet—at 10-cm resolution. I find it both really cool and really creepy. As long as they don't have near-real-time photos...

Grant me the serenity

Via Sullivan, artist Heather Dewey-Hagborg is creating 3D portraits from random hairs:

Collecting hairs she finds in random public places – bathrooms, libraries, and subway seats – she uses a battery of newly developing technologies to create physical, life-sized portraits of the owners of these hairs. You can see the portrait she’s made from her own hair in the photo below. While the actual likeness is a point of contention, these images bring about some creepy-yet-amazing comments; on genetic identity (how much of “you” really resides in your DNA?); on the possibilities of surveillance (what if your jealous partner started making portraits from hairs they found around your house?); and on the subjectivity inherent in working with “hard” data and computer systems (how much of a role do human assumptions play in this machine made portrait?).

The artist's site is here.

All right. This came a little sooner than I expected, and from a different source. I've long recognize the necessity of adapting to, rather than raging impotently against, the fundamental changes to the security and privacy mores we've had for several thousand years. (As Bruce Schneier has pointed out, "Fifteen years ago, [CCTV cameras] weren't everywhere. Fifteen years from now, they'll be so small we won't be able to see them.") But this project, if it works as hoped, actually freaks me out a little.

I'm going to whistle past this graveyard for the time being...

Google Maps goes inside

I don't know how extensive this is, but Google Maps street view now goes inside buildings:

To see this for yourself, go on Google Maps to 1028 W Diversey Pkwy, Chicago, 60614. Click on the balloon over Paddy Long's Pub, and click Street View. Notice the double chevron pointing toward the sidewalk:

Click that. And then explore.

I can only weep that we didn't have this kind of data throughout history to see how people lived in the past. And I can only weep for what this will do to privacy.

Update: It looks like they mostly have bars and pubs, including Tommy Nevin's, where Parker spent much of his puppyhood.

Whither Lorem Ipsum?

Jeff Atwood has the definitive explanation:

["Lorem ipsum"] is arbitrarily rearranged and not quite coherent Latin, extracted from a book Cicero wrote in 45 BC. Here's the complete quote, with the bits and pieces that make up Lorem Ipsum ....

Nemo enim ipsam voluptatem, quia voluptas sit, aspernatur aut odit aut fugit, sed quia consequuntur magni dolores eos, qui ratione voluptatem sequi nesciunt, neque porro quisquam est, qui dolorem ipsum, quia dolor sit amet, consectetur, adipisci[ng] velit, sed quia non numquam [do] eius modi tempora inci[di]dunt, ut labore et dolore magnam aliquam quaerat voluptatem. Ut enim ad minima veniam, quis nostrum exercitationem ullam corporis suscipit laboriosam, nisi ut aliquid ex ea commodi consequatur? Quis autem vel eum iure reprehenderit, qui in ea voluptate velit esse, quam nihil molestiae consequatur, vel illum, qui dolorem eum fugiat, quo voluptas nulla pariatur?

At vero eos et accusamus et iusto odio dignissimos ducimus, qui blanditiis praesentium voluptatum deleniti atque corrupti, quos dolores et quas molestias excepturi sint, obcaecati cupiditate non provident, similique sunt in culpa, qui officia deserunt mollitia animi, id est laborum et dolorum fuga.

But what does it all mean?

He even included a lengthy list of websites that have tons of the stuff hanging around.

Quod erat demonstrandum.

Another quick link roundup

I like being busy, but it does take time away from lower-priority pursuits like blogging. If I had more time, I'd pontificate on the following:

For now, though, it's back to the mines.