Search code examples
gtkcoordinatesgisscalecartography

how to scale map coordinates to ensure it is completely visible


I'm working on a GIS-like app, and I need to draw a (2d)cartographic map on a Gtk window. We get the coordinates - already converted into standard x, y format - from PROJ.4.

All points have very large numbers as coordinates. For example, a typically point could be described as below:

x = 820787.12345...

y = 3937564.12345...

This area is still too large to be drawn in my GTK window(max resolution: 1366 * 768)!

So, I have a simple, stupid question: is there any standard method to coherently scale the size of a cartographic map before drawing it, to ensure that my map is fully displayed in my default drawing area(without loss of precision)?

Yes, I know I simply could first divide each coordinate by a constant, before joining the points; but this "raw" method seems(to me, of course) sloppy and inaccurate.

If i could solve my problem, I promise to make a demo to share with other users.

Thanks

IT


Solution

  • Not sure if i am right, but i use cairo for drawing on gtk_windows. if you are using cairo, this might be helpful:

    // save cairo to simply restore old scale_map
    cairo_save(cr);
    
    // move cairo center to your zero pos of your graph
    cairo_translate(cr, x_zero_pos, y_zero_pos);
    
    // scale on max bounds <--- this is what you are looking for
    cairo_scale(cr, graph_width / max_x_amplitude,
                   -graph_height / max_y_amplitude);
    
    // now you can draw your line with real values
    cairo_line....s.o
    
    //restore your cairo. otherwise the linewidth will be depending on the scale
    cairo_restore(cr);
    
    // finally paint
    cairo_set_line_width(cr, linewidth);
    cairo_stroke(cr);