Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re^4: DBI placeholders for spatial data

by Bod (Parson)
on Jun 26, 2021 at 22:00 UTC ( [id://11134352]=note: print w/replies, xml ) Need Help??


in reply to Re^3: DBI placeholders for spatial data
in thread DBI placeholders for spatial data

To test this I have used this code:

my $test = 'POINT( 20 10 )'; $dbh->do("INSERT INTO Test SET start = ST_GeomFromText(?, 4326), end = + ST_GeomFromText(?, 4326)", undef, $test, $test); if ($dbh->err) { print "ERROR: " . $dbh->errstr; } else { print "SUCCESS!"; } print "\n";
And from the test it I get this result:
SELECT ST_AsText(start) FROM Test ------------ POINT(20 10)
I think we can conclude that feeding POINT($lng $lat) to the placeholder works :)

A quick note for anyone finding this in future...
POINT takes longitude first then latitude. Several sources online say that it doesn't matter which way around they are. However, if you want ST_Distance_Sphere to give a correct result, they need to be longitude followed by latitude. This is the reason I created a module to handles points, so I don't need to worry about the order except within the module.

Edited to remove rogue comma pointed out by LanX

Replies are listed 'Best First'.
Re^5: DBI placeholders for spatial data
by LanX (Saint) on Jun 26, 2021 at 22:31 UTC
    > feeding POINT($lng, $lat) to the placeholder works

    with comma???

    Cheers Rolf
    (addicted to the Perl Programming Language :)
    Wikisyntax for the Monastery

      with comma???

      No! Not with a comma!
      That was a typo and I have edited the previous comment to remove the rogue comma.

      Thanks for noticing my mistake.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11134352]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others surveying the Monastery: (3)
As of 2024-04-19 23:42 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found