3

I have an raster file in my server space, which has the same projection as my webmap, and I would like to crop the image by passing the visible extent of a webmap. I think the cropping function is easily possible via a python script server side, but the process of converting the map envelope coordinates to a bounding box the script could use to cut the image to that exact extent is beyond me at the moment. Any ideas, methods, or general roadmap would be helpful.

In a nutshell, I am trying to reproduce the "export" functionality of an ESRI map service without using ArcServer.

Like this: http://services.arcgisonline.com/ArcGIS/rest/services/World_Imagery/MapServer/export?bbox=-9562211.80152863,4584479.44244939,-9519931.21541649,4626760.02856153&size=1024,1024&format=jpg&imageSR=102100&bboxSR=102100&f=image

Am I crazy or what?

2
  • could you be more specific about your problem? What are you serving the data from? it sounds like you want to implement something like a WMS is that correct?
    – scw
    Commented May 15, 2011 at 5:52
  • Thats right, although I don't need all of the capabilities of a WMS, just the ability to pass a bounding box and get an image back. Ideally, I'd like to serve the imagery from Google AppEngine, and I did find this: code.google.com/p/gae-wms/wiki/InstructionsForUse but it a bit complicated (can get it to build and run, but doesnt work) and seems like overkill for my needs.
    – ericoneal
    Commented May 18, 2011 at 16:08

1 Answer 1

2

Clipping an image to the extents of a bounding box is very easy to do with the gdal_translate utility from GDAL. The documentation for it is here. You'd want to use the "-projwin" option like this,

gdal_translate -projwin ulx uly lrx lry infile outfile  

For the URL you gave, I would assume the following should work (Note that your ESRI command specifies LL and UR, while GDAL uses UL and LR)

$ gdal_translate -projwin -9562211.80152863 4626760.02856153 -9519931.21541649 4584479.44244939  <source_image> <output_image>

This would give you an output_image that is clipped to the extents of the bounding box. You should note that you cannot control the size of the resulting image when doing this. You get back as many pixels are needed to fill the extent. If you want to make the output_image a specific size, you can do that as a second step with gdalwarp and specify whatever resampling type you want to use.

GDAL has an excellent Python API, so you could combine both operations and glue the output into your processing setup, but I have to wonder whether this is really what you want? If all you need to do is display your image over a web map, it would be far simpler to setup Mapserver, point it at your image and either use WMS, or a tile request to bring the data into your mapping API.

Roger

1
  • A good answer and I am currently using MapServer, but I guess I should have been more clear. Specifically, I am trying to move all of the map hosting functionality to AppEngine, which unfortunately, does not support GDAL tools. GAE-WMS appears to do what I need, but only works with tiled rasters which I cannot use do to the nature of my application. For now, it appears that I will continue hosting my raster data elsewhere....
    – ericoneal
    Commented Aug 3, 2011 at 13:42

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.