It's true that is not very clear. A simple example:
from topojson.conversion import convert
from topojson import geojson
import json
with open("test.geojson") as f:
test_geojson = json.load(f)
print test_geojson
{u'type': u'FeatureCollection', u'features': [{u'geometry': {u'type': u'Polygon', u'coordinates': [[[-83.23145862723665, 42.61719935058299], [-83.2316352368618, 42.61737853618379], [-83.23166951279292, 42.61742295755952], [-83.23119346860754, 42.617678900083554], [-83.23097637034452, 42.6174586310034], [-83.23145862723665, 42.61719935058299]]]}, u'type': u'Feature', u'properties': {u'LOWPARCELID': u'1902226080'}}]}
# to TopoJSON
tj = convert(test_geojson)
print tj
{'objects': {'name': {u'type': 'GeometryCollection', 'geometries': [{u'type': u'Polygon', 'properties': {u'LOWPARCELID': u'1902226080'}, 'arcs': [[0]]}]}}, 'type': 'Topology', 'bbox': [-83.23166951279292, 42.61719935058299, -83.23097637034452, 42.617678900083554], 'arcs': [[[3042, 0], [-2548, 3736], [-494, 926], [6867, 5337], [3132, -4593], [-6957, -5406]]], 'transform': {'translate': [-83.23166951279292, 42.61719935058299], 'scale': [6.932117695749783e-08, 4.795974603069803e-08]}}
# to GeoJSON
print geojson(tj)
{'type': 'FeatureCollection', 'features': [{'geometry': {'type': u'Polygon', 'coordinates': [[[-83.23145863777262, 42.61719935058299], [-83.2316352681315, 42.617378528194166], [-83.23166951279292, 42.617422938918985], [-83.23119348427075, 42.617678900083554], [-83.23097637034452, 42.617458620970034], [-83.23145863777262, 42.61719935058299]]]}, 'type': 'Feature', 'properties': {u'LOWPARCELID': u'1902226080'}}]}
But it works only with GeoJSON files with a features
key (FeatureCollection)
test = { "type": "Polygon",
"coordinates": [
[ [100.0, 0.0], [101.0, 0.0], [101.0, 1.0], [100.0, 1.0], [100.0, 0.0] ]
]
}
tj = convert(test)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "topojson/conversion.py", line 22, in convert
output_dict = topology(input_dict, *args, **kwargs)
File "topojson/topology.py", line 20, in topology
[x0,x1,y0,y1]=bound(objects)
File "topojson/bounds.py", line 20, in bound
b.obj(objects)
File "topojson/mytypes.py", line 46, in obj
self.outObj[fName]=self.FeatureCollection(obj[fName])
File "topojson/mytypes.py", line 19, in FeatureCollection
for feature in collection['features']:
KeyError: 'features'
New
The result of setup.py build/install is not correct with the setup.py of the git repository
A correct structure for Python 2.7.x is
The init.py file is init.py
Then (with see "dir for humans")
import topojson
from see import see
see(topojson)
.geojson() .topojson()
# therefore
from topojson.topojson.conversion import convert
from topojson.geojson import geojson