Coordinates of the upper left corner=286185.598266, 5180967.071686, Coordinates of the lower right corner=286223.863098, 5180909.674438 Pixel size=0.0463053,-0.0463053 How is the image size calculated, if the coordinates and pixel size are known? Approximately should be 1024х 1536 Is there a script or formula?

I work with the library Gdal

   gdalData_1 = gdal.Open(images_1)
   gdalData_2 = gdal.Open(images_2)
   rasterXSize = gdalData_1.RasterXSize
   rasterYSize = gdalData_1.RasterYSize
   print (rasterXSize ,rasterYSize )

Output = 1024 х 1536

I want to calculate the same thing, only knowing the resolution of pixels and the value of 4 coordinates


For me it's basic mathematics.

According to your data:

minx = 286185.598266
maxx = 286223.863098
miny = 5180909.674438
maxy = 5180967.071686
pixel_size = 0.0463053

so you can calculate height and width of your image in meters:

width = maxx-minx
height = maxy-miny

and the numbers of pixels in each direction by dividing by the pixel_size

cols = width/pixel_size
rows = height/pixel_size

with your data it gives a raster of approx 826 x 1240

  • Thanks, I tried to do just that, but forgot to divide by pixel size – Zhora Zhora Aug 3 '17 at 9:48

You are trying to calculate the number of rows and number of columns in a raster. Rows number is given by the latitudinal difference (e.g. in meters) divided by the cell's resolution, while columns number is given by the longitudinal difference divided by cell resolution.

Here is an example. Assume a cell resolution of (0.5, 0.5) meters.

  • rows = (UL.y - LL.y) / cell resolution.y = (520102 - 520100) / 0.5 = 4
  • cols = (UR.x - UL.x) / cell resolution.x = (136406 - 136400) / 0.5 = 12

Note that UL means Upper Left, LL is Lower Left, and UR is Upper Right. Also note that the units used for cell resolution must be the same as those used for coordinates.

In your case, the raster is not aligned with the latitudes / longitudes, so you should estimated the distance between UL and UR using the Euclidean distance eq., namely: D = ((x1 - x2) ^ 2 + (y1 - y2) ^ 2) ^ 0.5. In your data however it gives a different result. In addition, it seems that either a LL or a LR point is missing to estimate the number of rows. Please check the data point and provide at least 3 corners of the raster. An illustration

  • I only know two coordinates, the upper left and lower right – Zhora Zhora Aug 3 '17 at 7:05
  • @ZhoraZhora, note that you've mentioned having the UL and UR corners in the question, I've edited your question changing UR, to LR. – dof1985 Aug 3 '17 at 9:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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