No dependencies at all? Not even pyproj? It's not impossible, but it's a fairly tall order.
–
MerseyVikingMar 3 '12 at 11:36

I want few deps because I'm writing a very minimal monitoring app for geospatial services (starting with WMS). Would you recommend having proj4 as a required lib dependency? Your answer is a little scary :-)
–
Pimin Konstantin KefaloukosMar 3 '12 at 14:33

As you say in your answer. I can tell the unit from the downloaded proj4 file. If it's in meters it's easy. If not (e.g. geograph. coordinates), I find the UTM zone, transform geogr. extent to this projection, make a 100x100 box, transform back to the orig. srs. That leaves one question: how do I find the utm zone? Found an answer for that: stackoverflow.com/questions/9186496/…
–
Pimin Konstantin KefaloukosMar 3 '12 at 14:50

I think proj.4 is a small price to pay for simplicity, especially as there are Python bindings for it (pyproj). There are other projection libraries out there, but Proj.4 seems to be the de-facto standard. It also has no other dependencies.
–
MerseyVikingMar 5 '12 at 10:36

1 Answer
1

If your maps are always going to be in a projected coordinate system, that is locations are expressed in linear units, then you just need to know which units it's in and multiply by the relevant conversion factor. For instance, read in the epsg file that comes with proj.4, and parse it for the +units parameter or the +to_meters parameter.

If, however, you're going to get unprojected data, that is in a geographic CS, you're going to have to learn the ins and outs of datum shifts and projections.
I'd be inclined to download the source for proj.4 and study it carefully, then find a couple of good books on the mathematics of map projections. If you want to cover every coordinate system, you're going to have to essentially rewrite significant chunks of proj.4.

Because you don't know where in the world your map is likely to be, the basic steps would be to shift the datum to a common standard such as WGS84, then I'd determine which UTM zone your rectangle is in and project it to that zone. From there you can calculate your random box, not forgetting that a rectangular region in a geographic CS is unlikely to be rectangular after it's projected, so you'll have to account for a skewed, warped, and curved initial bounding box (or if you're using UTM and your data is near the poles, you're going to have to choose another projection) to make sure your random box doesn't extend outside it.

Then if you want to get the extents of your random box back into the original CS, you'll need to reverse the process, which of course means it almost certainly won't be quite rectangular, although 100m isn't too big a deal.

I see. The use of the bbox is for a Nagios plugin that monitors WMS services (github.com/skipperkongen/GeoNagios). Precision is not a big deal. Basically I want a rough 100x100m to be more gentle to the WMS service I'm monitoring. Thank you for your answer.
–
Pimin Konstantin KefaloukosMar 3 '12 at 14:22