Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Errors on CRS issue when input dataset is empty #11

Open
alpha-beta-soup opened this issue May 8, 2023 · 2 comments
Open

Errors on CRS issue when input dataset is empty #11

alpha-beta-soup opened this issue May 8, 2023 · 2 comments
Labels
enhancement New feature or request

Comments

@alpha-beta-soup
Copy link
Member

Using this in a workflow, one input (Postgres table) was empty (which is valid). Instead of doing nothing and exiting gracefully, I get the following traceback:

Traceback (most recent call last):
  File "/home/richard/landcare/luis/.snakemake/conda/ce91d2d98a6110cf88fbd80a788421dc_/bin/vector2dggs", line 8, in <module>
    sys.exit(main())
             ^^^^^^
  File "/home/richard/landcare/luis/.snakemake/conda/ce91d2d98a6110cf88fbd80a788421dc_/lib/python3.11/site-packages/vector2dggs/cli.py", line 25, in main
    cli()
  File "/home/richard/landcare/luis/.snakemake/conda/ce91d2d98a6110cf88fbd80a788421dc_/lib/python3.11/site-packages/click/core.py", line 1130, in __call__
    return self.main(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/richard/landcare/luis/.snakemake/conda/ce91d2d98a6110cf88fbd80a788421dc_/lib/python3.11/site-packages/click/core.py", line 1055, in main
    rv = self.invoke(ctx)
         ^^^^^^^^^^^^^^^^
  File "/home/richard/landcare/luis/.snakemake/conda/ce91d2d98a6110cf88fbd80a788421dc_/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/ce91d2d98a6110cf88fbd80a788421dc_/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/ce91d2d98a6110cf88fbd80a788421dc_/lib/python3.11/site-packages/click/core.py", line 760, in invoke
    return __callback(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/richard/landcare/luis/.snakemake/conda/ce91d2d98a6110cf88fbd80a788421dc_/lib/python3.11/site-packages/vector2dggs/h3.py", line 304, in h3
    _index(
  File "/home/richard/landcare/luis/.snakemake/conda/ce91d2d98a6110cf88fbd80a788421dc_/lib/python3.11/site-packages/vector2dggs/h3.py", line 102, in _index
    df = df.to_crs(cut_crs)
         ^^^^^^^^^^^^^^^^^^
  File "/home/richard/landcare/luis/.snakemake/conda/ce91d2d98a6110cf88fbd80a788421dc_/lib/python3.11/site-packages/geopandas/geodataframe.py", line 1364, in to_crs
    geom = df.geometry.to_crs(crs=crs, epsg=epsg)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/richard/landcare/luis/.snakemake/conda/ce91d2d98a6110cf88fbd80a788421dc_/lib/python3.11/site-packages/geopandas/geoseries.py", line 1124, in to_crs
    self.values.to_crs(crs=crs, epsg=epsg), index=self.index, name=self.name
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/richard/landcare/luis/.snakemake/conda/ce91d2d98a6110cf88fbd80a788421dc_/lib/python3.11/site-packages/geopandas/array.py", line 762, in to_crs
    raise ValueError(
ValueError: Cannot transform naive geometries.  Please set a crs on the object first.
@alpha-beta-soup alpha-beta-soup added the enhancement New feature or request label May 8, 2023
@alpha-beta-soup
Copy link
Member Author

I think correct behaviour in this case should be a non-zero exit, but with a more explict message that the input is empty.

@alpha-beta-soup
Copy link
Member Author

alpha-beta-soup commented Jun 20, 2023

One current workaround

FEATURE_COUNT=$(ogrinfo -so {datasource} {layer} | sed -n 's/Feature Count: //p');
if [ "$FEATURE_COUNT" -eq '0' ]; then
    echo "{layer} is empty, skipping" && mkdir -p {output}
else
    vector2dggs h3 ...
fi;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant