如何从表格中获取坐标

时间:2019-04-02 13:53:16

标签: sql postgresql postgis

我需要从locations表中获取坐标并将其替换为我的数据53.4015174, 44.967495

SELECT P.* 
    FROM PRODUCTS AS P
        LEFT JOIN MERCHANTS AS M ON (M.MERCHANT_ID = P.STORE_ID)
        LEFT JOIN CATEGORIES AS C ON (C.CATEGORIES_NAME = P.CATEGORIES)
        LEFT JOIN LOCATIONS AS LO ON (LO.LOCATION_ID = 20)
            WHERE P.CATEGORIES ILIKE ANY(ARRAY['Cameras']) AND
                ST_DWithin(M.LOCATION::geography, ST_GeogFromText('POINT(53.4015174 44.967495)'), LO.RADIUS, false)
                GROUP BY P.PRODUCT_ID, M.MERCHANT_ID

1 个答案:

答案 0 :(得分:1)

将SRID正确设置为此查询4326;

SELECT ST_SetSRID(ST_MakePoint(-71.1043443253471, 42.3150676015829),4326);

SELECT P.* 
    FROM PRODUCTS AS P
        LEFT JOIN MERCHANTS AS M ON (M.MERCHANT_ID = P.STORE_ID)
        LEFT JOIN CATEGORIES AS C ON (C.CATEGORIES_NAME = P.CATEGORIES)
        LEFT JOIN LOCATIONS AS LO ON (LO.LOCATION_ID = 20)
            WHERE P.CATEGORIES ILIKE ANY(ARRAY['Cameras']) AND
                ST_DWithin(M.LOCATION::geography, ST_AsText(ST_SetSRID(ST_MakePoint(-71.1043443253471, 42.3150676015829),4326))
                GROUP BY P.PRODUCT_ID, M.MERCHANT_ID