текст из заявления С геомотрией и географией - PullRequest
0 голосов
/ 04 мая 2018
WITH values(location, userid) as (
VALUES (st_geomfromewkt('0101000000000000C04141464000000000FE174440'),5))

SELECT st_distance(p.location,(SELECT location FROM values where v.userid = "blacklisterId")::geometry)
FROM values as v,live.partners as p
Inner JOIN backend.cars c ON (c."userId" = p."partnerId" AND c.active = true)
Inner JOIN backend."carCompatibleTariffs" cCT ON c."carId" = cCT."carId" and  1 = cCT."tariffId" AND cCT.active = true
LEFT JOIN backend."userBlacklist" bl on 5 = bl."blacklisterId" AND p."partnerId" = bl."blacklistedId"
WHERE bl."blacklistedId" ISNULL
--AND st_dwithin(p.location::geography,(SELECT FROM values where v.userid = "blacklisterId")::geography,1500)
--ORDER BY st_distance(p.location,(SELECT location FROM values where v.userid = "blacklisterId")::geometry) ASC;

Как воспринимать таблицу текстовых значений как геометрию или географию, я пытался сделать это с помощью ST_GeographyFromText, ST_GeogmetryFromText и st_makepoint ((Select st_x), (Select st_y)), но он всегда возвращает ноль, как я могу решить это?

Ответы [ 2 ]

0 голосов
/ 04 мая 2018

Это могло быть вашим намерением:


WITH vvv(location, userid) as (
    VALUES (st_geomfromewkt('0101000000000000C04141464000000000FE174440'),5)
    )
SELECT st_distance(p.location, v.location::geometry) AS THE_DISTANCE
FROM vvv as v
JOIN live.partners as p
    ON p."partnerId" = v.userid
WHERE EXISTS (
    SELECT * 
    FROM backend.cars c
    JOIN backend."carCompatibleTariffs" cCT
            ON c."carId" = cCT."carId"
            AND cCT."tariffId" = 1 AND cCT.active = true
    WHERE c."userId" = p."partnerId"
    AND c.active = true
    )
AND NOT EXISTS(
    SELECT * FROM backend."userBlacklist" bl
    WHERE p."partnerId" = bl."blacklistedId"
    AND 5 = bl."blacklisterId"
    )
    ;
0 голосов
/ 04 мая 2018

Ваша проблема может быть где-то еще. Ваша геометрия кажется верной:

WITH values(location, userid) AS 
(VALUES ('0101000000000000C04141464000000000FE174440',5),
        ('0101000000000000200A45464000000000D7174440',16))
SELECT ST_Distance(location::GEOMETRY,ST_GeomFromText('POINT(44 45)')) FROM values;

   st_distance    
------------------
 4.83948955585514
 4.84387473202619
(2 Zeilen)

Вот несколько примеров различных типов литералов геометрии:

ST_GeomFromText

db=# SELECT ST_GeomFromText('POINT(1 2)');
              st_geomfromtext               
--------------------------------------------
 0101000000000000000000F03F0000000000000040
(1 Zeile)

ST_GeomFromGeoJSON:

db=# SELECT ST_GeomFromGeoJSON('{"type":"Point","coordinates":[1,2]}');
             st_geomfromgeojson             
--------------------------------------------
 0101000000000000000000F03F0000000000000040
(1 Zeile)

ST_GeomFromEWKT

db=# SELECT ST_GeomFromEWKT('SRID=4269;POINT(1 2)');
                  st_geomfromewkt                   
----------------------------------------------------
 0101000020AD100000000000000000F03F0000000000000040
(1 Zeile)

ST_GeomFromGML

db=# SELECT ST_GeomFromGML('<gml:Point><gml:coordinates>1,2</gml:coordinates></gml:Point>');
               st_geomfromgml               
--------------------------------------------
 0101000000000000000000F03F0000000000000040
(1 Zeile)

ST_GeomFromKML

db=# SELECT ST_GeomFromKML('<Point><coordinates>1,2</coordinates></Point>');
                   st_geomfromkml                   
----------------------------------------------------
 0101000020E6100000000000000000F03F0000000000000040
(1 Zeile)
...