Skip to content

Commit fe6ec35

Browse files
authored
Merge pull request #1276 from CodeForPhilly/staging
Staging
2 parents 438b9b7 + 34939eb commit fe6ec35

71 files changed

Lines changed: 3357 additions & 3965 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/release.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ jobs:
2525
run: npm ci
2626

2727
- name: Create Tag
28-
uses: cycjimmy/semantic-release-action@v4.2.1
28+
uses: cycjimmy/semantic-release-action@v4.2.2
2929
env:
3030
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
3131

data/.gitattributes

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
backup_data/*.parquet filter=lfs diff=lfs merge=lfs -text
2+
backup_data/*.pmtiles filter=lfs diff=lfs merge=lfs -text

data/Dockerfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ RUN apt-get update && apt-get install -y \
3838
&& rm -rf /var/lib/apt/lists/*
3939

4040
COPY --from=tippecanoe /usr/local/bin/tippecanoe /usr/local/bin/tippecanoe
41+
COPY --from=tippecanoe /usr/local/bin/tile-join /usr/local/bin/tile-join
4142
COPY --from=dependencies /app /app
4243

4344
ENV GDAL_VERSION=3.6.2 \
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
version https://git-lfs.github.com/spec/v1
2+
oid sha256:49ef5d3e7f05edb52f94195dd0bab6312154478097f08d06316186956fe43f81
3+
size 97703217
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
version https://git-lfs.github.com/spec/v1
2+
oid sha256:62d1cec2f016055774449c324ecd012540ee921fec9abefcd6321bf02111d671
3+
size 8141995

data/src/classes/featurelayer.py

Lines changed: 4 additions & 103 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import logging as log
22
import os
3-
import subprocess
43
import traceback
54
from concurrent.futures import ThreadPoolExecutor, as_completed
65

@@ -11,15 +10,14 @@
1110
from shapely import wkb
1211
from tqdm import tqdm
1312

13+
from src.classes.bucket_manager import GCSBucketManager
14+
from src.classes.file_manager import FileManager, FileType, LoadType
15+
from src.classes.loaders import generate_pmtiles
1416
from src.config.config import (
1517
FORCE_RELOAD,
1618
USE_CRS,
1719
log_level,
18-
min_tiles_file_size_in_bytes,
19-
write_production_tiles_file,
2020
)
21-
from src.classes.bucket_manager import GCSBucketManager
22-
from src.classes.file_manager import FileManager, FileType, LoadType
2321
from src.loaders import load_carto_data, load_esri_data
2422

2523
log.basicConfig(level=log_level)
@@ -281,101 +279,4 @@ def build_and_publish(self, tiles_file_id_prefix: str) -> None:
281279
Raises:
282280
ValueError: Raised if the generated PMTiles file is smaller than the minimum allowed size, indicating a potential corruption or incomplete file.
283281
"""
284-
zoom_threshold: int = 13
285-
286-
# Export the GeoDataFrame to a temporary GeoJSON file
287-
temp_geojson_points: str = (
288-
f"storage/temp/temp_{tiles_file_id_prefix}_points.geojson"
289-
)
290-
temp_geojson_polygons: str = (
291-
f"storage/temp/temp_{tiles_file_id_prefix}_polygons.geojson"
292-
)
293-
temp_pmtiles_points: str = (
294-
f"storage/temp/temp_{tiles_file_id_prefix}_points.pmtiles"
295-
)
296-
temp_pmtiles_polygons: str = (
297-
f"storage/temp/temp_{tiles_file_id_prefix}_polygons.pmtiles"
298-
)
299-
temp_merged_pmtiles: str = (
300-
f"storage/temp/temp_{tiles_file_id_prefix}_merged.pmtiles"
301-
)
302-
303-
# Reproject
304-
gdf_wm = self.gdf.to_crs(epsg=4326)
305-
gdf_wm.to_file(temp_geojson_polygons, driver="GeoJSON")
306-
307-
# Create points dataset
308-
self.centroid_gdf = self.gdf.copy()
309-
self.centroid_gdf["geometry"] = self.centroid_gdf["geometry"].centroid
310-
self.centroid_gdf = self.centroid_gdf.to_crs(epsg=4326)
311-
self.centroid_gdf.to_file(temp_geojson_points, driver="GeoJSON")
312-
313-
# Command for generating PMTiles for points up to zoom level zoom_threshold
314-
points_command: list[str] = [
315-
"tippecanoe",
316-
f"--output={temp_pmtiles_points}",
317-
f"--maximum-zoom={zoom_threshold}",
318-
"--minimum-zoom=10",
319-
"-zg",
320-
"-aC",
321-
"-r0",
322-
temp_geojson_points,
323-
"-l",
324-
"vacant_properties_tiles_points",
325-
"--force",
326-
]
327-
328-
# Command for generating PMTiles for polygons from zoom level zoom_threshold
329-
polygons_command: list[str] = [
330-
"tippecanoe",
331-
f"--output={temp_pmtiles_polygons}",
332-
f"--minimum-zoom={zoom_threshold}",
333-
"--maximum-zoom=16",
334-
"-zg",
335-
"--no-tile-size-limit",
336-
temp_geojson_polygons,
337-
"-l",
338-
"vacant_properties_tiles_polygons",
339-
"--force",
340-
]
341-
342-
# Command for merging the two PMTiles files into a single output file
343-
merge_command: list[str] = [
344-
"tile-join",
345-
f"--output={temp_merged_pmtiles}",
346-
"--no-tile-size-limit",
347-
temp_pmtiles_polygons,
348-
temp_pmtiles_points,
349-
"--force",
350-
]
351-
352-
# Run the commands
353-
for command in [points_command, polygons_command, merge_command]:
354-
subprocess.run(command)
355-
356-
write_files: list[str] = [f"{tiles_file_id_prefix}_staging.pmtiles"]
357-
358-
if write_production_tiles_file:
359-
write_files.append(f"{tiles_file_id_prefix}.pmtiles")
360-
361-
# Check whether the temp saved tiles files is big enough.
362-
file_size: int = os.stat(temp_merged_pmtiles).st_size
363-
if file_size < min_tiles_file_size_in_bytes:
364-
raise ValueError(
365-
f"{temp_merged_pmtiles} is {file_size} bytes in size but should be at least {min_tiles_file_size_in_bytes}. Therefore, we are not uploading any files to the GCP bucket. The file may be corrupt or incomplete."
366-
)
367-
368-
bucket = google_cloud_bucket(require_write_access=True)
369-
if bucket is None:
370-
print("Skipping PMTiles upload due to read-only bucket access.")
371-
return
372-
373-
# Upload PMTiles to Google Cloud Storage
374-
bucket = google_cloud_bucket()
375-
for file in write_files:
376-
blob = bucket.blob(file)
377-
try:
378-
blob.upload_from_filename(temp_merged_pmtiles)
379-
print(f"PMTiles upload successful for {file}!")
380-
except Exception as e:
381-
print(f"PMTiles upload failed for {file}: {e}")
282+
generate_pmtiles(self.gdf, tiles_file_id_prefix)

0 commit comments

Comments
 (0)