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

StackOverflow https://stackoverflow.com/questions/18337780

Question

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

Was it helpful?

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").

OTHER TIPS

The Python script globalmaptiles.py on this page (scroll down to see the download link) does exactly what you want.

Its purpose is to give you the coordinates of the tile that contains the point you give, for a certain zoom level, but it also converts input in WGS 84 to spherical mercator meters (EPSG:900913).

To get the coordinates of the bounding box in WGS 84 you can use a Google Maps Lab extension, either LatLng Marker or LatLng Tooltip.

So to answer your question exactly, the bounding box in WGS 84 for Nassau County in Long Island would be (I think):

  • top left: 40.920, -73.761
  • bottom right: 40.597, -73.415

which would give in spherical mercator meters, using the above tool:

  • xmin,ymin,xmax,ymax: -8211036.960402652,5000548.83362593,-8172520.416588181,4953079.755896228

Using a bounding box in this way should considerably speed up rendering in Tilemill (of course you have to re-generate OSM-Bright for the modification to take effect).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top