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

time.localtime() does not accept negative arguments on Windows #17

Closed
sphoto opened this issue Dec 5, 2021 · 3 comments
Closed

time.localtime() does not accept negative arguments on Windows #17

sphoto opened this issue Dec 5, 2021 · 3 comments
Assignees
Labels
bug Something isn't working

Comments

@sphoto
Copy link

sphoto commented Dec 5, 2021

ogr2osm DEM_10x10m_EPSG4326.shp -t contour.py --id=60000000000 --split-ways=500 --pbf -o DEM_10x10m_EPSG4326.pbf
Found valid translation class ContourTranslation
Preparing to convert 'DEM_10x10m_EPSG4326.shp' to 'DEM_10x10m_EPSG4326.pbf'.
Detected projection metadata:
GEOGCS["WGS 84",
    DATUM["WGS_1984",
        SPHEROID["WGS 84",6378137,298.257223563,
            AUTHORITY["EPSG","7030"]],
        AUTHORITY["EPSG","6326"]],
    PRIMEM["Greenwich",0,
        AUTHORITY["EPSG","8901"]],
    UNIT["degree",0.0174532925199433,
        AUTHORITY["EPSG","9122"]],
    AXIS["Latitude",NORTH],
    AXIS["Longitude",EAST],
    AUTHORITY["EPSG","4326"]]
Splitting long ways
Writing file header
Writing nodes
Traceback (most recent call last):
  File "C:\Python39\lib\runpy.py", line 197, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "C:\Python39\lib\runpy.py", line 87, in _run_code
    exec(code, run_globals)
  File "C:\Python39\Scripts\ogr2osm.exe\__main__.py", line 7, in <module>
  File "C:\Python39\lib\site-packages\ogr2osm\ogr2osm.py", line 282, in main
    osmdata.output(datawriter)
  File "C:\Python39\lib\site-packages\ogr2osm\osm_data.py", line 428, in output
    dw.write_nodes(self.__nodes)
  File "C:\Python39\lib\site-packages\ogr2osm\pbf_datawriter.py", line 291, in write_nodes
    primitive_group = PbfPrimitiveGroupDenseNodes(self.add_version, \
  File "C:\Python39\lib\site-packages\ogr2osm\pbf_datawriter.py", line 106, in __init__
    super().__init__(add_version, add_timestamp, suppress_empty_tags)
  File "C:\Python39\lib\site-packages\ogr2osm\pbf_datawriter.py", line 46, in __init__
    self._timestamp = time.localtime(-1)
OSError: [Errno 22] Invalid argument

Please see: https://stackoverflow.com/questions/16387787/odd-behaviour-of-ephems-python-package-localtime-function

@roelderickx roelderickx self-assigned this Dec 5, 2021
@roelderickx roelderickx added the bug Something isn't working label Dec 5, 2021
@roelderickx
Copy link
Owner

Thanks for your bug report and for your investigation @sphoto

I was not aware of this behaviour on Windows. After closer inspection we only need to store the amount of (milli)seconds since the 1970 epoch in stead of a complete time_struct, so there is no need to call time.localtime(-1) either. I implemented a fix and the modified code is available in the issue17 branch.

I have seen another potential problem though, according to https://docs.python.org/3/library/time.html#time.time the epoch is not necessarily January 1, 1970, 00:00:00 (UTC) on all systems, while it should be for the PBF file specification. On Windows and most Unix systems it should work as expected. I'll have a look on which systems there is a different epoch and if it needs fixing before merging to the main branch.

@roelderickx
Copy link
Owner

roelderickx commented Dec 5, 2021

In practice, the epoch is always assumed to be January 1, 1970, 00:00:00 (UTC). See this python dev-thread.
The fix has been merged into the main branch.

@sphoto
Copy link
Author

sphoto commented Dec 5, 2021

Thank you for fixing this issue so fast! It works now on my Windows machine.

@sphoto sphoto closed this as completed Dec 5, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants