Skip to content

Commit

Permalink
Merge pull request #154 from natsuapo/master
Browse files Browse the repository at this point in the history
  • Loading branch information
mattijn authored Apr 7, 2022
2 parents 97372c1 + 3e8946f commit 6c140a8
Showing 1 changed file with 27 additions and 9 deletions.
36 changes: 27 additions & 9 deletions topojson/core/extract.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class Extract(object):
object created including the keys `type`, `linestrings`, `coordinates` `bookkeeping_geoms`, `bookkeeping_coords`, `objects`
"""

def __init__(self, data, options={}):
def __init__(self, data, options={}):
# initation topology options
if isinstance(options, TopoOptions):
self.options = options
Expand Down Expand Up @@ -458,13 +458,24 @@ def _extract_featurecollection(self, geom):

# each Feature becomes a new GeometryCollection
for idx, feature in enumerate(obj["features"]):
# A GeoJSON Feature is mapped to a GeometryCollection
feature["type"] = "GeometryCollection"
feature["geometries"] = [feature["geometry"]]
feature.pop("geometry", None)
data["feature_{}".format(str(idx).zfill(zfill_value))] = geometry.shape(
feature
) # feature
# A GeoJSON Feature is mapped to a GeometryCollection => directly mapped to specific geometry, so that to save the attributes
feature["type"] = feature["geometry"]['type']
# feature["geometry"] = feature["geometry"]
# feature.pop("geometry", None)

feature_dict = {**(feature.get('properties') if feature.get('properties') else {}), **{'geometry' : geometry.shape(
feature['geometry']
)}}

if feature["type"] == 'GeometryCollection':
feature_dict['geometries'] = feature['geometry']['geometries']

### here not save the features for visualization:
data["feature_{}".format(str(idx).zfill(zfill_value))] = feature_dict # feature

# data["feature_{}".format(str(idx).zfill(zfill_value))] = geometry.shape(
# feature
# ) # feature

# new data dictionary is created, throw the geometries back to main()
self._is_single = False
Expand Down Expand Up @@ -630,7 +641,14 @@ def _extract_dictionary(self, geom):
# extract geometry and collect type and properties
geom = self._obj["geometry"]
self._obj.pop("geometry", None)
self._obj = {"properties": self._obj, "type": geom.geom_type}

if geom.geom_type == 'GeometryCollection':
geometries = self._obj["geometries"]
self._obj.pop("geometries",None)
self._obj = {"properties" : self._obj, "type" : geom.geom_type,'geometries':geometries}
else:
self._obj = {"properties": self._obj, "type": geom.geom_type}

self._data[self._key] = self._obj

# no direct shapely geometries available. Try forcing
Expand Down

0 comments on commit 6c140a8

Please sign in to comment.