1

Based on the following code block:

var SphericalMercator = require('sphericalmercator');
var mercator = new SphericalMercator({
    size: 256
})

var bbox = mercator.bbox(
   +req.params.x,
   +req.params.y,
   +req.params.z,
   false,
   '4326');
var test_query = 'SELECT st_asgeojson(wkb_geometry) AS feature FROM ogrgeojson where 
ST_INTERSECTS(wkb_geometry, ' + bbox + ')';

I run this as a query and get the following error:

error: function st_intersects(geometry, numeric, numeric, numeric, numeric) does not exist]

hint: 'No function matches the given name and argument types. You might need to add explicit type casts.'

I am not sure how I should be wrapping the bbox. Additionally things that I have tried have resulted in column errors.

2 Answers 2

2
var point      = 'ST_SetSRID(ST_MakePoint(' + 
                   req.params.x + ',' + 
                   req.params.y + '),4326)';
var test_query = 'SELECT st_asgeojson(wkb_geometry) AS feature ' + 
                 'FROM ogrgeojson WHERE ' +
                 'ST_INTERSECTS(wkb_geometry, ' + point + ')';
3
  • 1
    Your answer is code only, please add addition description.
    – artwork21
    Jul 21, 2015 at 0:21
  • Paul solution works great. The thing is , please check postgis function: postgis.org/docs/ST_Intersects.html . Input information for this function is (geometry, geometry), and from shkfnly's code the function is receiving (geometry, numeric, numeric, numeric, numeric) Jul 21, 2015 at 2:01
  • 1
    Right, his "box" is spooling out to number,number,number,number when JS runs tostring on it, hence the funny signature it ends up trying to call in the db. Jul 21, 2015 at 13:05
0

After some tinkering I realized that I had to encode the bbox in an ST_MakeEnvelope call: postgis.net/docs/ST_MakeEnvelope.html. This is because the call to mercator simply returns a conversion from the point being represented to the [minLng, minLat, maxLng, maxLat]. I can use ST_MakeEnvelope to return the proper PostGIS type based on this input. Code is as follows.

var test_query = 'SELECT st_asgeojson(wkb_geometry) AS feature 
                  FROM ogrgeojson
                  WHERE ST_INTERSECTS(wkb_geometry, ST_MakeEnvelope('+ bbox + ', 4326))';

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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