Jump to content
Sign in to follow this  
Janex72

Convert Lat:Lon to LKS-92

Recommended Posts

Hi all.

I, searching library for convert GIS coordinates (Lat:Lon) to Latvian standart LKS-92

 

Some one can help me, please?

 

WBR

Janex

Share this post


Link to post

There is the open source proj4 library which you could compile to a dll (if there is no download available, I haven't checked) and call from Delphi. It can convert from basically any GIS coordinate system to any other, but it is not easy to use.

Share this post


Link to post
Posted (edited)

Which LKS-92 coordinates? There are LKS-92 XYZ (spatial rectangular co-ordinates), LKS-92 BLh (geospatial co-ordinates on rotational ellipsoid) and LKS-92 TM (Transverse Mercator projections in plane co-ordinates). One (BLh) is already in long and latitude.

Quote

8.2. as geospatial co-ordinates on rotational ellipsoid, designated with LKS-92 BLh, where:

8.2.1. northern latitude is designated with B; 8.2.2. eastern longitude is designated with L;

8.2.3. geodetic (ellipsoid) height is designated with h;

8.2.4. northern latitude and eastern longitude is expressed in degrees (°), minutes (’) and seconds (");

8.2.5. height is expressed in metres

Ref:  Republic of Latvia Cabinet Regulation No. 879 Adopted 15 November 2011 Regulations Regarding the Geodetic Reference System and the Topographic Map System

        found at: Ministru kabineta (fao.org) (from Food and Agriculture Organization of the United Nations (FAO) website)

Note: some latter revisions but they do not appear to have been translated (This document has not been officially translated by the State Language Centre.). Main ref site:

   Ģeodēziskās atskaites sistēmas un topogrāfisko karšu sistēmas noteikumi (likumi.lv)

 

Edited by Brian Evans

Share this post


Link to post
Posted (edited)

Untested:
This is a proposal from ChatGPT regarding such conversion:

This is quite complex, and I've tried to double-check against Wolfram-Alpha, but it seems to stay with this standard approach.
Would be interesting to know if this works and is correct for you.
As it tells below: Better test deeply and against some known positions, before using this productive.

 

Quote

Additional Resources:

By leveraging these resources and thoroughly testing the implementation, you can enhance the reliability and accuracy of the coordinate conversion process in your Delphi application.

 
User
 
Please provide always the full sourcecode, to be able to directly test it.
 
ChatGPT

Creating a full and accurate implementation for the conversion of latitude and longitude to the LKS-92 coordinate system in Delphi is a complex task that requires precise geodetic calculations. Based on your request for a complete source code that you can directly test, here's an extended version of the Delphi unit I provided earlier. This version includes the necessary functions and calculations for the Transverse Mercator projection based on the WGS84 ellipsoid, which is used for LKS-92.

Delphi Unit: LKS92Conversion.pas



 

 

 

unit LKS92Conversion;

interface

uses
  System.SysUtils, System.Math;

type
  TCoordinate = record
    Easting: Double;
    Northing: Double;
  end;

function LatLonToLKS92(Lat, Lon: Double): TCoordinate;

implementation

const
  // WGS84 Ellipsoid constants
  a = 6378137.0; // Semi-major axis
  f = 1 / 298.257223563; // Flattening
  e = sqrt(2 * f - f * f); // First eccentricity
  // LKS-92 constants
  n0 = -6000000.0;
  e0 = 500000.0;
  k0 = 0.9996;
  lambda0 = 24; // Central meridian in degrees

function DegToRad(Degree: Double): Double;
begin
  Result := Degree * (Pi / 180);
end;

function LatLonToLKS92(Lat, Lon: Double): TCoordinate;
var
  LatRad, LonRad, N, T, C, A, M, x, y: Double;
begin
  LatRad := DegToRad(Lat);
  LonRad := DegToRad(Lon - lambda0);

  N := a / sqrt(1 - e * e * sqr(sin(LatRad)));
  T := sqr(tan(LatRad));
  C := (e * e / (1 - e * e)) * sqr(cos(LatRad));
  A := cos(LatRad) * LonRad;

  M := a * ((1 - e * e / 4 - 3 * e * e * e * e / 64 - 5 * e * e * e * e * e * e / 256) * LatRad
       - (3 * e * e / 8 + 3 * e * e * e * e / 32 + 45 * e * e * e * e * e * e / 1024) * sin(2 * LatRad)
       + (15 * e * e * e * e / 256 + 45 * e * e * e * e * e * e / 1024) * sin(4 * LatRad)
       - (35 * e * e * e * e * e * e / 3072) * sin(6 * LatRad));

  // Calculate Easting and Northing
  x := k0 * N * (A + (1 - T + C) * A * A * A / 6
      + (5 - 18 * T + T * T + 72 * C - 58 * e * e / (1 - e * e)) * A * A * A * A * A / 120);

  y := k0 * (M + N * tan(LatRad) * (A * A / 2 + (5 - T + 9 * C + 4 * C * C) * A * A * A * A / 24
      + (61 - 58 * T + T * T + 600 * C - 330 * e * e / (1 - e * e)) * A * A * A * A * A * A / 720));

  Result.Easting := e0 + x;
  Result.Northing := n0 + y;
end;

end.


 

Quote
 

How to Use This Unit:

  1. Include this unit in your Delphi project.
  2. Call the LatLonToLKS92 function with the latitude and longitude values you wish to convert.
  3. The function will return a TCoordinate record with the Easting and Northing values in the LKS-92 system.

Testing and Validation:

  • It's important to test this code with known coordinates to validate its accuracy.
  • Compare the results with a trusted geodetic software or conversion tool to ensure precision.

Disclaimer:

  • This implementation is based on standard formulas and should be used as a starting point.
  • Due to the complexity of geodetic calculations, you should thoroughly validate the results for your specific use case.

Feel free to adjust the code as needed for your specific requirements and to ensure compatibility with your existing systems.

 


------------------------------------------------------------
With Wolfram Alpha:
 

Quote

ChatGPT
Used Wolfram

The conversion of geographical coordinates (latitude and longitude) to the LKS-92 coordinate system (Latvijas Koordinātu Sistēma 1992) is a specific process that usually involves a transformation using a special geodetic reference system. LKS-92 uses the WGS 84 geodetic datum and is a UTM-based system based on zone 34N.

Since Wolfram Alpha does not provide a direct conversion to the LKS-92 system, I will describe a general approach for converting geographic coordinates to a UTM-based system in Delphi. This approach can then be customized for LKS-92 with specific parameters.
Delphi source code for the conversion to a UTM system

The following Delphi code demonstrates how to convert latitude and longitude to UTM coordinates. Note that specific adjustments are required for accurate conversion to LKS-92, such as using the correct UTM zone and specific datum adjustments if necessary.

 

uses
  SysUtils, Math;

type
  TLatLon = record
    Latitude: Double;
    Longitude: Double;
  end;

  TUTMCoordinates = record
    Easting: Double;
    Northing: Double;
    Zone: Integer;
  end;

function LatLonToUTM(LatLon: TLatLon): TUTMCoordinates;
const
  WGS84_A = 6378137.0; // Major semiaxis [m]
  WGS84_B = 6356752.314245; // Minor semiaxis [m]
  WGS84_F = 1/298.257223563; // Flattening
  WGS84_E = 0.081819190842622; // First eccentricity
  K0 = 0.9996; // Scale factor
var
  Lat, Lon, N, T, C, A, M: Double;
  Zone: Integer;
begin
  Lat := DegToRad(LatLon.Latitude);
  Lon := DegToRad(LatLon.Longitude);

  Zone := Floor((LatLon.Longitude + 180) / 6) + 1;
  N := WGS84_A / Sqrt(1 - WGS84_E * WGS84_E * Sin(Lat) * Sin(Lat));
  T := Tan(Lat) * Tan(Lat);
  C := WGS84_E * WGS84_E * Cos(Lat) * Cos(Lat) / (1 - WGS84_E * WGS84_E);
  A := Cos(Lat) * (Lon - DegToRad((Zone - 1) * 6 - 180 + 3));

  M := Lat * (1 - WGS84_E * WGS84_E / 4 - 3 * WGS84_E * WGS84_E * WGS84_E * WGS84_E / 64 - 5 * WGS84_E * WGS84_E * WGS84_E * WGS84_E / 256) -
       Sin(2 * Lat) * (3 * WGS84_E * WGS84_E / 8 + 3 * WGS84_E * WGS84_E * WGS84_E * WGS84_E / 32 + 45 * WGS84_E * WGS84_E * WGS84_E * WGS84_E / 1024) +
       Sin(4 * Lat) * (15 * WGS84_E * WGS84_E * WGS84_E * WGS84_E / 256 + 45 * WGS84_E * WGS84_E * WGS84_E * WGS84_E / 1024) -
       Sin(6 * Lat) * (35 * WGS84_E * WGS84_E * WGS84_E * WGS84_E / 3072);

  Result.Easting := (K0 * N * (A + (1 - T + C) * A * A * A / 6 + (5 - 18 * T + T * T + 72 * C - 58 * WGS84_E * WGS84_E) * A * A * A * A * A / 120) + 500000.0);
  Result.Northing := (K0 * (M + N * Tan(Lat) * (A * A / 2 + (5 - T + 9 * C + 4 * C * C) * A * A * A * A / 24 + (61 - 58 * T + T * T + 600 * C - 330 * WGS84_E * WGS84_E) * A * A * A * A * A * A / 720)));
  if LatLon.Latitude < 0 then
    Result.Northing := Result.Northing + 10000000.0; // Add offset for southern hemisphere
  Result.Zone := Zone;
end;

 

Quote

Anpassungen für LKS-92

  • UTM-Zone: LKS-92 verwendet die UTM-Zone 34N. Stelle sicher, dass die Berechnung für diese spezifische Zone durchgeführt wird.
  • Datum: Überprüfe, ob Anpassungen am WGS84-Datum erforderlich sind, um die Genauigkeit für LKS-92 zu erhöhen.


-------------------------------------------------------------------

The same task to Bard, comes up with this, more simple solution:

function ConvertLatLonToLKS92(Latitude: Extended; Longitude: Extended): Extended;
var
  DeltaX, DeltaY: Extended;
  SinLatitude: Extended;
begin
  SinLatitude := Sin(Latitude * Pi / 180);
  DeltaX := 268.3383 * Cos(Longitude * Pi / 180) * SinLatitude;
  DeltaY := 614.6800 * SinLatitude - 511.000 * Cos(Longitude * Pi / 180) * SinLatitude;

  Result := Latitude * 100000 + Longitude * 1000 + (DeltaX + DeltaY) / 100;
end;

 

I think GPT is too complex and Bard is too simple, or is any working for you?

 

 

Edited by Rollo62

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×