Skip to content

Commit

Permalink
Sanitize geojsons for NaN values
Browse files Browse the repository at this point in the history
  • Loading branch information
dmannarino committed Dec 1, 2024
1 parent d5a28d9 commit f93b536
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions batch/python/tiles_geojson.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import json
import math
import subprocess
from concurrent.futures import ProcessPoolExecutor, as_completed
from typing import List, Dict, Any
from typing import List, Dict, Any, Optional
from geojson import Feature, FeatureCollection
from shapely.geometry import Polygon
from shapely.ops import unary_union
Expand Down Expand Up @@ -30,7 +31,13 @@ def extract_metadata_from_gdalinfo(gdalinfo_json: Dict[str, Any]) -> Dict[str, A
bands = [
{
"data_type": band.get("type", None),
"no_data": band.get("noDataValue", None),
"no_data": (
"nan" if (
band.get("noDataValue", None) is not None
and math.isnan(band.get("noDataValue"))
)
else band.get("noDataValue", None)
),
"nbits": band.get("metadata", {}).get("IMAGE_STRUCTURE", {}).get("NBITS", None),
"blockxsize": band.get("block", [None])[0],
"blockysize": band.get("block", [None])[1],
Expand Down

0 comments on commit f93b536

Please sign in to comment.