Skip to content

Commit

Permalink
[Bugfix] Order values when extracting from DB
Browse files Browse the repository at this point in the history
Fixed problem with the point ordering
  • Loading branch information
meyerlor committed Jan 25, 2024
1 parent 0744374 commit 2a24fcc
Showing 1 changed file with 15 additions and 14 deletions.
29 changes: 15 additions & 14 deletions altiProfil/lib/AltiServicesFromDB.php
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ protected function queryProfil($p1Lon, $p1Lat, $p2Lon, $p2Lat){
ST_Transform(ST_SetSRID(ST_MakePoint(%5$f, %6$f),4326), %4$s)
)
AS geom
),
),
linemesure AS(
-- Add a mesure dimension to extract steps
SELECT
Expand All @@ -126,19 +126,19 @@ protected function queryProfil($p1Lon, $p1Lat, $p2Lon, $p2Lat){
ELSE %8$d*5
END as resolution
FROM line
),
),
points2d AS (
SELECT ST_GeometryN(ST_LocateAlong(linem, i), 1) AS geom, resolution FROM linemesure
SELECT ST_GeometryN(ST_LocateAlong(linem, i), 1) AS geom, resolution FROM linemesure ORDER BY i
),
cells AS (
-- Get DEM elevation for each
SELECT
p.geom AS geom,
ST_Value(%1$s.rast, 1, p.geom) AS val,
SELECT
p.geom AS geom,
ST_Value(%1$s.rast, 1, p.geom) AS val,
resolution
FROM %1$s, points2d p
WHERE ST_Intersects(%1$s.rast, p.geom)
),
),
-- Instantiate 3D points
points3d AS (
SELECT ST_SetSRID(
Expand All @@ -150,15 +150,15 @@ protected function queryProfil($p1Lon, $p1Lat, $p2Lon, $p2Lat){
SELECT ST_MakeLine(geom)as geom, MAX(resolution) as resolution FROM points3d
),
xz AS(
SELECT dp.geom as geom, dp.path[1] as pt_index, ST_distance(origin, dp.geom) as dist, resolution
FROM (
SELECT ST_DumpPoints(geom) AS dp,
ST_StartPoint(geom) AS origin, resolution
FROM line3D
) as dumpline3D
SELECT (ST_DumpPoints(geom)).geom AS geom,
ST_StartPoint(geom) AS origin, resolution
FROM line3D
)
-- Build 3D line from 3D points
SELECT dist AS x, ST_Z(geom) as y, ST_X(geom) as lon, ST_Y(geom) as lat, resolution FROM xz ORDER BY pt_index',
SELECT ST_distance(origin, geom) AS x, ST_Z(geom) as y, ST_X(geom) as lon, ST_Y(geom) as lat, resolution FROM xz',
$this->AltiProfileTable,
$p1Lon, $p1Lat,
$this->Srid,
Expand Down Expand Up @@ -230,3 +230,4 @@ protected function queryProfil($p1Lon, $p1Lat, $p2Lon, $p2Lat){
return json_encode($data);
}
}

0 comments on commit 2a24fcc

Please sign in to comment.