@@ -2194,6 +2194,26 @@ def grid_count_pixel_in(
2194
2194
grid_count_ (grid , i , j )
2195
2195
2196
2196
2197
+ @njit (cache = True )
2198
+ def reduce_size (x , y ):
2199
+ """
2200
+ Reduce array size if last position is repeated, in order to save compute time
2201
+
2202
+ :param array x: longitude
2203
+ :param array y: latitude
2204
+
2205
+ :return: reduce arrays x,y
2206
+ :rtype: ndarray,ndarray
2207
+ """
2208
+ i = x .shape [0 ]
2209
+ x0 , y0 = x [0 ], y [0 ]
2210
+ while True :
2211
+ i -= 1
2212
+ if x [i ] != x0 or y [i ] != y0 :
2213
+ i += 1
2214
+ return x [:i ], y [:i ]
2215
+
2216
+
2197
2217
@njit (cache = True )
2198
2218
def poly_indexs (x_p , y_p , x_c , y_c ):
2199
2219
"""
@@ -2208,9 +2228,10 @@ def poly_indexs(x_p, y_p, x_c, y_c):
2208
2228
nb_c = x_c .shape [0 ]
2209
2229
indexs = - ones (nb_p , dtype = numba_types .int32 )
2210
2230
for i in range (nb_c ):
2211
- x_c_min , y_c_min = x_c [i ].min (), y_c [i ].min ()
2212
- x_c_max , y_c_max = x_c [i ].max (), y_c [i ].max ()
2213
- v = create_vertice (x_c [i ], y_c [i ])
2231
+ x_ , y_ = reduce_size (x_c [i ], y_c [i ])
2232
+ x_c_min , y_c_min = x_ .min (), y_ .min ()
2233
+ x_c_max , y_c_max = x_ .max (), y_ .max ()
2234
+ v = create_vertice (x_ , y_ )
2214
2235
for j in range (nb_p ):
2215
2236
if indexs [j ] != - 1 :
2216
2237
continue
@@ -2235,9 +2256,10 @@ def insidepoly(x_p, y_p, x_c, y_c):
2235
2256
nb_c = x_c .shape [0 ]
2236
2257
flag = zeros (nb_p , dtype = numba_types .bool_ )
2237
2258
for i in range (nb_c ):
2238
- x_c_min , y_c_min = x_c [i ].min (), y_c [i ].min ()
2239
- x_c_max , y_c_max = x_c [i ].max (), y_c [i ].max ()
2240
- v = create_vertice (x_c [i ], y_c [i ])
2259
+ x_ , y_ = reduce_size (x_c [i ], y_c [i ])
2260
+ x_c_min , y_c_min = x_ .min (), y_ .min ()
2261
+ x_c_max , y_c_max = x_ .max (), y_ .max ()
2262
+ v = create_vertice (x_ , y_ )
2241
2263
for j in range (nb_p ):
2242
2264
if flag [j ]:
2243
2265
continue
0 commit comments