Skip to content
This repository has been archived by the owner on Jan 9, 2025. It is now read-only.

Commit

Permalink
Create function to create chunked remap files
Browse files Browse the repository at this point in the history
  • Loading branch information
santind committed Dec 13, 2024
1 parent a2cf154 commit 833594a
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions mapswipe/workflows/project_remap.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from importlib.resources import files, as_file
import math
import pandas as pd
import numpy as np
from pysal.explore import esda
Expand Down Expand Up @@ -209,3 +210,17 @@ def apply_threshold_filter(gdf, threshold_n, threshold_type, selection_col):
gdf[selection_col] = 0.0
gdf[selection_col].iloc[-threshold_n:] = 1.0
return gdf


def generate_maproulette_shapefiles(gdf, project_id, file_size=10**6):
task_size = len(gdf.set_index("task_id")["geometry"].head(10).to_json()) // 10
chunk_size = file_size // task_size
gdf = gdf.set_index("task_id")
chunks = [gdf.iloc[i:i + chunk_size] for i in range(0, len(gdf), chunk_size)]
files = []
for idx, gdf_chunk in enumerate(chunks, start=1):
file_name = f"remap_maproulette_{project_id}_file{idx}of{len(chunks)}.geojson"
with open(file_name, "w", encoding="utf8") as f:
f.write(gdf_chunk["geometry"].to_json())
files.append(file_name)
return files

0 comments on commit 833594a

Please sign in to comment.