[MapProxy] Wrong reprojection to SRS which use units=us-ft when using Mapproxy with pyproj

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view

[MapProxy] Wrong reprojection to SRS which use units=us-ft when using Mapproxy with pyproj

Martin Icking

I discovered that using MapProxy with pyproj you cannot successfully reproject to an SRS that uses units different from meter.

In my case I tried to reproject OSM data into EPSG:32019 which resulted in wrong tiles.


The issue is caused by a nasty behavior of the pyproj library which has already been mentioned in multiple pyproj issues, see here: https://github.com/jswhit/pyproj/issues/67

Software using pyproj should use the additional parameter “preserve_units=True” when instantiating a new class, e.g.


ny_state = pyproj.Proj(init="EPSG:2263", preserve_units=True)


Currently MapProxy does not set this parameter, by that pyproj assumes that each SRS is based on “units=m”.

I’ve successfully tried a quick fix in mapproxy’s proj.py (I’m not a Python developer at all, so there might be nicer solutions):


def try_pyproj_import():


        from pyproj import Proj, transform, set_datapath

    except ImportError:

        return False


    # this new class overrides the constructor of the Proj class to set preserve_units to True by default

    class myProj(Proj):

        def __new__(self, projparams=None, preserve_units=True, **kwargs):

            return super(myProj, self).__new__(self,projparams,preserve_units,**kwargs)


    log_system.info('using pyproj for coordinate transformation')

    return myProj, transform, set_datapath


Best regards


MapProxy mailing list
[hidden email]