Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

I have been investigating using TopoJSON files to map floor plans for various buildings. As GeoJSON these files render perfectly, however after converting to TopoJSON they are missing a lot of the lines used to render them and the number of geometries is much less than the number of features in the GeoJSON.

I experimented by increasing the quantize parameter but after a certain point it doesn't add any more detail. Is it possible to convert from GeoJSON to TopoJSON without having my features quantized?

share|improve this question

1 Answer 1

up vote 4 down vote accepted

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 to topojson, 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:

ogr2ogr -f 'ESRI Shapefile' -t_srs EPSG:4326 input-fixed.shp input.shp
topojson -o output.json -- input-fixed.shp

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°.

share|improve this answer
    
The files that I am using come originally from cad files and are using a Local Coordinate system, and all of my attempts to convert the file into epsg:4362 using ogr2ogr or qgis render exactly the same file as the one I started with. That file can be found at [link]b3nson.net/marketart/asMapJSON/surf13_l.json also an example of the topoJSON mapped next to the geoJSON can be found at [link]b3nson.net/marketart/asMapJSON/q1e9.htm , although it takes a minute to load. I am big fan of your work, thanks so much for your first reply. –  Alex Muro Mar 13 '13 at 15:56
    
You'll need a .prj file to convert from that coordinate system to EPSG:4362. –  mbostock Mar 13 '13 at 16:36
    
Also, I filed a related feature request for topojson. –  mbostock Mar 13 '13 at 16:41

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.