def _get_column_major(self, df, row_tuple): valid_indices = self._compute_validity_mask(df, row_tuple) from cudf import DataFrame result = DataFrame() for ix, col in enumerate(df.columns): if ix in valid_indices: result[ix] = list(df._cols.values())[ix] # Build new index - COLUMN based MultiIndex # --------------- if len(row_tuple) < len(self.levels): columns = self._popn(len(row_tuple)) result.columns = columns.take(valid_indices) else: result.columns = self.take(valid_indices) if len(result.columns.levels) == 1: columns = [] for code in result.columns.codes[result.columns.codes.columns[0]]: columns.append(result.columns.levels[0][code]) name = result.columns.names[0] result.columns = StringIndex(columns, name=name) return result
def point_in_polygon( test_points_x, test_points_y, poly_offsets, poly_ring_offsets, poly_points_x, poly_points_y, ): """ Compute from a set of points and a set of polygons which points fall within which polygons. Note that `polygons_(x,y)` must be specified as closed polygons: the first and last coordinate of each polygon must be the same. Parameters ---------- test_points_x x-coordinate of test points test_points_y y-coordinate of test points poly_offsets beginning index of the first ring in each polygon poly_ring_offsets beginning index of the first point in each ring poly_points_x x closed-coordinate of polygon points poly_points_y y closed-coordinate of polygon points Examples -------- Test whether 3 points fall within either of two polygons >>> result = cuspatial.point_in_polygon( [0, -8, 6.0], # test_points_x [0, -8, 6.0], # test_points_y cudf.Series([0, 1], index=['nyc', 'hudson river']), # poly_offsets [0, 3], # ring_offsets [-10, 5, 5, -10, 0, 10, 10, 0], # poly_points_x [-10, -10, 5, 5, 0, 0, 10, 10], # poly_points_y ) # The result of point_in_polygon is a DataFrame of Boolean # values indicating whether each point (rows) falls within # each polygon (columns). >>> print(result) nyc hudson river 0 True True 1 True False 2 False True # Point 0: (0, 0) falls in both polygons # Point 1: (-8, -8) falls in the first polygon # Point 2: (6.0, 6.0) falls in the second polygon note input Series x and y will not be index aligned, but computed as sequential arrays. Returns ------- result : cudf.DataFrame A DataFrame of boolean values indicating whether each point falls within each polygon. """ if len(poly_offsets) == 0: return DataFrame() ( test_points_x, test_points_y, poly_points_x, poly_points_y, ) = normalize_point_columns( as_column(test_points_x), as_column(test_points_y), as_column(poly_points_x), as_column(poly_points_y), ) result = cpp_point_in_polygon( test_points_x, test_points_y, as_column(poly_offsets, dtype="int32"), as_column(poly_ring_offsets, dtype="int32"), poly_points_x, poly_points_y, ) result = gis_utils.pip_bitmap_column_to_binary_array( polygon_bitmap_column=result, width=len(poly_offsets) ) result = DataFrame(result) result = DataFrame._from_data( {name: col.astype("bool") for name, col in result._data.items()} ) result.columns = [x for x in list(reversed(poly_offsets.index))] result = result[list(reversed(result.columns))] return result
def transform(self, columns: ColumnNames, gdf: cudf.DataFrame) -> cudf.DataFrame: gdf.columns = self.output_column_names(columns) return gdf