locationtech / locationtech/proj4j

Incorrect transformation when longitude >180

Open
#118 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

enhancement
Dominant language
Java
Stars
232
Forks
86
PR merge metrics
No merged PRs in 30d

Description

An unexpected coordinate truncation happens when coordinates exceed -180, which does not seem to happen in the Python variant.

The truncation happens here:
https://github.com/locationtech/proj4j/blob/master/core/src/main/java/org/locationtech/proj4j/proj/Projection.java#L326

I discovered this via this Geotrellis code:

val orig = Point(182.086672726415,69.3350337120443)
val origNormalized = Point(182.086672726415 - 360,69.3350337120443)
val utm01 = CRS.fromName("EPSG:32601")

val reprojected = orig.reproject(LatLng, utm01)
val normalizedReprojected = origNormalized.reproject(LatLng, utm01)
val roundTrip = reprojected.reproject(utm01,LatLng)
assertTrue(reprojected.equalsExact(normalizedReprojected, 0.1) )
assertTrue(orig.equalsExact(roundTrip, 0.00001) )

Python variant can also be tested:

import pyproj

# Define the input coordinates in EPSG:4326
longitude, latitude = 182.086672726415, 69.3350337120443

# Define the source and target CRS
source_crs = pyproj.CRS("EPSG:4326")
target_crs = pyproj.CRS("EPSG:32601")  # UTM Zone 1N

# Create a transformer object
transformer = pyproj.Transformer.from_crs(source_crs, target_crs, always_xy=True)

# Transform the coordinates
utm_x, utm_y = transformer.transform(longitude, latitude)

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start at core/src/main/java/org/locationtech/proj4j/proj/Projection.java around line 326 and reproduce the transformation with the coordinates in the issue, comparing longitude values above 180 with their normalized equivalents. Check the Python result as a behavioral reference. Done means the original and normalized coordinates reproject consistently and the round trip preserves the original longitude within the stated tolerance.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
data
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.