{"id":24720,"library":"topojson","title":"topojson - encode geographic data as topology in Python","description":"topojson is a Python library to encode geographic data into the TopoJSON format, which encodes topology. It supports input from GeoJSON, Shapefile, GeoDataFrame, and other sources, and can output TopoJSON, GeoJSON, or GeoDataFrames. Current version is 1.10, requiring Python >=3.8. Release cadence is irregular, roughly several months between versions.","status":"active","version":"1.10","language":"python","source_language":"en","source_url":"https://github.com/mattijn/topojson","tags":["topojson","geography","gis","topology","geojson","data-conversion"],"install":[{"cmd":"pip install topojson","lang":"bash","label":"PyPI"},{"cmd":"conda install -c conda-forge topojson","lang":"bash","label":"conda-forge"}],"dependencies":[{"reason":"Array computations","package":"numpy","optional":false},{"reason":"Geometry operations","package":"shapely","optional":false},{"reason":"DataFrame handling","package":"pandas","optional":false},{"reason":"GeoDataFrame input/output","package":"geopandas","optional":true},{"reason":"Shapefile reading","package":"fiona","optional":true},{"reason":"JSON serialization","package":"simplejson","optional":true}],"imports":[{"note":"","wrong":null,"symbol":"Topology","correct":"from topojson import Topology"},{"note":"Wildcard imports not recommended; use explicit imports.","wrong":"from topojson import *","symbol":"topojson","correct":"import topojson"}],"quickstart":{"code":"from topojson import Topology\nimport geopandas as gpd\n\n# Load a GeoJSON or Shapefile into a GeoDataFrame\n# Example: gdf = gpd.read_file('path/to/file.geojson')\n# Or use built-in example\ndata = {\n    'type': 'FeatureCollection',\n    'features': [\n        {\n            'type': 'Feature',\n            'properties': {},\n            'geometry': {\n                'type': 'Polygon',\n                'coordinates': [[[0,0],[1,0],[1,1],[0,1],[0,0]]]\n            }\n        }\n    ]\n}\ntopo = Topology(data, prequantize=False)\ntopojson_str = topo.to_json()\nprint(topojson_str[:200])","lang":"python","description":"Creates a Topology from a GeoJSON dict and outputs TopoJSON string."},"warnings":[{"fix":"Do not rely on feature ordering; use properties to identify features.","message":"Input data order is not preserved in the output TopoJSON. Topology is computed based on shared arcs, and feature order may change.","severity":"gotcha","affected_versions":"all"},{"fix":"Set `ignore_index=True` in `Topology()` to restore old behavior of ignoring ids.","message":"In version 1.9, the `ignore_index` parameter was introduced. By default, feature ids from GeoJSON source are kept unless duplicates exist. This changes previous behavior where ids were always dropped.","severity":"breaking","affected_versions":">=1.9"},{"fix":"Use `Topology(data, prequantize=False)` for exact coordinate preservation.","message":"When using `prequantize=True` (default), coordinates are quantized to integers, which may reduce precision but also reduces file size. For lossless topology, set `prequantize=False`.","severity":"gotcha","affected_versions":"all"},{"fix":"Update NumPy to a recent version (>=1.20).","message":"In version 1.6, deprecated NumPy functions (e.g., `np.in1d`) were replaced. Issues may arise with older NumPy versions.","severity":"deprecated","affected_versions":">=1.6"}],"env_vars":null,"last_verified":"2026-05-01T00:00:00.000Z","next_check":"2026-07-30T00:00:00.000Z","problems":[{"fix":"Upgrade topojson: `pip install --upgrade topojson`","cause":"Using `ignore_index` parameter with topojson version <1.9.","error":"TypeError: __init__() got an unexpected keyword argument 'ignore_index'"},{"fix":"Wrap input in a GeoJSON FeatureCollection dict or use a GeoDataFrame.","cause":"Passing an unsupported data format (e.g., plain list of coordinates).","error":"ValueError: Input data must be a dict with 'type' and 'features' keys or a GeoDataFrame"},{"fix":"Use `from topojson import Topology`.","cause":"Importing incorrectly (e.g., `import topojson` then using `topojson.Topology` but the module may not expose the class directly in old versions).","error":"AttributeError: module 'topojson' has no attribute 'Topology'"}],"ecosystem":"pypi","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}