.map_data


class: MapData

class MapData(**kwargs)[source]

The map geometry data which defines the areas and features of the map itself.

Class Inheritance
Inheritance diagram of MapData

copy(other=None, overwrite=True, **kwargs)

Copy the configuration settings from this instance to the other instance.

Parameters:
  • other (HighchartsMeta) – The target instance to which the properties of this instance should be copied. If None, will create a new instance and populate it with properties copied from self. Defaults to None.

  • overwrite (bool) – if True, properties in other that are already set will be overwritten by their counterparts in self. Defaults to True.

  • kwargs – Additional keyword arguments. Some special descendents of HighchartsMeta may have special implementations of this method which rely on additional keyword arguments.

Returns:

A mutated version of other with new property values

classmethod from_dict(as_dict: dict, allow_snake_case: bool = True)[source]

Construct an instance of the class from a dict object.

Parameters:
  • as_dict (dict) – A dict representation of the object.

  • allow_snake_case (bool) – If True, interprets snake_case keys as equivalent to camelCase keys. Defaults to True.

Returns:

A Python object representation of as_dict.

Return type:

HighchartsMeta

classmethod from_geodataframe(as_gdf, prequantize=False, **kwargs)[source]

Create a MapData instance from a geopandas.GeoDataFrame.

Parameters:
  • as_gdf (geopandas.GeoDataFrame) – The geopandas.GeoDataFrame containing the map geometry.

  • prequantize (bool) – If True, will perform the TopoJSON optimizations (“quantizing the topology”) before generating the Topology instance. Defaults to False.

  • kwargs (dict) – additional keyword arguments which are passed to the Topology constructor

Return type:

MapData

classmethod from_geojson(as_geojson_or_file: str | bytes, allow_snake_case: bool = True)[source]

Construct an instance of the class from a JSON string.

Parameters:
  • as_geojson_or_file (str or bytes) – The GeoJSON string for the object or the filename of a file that contains the GeoJSON string.

  • allow_snake_case (bool) – If True, interprets snake_case keys as equivalent to camelCase keys. Defaults to True.

Returns:

A Python objcet representation of as_geojson_or_file.

Return type:

MapData

classmethod from_js_literal(as_str_or_file, allow_snake_case: bool = True, _break_loop_on_failure: bool = False)

Return a Python object representation of a Highcharts JavaScript object literal.

Parameters:
  • as_str_or_file (str) – The JavaScript object literal, represented either as a str or as a filename which contains the JS object literal.

  • allow_snake_case (bool) – If True, interprets snake_case keys as equivalent to camelCase keys. Defaults to True.

  • _break_loop_on_failure (bool) – If True, will break any looping operations in the event of a failure. Otherwise, will attempt to repair the failure. Defaults to False.

Returns:

A Python object representation of the Highcharts JavaScript object literal.

Return type:

HighchartsMeta

classmethod from_json(as_json_or_file: str | bytes, allow_snake_case: bool = True)[source]

Construct an instance of the class from a JSON string.

Parameters:
  • as_json_or_file – The JSON string for the object or the filename of a file that contains the JSON string.

  • allow_snake_case (bool) – If True, interprets snake_case keys as equivalent to camelCase keys. Defaults to True.

Returns:

A Python objcet representation of as_json.

Return type:

MapData

classmethod from_shapefile(shp_filename)[source]

Create a MapData instance from an ESRI Shapefile.

Parameters:

shp_filename (str or bytes) –

The full filename of an ESRI Shapefile to load.

Note

ESRI Shapefiles are actually composed of three files each, with one file receiving the .shp extension, one with a .dbf extension, and one (optional) file with a .shx extension.

Highcharts Maps for Python will resolve all three files given a single base filename. Thus:

/my-shapefiles-folder/my_shapefile.shp

will successfully load data from the three files:

/my-shapefiles-folder/my_shapefile.shp /my-shapefiles-folder/my_shapefile.dbf /my-shapefiles-folder/my_shapefile.shx

Tip

Highcharts for Python will also correctly load and unpack shapefiles that are grouped together within a ZIP file.

Return type:

MapData

classmethod from_topojson(as_topojson_or_file: str | bytes, allow_snake_case: bool = True)[source]

Construct an instance of the class from a TopoJSON string.

Parameters:
  • as_topojson_or_file (str or bytes) – The TopoJSON string for the object or the filename of a file that contains the TopoJSON string.

  • allow_snake_case (bool) – If True, interprets snake_case keys as equivalent to camelCase keys. Defaults to True.

Returns:

A Python objcet representation of as_topojson_or_file.

Return type:

MapData

to_dict() dict

Generate a dict representation of the object compatible with the Highcharts JavaScript library.

Note

The dict representation has a property structure and naming convention that is intentionally consistent with the Highcharts JavaScript library. This is not Pythonic, but it makes managing the interplay between the two languages much, much simpler.

Returns:

A dict representation of the object.

Return type:

dict

to_geodataframe(object_name=None)[source]

Generate a geopandas.GeoDataFrame instance of the map geometry.

Parameters:

object_name (str or int or None) – If the map data contains multiple objects, you can generate serialize a specific object by specifying its name or index. Defaults to None, which behaves as an index of 0.

Return type:

geopandas.GeoDataFrame

to_geojson(filename=None, encoding='utf-8')[source]

Generate a GeoJSON string/byte string representation of the object.

Note

This method will either return a standard str or a bytes object depending on the JSON serialization library you are using. For example, if your environment has orjson, the result will be a bytes representation of the string.

Parameters:
  • filename (Path-like) – The name of a file to which the JSON string should be persisted. Defaults to None

  • encoding (str) – The character encoding to apply to the resulting object. Defaults to 'utf-8'.

Returns:

A GeoJSON representation of the object

Return type:

str or bytes

to_js_literal(filename=None, encoding='utf-8') str | None[source]

Return the object represented as a str containing the JavaScript object literal.

Parameters:
  • filename (Path-like) – The name of a file to which the JavaScript object literal should be persisted. Defaults to None

  • encoding (str) – The character encoding to apply to the resulting object. Defaults to 'utf-8'.

Return type:

str or None

to_json(filename=None, encoding='utf-8')[source]

Generate a JSON string/byte string representation of the object compatible with the Highcharts JavaScript library.

Note

This method will either return a standard str or a bytes object depending on the JSON serialization library you are using. For example, if your environment has orjson, the result will be a bytes representation of the string.

Parameters:
  • filename (Path-like) – The name of a file to which the JSON string should be persisted. Defaults to None

  • encoding (str) – The character encoding to apply to the resulting object. Defaults to 'utf-8'.

Returns:

A JSON representation of the object compatible with the Highcharts library.

Return type:

str or bytes

to_topojson(filename=None, encoding='utf-8')[source]

Generate a TopoJSON string/byte string representation of the object.

Note

This method will either return a standard str or a bytes object depending on the JSON serialization library you are using. For example, if your environment has orjson, the result will be a bytes representation of the string.

Parameters:
  • filename (Path-like) – The name of a file to which the JSON string should be persisted. Defaults to None

  • encoding (str) – The character encoding to apply to the resulting object. Defaults to 'utf-8'.

Returns:

A TopoJSON representation of the object

Return type:

str or bytes

static trim_dict(untrimmed: dict, to_json: bool = False) dict

Remove keys from untrimmed whose values are None and convert values that have .to_dict() methods.

Parameters:
  • untrimmed (dict) – The dict whose values may still be None or Python objects.

  • to_json (bool) – If True, will remove all keys from untrimmed that are not serializable to JSON. Defaults to False.

Returns:

Trimmed dict

Return type:

dict

static trim_iterable(untrimmed, to_json=False)

Convert any EnforcedNullType values in untrimmed to 'null'.

Parameters:
  • untrimmed (iterable) – The iterable whose members may still be None or Python objects.

  • to_json (bool) – If True, will remove all members from untrimmed that are not serializable to JSON. Defaults to False.

Return type:

iterable

property force_geojson: bool | None

If True, will serialize as GeoJSON. If False, will serialize as TopoJSON which sends less data over the wire. Defaults to False.

Return type:

bool

property topology: Topology | None

The topology that defines the map areas that should be rendered in the map.

Return type:

Topology


class: AsyncMapData

class AsyncMapData(**kwargs)[source]

Configuration of map geometry which Highcharts Maps should fetch asynchronously using client-side JavaScript.

Note

When serialized to a JS literal will execute an async (JavaScript) fetch() call to download the map data from .url.

Class Inheritance
Inheritance diagram of AsyncMapData

copy(other=None, overwrite=True, **kwargs)

Copy the configuration settings from this instance to the other instance.

Parameters:
  • other (HighchartsMeta) – The target instance to which the properties of this instance should be copied. If None, will create a new instance and populate it with properties copied from self. Defaults to None.

  • overwrite (bool) – if True, properties in other that are already set will be overwritten by their counterparts in self. Defaults to True.

  • kwargs – Additional keyword arguments. Some special descendents of HighchartsMeta may have special implementations of this method which rely on additional keyword arguments.

Returns:

A mutated version of other with new property values

classmethod from_dict(as_dict: dict, allow_snake_case: bool = True)

Construct an instance of the class from a dict object.

Parameters:
  • as_dict (dict) – A dict representation of the object.

  • allow_snake_case (bool) – If True, interprets snake_case keys as equivalent to camelCase keys. Defaults to True.

Returns:

A Python object representation of as_dict.

Return type:

HighchartsMeta

classmethod from_js_literal(as_str_or_file, allow_snake_case: bool = True, _break_loop_on_failure: bool = False)

Return a Python object representation of a Highcharts JavaScript object literal.

Parameters:
  • as_str_or_file (str) – The JavaScript object literal, represented either as a str or as a filename which contains the JS object literal.

  • allow_snake_case (bool) – If True, interprets snake_case keys as equivalent to camelCase keys. Defaults to True.

  • _break_loop_on_failure (bool) – If True, will break any looping operations in the event of a failure. Otherwise, will attempt to repair the failure. Defaults to False.

Returns:

A Python object representation of the Highcharts JavaScript object literal.

Return type:

HighchartsMeta

classmethod from_json(as_json_or_file, allow_snake_case: bool = True)

Construct an instance of the class from a JSON string.

Parameters:
  • as_json_or_file – The JSON string for the object or the filename of a file that contains the JSON string.

  • allow_snake_case (bool) – If True, interprets snake_case keys as equivalent to camelCase keys. Defaults to True.

Returns:

A Python objcet representation of as_json.

Return type:

HighchartsMeta

to_dict() dict

Generate a dict representation of the object compatible with the Highcharts JavaScript library.

Note

The dict representation has a property structure and naming convention that is intentionally consistent with the Highcharts JavaScript library. This is not Pythonic, but it makes managing the interplay between the two languages much, much simpler.

Returns:

A dict representation of the object.

Return type:

dict

to_js_literal(filename=None, encoding='utf-8') str | None[source]

Return the object represented as a str containing the JavaScript object literal.

Parameters:
  • filename (Path-like) – The name of a file to which the JavaScript object literal should be persisted. Defaults to None

  • encoding (str) – The character encoding to apply to the resulting object. Defaults to 'utf-8'.

Return type:

str or None

to_json(filename=None, encoding='utf-8')

Generate a JSON string/byte string representation of the object compatible with the Highcharts JavaScript library.

Note

This method will either return a standard str or a bytes object depending on the JSON serialization library you are using. For example, if your environment has orjson, the result will be a bytes representation of the string.

Parameters:
  • filename (Path-like) – The name of a file to which the JSON string should be persisted. Defaults to None

  • encoding (str) – The character encoding to apply to the resulting object. Defaults to 'utf-8'.

Returns:

A JSON representation of the object compatible with the Highcharts library.

Return type:

str or bytes

static trim_dict(untrimmed: dict, to_json: bool = False) dict

Remove keys from untrimmed whose values are None and convert values that have .to_dict() methods.

Parameters:
  • untrimmed (dict) – The dict whose values may still be None or Python objects.

  • to_json (bool) – If True, will remove all keys from untrimmed that are not serializable to JSON. Defaults to False.

Returns:

Trimmed dict

Return type:

dict

static trim_iterable(untrimmed, to_json=False)

Convert any EnforcedNullType values in untrimmed to 'null'.

Parameters:
  • untrimmed (iterable) – The iterable whose members may still be None or Python objects.

  • to_json (bool) – If True, will remove all members from untrimmed that are not serializable to JSON. Defaults to False.

Return type:

iterable

property fetch_config: FetchConfiguration | None

Optional configuration settings to use when executing the (JavaScript) asynchronous fetch() call to download the map geometry. Defaults to None.

Note

The .url. setting will override any URL set in the FetchConfiguration.

Return type:

FetchConfiguration or None

property fetch_counter: int

The number to append to the topology variable name when serializing the map data. Defaults to 0.

Return type:

int

property selector: CallbackFunction | None

An optional (JavaScript) function which receives the map geometry downloaded from .url, can perform some (arbitrary - it’s up to you!) operation on that data, and returns a new set of map geometries which will be visualized by Highcharts for Maps. Defaults to None.

Note

The selector function must accept a single argument: topology and must return a single value (which will be assigned to the JavaScript variable named topology).

Return type:

CallbackFunction or None

property url: str | None

The URL that the (JavaScript) fetch() function will be requesting, which should return either TopoJSON or GeoJSON data. Defaults to None.

Note

This property will overwrite any URL configured within .fetch_config.

Return type:

str or None