Skip to content

Commit

Permalink
rename objects_name to object_name (#131)
Browse files Browse the repository at this point in the history
  • Loading branch information
mattijn committed Sep 7, 2021
1 parent 4321fd4 commit 813ebd8
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 19 deletions.
2 changes: 1 addition & 1 deletion docs/api/topojson.core.topology.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ coordinates but foremost the computation of a topology.
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`.
> + ###### `objects_name` : str
> + ###### `object_name` : str
Name 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`.
Expand Down
4 changes: 2 additions & 2 deletions docs/example/input-types.md
Original file line number Diff line number Diff line change
Expand Up @@ -329,8 +329,8 @@ import json

with open("tests/files_topojson/naturalearth_lowres_africa.topojson", 'r') as f:
data = json.load(f)
# parse topojson file using `objects_name`
topo = topojson.Topology(data, objects_name="data")
# parse topojson file using `object_name`
topo = topojson.Topology(data, object_name="data")
topo.toposimplify(4).to_svg()
```
<img src="../images/africa_toposimp.svg">
Expand Down
8 changes: 4 additions & 4 deletions tests/test_topology.py
Original file line number Diff line number Diff line change
Expand Up @@ -456,8 +456,8 @@ def test_topology_topojson_to_alt():
with open("tests/files_topojson/naturalearth_lowres_africa.topojson", 'r') as f:
data = json.load(f)

# parse topojson file using `objects_name`
topo = topojson.Topology(data, objects_name="data")
# parse topojson file using `object_name`
topo = topojson.Topology(data, object_name="data")
# apply toposimplify and serialize to altair
chart = topo.toposimplify(1).to_alt()

Expand All @@ -469,8 +469,8 @@ def test_topology_topojson_to_alt_int64():
with open("tests/files_topojson/mesh2d.topojson", 'r') as f:
data = json.load(f)

# parse topojson file using `objects_name`
topo = topojson.Topology(data, objects_name="mesh2d_flowelem_bl")
# parse topojson file using `object_name`
topo = topojson.Topology(data, object_name="mesh2d_flowelem_bl")
# apply toposimplify and serialize to altair
chart = topo.toposimplify(1).to_alt()

Expand Down
2 changes: 1 addition & 1 deletion topojson/core/hashmap.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ def _hashmapper(self, data):
objects["geometries"].append(feat)

data["objects"] = {}
data["objects"][self.options.objects_name] = objects
data["objects"][self.options.object_name] = objects

# prepare to return object
data = self._data
Expand Down
14 changes: 7 additions & 7 deletions topojson/core/topology.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ class Topology(Hashmap):
clockwise for interior rings. Or `CCW_CW` for counter-clockwise for outer
rings and clockwise for interior rings.
Default is `CW_CCW` for TopoJSON.
objects_name : str
object_name : str
Name 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`.
Expand All @@ -106,7 +106,7 @@ def __init__(
simplify_with="shapely",
simplify_algorithm="dp",
winding_order="CW_CCW",
objects_name="data"
object_name="data"
):

options = TopoOptions(locals())
Expand Down Expand Up @@ -144,7 +144,7 @@ def __repr__(self):
@property
def __geo_interface__(self):
topo_object = copy.deepcopy(self.output)
objectname = self.options.objects_name
objectname = self.options.object_name
return serialize_as_geojson(topo_object, validate=False, objectname=objectname)

def to_dict(self, options=False):
Expand Down Expand Up @@ -257,7 +257,7 @@ def to_geojson(
"""
topo_object = copy.deepcopy(self.output)
topo_object = self._resolve_coords(topo_object)
objectname = self.options.objects_name
objectname = self.options.object_name
fc = serialize_as_geojson(
topo_object, validate=validate, objectname=objectname, order=winding_order
)
Expand Down Expand Up @@ -298,7 +298,7 @@ def to_gdf(

topo_object = copy.deepcopy(self.output)
topo_object = self._resolve_coords(topo_object)
objectname = self.options.objects_name
objectname = self.options.object_name
fc = serialize_as_geojson(
topo_object, validate=validate, objectname=objectname, order=winding_order
)
Expand Down Expand Up @@ -331,7 +331,7 @@ def to_alt(
from ..utils import serialize_as_altair

topo_object = self.to_json()
objectname = self.options.objects_name
objectname = self.options.object_name


return serialize_as_altair(topo_object, color, tooltip, projection, objectname)
Expand Down Expand Up @@ -532,7 +532,7 @@ def toposimplify(
return result

def _resolve_coords(self, data):
objectname = self.options.objects_name
objectname = self.options.object_name
if not objectname in data["objects"].keys():
raise SystemExit(f"'{objectname}' is not an object name in your topojson file")
geoms = data["objects"][objectname]["geometries"]
Expand Down
8 changes: 4 additions & 4 deletions topojson/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def __init__(
simplify_with="shapely",
simplify_algorithm="dp",
winding_order=None,
objects_name="data"
object_name="data"
):
# get all arguments
arguments = locals()
Expand Down Expand Up @@ -82,10 +82,10 @@ def __init__(
else:
self.winding_order = None

if "objects_name" in arguments:
self.objects_name = arguments["objects_name"]
if "object_name" in arguments:
self.object_name = arguments["object_name"]
else:
self.objects_name = "data"
self.object_name = "data"

def __repr__(self):
return "TopoOptions(\n {}\n)".format(pprint.pformat(self.__dict__))
Expand Down

0 comments on commit 813ebd8

Please sign in to comment.