Extract lat/lon from geography (point)

Options

Is there a way to extract lat/lon from a geography (point, in this case)? I'm getting a geo point as an input into an endpoint and want to use the lat/lng in a distance calculation, but the distance calculation only accepts decimal values, and thus I must extract lat/lng from the input.

In this case using GET data GET lat yields nothing, and storing the input as a variable in the debugger appears to return a PostGIS data type (POINT(lat lng)), where nothing can be extracted.

Converting to text and doing a substring isn't ideal.

Is there any ST_X/ST_Y PostGIS equivalent given it looks like the geography point data type is being used here?

Tagged:

Best Answer

  • Cameron B
    Cameron B Member, Administrator

    ADMIN

    Answer ✓
    Options

    That makes way more sense to be passing it in to be used as a geo point datatype.

    Can you try using the utility function Get All Input. You should be able to use that input variable and select the object and use dot notation to get its values.

    I'm hopeful this will work 🤞

Answers

  • Cameron B
    Cameron B Member, Administrator

    ADMIN

    Options

    How is the input being passed? Is it formatted as a string (and presumably with escaped characters?

    This worked for me, where I pass the geo point as an escaped string:






  • cw
    cw Member
    Options

    I'm passing it in as a properly structured geo point object (input type: geo_point), which is detected and used correctly. Extracting the lat/lng individually is the issue.

    I've worked around it for now by inputting two decimals for each lat and lng, using those where I need it in the distance calculation, and then rebuilding the geo_point object as a new variable inside my function stack for use in a WITHIN filter elsewhere.

  • cw
    cw Member
    Options

    That works! Now, you said it makes way more sense, why is that if it needs additional post-processing just like constructing the geo-point over again?

  • Cameron B
    Cameron B Member, Administrator

    ADMIN

    Options

    To be completely transparent, I had assumed you were trying to use text because you had mentioned substrings.

    Otherwise, the point is just a datatype that's recognized as that datatype. An object is an object, an array is recognized as an array, etc. Hope this helps :)