Skip to content

Commit

Permalink
Merge pull request #241 from geometalab/dev-qgis3
Browse files Browse the repository at this point in the history
Release v3.0.5
  • Loading branch information
mnboos committed Jun 9, 2019
2 parents 4621a05 + fe585a1 commit 920c43e
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 3 deletions.
5 changes: 4 additions & 1 deletion metadata.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ about=Plugin which reads vector tiles according to Mapbox' Vector Tiles specific
* OpenMapTiles.com with OSM Bright MB GL style (default)
* Nextzen.org
This Python plugin uses prebuilt C++ binaries for performance reasons.
version=3.0.4
version=3.0.5
author=Martin Boos
email=geometalab@gmail.com

Expand All @@ -22,6 +22,9 @@ email=geometalab@gmail.com

# Uncomment the following line and add your changelog:
changelog=
---3.0.5---
* Bugfix: Layer names from the TileJSON containing characters invalid for a filepath, would lead to an exception.
* Feature: ArcGIS support via TileJSON
---3.0.4---
* Feature: Loading a TileJSON from the harddisk is now supported
* Bugfix: Native library might have prevented deinstallation of plugin
Expand Down
16 changes: 16 additions & 0 deletions plugin/util/file_helper.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import os
import re
import shutil
import sys
import tempfile
Expand Down Expand Up @@ -121,6 +122,21 @@ def get_geojson_file_name(name):
return os.path.join(path, name_with_extension)


def get_valid_filename(s):
"""
Return the given string converted to a string that can be used for a clean
filename. Remove leading and trailing spaces; convert other spaces to
underscores; and remove anything that is not an alphanumeric, dash,
underscore, or dot.
>>> get_valid_filename("john's portrait in 2004.jpg")
'johns_portrait_in_2004.jpg'
Source: https://github.com/django/django/blob/master/django/utils/text.py
"""
s = str(s).strip().replace(" ", "_")
return re.sub(r"(?u)[^-\w.]", "", s)


def is_sqlite_db(path):
header_string = "SQLite"
chunksize = len(header_string)
Expand Down
6 changes: 4 additions & 2 deletions plugin/vt_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
get_geojson_file_name,
get_style_folder,
get_styles,
get_valid_filename,
is_gzipped,
)
from .util.log_helper import critical, debug, info, remove_key
Expand Down Expand Up @@ -507,7 +508,8 @@ def _process_tiles(self, tiles, layer_filter):
self._update_progress(progress=index + 1)

def _get_geojson_filename(self, layer_name, geo_type):
return "{}.{}.{}".format(self._source.name().replace(" ", "_"), layer_name, geo_type)
file_name = "{}.{}.{}".format(self._source.name().replace(" ", "_"), layer_name, geo_type)
return get_valid_filename(file_name)

def _create_qgis_layers(self, merge_features, apply_styles, clip_tiles):
"""
Expand Down Expand Up @@ -622,7 +624,7 @@ def _create_qgis_layers(self, merge_features, apply_styles, clip_tiles):
info("Layer creation complete")

@staticmethod
def _update_layer_source(layer_source, feature_collection):
def _update_layer_source(layer_source: str, feature_collection: dict) -> None:
"""
Updates the layers GeoJSON source file
:param layer_source: The path to the geoJSON file that is the source of the layer
Expand Down

0 comments on commit 920c43e

Please sign in to comment.