I need to create a python function that translates from a lat/lng/h(m) ellipsoid to a…
- User
I need to create a python function that translates from a lat/lng/h(m) ellipsoid to a local coordinate system in feet: 65KI 6378137.00000 298.2572229329 D5KI 1.0000000000 0.00000 0.00000 64KI3 45.274211305 -95.011079858 625.03785 1387.69317 1.0000540297
49KI3 6378137.00000 298.2572229329 0.000000000 0.000000000 0.000000000 0.00000 0.00000 0.00000 0.0000000000 50KI 809.01308 1240.53352 -0.06330 -0.07307 -0.0253147588 0.9999598398 81KI1 625.04704 1387.69545 30.66315 0.0000000000 0.0000000000 Assistant
- User
I also need to do the inverse calculation.
Assistant
To perform the inverse transformation (from local coordinates in feet back to WGS84 latitude/longitude/height), we use the same projection parameters but reverse the coordinate transformation direction.
Solution Code (Inverse Function)
import pyproj def local_to_lat_lng_h(easting_ft, northing_ft, height_ft): """ Translates local coordinates (easting, northing in feet) and height in feet to WGS84 (latitude, longitude, height in meters). Parameters: easting_ft (float): Easting coordinate in feet. northing_ft (float): Northing coordinate in feet. height_ft (float): Height in feet. Returns: tuple: (latitude, longitude, height_m) in degrees and meters. """ # Define the source CRS (local Transverse Mercator) src_crs = pyproj.CRS.from_proj4( f"+proj=tmerc +lat_0={45.274211305} +lon_0={-95.011079858} " f"+k={1.0000540297} +x_0={625.03785} +y_0={1387.69317} " "+ellps=WGS84 +units=us-ft +no_defs" ) # Target CRS is WGS84 (EPSG:4326) target_crs = pyproj.CRS.from_epsg(4326) # Create transformer transformer = pyproj.Transformer.from_crs(src_crs, target_crs, always_xy=True) # Transform easting/northing (feet) to longitude/latitude lng, lat = transformer.transform(easting_ft, northing_ft) # Convert height from feet to meters height_m = height_ft / 3.28084 return (lat, lng, height_m)
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.