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

Constant ValueErrors before EPSG is set #269

Open
lvh opened this issue Dec 11, 2019 · 1 comment
Open

Constant ValueErrors before EPSG is set #269

lvh opened this issue Dec 11, 2019 · 1 comment

Comments

@lvh
Copy link
Contributor

lvh commented Dec 11, 2019

def get_code_from_epsg(epsg_string: StrOrInt) -> int:
    code = str(epsg_string).upper()
    if code.startswith("EPSG:"):
        code = code.replace("EPSG:", "")
    elif code.startswith("USER:"):
        code = code.replace("USER:", "")
    return int(code)

That last line errors when no EPSG is set, because epsg_string will be "" and so will "code". This function gets called from:

    def _get_qgis_crs(self) -> str:
        canvas = self.iface.mapCanvas()
        auth_id: str = canvas.mapSettings().destinationCrs().authid()
        return str(get_code_from_epsg(auth_id))

Because _get_qgis_crs gets called all the time (in _on_timeout, in _handle_mouse_move...) this basically results in constant errors.

I'll try to write a patch.

@lvh
Copy link
Contributor Author

lvh commented Dec 11, 2019

I'm actually open to suggestions for how to fix it. One is to change the return type to Optional[int] and push the optionality up the stack. Another is to return int(code) if code else 3857, but that might be seen as further reinforcing the dependence on 3857 that I think you've tried to get rid of elsewhere. (That said.... if you want a different EPSG maybe specify one :))

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

No branches or pull requests

1 participant