Today we’ll have a small puzzle, why does a simple albeit long GeoJson line between two points looks curved in BigQuery GeoViz? Here is the line —

{"type": "LineString", "coordinates": [[-80,0], [80,80]]}

Here is how it appears in GeoViz:

Line in BigQuery GeoViz

If you draw the same line in other tools, you typically get a line that looks straight, and more importantly covers different area, crossing UK instead of Poland. E.g. in GeoJson.io:

Line in GeoJson.io

What’s going on here?

Is it geodesic vs Cartesian?

BigQuery GIS users would know the BigQuery has geography type, rather than geometry, so all lines are geodesic on sphere. However this is not the reason, at least not directly. Also, the geodesic line between these points would look very different from either of the lines above — it goes over Arctic:

Geodesic line

Two things to note here:

First example used ST_GeogFromGeoJson. When reading GeoJson, BigQuery tessellates long lines to approximate the GeoJson’s Cartesian lines with the geodesic lines BigQuery uses for Geography. So the resulting LineString has more points, but runs close enough to the original “straight” line.

Last example used ST_GeogFromText. Here BigQuery assumes the input already uses geodesic lines, and does not perform any conversion. BQ GeoViz is able to draw it correctly by asking for GeoJson version behind the scenes (it wraps the query you write with another one with ST_AsGeoJson call).

Projections matter!

The issue is projections. GeoJson is specified to use “geographic coordinate reference system, using the World Geodetic System 1984 (WGS 84) [WGS84] datum, with longitude and latitude units of decimal degrees”, which is essentially longitude-latitude coordinates. This is the Plate Carrée (or equirectangular) projection.

If we used this projection in GeoViz, the line would be straight. But common web maps, including BigQuery GeoViz and GeoJson.io use Web Mercator projection. This projection stretches the polar regions. We start with a straight line in equirectangular projection, draw it on Earth surface, and then stretch map’s polar regions, we get the curved line that you see in GeoViz.

Where does this happen?

One question remains: where does this conversion from Plate Carrée to Web Mercator happen? Does GeoViz draw curved lines?

GeoViz converts vertex coordinates to Web Mercator, but does not do anything with lines, it just draws straight lines on its map (it is open-source, you can check!) — same way as most other simple visualization tools, including geojson.io shown above.

But let’s recall the tessellation BigQuery GIS does to approximate a long Cartesian line with many shorter geodesic ones. BQ GeoViz gets this tessellated line from BigQuery, rather than the original one. That line has a lot of intermediate points in the middle of the line, enough so that when BQ GeoViz draws that complex line, the line’s path on Earth follows GeoJson semantics.

Essentially, BQ GeoViz drawing correct lines is side effect of converting from “flat” edges to geodesic edges, there is nothing special done for Web Mercator here.