Search code examples
postgresqlpostgisopenstreetmaptilemill

Is there an easy way to get the config["postgis"]["extent"] values from a postgis database for osm-bright?


I have successfully set up a postgis server for use with OSM-Bright. I must admit that the server is a bit of a black box to me, so while I have it set up and it's working fine, I don't know the ins and outs of how to use it optimally.

In the OSM-Bright config file, there is a value called config["postgis"]["extent"]. In the comments it says that it can speed queries to limit the extents from the entire earth to just the area you need using "XMIN,YMIN,XMAX,YMAX" in the same units as the database (probably spherical mercator meters).

My question is if there's an easy way to get these values?

For example, let's say I have a project where I need to map only a subset of Nassau County on Long Island, NY. My OSM DB has the entire US North American dataset. Is there a way or a tool I can use to get the extents of Long Island converted for my database's projection easily?

Many thanks for your help in advance.

Cheers, Steve


Solution

  • I'm also using PostGIS/OSM-Bright/TileMill setup (for the first time). I imported my OSM data with osm2pgsql; the tables of interest seem to be planet_osm_polygon, planet_osm_point, planet_osm_line, and planet_osm_roads.

    You can get the extent value for each table by running a query like this:

    SELECT ST_Extent(way) FROM planet_osm_polygon
    

    Or to get the extent (i.e., bounding box for ALL of your OSM data) you can run a query like this:

    SELECT
      ST_Extent( way )
    FROM (
      SELECT way FROM planet_osm_polygon
      UNION
      SELECT way FROM planet_osm_point
      UNION
      SELECT way FROM planet_osm_line
      UNION
      SELECT way FROM planet_osm_roads
    ) as foo;
    

    This will return a box with minX, minY, maxX, maxY values (e.g., BOX(739651.875 2908247.25,794875.8125 2970042.75) -> config["postgis"]["extent"] = "739651.875 2908247.25 794875.8125 2970042.75").