3

I have a list of points stored in my database, in a text format.

lat | long
"-73.88110000007934", "40.817699999744555"
"-73.92675000057572","40.81840599962764"
"-73.883573184", "40.751662187"

I have a geojson file similar to this one:

d= { "type": "Polygon", "coordinates": [ [ [ -73.869424572841766, 40.74915687096788 ], [ -73.891431299772762, 40.74684466041932 ], [ -73.895071432408585, 40.746465470812154 ], [ -73.896187378678206, 40.748509425180877 ], [ -73.895839541851402, 40.74854687570604 ], [ -73.895252427743969, 40.748306609450246 ], [ -73.896540410855621, 40.750541998143589 ], [ -73.895798686138292, 40.750619721332619 ], [ -73.896522306614344, 40.754388796109033 ], [ -73.881648121884808, 40.755951617041873 ], [ -73.872218558824784, 40.756943248067479 ], [ -73.871679923567925, 40.753987174396038 ], [ -73.872070465138904, 40.753862007052064 ], [ -73.869424572841766, 40.74915687096788 ] ] ] }

When I tried to use

ST_Within('POINT(-73.883573184, 40.751662187)' 
    ,
    ST_GeomFromGeoJSON(d) 
)

Based on what I have understood, they have the same object (geom), but I couldn't succeed in converting/CASTing objects, HOW CAN I do this the right way ?

  • 1
    What is the error message? What is your full query? What is the result of just doing SELECT ST_GeomFromGeoJSON(d)? Also, you should convert your points stored as text to actual 2D geometry. – alphabetasoup Jan 31 '16 at 22:00
  • You have a comma in your POINT WKT. It should be 'POINT(-73.883573184 40.751662187)' – Jay Cummins Feb 1 '16 at 13:46
3

You must convert point coordinates to geometry

SELECT ST_Within(St_GeomFromText('POINT(-73.883573184  40.751662187)'), ST_GeomFromGeoJSON(d));

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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