Functions
topojson.read
builtin
Read into a TopoJSON from a JSON file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
str
|
Path to a file |
required |
Returns:
| Type | Description |
|---|---|
TopoJSON
|
TopoJSON object |
Raises:
| Type | Description |
|---|---|
OsError
|
Unable to find, open or read the file. |
RuntimeError
|
Unable to deserialize the file. |
topojson.feature
builtin
Returns the GeoJSON Feature or FeatureCollection for the specified
object in the given topology. If the object is a
Geometry_GeometryCollection, a GeoJSON_FeatureCollection is
returned, and each geometry in the collection is mapped to a Feature.
Otherwise, a Feature is returned. The returned feature is a shallow
copy of the source object: they may share identifiers, bounding boxes,
properties and coordinates.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
TopoJSON
|
Topology object |
required |
|
Geometry
|
Geometry |
required |
Returns:
| Type | Description |
|---|---|
GeoJSON
|
GeoJSON Feature or FeatureCollection |
Examples:
- A point is mapped to a feature with a geometry object of type "Point".
- Likewise for line strings, polygons, and other simple geometries.
- A null geometry object (of type null in TopoJSON) is mapped to a feature with a null geometry object.
- A geometry collection of points is mapped to a feature collection of features, each with a point geometry.
- A geometry collection of geometry collections is mapped to a feature collection of features, each with a geometry collection.
topojson.merge
builtin
merge(topology: TopoJSON, objects) -> FeatureGeometryType_MultiLineString
Returns the GeoJSON MultiPolygon geometry object representing the union for the specified array of Polygon and MultiPolygon objects in the given topology. Interior borders shared by adjacent polygons are removed. See Merging States for an example. The returned geometry is a shallow copy of the source object: they may share coordinates.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
TopoJSON
|
Topology object |
required |
|
Geometry
|
Geometry |
required |
Returns:
| Type | Description |
|---|---|
FeatureGeometryType_MultiLineString
|
GeoJSON MultiPolygon geometry object |
Raises:
| Type | Description |
|---|---|
KeyError
|
When |
TypeError
|
Selected object is not a |
topojson.mesh
builtin
mesh(topology: TopoJSON, object: Optional[Geometry], filter: Optional[Callable[[Geometry, Geometry], bool]]) -> FeatureGeometryType_MultiLineString
Returns the GeoJSON MultiLineString geometry object representing the mesh for the specified object in the given topology. This is useful for rendering strokes in complicated objects efficiently, as edges that are shared by multiple features are only stroked once. If object is not specified, a mesh of the entire topology is returned. The returned geometry is a shallow copy of the source object: they may share coordinates.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
TopoJSON
|
TopoJSON object containing the object to mesh |
required |
|
Optional[Geometry]
|
Specfied geometry to mesh |
None
|
|
Optional[Callable[[Geometry, Geometry], bool]]
|
The filter function is called once for each candidate arc and takes two arguments, a and b, two geometry objects that share that arc. Each arc is only included in the resulting mesh if the filter function returns true. For typical map topologies the geometries a and b are adjacent polygons and the candidate arc is their boundary. If an arc is only used by a single geometry then a and b are identical. |
None
|
Returns:
| Type | Description |
|---|---|
FeatureGeometryType_MultiLineString
|
GeoJSON MultiLineString geometry object |
Warnings
Currently, filter argument does not change the result because it is
avoided due to performance issues.
Raises:
| Type | Description |
|---|---|
KeyError
|
When |
topojson.neighbors
builtin
Returns an array representing the set of neighboring objects for each
object in the specified objects array. The returned array has the same
number of elements as the input array; each element i in the returned
array is the array of indexes for neighbors of object i in the input
array. For example, if the specified objects array contains the
features foo and bar, and these features are neighbors, the returned
array will be [[1], [0]], indicating that foo is a neighbor of bar
and vice versa. Each array of neighbor indexes for each object is
guaranteed to be sorted in ascending order.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
list[Geometry]
|
List of neighboring objects |
required |
Returns:
| Type | Description |
|---|---|
list[list[int]]
|
Neighboring objects |
Raises:
| Type | Description |
|---|---|
KeyError
|
When |
topojson.bbox
builtin
Returns the computed bounding box of the specified topology \([x_0, y_0, x_1, y_1]\) where \(x_0\) is the minimum x-value, \(y_0\) is the minimum y-value, x_1 is the maximum x-value, and \(y_1\) is the maximum y-value. If the topology has no points and no arcs, the returned bounding box is \([\infty, \infty, -\infty, -\infty]\).
(This method ignores the existing topology.bbox, if any.)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
TopoJSON
|
TopoJSON object |
required |
Returns:
| Type | Description |
|---|---|
list[float]
|
Computed bounding box |
topojson.quantize
builtin
Returns a shallow copy of the specified topology with quantized and delta-encoded arcs according to the specified transform object. If the topology is already quantized, an error is thrown. See also topoquantize.
The corresponding transform object is first computed using the bounding
box of the topology. The quantization number transform must be a
positive integer greater than one which determines the maximum number
of expressible values per dimension in the resulting quantized
coordinates; typically, a power of ten is chosen such as 1e4, 1e5 or
1e6. If the topology does not already have a topology.bbox, one is
computed using topojson.bbox.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
TopoJSON
|
TopoJSON object to quantize |
required |
|
float
|
The quantization number |
required |
Returns:
| Type | Description |
|---|---|
TopoJSON
|
Shallow copy with quantized and delta-encoded arcs. |
Raises:
| Type | Description |
|---|---|
RuntimeError
|
If topology is already quantized or transform is smaller than 2. |