1

I am querying a point feature using a PostGIS request fired in JavaScript. The decoded URL looks like this and returns great results for polygon features.

http://test.tablelocation.com/api/v1/sql/?q=select '+tempCoi+' from '+tempTableName+' where ST_Intersects(the_geom, ST_GeomFromText('POINT('+clickLng+' '+clickLat+')',4326))&format=json&diagnostics=true&_maxage=86400&callback=?

As you can see, there are a few dynamic Javascript variables that are injected into each URL request. Two of these variables (clickLng and clickLat) specify the lat/lng of my query. They are generated based on where the user clicks on a google map. I am returning one attribute from the point layer referenced via the tempCoi variable. When I try to query a point feature, no data is returned.

I am guessing that this is because the location of my query is too specific (i.e. 6+ decimal points).

To make a long question shorter, is there a way to fuzz my data request.

For example, if I click at 45.123456N and -113.654987W how could I look for the closest point to that query?

Hope this is clear...

2

Passing SQL in your URLs directly looks risky to me.

Otherwise, the method you are looking for is https://postgis.net/docs/ST_DWithin.html

  • Thanks Relet.. I'll look into ST_DWithin. Why is passing URLs risky? I am pretty new to web development. – jotamon Mar 28 '12 at 13:02
  • Passing SQL code is risky. What happens if someone calls that URL with q=drop+database+yourdatabasename ? You may have set the correct permissions to disallow that, but in general database permissions are not fine grained enough to prevent all forms of possible abuse (for a less drastic example, reading data from tables that shouldn't be public). – relet Mar 28 '12 at 13:18

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.