A5Pandas module¶
A5Pandas module for A5 cell operations on pandas DataFrames and GeoDataFrames.
A5Pandas
¶
Source code in vgridpandas/a5pandas.py
183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 | |
a52geo(a5_col=None, split_antimeridian=False)
¶
Add geometry with A5 geometry to the DataFrame.
Parameters¶
split_antimeridian : bool, optional Split antimeridian-crossing cells. Default: False
Source code in vgridpandas/a5pandas.py
235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 | |
a5bin(resolution, stats='count', numeric_col=None, category_col=None, lat_col='lat', lon_col='lon', split_antimeridian=False)
¶
Bin points into a5 cells and compute statistics.
Source code in vgridpandas/a5pandas.py
318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 | |
latlon2a5(resolution, lat_col='lat', lon_col='lon', set_index=False)
¶
Adds A5 hex to (Geo)DataFrame.
pd.DataFrame: uses lat_col and lon_col (default lat and lon)
gpd.GeoDataFrame: uses geometry
Assumes coordinates in epsg=4326.
Parameters¶
resolution : int A5 resolution lat_col : str Name of the latitude column (if used), default 'lat' lon_col : str Name of the longitude column (if used), default 'lon' set_index : bool If True, the columns with A5 hex is set as index, default 'True'
Returns¶
(Geo)DataFrame with A5 IDs added
Source code in vgridpandas/a5pandas.py
188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 | |
linetrace(resolution, explode=False)
¶
A5 cell representation of a (Multi)LineString traced along its vertices.
Parameters¶
resolution : int A5 resolution explode : bool If True, will explode the resulting list vertically. All other columns' values are copied. Default: False
Source code in vgridpandas/a5pandas.py
298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 | |
polyfill(resolution, predicate=None, compact=False, explode=False, split_antimeridian=False)
¶
Parameters¶
resolution : int A5 resolution predicate : str, optional Spatial predicate to apply ('intersect', 'within', 'centroid_within', 'largest_overlap') compact : bool, optional Whether to compact the A5 hexes explode : bool If True, will explode the resulting list vertically. All other columns' values are copied. Default: False split_antimeridian : bool, optional Split antimeridian-crossing cells when converting to geometry. Default: False
Source code in vgridpandas/a5pandas.py
260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 | |
linetrace(geometry, resolution)
¶
Trace a (Multi)LineString with A5 cells along great-circle arcs between vertices.
Uses a5.line_string_to_cells (same approach as polyline2a5 in vgrid).
Cells may repeat at self-intersections or shared vertices.
Source code in vgridpandas/a5pandas.py
143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 | |
poly2a5(geometry, resolution, predicate=None, compact=False, split_antimeridian=False)
¶
Convert polygon geometries (Polygon, MultiPolygon) to A5 grid cells.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
resolution
|
int
|
A5 resolution level [0..29] |
required |
geometry
|
Polygon or MultiPolygon
|
Polygon geometry to convert |
required |
predicate
|
str
|
Spatial predicate to apply ('intersect', 'within', 'centroid_within', 'largest_overlap') |
None
|
split_antimeridian
|
bool
|
Split antimeridian-crossing cells if True. |
False
|
Example
from shapely.geometry import Polygon poly = Polygon([(-122.5, 37.7), (-122.3, 37.7), (-122.3, 37.9), (-122.5, 37.9)]) cells = poly2a5(poly, 10, predicate="intersect", compact=True) len(cells) > 0 True
Source code in vgridpandas/a5pandas.py
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 | |
polyfill_row(geometry, resolution, predicate=None, compact=False, split_antimeridian=False)
¶
Return cell ids covering a single row geometry.
Source code in vgridpandas/a5pandas.py
168 169 170 171 172 173 174 175 176 177 178 179 180 | |