[gradsusr] KML Coordinates

Jennifer M Adams jadams21 at gmu.edu
Tue Oct 22 19:38:02 EDT 2019


Hi, Andrew —
I put the following diagram in the source code where those KML bounding box coordinates are generated to remind myself what the code is doing:

  (0,0)
  +-----+-----+-> I
  |     |     |        * denotes the center of the grid cell (GrADS uses this)
  |  *  |  *  |        + denotes i,j points in standard TIFF PixelIsArea raster space
  |   (1,1)   |
  +-----+-----+
  |     |     |
  |  *  |  *  |
  |     |   (2,2)
  |-----+-----+
  V
  J

  /* i,j raster values correspond to the corners of the grid cells instead of the centers  */


The KML bounding box has the lat/lon of the lower left and upper right corners of the grid that covers your dimension environment specifications. But the grid coordinate is in the center of the grid box, so you need to add/subtract a half a grid box to get the corner values. Here is a script fragment to get the X,Y grid values from the ‘q dims’ output , round them outward to the nearest integer, then adjust by +/- 0.5 to get the corner values then convert them to world coordinates using ‘q gr2w’.  I tested this a bit and the southwest and northeast corners of the BoundingBox do match the KML output. You should double check against the KML output for your case just to be sure.

* Get the grid coordinates
'q dims'
xdims=sublin(result,2)
ydims=sublin(result,3)
gx1=subwrd(xdims,11) ; gx2=subwrd(xdims,13)
gy1=subwrd(ydims,11) ; gy2=subwrd(ydims,13)

* Round X,Y grid coordinates outward to largest integer part
igx1=math_int(gx1) ; igy1=math_int(gy1)
igx2=math_int(gx2) ; igy2=math_int(gy2)
if (igx2!=gx2) ; igx2=math_int(gx2+1) ; endif
if (igy2!=gy2) ; igy2=math_int(gy2+1) ; endif

* Get the corner lat/lon of the lower left grid box
'q gr2w 'igx1-0.5' 'igy1-0.5
bbw=subwrd(result,3)
bbs=subwrd(result,6)
* Get the corner lat/lon of the upper right grid box
'q gr2w 'igx2+0.5' 'igy2+0.5
bbe=subwrd(result,3)
bbn=subwrd(result,6)

say 'bbw = 'bbw
say 'bbe = 'bbe
say 'bbs = 'bbs
say 'bbn = 'bbn


—Jennifer


On Oct 18, 2019, at 10:15 PM, Andrew Revering <andy at f5data.com<mailto:andy at f5data.com>> wrote:

I want to figure out how to calculate or obtain the coordinates defined in the generated KML file from the 'set kml' command.
Simply using the defined coordinates of the 'set lat / set lon' commands do not match up exactly with what's in the KML file, and I can't figure out the logic to skew those numbers manually.
Because of the way my system is set up, it's inconvenient to use the KML option and parse the kml file.
I'm also generating the PNG myself with the following code. I'm not sure if that matters, but I just want to make sure that my edge coordinates are exact.
Ideas?

Here is my abbreviated code.

* define my map bounds
'set lon -129 -64'
'set lat 23.5 52'

* generate the base PNG layer instead of using the KML's TIF
'set parea 0 11 0 8.5'
'set grid off'
'set mproj scaled'
'set mpdraw off'
'set grads off'
'set gxout shaded'
'display var'
'printim myimg.png x2048 y1024 -t 0'

* KML file providing coordinates I want to obtain without having to produce this KML
'set mproj latlon'
'set gxout kml'
'set kml -img mykml'
'display var'

Resulting coordinates in KML say:
    <LatLonBox>
      <west>   -129.02</west>
      <east>   -63.975</east>
      <south>    23.485</south>
      <north>    52.015</north>
      <rotation>0.0</rotation>
    </LatLonBox>
Which are not the same as my 'set lon/set lat' definitions.

These scripts run for different domains and maps that I can't simply write this down once and use those values. They are modified on the fly so I need to figure it out on the fly.

Thanks in advance!
_______________________________________________
gradsusr mailing list
gradsusr at gradsusr.org<mailto:gradsusr at gradsusr.org>
http://secure-web.cisco.com/1TBQ-t6lQ1jE6fWLJN84Awg73tAKNYehALqTZSzMfYxJKJ0sCYj7oA61ZJVsfDAggYIhq_cPsi5cfdfHBbDjWDsJJFF-2LeEZtgytY8XVXEnVswMcSXWrwW4izUJ3z-XyvSJZ2YCSfKwgYpBkLsf4mqMn4CUeLu_62B-z77V4VgqLwlwTSY4e4j2jjqucVvBgQCEVu6F-QRqlkc6xgO9oAYflnTLUAknkZlu9yOfkk9mT0f6ga8hptmCvQJ-4A0Dqx4nO5J2y1atL0qp9-A4YJ0tC2vKpaTwHdFvq0w-yCszDnsKl0XJ7NiC_f_prBDuesKVTepQT4Byvx5LkdGJUAFe8i0p6WxlZMRxk4O-6lJsl0WO3trucWKuN1OLisHpMVbrfnxmzqc_qP3XLHaqQMGxLj84J5K8p2tomqZlZvbFUj8Akk-KIQieN6ugYcFzj/http%3A%2F%2Fgradsusr.org%2Fmailman%2Flistinfo%2Fgradsusr

--
Jennifer Miletta Adams
Center for Ocean-Land-Atmosphere Studies (COLA)
George Mason University



-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://gradsusr.org/pipermail/gradsusr/attachments/20191022/5892f748/attachment.html>


More information about the gradsusr mailing list