-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
+ Post processing, + Transliterations, HTML stats, upgrade geojson-stats
- Loading branch information
Showing
12 changed files
with
827 additions
and
67 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
from geojson_stats.stats import Stats | ||
from geojson_stats.html import Html | ||
|
||
CONFIG_AREA = ["building"] | ||
CONFIG_LENGTH = ["highway", "waterway"] | ||
|
||
class GeoJSONStats(Stats): | ||
"""Used for collecting stats while processing GeoJSON files line by line""" | ||
|
||
def __init__(self, filters, *args, **kwargs): | ||
super().__init__(*args, **kwargs) | ||
|
||
self.config.clean = True | ||
self.config.properties_prop = "properties.tags" | ||
|
||
if filters and filters.tags: | ||
|
||
for tag in CONFIG_AREA: | ||
if self.check_filter(filters.tags, tag): | ||
self.config.keys.append(tag) | ||
self.config.value_keys.append(tag) | ||
self.config.area = True | ||
|
||
for tag in CONFIG_LENGTH: | ||
if self.check_filter(filters.tags, tag): | ||
self.config.keys.append(tag) | ||
self.config.value_keys.append(tag) | ||
self.config.length = True | ||
|
||
def check_filter(self, tags, tag): | ||
""" | ||
Check if a tag is present in tag filters | ||
""" | ||
|
||
if tags.all_geometry: | ||
if tags.all_geometry.join_or and tag in tags.all_geometry.join_or: | ||
return True | ||
if tags.all_geometry.join_and and tag in tags.all_geometry.join_and: | ||
return True | ||
if tags.polygon: | ||
if tags.polygon.join_or and tag in tags.polygon.join_or: | ||
return True | ||
if tags.polygon.join_and and tag in tags.polygon.join_and: | ||
return True | ||
if tags.line: | ||
if tags.line.join_or and tag in tags.line.join_or: | ||
return True | ||
if tags.line.join_and and tag in tags.line.join_and: | ||
return True | ||
|
||
def raw_data_line_stats(self, json_object: dict): | ||
""" | ||
Process a GeoJSON line (for getting stats) and return that line | ||
""" | ||
self.get_object_stats(json_object) | ||
|
||
def html(self, tpl): | ||
return Html(tpl, self) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
|
||
import json | ||
from .transliterator import Transliterator | ||
from .geojson_stats import GeoJSONStats | ||
|
||
class PostProcessor(): | ||
"""Used for posst-process data while processing GeoJSON files line by line""" | ||
|
||
options = {} | ||
filters = {} | ||
functions = [] | ||
|
||
def __init__(self, options, *args, **kwargs): | ||
self.options = options | ||
|
||
def post_process_line(self, line: str): | ||
""" | ||
Parses line, run functions over it and returns it | ||
""" | ||
|
||
line_object = json.loads(line) | ||
|
||
for fn in self.functions: | ||
fn(line_object) | ||
|
||
return json.dumps(line_object) | ||
|
||
def init(self): | ||
""" | ||
Initialize post-processor | ||
""" | ||
|
||
if self.options["include_stats"]: | ||
self.geoJSONStats = GeoJSONStats(self.filters) | ||
self.functions.append(self.geoJSONStats.raw_data_line_stats) | ||
|
||
if self.options["include_translit"]: | ||
self.transliterator = Transliterator() | ||
self.functions.append(self.transliterator.translit) |
Oops, something went wrong.