I have this query, which works well, for an OSM database:

SELECT row_to_json(fc)
  SELECT ST_AsGeoJSON(ST_Transform(ST_Intersection(lg.geometry, bbox.geom), 4326))::json As geometry,
    SELECT row_to_json(t)
    FROM (
      SELECT name, type, admin_level
    ) t
As properties
  osm_admin As lg,
  (SELECT ST_Transform(ST_MakeEnvelope(10.735445022583008, 59.913428634991995,
      10.776472091674805, 59.933989460416115, 4326),3857) as geom) as bbox
    WHERE ST_Intersects(lg.geometry, bbox.geom)
  ) fc;

I'd like to filter this generic query a bit, depending on the zoom level. E.g. I'd like to add filter for zoom level WHERE admin_level < 4. I also need to add other filters for other queries, based on this template (where admin_level is a property of the osm_admin table).

Where can I insert such a WHERE clause?

  • 3
    have you tried WHERE ST_Intersects(lg.geometry, bbox.geom) AND admin_level < 4? – Surya Jan 13 '15 at 15:14
  • I hadn't, but that works swimmingly! Embarassed... Thanks! Feel free to write up an answer that I can accept. – knutole Jan 13 '15 at 15:22
  • 2
    Is it really worth it because it is so trivial? No bad feelings for you, everybody forgets the basics every now and then. – user30184 Jan 13 '15 at 15:35
  • 1
    @user30184 I know it might be trivial, but it might be worth adding the answer so that the question doesn't get recycled periodically. Also it could also of been added at the end ...) fc WHERE admin_level < 4; – MickyT Jan 13 '15 at 17:58

Please add WHERE ST_Intersects(lg.geometry, bbox.geom) AND admin_level < 4. This will give you the result for those features which intersect with the given geometry AND whose admin_level is less than 4.


Just use AND in your WHERE clause...

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.