manaakiwhenua / vector2dggs

DGGS indexer for vector data
https://pypi.org/project/vector2dggs/
GNU Lesser General Public License v3.0
6 stars 0 forks source link

Error when working with multipart features #22

Closed alpha-beta-soup closed 1 year ago

alpha-beta-soup commented 1 year ago

https://github.com/manaakiwhenua/vector2dggs/blob/8a37db87104286fc48bb0c5cfa8c1e811d78085a/vector2dggs/h3.py#L195

This line drops empty or null geometries, but it does so after exploding the geodataframe (twice) to account for geometry collections and multitpart geometries, but the df used to get the labels of null/empty geometries at that point is irrelevant after the explosions. It should be two separate invocations, not one chained operation.

alpha-beta-soup commented 1 year ago

Example error trace for this

Traceback (most recent call last):
  File "/home/richard/landcare/luis/.snakemake/conda/1de9b4a2e021e0930127f39ae4ab0930_/bin/vector2dggs", line 8, in <module>
    sys.exit(main())
             ^^^^^^
  File "/home/richard/landcare/luis/.snakemake/conda/1de9b4a2e021e0930127f39ae4ab0930_/lib/python3.11/site-packages/vector2dggs/cli.py", line 25, in main
    cli()
  File "/home/richard/landcare/luis/.snakemake/conda/1de9b4a2e021e0930127f39ae4ab0930_/lib/python3.11/site-packages/click/core.py", line 1130, in __call__
    return self.main(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/richard/landcare/luis/.snakemake/conda/1de9b4a2e021e0930127f39ae4ab0930_/lib/python3.11/site-packages/click/core.py", line 1055, in main
    rv = self.invoke(ctx)
         ^^^^^^^^^^^^^^^^
  File "/home/richard/landcare/luis/.snakemake/conda/1de9b4a2e021e0930127f39ae4ab0930_/lib/python3.11/site-packages/click/core.py", line 1657, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/richard/landcare/luis/.snakemake/conda/1de9b4a2e021e0930127f39ae4ab0930_/lib/python3.11/site-packages/click/core.py", line 1404, in invoke
    return ctx.invoke(self.callback, **ctx.params)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/richard/landcare/luis/.snakemake/conda/1de9b4a2e021e0930127f39ae4ab0930_/lib/python3.11/site-packages/click/core.py", line 760, in invoke
    return __callback(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/richard/landcare/luis/.snakemake/conda/1de9b4a2e021e0930127f39ae4ab0930_/lib/python3.11/site-packages/vector2dggs/h3.py", line 402, in h3
    _index(
  File "/home/richard/landcare/luis/.snakemake/conda/1de9b4a2e021e0930127f39ae4ab0930_/lib/python3.11/site-packages/vector2dggs/h3.py", line 195, in _index
    .drop(df[(df.geometry.is_empty|df.geometry.isna())].index)
     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/richard/landcare/luis/.snakemake/conda/1de9b4a2e021e0930127f39ae4ab0930_/lib/python3.11/site-packages/pandas/core/frame.py", line 5258, in drop
    return super().drop(
           ^^^^^^^^^^^^^
  File "/home/richard/landcare/luis/.snakemake/conda/1de9b4a2e021e0930127f39ae4ab0930_/lib/python3.11/site-packages/pandas/core/generic.py", line 4549, in drop
    obj = obj._drop_axis(labels, axis, level=level, errors=errors)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/richard/landcare/luis/.snakemake/conda/1de9b4a2e021e0930127f39ae4ab0930_/lib/python3.11/site-packages/pandas/core/generic.py", line 4620, in _drop_axis
    raise KeyError(f"{labels} not found in axis")
KeyError: '[50 58 88 103 104 116 141 223 279 442 668 1648 1741 1781 2497 2528 2584\n 2629 2871 3007 3174 3353 4203 4338 4354 4358 4391 4550 4637 4695 4803\n 4867 4953 5042 5112 5199 5217 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 39\n 40 73 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38\n 41 42 43 44 45 46 47 48 49 51 52 53 54 55 56 57 59 60 61 62 63 64 65 66\n 67 68 69 70 71 72 74 75 76 77 78 79 80 81 82 83 84 130 85 86 87 89 90 91\n 92 93 94 95 96 97 3725 98 99 100 101 102 105 106 107 108 109 110 111 112\n 113 3357 114 115 117 118 119 120 121 122 123 124 125 126 127 128 129 171\n 131 132 133 134 135 136 137 138 139 140 142 143 144 145 146 147 148 149\n 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167\n 168 169 170 197 172 173 174 175 176 177 178 179 180 181 182 183 184 185\n 186 187 188 189 190 191 192 193 194 195 196 198 199 200 201 202 203 204\n 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222\n 224 257 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240\n 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 258 259\n 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277\n 278 280 281 282 283 284 3358 285 286 287 288 289 290 291 292 293 294 295\n 296 297 298 299 4509 435 495 602 734 855 873 874 957 1048 1061 1208 1242\n 1338 1324 1503 1813 2394 2772 2773 2787 2795 2799 2800 3144 3145 3169\n 3232 3259 3309 3329 3332 3360 3448 3449 3476 3513 3516 3570 3571 3890\n 3913 3988 4067 4093 4130 4131 4132 4133 4167 4204 4210 4211 4271 4230\n 4231 4244 4245 4246 4247 4248 4249 4250 4251 4254 4255 4256 4260 4361\n 4264 4265 4266 4269 4310 4311 4315 4317 4336 4337 4339 4340 4346 4406\n 4425 4435 4444 4496 4500 4508 4513 4514 4515 4517 4518 4519 4582 4602\n 4644 4714 4737 4742 4764 4784 4811 4815 4829 4832 4906 4908 4933 5017\n 5036 5076 5175 5214] not found in axis'

Known to be reproducible using NZ Property Titles layer, with NZ REC watersheds (Awanui catchment) as a clip source before running vector2dggs.