# Finding the "square" bounding boxes of a country

I want to find the square bounding boxes that cover a country, of different sizes.

First off, I know that they won't really be square, but just going by the numbers they can be said to be.

The main challenge I have is I don't know where get the data of the points of the countries and/or the borders. After that I think I can calculate the boxes by iterating over them.

Let's say I want do this for the continental US and with boxes of size 50 (lat, lon), then I can easily do this manually. The first box (starting from NW) would be [[50, -150], [0, -100]], and the second is [[50, -150], [0, -100]], and I'm done.

Now let's say the size is 25, and now the first box is [[50, -125], [25, -100]]. I will end up with more boxes but a more defined area and overall smaller. I guess another term could be "search grid" calculations.

Is there any publicly available datasets or APIs that I can use to determine if a bounding box or a point belongs to a country?

• Yes, this is GIS 'bread and butter', it's just a simple spatial query. Do you have any software in mind? Do you want to do this interactively or are you writing a script or program? Jul 12, 2018 at 5:28
• What you're describing is more commonly referred to as spatial indexing. Here's how its done with SQL Server. Jul 12, 2018 at 14:24
• I would only need to do this once per country, then store the boxes in a database. Not interactive. Jul 13, 2018 at 1:18

One way you might be able to do it is if you have a shapefile of that country. You could use a tool like Clip in ArcMap.

Open the tool and try to clip any raster with it. When you assign the shapefile, extent values automatically populate the fields in the tool window. You can make a note of it and close the tool without running it.

• Are there any open source or free sources that can provide this shape file information? Jul 13, 2018 at 1:22
• Yep, for sure. Start here: census.gov/geo/maps-data/data/tiger-cart-boundary.html. You can download the US or individual states. If you are looking for another country, google "world shapefile", etc. Jul 17, 2018 at 2:37

There's a bit of a confused terminology here. A bounding box is usually a representation of the extent of a geometry. See the tag. What you describe is really some kind of of squares, like a .

The main challenge I have is I don't know where get the data of the points of the countries and/or the borders. After that I think I can calculate the boxes by iterating over them.

Essentially your issue here is that you lack a dataset. If you need country borders, you can download them from several places; Natural Earth is a good option.

Then you can use a tool like the "create vector grid" tool in QGIS for a fishnet, or obtain a bounding box in a similar way.

If you want to determine if a bounding box or a point belongs to a country, that process is called reverse geocoding. There are many geocoding services like Nominatim, Google, Mapquest, Opencage, Photon that can do that. here is an example.