Skip to content

Commit

Permalink
use wgs84 converter functions from ezdxf.math
Browse files Browse the repository at this point in the history
  • Loading branch information
mozman committed Mar 6, 2024
1 parent 5258801 commit c5e92c5
Showing 1 changed file with 6 additions and 11 deletions.
17 changes: 6 additions & 11 deletions src/ezdxf/addons/drawing/json.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,8 @@
from typing_extensions import TypeAlias, override
import abc
import json
import math

from ezdxf.math import Vec2
from ezdxf.math import Vec2, world_mercator_to_gps
from ezdxf.path import Command, nesting
from ezdxf.npshapes import orient_paths, single_paths

Expand Down Expand Up @@ -340,7 +339,7 @@ def no_transform(location: Vec2) -> tuple[float, float]:
return (location.x, location.y)


def make_function_wgs84_3395_to_4326(tol: float = 1e-6) -> TransformFunc:
def make_world_mercator_to_gps_function(tol: float = 1e-6) -> TransformFunc:
"""Returns a function to transform WGS84 World Mercator `EPSG:3395 <https://epsg.io/3395>`_
location given as cartesian 2D coordinates x, y in meters into WGS84 decimal
degrees as longitude and latitude `EPSG:4326 <https://epsg.io/4326>`_ as
Expand All @@ -350,14 +349,10 @@ def make_function_wgs84_3395_to_4326(tol: float = 1e-6) -> TransformFunc:
tol: accuracy for latitude calculation
"""
from ezdxf.addons.geo import wgs84_3395_to_4326
from ezdxf.math import Vec3

def _transform(location: Vec2) -> tuple[float, float]:
"""Transforms WGS84 World Mercator EPSG:3395 coordinates to WGS84 EPSG:4326."""
result = wgs84_3395_to_4326(Vec3(location), tol)
return result.x, result.y

return world_mercator_to_gps(location.x, location.y, tol)
return _transform


Expand All @@ -380,10 +375,10 @@ class GeoJSONBackend(_JSONBackend):
.. autofunction:: no_transform
Factory function to make a transform function from WGS84 World Mercator
`EPSG:3395 <https://epsg.io/3395>`_ coordinates to WGS84 `EPSG:4326 <https://epsg.io/4326>`_,
uses the converter function from the :mod:`ezdxf.addons.geo` add-on.
`EPSG:3395 <https://epsg.io/3395>`_ coordinates to WGS84 (GPS)
`EPSG:4326 <https://epsg.io/4326>`_.
.. autofunction:: make_function_wgs84_3395_to_4326
.. autofunction:: make_world_mercator_to_gps_function
The GeoJSON format supports only straight lines so curved shapes are flattened to
polylines and polygons.
Expand Down

0 comments on commit c5e92c5

Please sign in to comment.