88import enum
99import logging
1010import pathlib
11+ import math
1112import warnings
1213from collections import defaultdict
1314from collections .abc import Hashable , Iterable , Sequence
@@ -1092,7 +1093,7 @@ def grid_kinds(self) -> frozenset[UGridKind]:
10921093 items .append (UGridKind .edge )
10931094 return frozenset (items )
10941095
1095- def _make_polygons (self ) -> numpy . ndarray :
1096+ def _make_polygons (self ):
10961097 """Generate list of Polygons"""
10971098 topology = self .topology
10981099 # X,Y coords of each node
@@ -1115,10 +1116,15 @@ def _make_polygons(self) -> numpy.ndarray:
11151116 for unique_size in unique_sizes :
11161117 # Extract the face node data for every polygon of this size
11171118 indices = numpy .flatnonzero (polygon_sizes == unique_size )
1118- nodes = numpy .ma .getdata (face_node )[indices , :unique_size ]
1119- coords = numpy .stack ([node_x [nodes ], node_y [nodes ]], axis = - 1 )
1120- # Generate the polygons directly in to their correct locations
1121- shapely .polygons (coords , indices = indices , out = polygons )
1119+ chunk_size = 1000
1120+ chunk_count = math .ceil (len (indices ) / chunk_size )
1121+ for chunk_index in range (chunk_count ):
1122+ chunk_slice = slice (chunk_index * chunk_size , (chunk_index + 1 ) * chunk_size )
1123+ chunk_indices = indices [chunk_slice ]
1124+ nodes = numpy .ma .getdata (face_node )[chunk_indices , :unique_size ]
1125+ coords = numpy .stack ([node_x [nodes ], node_y [nodes ]], axis = - 1 )
1126+ # Generate the polygons directly in to their correct locations
1127+ shapely .polygons (coords , indices = chunk_indices , out = polygons )
11221128
11231129 return polygons
11241130
0 commit comments