Skip to content

Commit

Permalink
Merge pull request #2 from fuzailpalnak/feature/one_line_print
Browse files Browse the repository at this point in the history
moved to py-oneliner for single line print
  • Loading branch information
fuzailpalnak authored Oct 25, 2020
2 parents 28fe0bd + f9514dd commit 43084c9
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 34 deletions.
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
install_requires = [
"shapely == 1.7.0",
"geojson >= 2.5.0",
"py-oneliner == 0.0.1"
]

setup(
Expand Down
44 changes: 29 additions & 15 deletions shape_merge/merge.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@
from shapely.geometry import shape, mapping
from shapely.ops import cascaded_union

from shape_merge.printer import Printer
from shape_merge.save import SaveFiona, SaveGeoJson

from py_oneliner import one_liner


class ShapeMerge:
def __init__(self, bounds_buffer=0, geometry_buffer=0, geometry_type=None):
Expand Down Expand Up @@ -106,8 +107,11 @@ def populate_index_by_feature(self, feature: dict):
self._index.insert(feature_id, geometry.bounds)
self._feature_geometry_collection[feature_id] = feature["geometry"]

Printer.print("Index Created for feature_id : {}".format(feature_id))

one_liner.one_line(
tag="Index Created for feature_id",
tag_data=f"{feature_id}",
tag_color="cyan",
)
if self._save is None:
self._save = SaveGeoJson()

Expand Down Expand Up @@ -258,22 +262,32 @@ def merge_geometries(self) -> OrderedDict:
for iterator, individual_collection in enumerate(
self._feature_geometry_collection.items()
):
Printer.print(
"Merging of Geometry In Progress: {} / {}".format(
str(iterator + 1), str(len(self._feature_geometry_collection)),
)
one_liner.one_line(
tag="Merging of Geometry In Progress",
tag_data=f"{str(iterator + 1)} / {str(len(self._feature_geometry_collection))}",
tag_color="cyan",
to_reset_data=True,
)

self._find_my_neighbour(individual_collection[0], individual_collection[1])
Printer.print_new_line(
"Reduced Geometry Count From {} to {}".format(
len(self._feature_geometry_collection), len(self._combined_geometries)
)

one_liner.one_line(
tag="Geometry Count",
tag_data=f"from {len(self._feature_geometry_collection)} "
f"to {str(len(self._combined_geometries))}",
tag_color="cyan",
to_reset_data=True,
to_new_line_data=True,
)

if self._save is not None:
Printer.print_new_line(
"Saving InProgress For Geometry as Type : {}".format(
self._save.__class__.__name__
)
one_liner.one_line(
tag="Saving InProgress",
tag_data=f"{self._save.__class__.__name__}",
tag_color="cyan",
tag_data_color="red",
to_reset_data=True,
to_new_line_data=True,
)
self._save.save(self._combined_geometries)
return self._combined_geometries
14 changes: 0 additions & 14 deletions shape_merge/printer.py

This file was deleted.

13 changes: 8 additions & 5 deletions shape_merge/save.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

from collections import OrderedDict

from shape_merge.printer import Printer
from py_oneliner import one_liner


class Save:
Expand Down Expand Up @@ -47,10 +47,13 @@ def save(self, merged_collection: OrderedDict):
with fiona.open(
out_file, "w", crs=self.crs, driver="ESRI Shapefile", schema=self.schema
) as output:
Printer.print_new_line(
"File initialized with geometry :{}, crs: {}, schema: {}".format(
self.geometry_type, self.crs, self.schema
)
one_liner.one_line(
tag="Save File Initiated",
tag_data=f"geometry: {self.geometry_type}, crs: {self.crs}, schema: {self.schema}",
tag_color="yellow",
tag_data_color="green",
to_reset_data=True,
to_new_line_data=True,
)
for i in merged_collection.keys():
newline = {
Expand Down

0 comments on commit 43084c9

Please sign in to comment.