[postgis-users] ST_Intersects ST_GeomFromGeoJSON syntax

Joseph Spenner joseph85750 at yahoo.com
Wed Jan 7 07:36:27 PST 2015

 Hugues:  Thanks for the info!  I saw the link you posted a few days ago, but was still having trouble making it work.The goal is to take what I have, which uses the "ST_Intersects(ST_GeomFromText", and modify my existing query to use a similar query with "ST_Intersects(ST_GeomFromGeoJSON" instead.The original query takes in a polygon as a string of points (ie: -102.87 43.71, -101.48 43.17, -101.7 42.04, -104.19 41.32, -104.95 42.53) and returns all stored polygons which the input polygon intersects (or contains, etc, anything in common).My goal is to do the same thing, but use a GeoJSON string as the input instead, and return all stored polys which intersect.

Is this possible?
Regards,Joseph Spenner

      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

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.



-------- 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?
Regards,Joseph Spenner

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

More information about the postgis-users mailing list