2

I tried to use solution posted here, but ST_Distance in the Virtual Layer query doesn't work properly in Qgis (v3.2) on Mac, the result is showing blank while the same script is working properly in QGIS (v3.4) on Windows.

Here is my test script for virtual layer:

WITH distances AS(
  SELECT 
    s.id site_id,
    a.Mem_ID mem_id,
    ST_Distance(
            s.geometry, 
            a.geometry
            ) dist
  FROM site_a27 s
  CROSS JOIN A27_re a

)
SELECT * FROM distances

table for site_a27:

id,name,Response_X,Response_Y
1A27,bade,121.301412,24.968988

table for A27_re:

Mem_ID,Response_X,Response_Y
19960126000178,121.312175,24.987227
19960129000943,121.302705,24.978186
19960131001647,121.303628,24.957379
19960131002543,121.300855,24.984292
19960203000247,121.296974,24.968484

output of virtual layer on Mac: attribute table of virtual layer on Mac

output of virtual layer on Windows: attribute table of virtual layer on Windows

Information about my QGIS version on Mac: enter image description here

How do I solve this in QGIS on Mac?

11
  • The doc says "This function only supports Long/Lat coordinates, and will return NULL for any planar CRS". Double check the 2 layers projection
    – JGH
    Dec 16, 2019 at 15:54
  • @JGH, That is the case when adding the boolean True for the use_ellipsoid parameter. Without that parameter: "return the distance between geom1 and geom2 (always measured in CRS units)". But I agree with the check of the layers CRS. Dec 17, 2019 at 0:55
  • Both layers are WGS84 as default and the results of dist field are still blank on Mac. Could that be a bug only on Mac?
    – Pete
    Dec 17, 2019 at 12:25
  • I have added the [mac] tag to your post. Try with the following query: SELECT 1 fid, ST_Distance(GeomFromText('POINT(0 0)'),GeomFromText('POINT(1 1)')) dist;. Does it return a distance in the table? Dec 17, 2019 at 19:21
  • 1
    Look at this message, maybe it can help you: github.com/qgis/QGIS-Website/issues/608#issuecomment-489320264 Dec 21, 2019 at 9:59

1 Answer 1

1

The issue was fixed by re-installing the newest version of QGIS (3.4).

The following link is to the bug reported about the SpatiaLite issue for the Homebrew installation: https://github.com/qgis/QGIS/issues/29714.

The following link is to the change of installers for macOS in the QGIS Website: https://github.com/qgis/QGIS-Website/issues/608.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.