Falsehoods programmers believe about maps

Ok, I’m probably not the first one to write a post about falsehoods programmers believe about maps, but I still remember reading “Falsehoods programmers believe about names” and “Falsehoods programmers believe about time“, and thinking “there should be a post like that about maps”. So, go ahead, read those two posts to get to know the style of a post like this and then read on here.

  1. All coordinates are in “Latitude/Longitude” (Why is this false?)
  2. If you know the “Latitude/Longitude” you can be certain of exactly where you are
  3. “Spatial is special”
  4. The earth is round (Why is this false?)
  5. The earth is ellipsoidal (Why is this false?)
  6. The GPS-satellites know where I am
  7. There is a single, right, map projection
  8. Scale numbers works on a screen (Why is this false?)
  9. There are no good alternatives to Google Maps
  10. Web Mercator works for all purposes
  11. The shortest path between two points is a straight line
  12. All programmers agree on the ordering of latitude and longitude pairs
  13. Given a paper map I can always digitize and georeference it
  14. My background map will be better if I cache it, always!
  15. GIS software is always expensive
  16. The whole world is mapped, thouroughly
  17. Looking up a street address and get it’s position is easy
  18. Offline maps is as easy as Goole Maps

That’s what I’ve come up with this far, I might fill in something here when I think about it. Comments? Additions? Any errors? Want citations? Well, the comment section is open, so go ahead!

Lightweight coordinate transformations in JavaScript

We (as in: people that work with geospatial JavaScript) have all been there: We have coordinates as “latlons” (i.e. Geographic coordinates in WGS84), but we need to transform them to some other coordinate system (as a Norwegian: replace “some other” with UTM Zone 33N). Ok, that shouldn’t be that difficult, just include proj4.js. It’s a mere 73.275 kb, and handles almost all coordinate transformations (given that you know their definitions).

But, sometime you just care about one single transformation (say: EPSG:4326 to EPSG:32633), and you are really concerned about file size (maybe you are targeting a mobile site), because size does matter and you feel that proj4.js weighs in a bit too heavy. Well, that was what Bjørn Sandvik thought yesterday:

Then I got around to thinkning: how hard can this be? After a bit of thinking I realized that, yes, this is actually rather complicated in terms of maths. But, after a bit more thinking, I remembered this project from a couple of years ago (blog post in Norwegian). Basically, my old department at NTNU had some fortran code from around 1990 written by professor Jon Holsen in Fortran.

A couple of years ago I ported that code to JavaScript (on GitHub), but did not think much more about it (although I heard reports that the department has used it some).

After looking at old notes and books on coordinate transformations it dawned on me that Holsen.js has a “bl_to_xy”-function, which transforms Geographic to planar coordinates. I then ripped out the relevant code, removed things that wasn’t needed for my simple WGS84 to UTM33 conversion, looked up the right params for UTM33N and made a gist in the middle of the night.

I did some testing against proj4js, and Bjørn did some more (reporting: “similar down to the centimetre”), and after figuring out that the original code used X for North and Y for East it seems to do the work. Result: a js file of about 100 lines, and that is rather readable lines as well. Running this code through a minifier (uglify.js) results in a 8 kb file (that is, about 10% of proj4js).

The code is tailored to transforming to one specific UTM Zone, but it should be easy to modify to work for other zones as well. Another idea is to make a similar script for transforming the other way, from UTM33 to Geographic coordinates. Holsen.js has support for this, so it shouldn’t be that difficult.

In closing: I think that small, simple scripts like this (which is small in size and does _one_ thing) is much more needed in JavaScript than in other languages. Download size matters for web apps, and the idea of one, monolithic library to solve all conceivable tasks does not work for JavaScript the way it does for Java and similar languages. Also: beeing able to provide a fellow geo-geek with working code in the course of a couple of hours is always cool! In addition: nice to see that work I did mostly for fun two years ago can be of use to someone.

Øltur til Brussel

I anledning 30-årdagen min fikk jeg en fantastisk gave fra samboer og bror: 3 dager i Brussel for å drikke øl sammen med broderen! Vi er begge relativt ølopptatte, men ingen av oss er noen særlige eksperter på belgisk øl (sånn rent bortsett fra at vi begge er glade i surøl da). Vi hadde tre fine dager i Brussel fra 1. til 4. mai og nå har jeg endelig fått somla meg til å skrive en oppsummering.

Jeg har eksperimentert litt med interaktive kart og litt sånnt, så dermed blir det ikke direkte en bloggpost, men en frittstående side. Les saken på http://code.atlefren.net/brussel/index.html. Kommentarer og sånn kan du legge igjen under her!

Og: skulle du være interessert i hvordan kartløsningen er laget: se github.

10 Open-Source Projects Every JavaScript Geo Dev Should Know About

That is not tied to a proprietary platform

An article flew by in my Twitter stream, with the title “10 Open-Source Projects Every #JavaScript Geo Dev Should Know About”. As I consider myself a Javascript Geo Dev i thought that there might be som OpenSource gems I’ve missed and clicked the link. The link brought me to esri.com and what I was presented with was this article, listing 10 open source javascripts projects that I’ve never heard of.

Why? Most of them (or all, no links, and I can’t bother to google them all) are ESRIs own libraries, and although OpenSource they are tied to the ESRI platform. In fact, from what I understand, 4 or 5 of them are directly tied to ArcGIS Online.

This made me feel a bit tricked. Not that there are anything wrong with ESRI releasing OpenSource code, but where there is an implicit requirement that you use their paid services, what is the use for others?

But, instead of complaining I’ll present a list of my own, that should be of a wider use to all Javascript Geo devs (although I’m rather certain that most of you’ve heard about most of them already!)

1. OpenLayers 3

We all know OpenLayers 2 (don’t we?) and most of you probably know that the brand new OpenLayers 3 is in the making (beta 4 now!). Lots of features, a complete rewrite and heavy use of the Closure compiler.

2. Leaflet

The web-friendly, lightweight, hipster no-frills mapping library that excels in beeing un-bloated and easy to use. Just try it, seriously!

3. Proj4js

A JavaScript port of proj.4, meaning that you can do all your coordinate re-projections right in the browser!

4. jsts

A JavaScript port of JTS Topology Suite, a library of spatial predicates and functions for processing geometry objects. It works, but is a rather straight Java-port, which leads me to the next entry:

5. Njord.js

Njord.js is a vanilla JS, client side lib for lightweight geoprocessing, envisioned to compete with jsts and heavily inspired by Shapely. It’s written by yours truly and is under development.

6. D3

A JavaScript visualization library for HTML and SVG. I personally know next to nothing about it and haven’t used it, but if you need to add some visualisations to your map app D3 seems to be the way to go.

7. Three.js

Three.js simplifies the task of working with WebGL from Javascript. We all know that 3d is the future, so why not start learning it. If you don’t think that mapping and 3d can be united, take a look at this lib.

8. KuGIS

KuGIS is a browser-driven GIS-application with support for a lot of spatial analysis. Driven by Leaflet and JSTS. Really shows what you can do in the browser these days.

9. Bootleaf

Although I haven’t used it myself I’ve heard some good things about this lib, actually just a “simple, responsive template for building web mapping applications with Bootstrap 3, Leaflet and typeahead.js”.

10. SpatialBB

Also written by yours truly, SpatialBB (or “spatially enabeled Backbone”) is an attempt to merge the MVC-capabilities of Backbone.js with the spatial capabilities of Leaflet. Also a work in (some state of) progress, but I kinda like the idea.

So, that was my list. What did I forget? Are there any gems that’s useful? Please point me in their direction!