This week's book giveaway is in the JavaScript forum.
We're giving away four copies of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js and have Paul Jensen on-line!
See this thread for details.
Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Image cropping and calculation of offsets -request a code review  RSS feed

 
suraj sahitya
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am using the java.awt.Rectangle class to construct subset of a GEOTIFF file. In order to do this I need to specify the x,y offset plus the width and height of each subset image.

Following is the code I have and I would appreciate a code review -

The number of pixels is 3600 and the width and height of each subset I need to calculate is 3600 (1 degree latitude by 1 degree longitude)
The original GEOTIFF encompasses 40 degree width and 30 degree in height
 
Paul Clapham
Sheriff
Posts: 22374
42
Eclipse IDE Firefox Browser MySQL Database
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't see too much wrong with it, except that your indentation is not very good. The opening and closing braces frequently don't line up, the indentation is inconsistent, and the whitespace at lines 12 and 13 doesn't seem to me to serve any purpose. I'd also use "xOffset" and "yOffset" rather than "xoffset" and "yoffset" as variable names, just like you used "cellSize".

And personally I would import java.awt.Rectangle so that I didn't have to spell out the package name all the time, but perhaps you're using another Rectangle class which would conflict with that import?

You're also hard-coding the magic numbers 30, 40, and 3600 rather than assigning them to variables with meaningful names which would help to explain their purpose.

However those are fairly trivial quibbles. On the whole it's a fairly reasonable piece of code.
 
Darryl Burke
Bartender
Posts: 5167
11
Java Netbeans IDE Opera
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You could useand then you wouldn't need the offset variables.
 
suraj sahitya
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Apologies. My business requirements have changed slightly. The code needs to crop squares out of an original grid from bottom to top. I have enclosed the code again this time with the proper identation hopefully.
Many thanks for the existing review already.

 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!