Skip to content

Commit

Permalink
fix: file path modified
Browse files Browse the repository at this point in the history
  • Loading branch information
sijandh35 committed Jan 23, 2024
1 parent 6621c22 commit 09f77b9
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

setup(
name='tileclipper',
version='1.0.0',
version='1.0.1',
description='The `TileClipper` package enables users to download map tiles within a specified bounding box from a tile server',
author='Sijan Dhungana',
author_email='[email protected]',
Expand Down
10 changes: 7 additions & 3 deletions tileclipper/clipper.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from math import floor, pi, log, tan, cos
from concurrent.futures import ThreadPoolExecutor
from tqdm import tqdm
from urllib.parse import urlparse

class TileClipper:
def __init__(self,
Expand Down Expand Up @@ -63,11 +64,12 @@ def bbox2tiles(self, zoom, bbox):
def download_tile(self, x, y, zoom):
self.logger.info(f"Zoom Level: {zoom}")
tile_url = self.base_url.replace('{z}', str(zoom)).replace('{x}', str(x)).replace('{y}', str(y))
parsed_url = urlparse(tile_url)
filename = os.path.basename(parsed_url.path)
response = requests.get(tile_url)
if response.status_code == 200:
directory = os.path.join(self.output_folder, f"{zoom}/{x}/")
os.makedirs(directory, exist_ok=True)
filename = tile_url.split('/')[-1] + '.png'
with open(os.path.join(directory, filename), 'wb') as file:
file.write(response.content)
self.logger.info(f"Tile downloaded successfully to: {directory}{filename}")
Expand All @@ -94,11 +96,12 @@ def download_tiles(self, zoom_start, zoom_end):
def download_tile_with_progress_local(self, x, y, zoom, progress_bar):
self.logger.info(f"Zoom Level: {zoom}")
tile_url = self.base_url.replace('{z}', str(zoom)).replace('{x}', str(x)).replace('{y}', str(y))
parsed_url = urlparse(tile_url)
filename = os.path.basename(parsed_url.path)
response = requests.get(tile_url)
if response.status_code == 200:
directory = os.path.join(self.output_folder, f"{zoom}/{x}/")
os.makedirs(directory, exist_ok=True)
filename = tile_url.split('/')[-1] + '.png'
local_file_path = os.path.join(directory, filename)

with open(local_file_path, 'wb') as file:
Expand All @@ -111,9 +114,10 @@ def download_tile_with_progress_local(self, x, y, zoom, progress_bar):
def download_tile_with_progress_s3(self, x, y, zoom, progress_bar):
self.logger.info(f"Zoom Level: {zoom}")
tile_url = self.base_url.replace('{z}', str(zoom)).replace('{x}', str(x)).replace('{y}', str(y))
parsed_url = urlparse(tile_url)
filename = os.path.basename(parsed_url.path)
response = requests.get(tile_url)
if response.status_code == 200:
filename = tile_url.split('/')[-1] + '.png'
s3_client = boto3.client(
service_name='s3',
aws_access_key_id=self.aws_access_key,
Expand Down

0 comments on commit 09f77b9

Please sign in to comment.