2 years ago

#73814

test-img

jdoe

Why does ST_Transform fail when transforming to 4326?

I have a postgis table with some data which looks like this:

distance id nr X Y description strecke point gsal_strecke rikz gsal_km_anf_p gsal_km_end_p gsal_geo_compound rk kilometer basepoint
2.088918198132633 9105 1 7.59833269418573 50.3171094720011 valide with result 3507 POINT (3400245.168425543 5576618.697108934) 3507 2.0 123905.310 123945.537 LINESTRING (3400253.52199817 5576605.02429315, 3400251.48999817 5576609.59229315, 3400247.37399817 5576618.87129315, 3400243.28599817 5576628.16129316, 3400239.24399817 5576637.47229316, 3400237.27599817 5576642.06929316) 1 123.92110139140328 POINT (3400247.0804134225 5576619.538465925)
4.601389947759623 9106 611171 8.83478109 54.7923646 crash 1201 POINT (3489442.4653895213 6073687.653162317) 1201 0.0 162291.691 162329.922 LINESTRING (3489446.77287361 6073662.83069441, 3489447.226 6073701.05844041) 1 162.31646103819043 POINT (3489447.066456252 6073687.598624319)

This table holds the end result of some calculations. In short what happens is, that a collection of points is inserted into the database and if they are within a certain perimter of a given rail, a basepoint to that rail is calculated. This calculation takes place in SRID 5683 The data is fetched by a Service, which returns them as geojson. According to the specification, geoJSON works best when used with WGS84 coordinates. So when fetching the data, I have to transform the coordinates.

The query I use looks like this:

select *, ST_X(ST_Transform(point, 4326)) as x, ST_Y(ST_Transform(point, 4326)) as y from bp40.bp40_punktlage;

The first of these two example rows yields the following result:

distance id nr X Y Objektbezeichnung strecke punkt gsal_strecke rikz gsal_km_anf_p gsal_km_end_p gsal_geo_compound rk kilometer fusspunkt x y
2.088918198132633 9105 1 7.59833269418573 50.3171094720011 valide mit ergebnis 3507 POINT (3400245.168425543 5576618.697108934) 3507 2.0 123905.310 123945.537 LINESTRING (3400253.52199817 5576605.02429315, 3400251.48999817 5576609.59229315, 3400247.37399817 5576618.87129315, 3400243.28599817 5576628.16129316, 3400239.24399817 5576637.47229316, 3400237.27599817 5576642.06929316) 1 123.92110139140328 POINT (3400247.0804134225 5576619.538465925) 7.598332691520598 50.317109473199004

Now for some reason I cannot explain, the second row just crashes yielding the follow error message:

SQL Error [XX000]: ERROR: transform: Invalid argument (22) According to the postgres documentation

This is a internal error, which does not really help me understand what is wrong here.

I have checked the geometry for validity (st_isvalid) and both rows contain valid geometry. Also the initial X,Y coordinates are valid and pinpoint the location I want them to be in.

EDIT 1 Out of curiosity i tried the following queries:

select st_transform(point,5682) from bp40_punktlage
--works just fine with both rows

select st_transform(st_transform(punkt, 5682),4326) from bp40_punktlage
-- crashes with the same error

PostgreSQL 13.4, compiled by Visual C++ build 1914, 64-bit Postgis Version : 3.1 USE_GEOS=1 USE_PROJ=1 USE_STATS=1

Edit 2 As requestet here is the CREATE TABLE statement:

CREATE TABLE bp40.bp40_punktlage (
    distance float8 NULL,
    id int4 NULL,
    nr varchar NULL,
    "X" float8 NULL,
    "Y" float8 NULL,
    "description" varchar NULL,
    strecke varchar NULL,
    point geometry NULL,
    gsal_strecke varchar(4) NULL,
    rikz float8 NULL,
    gsal_km_anf_p numeric(19, 3) NULL,
    gsal_km_end_p numeric(19, 3) NULL,
    gsal_geo_compound geometry NULL,
    rk int8 NULL,
    kilometer float8 NULL,
    basepoint geometry NULL
);

Inserts are a bit more complicated, since the data goes through several tables and processing steps until it arrives at the table shown in this post. I will try to add them over the course of the day.

Edit 3 The geometries are valid. st_srid() return 5863 for both points, as expected. I tried transforming them into 5862 just for the sake of trying. But it fails when transforming to 4326, no matter from which SRID i start

postgresql

postgis

coordinate-transformation

0 Answers

Your Answer

Accepted video resources