[Gdal-dev] Latitude view thinner than it should be

Frank Warmerdam warmerdam at pobox.com
Tue Sep 27 12:13:03 EDT 2005


On 9/27/05, Josepo Urrutia <find_all at hotmail.com> wrote:
> Using the GDAL/OGR library I've manage to import a S-57 map into a
> OGRDataSource, that is used to get access to the diferent OGRLayers and
> OGRFeatures.
>
> With this information I visualize the map onto the screen.
>
> To get access to the lat/lon data of the map (the initial and final latitude
> and longitude) I do a search to all the OGRFeatures and ORGGeometry of those
> features to look for the maximum and minimum. Is there a more direct way to
> get this inf.?

Josepo,

You can call OGRLayer::GetExtent() to fetch a layer extent.   In the
case of S-57 it still has to iterate over everything to get the extents but
at least it seems to do it at a lower level and should be somewhat faster.

> Then to calculate the pixel on the screen that represents a position I use
> this simple formule:
>
>         // Knowing the initial/final lon and the screen weigth
>         // we calculate the number of screen pixel for 1 longitude grade
>         pixel_per_lon_grade=(winw/(lon_end-lon_ini));
>
>         // lat_data and lon_data is the position we want to transform
>         // pixel_y and pixel_x is the resulting screen position
>         pixel_y=(lat_ini-lat_data)*pixel_per_lon_grade;
>         pixel_x=(lon_ini-lon_data)*pixel_per_lon_grade;
>
> The problems of using this formule is that the latitude view gets thinner
> than it should be.
>
> Obviously I'm forgetting something important (I told you I was a newbee with
> topographical maps, didn't I?), any ideas or suggestions?

The problem is that if you use direct lat/lon values to map on screen,
you will suffer increasing distortion as your move away from the
equator. If you look at globe you will see that one of the lat/long
grid boxes is squarish near the equator, but tall and thin near the poles.

The normal solution to see maps with reasonable local display is to
convert into a projected coordinate system, such as UTM.   Alternatively
you could hack an approximation of this by using a different pixel
size for lat and lon directions and compute the sizes based on your general
latitude.

Best regards,

--
---------------------------------------+--------------------------------------
I set the clouds in motion - turn up   | Frank Warmerdam, warmerdam at pobox.com
light and sound - activate the windows | http://pobox.com/~warmerdam
and watch the world go round - Rush    | Geospatial Programmer for Rent




More information about the Gdal-dev mailing list