1

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

SELECT row_to_json(fc)
FROM (
  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
FROM
  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?

4
  • 4
    have you tried WHERE ST_Intersects(lg.geometry, bbox.geom) AND admin_level < 4?
    – Surya
    Jan 13, 2015 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, 2015 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, 2015 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, 2015 at 17:58

2 Answers 2

4

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.

0

Just use AND in your WHERE clause...

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.