Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a problem with gdal.ReprojectImage from gdal1.8 Java bindings. When I perform the reprojection, the projected image is totally black. And the origin of the projected image is wrong too. There were no errors popping up at all. The code is the following:

           Dataset in_ds = gdal.Open(inPath, gdalconst.GA_ReadOnly);
           Dataset out_ds = in_ds.GetDriver().Create(outPath,in_ds.getRasterXSize(), in_ds.getRasterYSize(), in_ds.getRasterCount());

           try {
                   SpatialReference dstRef = new SpatialReference("");


                   if (gdal.ReprojectImage(in_ds, out_ds) == gdalconst.CE_Failure)
                           System.out.println("something is wrong");
           } finally {

Does anybody know what's going on here? Thanks a lot.

share|improve this question
Solution explained here : – user2949 May 11 '11 at 11:37
@Even Thank you for the link. For a response to be a proper reply it needs to stand on its own, so it has been converted to a comment. It would be a big improvement if you could supply a summary of the solution you are linking to. – whuber May 11 '11 at 13:37
up vote 2 down vote accepted

It looks like it's the line:


You're setting the destination's projection to (presumably) a different one to the source, but giving them the same coordinates. So your image is being reprojected to somewhere off the edge of your raster.

First of all, check that your source image has a projection - if not, you'll have to give it one in code (or provide it as a parameter to the ReprojectImage() function). Next, you'll have to know the bounding area of your destination image in the projection it has been assigned. If you don't know this beforehand, you'll have to take at least the four corner points of your source image (and ideally several points along each edge), reproject them (look here for a basic tutorial), and find the bounding box.

From this and knowing the size in pixels of your destination image, you can figure out the 6 georeference parameters - don't forget that almost always the y-pixel size is negative (and if like me, you use them all the time and still can't remember the order they go in, look here). The you can assign it to the destination image with SetGeoTransform(). Then ReprojectImage() will work.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.