python-vt2geojson icon indicating copy to clipboard operation
python-vt2geojson copied to clipboard

Source of the formula for coordinate tranformation?

Open NicoJG opened this issue 4 years ago • 0 comments

I am interested on where you got the formula from for the coodinate transformation?

I was searching for how to convert the coordinates of a Mapbox Vector Tile into Geodetical coordinate for a long time.

Do you have any resources that could help me understand this coordinate transformation?

The formula is implemented in the python-vt2geojson/vt2geojson/features.py file:

    def toGeoJSON(self):
        size = self.extent * 2 ** self.z
        x0 = self.extent * self.x
        y0 = self.extent * self.y

        def project_one(p_x, p_y):
            y2 = 180 - (p_y + y0) * 360. / size
            long_res = (p_x + x0) * 360. / size - 180
            lat_res = 360. / pi * atan(exp(y2 * pi / 180)) - 90
            return [long_res, lat_res]

NicoJG avatar Jun 11 '21 20:06 NicoJG