Skip to content
This repository has been archived by the owner on Sep 4, 2024. It is now read-only.

Points to matrix #380

Merged
merged 10 commits into from
Jul 31, 2023
8 changes: 6 additions & 2 deletions lmpy/data_preparation/build_grid.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ def build_grid(
"min_y_coordinate": min_y,
"max_y_coordinate": max_y,
"cell_sides": cell_sides,
"size": cell_size
"cell_size": cell_size
}
script_name = os.path.splitext(os.path.basename(__file__))[0]
if min_x >= max_x or min_y >= max_y:
Expand Down Expand Up @@ -197,6 +197,8 @@ def build_grid(
f"{cell_sides}-sided cells of {cell_size} size and x-extent {min_x} " +
f"to {max_x}, y-extent {min_y} to {max_y}.", refname=script_name)

# Note that site_id is 0-based
site_headers = []
shape_id = 0
for cell_wkt in wkt_generator:
geom = ogr.CreateGeometryFromWkt(cell_wkt)
Expand All @@ -208,11 +210,13 @@ def build_grid(
feat.SetField(site_x, centroid.GetX())
feat.SetField(site_y, centroid.GetY())
feat.SetField(site_id, shape_id)
site_headers.append((shape_id, centroid.GetX(), centroid.GetY()))
layer.CreateFeature(feat)
shape_id += 1
feat.Destroy()
data_set.Destroy()
report["size"] = shape_id
report["grid_size"] = shape_id
# report["site_headers"] = site_headers
if logger is not None:
logger.log(
f"Wrote {grid_file_name} with {shape_id} sites.", refname=script_name)
Expand Down
Loading
Loading