[postgis-users] ST_Intersects ST_GeomFromGeoJSON syntax

Hugues François hugues.francois at irstea.fr
Thu Jan 8 00:44:47 PST 2015


Hi Joseph,

 

If you take a look at the error returned, you can read that the problem comes from the ST_Intersects function which works with geometries but not with text. I think, if your geoJSON is right formatted, you can just remove the ST_AsText part and it should work.

 

However it also seems that your where clause is not written correctly you can just write your query like that :

 

select ST_Asgeojson( geom ) from polys

where ST_Intersects(ST_GeomFromGeoJSON('$jsonPoly'), geom);

 

HTH

 

Hug

 

De : postgis-users-bounces at lists.osgeo.org [mailto:postgis-users-bounces at lists.osgeo.org] De la part de Joseph Spenner
Envoyé : mercredi 7 janvier 2015 17:30
À : PostGIS Users Discussion
Objet : Re: [postgis-users] ST_Intersects ST_GeomFromGeoJSON syntax

 

More info.  Here are my 2 select statements.

This one works:

 

$sth = $dbh->prepare("select ST_Asgeojson( geom ) from polys where ST_Intersects(ST_GeomFromText('POLYGON(($textPoly, $closingLon $closingLat))', 4269), geom)=TRUE");

 

 

However, below is my new one, which I can't get to work:

 

$sth = $dbh->prepare("select ST_Asgeojson( geom ) from polys where ST_Intersects(ST_AsText(ST_GeomFromGeoJSON('$jsonPoly')), geom)=TRUE");











When I run with my new select statement, I get errors:

 

-----



DBD::Pg::st execute failed: ERROR:  function st_intersects(text, geometry) is not unique
LINE 1: ...ertseverity,ST_Asgeojson( geom ) from polys where ST_Interse...
                                                             ^
HINT:  Could not choose a best candidate function. You might need to add explicit type casts. at ./alertPoly2.cgi line 103.
DBD::Pg::st execute failed: ERROR:  function st_intersects(text, geometry) is not unique
LINE 1: ...ertseverity,ST_Asgeojson( geom ) from polys where ST_Interse...
                                                             ^
HINT:  Could not choose a best candidate function. You might need to add explicit type casts. at ./alertPoly2.cgi line 103.
------





Any help would be great.

 

Thanks!

 

 

 

 

________________________________

From: Hugues François <hugues.francois at irstea.fr>
To: Joseph Spenner <joseph85750 at yahoo.com>; PostGIS Users Discussion <postgis-users at lists.osgeo.org> 
Sent: Wednesday, January 7, 2015 1:17 AM
Subject: Re: [postgis-users] ST_Intersects ST_GeomFromGeoJSON syntax


Hello,

I'm not very familiar with the use of ST_GeomFromGeoJSON() but looking at the doc, it only accepts a single json string so you'd better remove all the ST_GeomFromText stuff: ST_GeomFromGeoJSON($jsonPolys). There are some examples at the bottom of the page http://www.postgis.org/docs/ST_GeomFromGeoJSON.html.

HTH

Hugues.


-------- Message d'origine--------
De: postgis-users-bounces at lists.osgeo.org de la part de Joseph Spenner
Date: mar. 06/01/2015 20:31
À: PostGIS Users Discussion
Objet : [postgis-users] ST_Intersects ST_GeomFromGeoJSON syntax

Hello,I currently have a select which works correctly:
$sth = $dbh->prepare("select ST_Asgeojson( geom ) from polys where ST_Intersects(ST_GeomFromText('POLYGON(($textPoly, $closingLon $closingLat))', 4269), geom)=TRUE");


I'm trying to do the same thing, using FromGeoJSON instead of Text.  Below is my attempt, but it's not working.  This is my statement, where $jsonPolys contains the JSON:
$sth = $dbh->prepare("select ST_Asgeojson( geom ) from polys where ST_Intersects(ST_GeomFromGeoJSON('POLYGON(($jsonPolys))', 4269), geom)=TRUE");

 I think the problem has something to do with the POLYGON text, since it may not be necessary.  But I can't get the syntax right.
Any ideas?
Thanks!
Regards,Joseph Spenner



-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/postgis-users/attachments/20150108/fc8964f2/attachment.html>


More information about the postgis-users mailing list