The issue here is TopoJSON’s default quantization behavior; you need to increase the quantization precision if you want to preserve detail when zoomed in. Try -q 1e5
to increase the quantization factor from the default by 10, or -q 1e6
by 100.
The appropriate value of Q depends on the maximum effective size of your map and limited by the original precision of the geometry. Your map appears to have 11 zoom levels by powers of 2, so starting with the smallest size of 560×410 at zoom level 0, the effective size of the map at zoom level 10 is 573,440×419,840. If you want to maintain this precision, you will need Q = 1e6 (and a significantly larger TopoJSON file).
More details: the quantization factor Q determines the maximum number of differentiable points and defaults to 10,000. For best efficiency, Q should be a factor of 10 because digits are base-10 encoded in JSON. The default value is appropriate for displaying a map on a computer screen which typically has at most a resolution of 2,560×1,440 pixels, well under 10,000×10,000. (Q is an upper bound on differentiability; if points are not uniformly spaced, you may get fewer differentiable points.)
TopoJSON uses quantization to determine whether two points are coincident for the purpose of simplification. This is required because GeoJSON does not encode topology, and exact matches would be overly strict due to floating point error in GeoJSON coordinates. Also, quantization is a major factor in reducing the size of the TopoJSON encoding, especially in conjunction with the delta encoding.
Slightly related, here is an example of the Asia Lambert Conic Conformal projection used for Russia.
You can use topojson.merge to do this, as shown in bl.ocks.org/5416405:
There are a few limitations to this approach (such as its dependence on an exact topology and lack of detection of holes), but it might for you as-is or with a few adjustments.
There is also the simpler approach of drawing the set of polygons for each region twice, once with a stroke and once with a fill, as shown in bl.ocks.org/5416440:
See also a very similar question on Stack Overflow.
Best Answer
TopoJSON uses fixed-precision integer coordinates, so no, you can’t create a TopoJSON file without first quantizing coordinates. The precision is controlled with the
-q
argument totopojson
, as described in the command-line reference.(Edit: as of TopoJSON 1.4, you can now construct lossless TopoJSON without quantization by saying
--no-quantization
(or equivalently-q 0
).)That said, it doesn’t sound like quantization is your problem here. Instead, I would guess that your input coordinates are not in WGS84 / EPSG:4326. I would use ogr2ogr to convert your geometry to spherical coordinates in degrees before converting to TopoJSON. For example:
Quantization is unlikely to be the problem here because quantization is localized to the input features’ bounding box, and thus automatically adapts to both small and large features. If you have a map of a very small space (such as building floor plans, and not the western hemisphere), the quantized coordinates will be correspondingly more precise, even at the same value of Q (
topojson
's-q
), because the scale of the topology’s transform will be that much larger.For example, say the bounding box of your input features is [[-122.395, 37.794], [-122.391, 37.797]], approxiamtely San Francisco’s Ferry Building. And say you used the default Q = 10,000. The quantized fixed coordinate [0,0] then maps to [-122.395, 37.794], and the fixed coordinate [9999,9999] maps to [-122.391, 37.797]. In other words, each increment in longitude corresponds to approximately 0.0000004° (4e-7), a tiny amount.
In contrast, with a world map spanning [[-180, -90], [180, 90]] at the same Q = 10,000, each increment in longitude corresponds to approximately 0.036°.