# topojson.core.topology

## Topology

```
Topology(self, data, topology=True, prequantize=True, topoquantize=False, presimplify=False, toposimplify=False, shared_coords=True, prevent_oversimplify=True, simplify_with='shapely', simplify_algorithm='dp', winding_order='CW_CCW')
```

Returns a TopoJSON topology for the specified geometric object. TopoJSON is an extension of GeoJSON providing multiple approaches to compress the geographical input data. These options include simplifying the linestrings or quantizing the coordinates but foremost the computation of a topology.

## Parameters

`data`

:anygeometric typeGeometric data that should be converted into TopoJSON

`topology`

: booleanSpecify if the topology should be computed for deriving the TopoJSON. Default is

`True`

.

`prequantize`

: boolean, intIf the prequantization parameter is specified, the input geometry is quantized prior to computing the topology, the returned topology is quantized, and its arcs are delta-encoded. Quantization is recommended to improve the quality of the topology if the input geometry is messy (i.e., small floating point error means that adjacent boundaries do not have identical values); typical values are powers of ten, such as

`1e4`

,`1e5`

or`1e5`

. Default is`True`

(which correspond to a quantize factor of`1e5`

).

`topoquantize`

: boolean or intIf the topoquantization parameter is specified, the input geometry is quantized after the topology is constructed. If the topology is already quantized this will be resolved first before the topoquantization is applied. See for more details the

`prequantize`

parameter. Default is`False`

.

`presimplify`

: boolean, floatApply presimplify to remove unnecessary points from linestrings before the topology is constructed. This will simplify the input geometries. Use with care. Default is

`False`

.

`toposimplify`

: boolean, floatApply toposimplify to remove unnecessary points from arcs after the topology is constructed. This will simplify the constructed arcs without altering the topological relations. Sensible values for coordinates stored in degrees are in the range of

`0.0001`

to`10`

. Defaults to`False`

.

`shared_coords`

: booleanSets the strategy to detect junctions. When set to

`True`

a path is considered shared when all coordinates appear in both paths (`coords-connected`

). When set to`False`

a path is considered shared when coordinates are the same path (`path-connected`

). The path-connected strategy is more ‘correct’, but slower. Default is`True`

.

`prevent_oversimplify`

: booleanIf this setting is set to

`True`

, the simplification is slower, but the likelihood of producing valid geometries is higher as it prevents oversimplification. Simplification happens on paths separately, so this setting is especially relevant for rings with no partial shared paths. This is also known as a topology-preserving variant of simplification. Default is`True`

.

`simplify_with`

: strSets the package to use for simplifying (both pre- and toposimplify). Choose between

`shapely`

or`simplification`

. Shapely adopts solely Douglas-Peucker and simplification both Douglas-Peucker and Visvalingam-Whyatt. The package simplification is known to be quicker than shapely. Default is`shapely`

.

`simplify_algorithm`

: strChoose between

`dp`

and`vw`

, for Douglas-Peucker or Visvalingam-Whyatt respectively.`vw`

will only be selected if`simplify_with`

is set to`simplification`

. Default is`dp`

, since it “produced the most accurate generalization” (Shi, W. & Cheung, C., 2006).

`winding_order`

: strDetermines the winding order of the features in the output geometry. Choose between

`CW_CCW`

for clockwise orientation for outer rings and counter- clockwise for interior rings. Or`CCW_CW`

for counter-clockwise for outer rings and clockwise for interior rings. Default is`CW_CCW`

.

`object_name`

: strName to use as key for the objects in the topojson file. This name is used for writing and reading topojson file formats. Default is

`data`

.

### to_dict

```
Topology.to_dict(self, options=False)
```

Convert the Topology to a dictionary.

## Parameters

### to_svg

```
Topology.to_svg(self, separate=False, include_junctions=False)
```

Display the arcs and junctions as SVG.

## Parameters

### to_json

```
Topology.to_json(self, fp=None, options=False, pretty=False, indent=4, maxlinelength=88)
```

Convert the Topology to a JSON object.

## Parameters

`fp`

: strIf set, writes the object to a file on drive. Default is

`None`

`options`

: booleanIf

`True`

, the options also will be included. Default is`False`

`pretty`

: booleanIf

`True`

, the JSON object will be ‘pretty’, depending on the`ident`

and`maxlinelength`

options Default is`False`

`indent`

: intIf

`pretty=True`

, declares the indentation of the objects. Default is`4`

.

`maxlinelength`

: intIf

`pretty=True`

, declares the maximum length of each line. Default is`88`

.

### to_geojson

```
Topology.to_geojson(self, fp=None, pretty=False, indent=4, maxlinelength=88, validate=False, objectname='data')
```

Convert the Topology to a GeoJSON object. Remember that this will destroy the computed Topology.

## Parameters

`fp`

: strIf set, writes the object to a file on drive. Default is

`None`

`pretty`

: booleanIf

`True`

, the JSON object will be ‘pretty’, depending on the`ident`

and`maxlinelength`

options. Default is`False`

`indent`

: intIf

`pretty=True`

, declares the indentation of the objects. Default is`4`

`maxlinelength`

: intIf

`pretty=True`

, declares the maximum length of each line. Default is`88`

`validate`

: booleanSet to

`True`

to validate each feature before inclusion in the GeoJSON. Only features that are valid geometries objects will be included. Default is`False`

`objectname`

: strThe name of the object within the Topology to convert to GeoJSON. Default is

`data`

`decimals`

: int or NoneEvenly round the coordinates to the given number of decimals. Default is

`None`

, which means no rounding is applied.

### to_gdf

```
Topology.to_gdf(self)
```

Convert the Topology to a GeoDataFrame. Remember that this will destroy the computed Topology.

Note: This function use the TopoJSON driver within Fiona to parse the Topology to a GeoDataFrame. If data is missing (eg. Fiona cannot parse nested geometry collections) you can trying using the `.to_geojson()`

function prior creating the GeoDataFrame.

### to_alt

```
Topology.to_alt(self, mesh=True, color=None, tooltip=True, projection='identity', objectname='data')
```

Display as Altair visualization.

## Parameters

`mesh`

: booleanIf

`True`

, render arcs only (mesh object). If`False`

render as geoshape. Default is`True`

`color`

: strAssign an property attribute to be used for color encoding. Remember that most of the time the wanted attribute is nested within properties. Moreover, specific type declaration is required. Eg

`color='properties.name:N'`

. Default is`None`

`tooltip`

: booleanOption to include or exclude tooltips on geoshape objects Default is

`True`

.

`projection`

: strDefines the projection of the visualization. Defaults to a non-geographic, Cartesian projection (known by Altair as

`identity`

).

`objectname`

: strThe name of the object within the Topology to display. Default is

`data`

### to_widget

```
Topology.to_widget(self, slider_toposimplify={'min': 0, 'max': 10, 'step': 0.01, 'value': 0.01}, slider_topoquantize={'min': 1, 'max': 6, 'step': 1, 'value': 100000.0, '> + ###### `base': ` : 10})
```

Create an interactive widget based on Altair. The widget includes sliders to interactively change the `toposimplify`

and `topoquantize`

settings.

## Parameters

### topoquantize

```
Topology.topoquantize(self, quant_factor, inplace=False)
```

Quantization is recommended to improve the quality of the topology if the input geometry is messy (i.e., small floating point error means that adjacent boundaries do not have identical values); typical values are powers of ten, such as `1e4`

, `1e5`

or `1e6`

.

## Parameters

## Returns

### toposimplify

```
Topology.toposimplify(self, epsilon, inplace=False)
```

Apply toposimplify to remove unnecessary points from arcs after the topology is constructed. This will simplify the constructed arcs without altering the topological relations. Sensible values for coordinates stored in degrees are in the range of `0.0001`

to `10`

.

## Parameters

## Returns