Did you notice "AI Assist" has been added to PythonCreator/PythonCaller in FME 2023.1?
I tried it.
It's not a question, just a chat. It would be nice if you can share your experiences on the AI Assist.
Create a new method to calculate coordinates of the extents for a web map tile.AI returned:
def calculate_tile_extents(x: int, y: int, z: int) -> tuple:
    """Calculates the extents of a web map tile given its x, y, and z coordinates."""
    n = 2.0 ** z
    lon_left = x / n * 360.0 - 180.0
    lat_bottom = math.degrees(math.atan(math.sinh(math.pi * (1 - 2 * y / n))))
    lon_right = (x + 1) / n * 360.0 - 180.0
    lat_top = math.degrees(math.atan(math.sinh(math.pi * (1 - 2 * (y + 1) / n))))
    return (lon_left, lat_bottom, lon_right, lat_top)Good, but I want to convert latitude, longitude to x, y in EPSG:3857 finally.
Create a new method to convert latitude and longitude to x and y in EPSG:3857.AI returned:
import pyproj
 
def lat_long_to_xy(lat, long):
    in_proj = pyproj.Proj(init='epsg:4326')
    out_proj = pyproj.Proj(init='epsg:3857')
    x, y = pyproj.transform(in_proj, out_proj, long, lat)
    return x, y"pyproj" is an external Python module, I don't want to install it, so...
Create a new method to convert latitude and longitude to x and y in EPSG:3857, without using any additional Python libraries.AI returned:
def lat_long_to_xy(lat: float, long: float):
    
    r_major = 6378137.0
    x = r_major * math.radians(long)
    scale = x / long
    y = 180.0 / math.pi * math.log(math.tan(math.pi / 4.0 + lat * (math.pi / 180.0) / 2.0)) * scale
    return x, yVery good 🙂

