1
votes

I've found many examples with converting coordinates to pixel for specific picture size. But that is not what I need.

I need to convert geo coordinates (latitude and longitude) to screen pixels with defined ratio pixels/degree without binding to picture size. It needed for drawing programmatically few lines on canvas (10-15 kilometers length of each line and 80x80 kilometers whole map).

How can I do that?

2
Multiply degrees by your (pixels/degree) constant to retrieve the pixel location. What else is there to it, especially since everything else concerns the specific sphere-to-plane projection you use, but did not mention?Marko Topolnik
@MarkoTopolnik, yes, I think about this simple method too. But is this method correct? As you know display is flat and earth is round.BArtWell
Well, either you accept the approximation, or you can't have a fixed pixels/degree ratio.Marko Topolnik

2 Answers

1
votes

If you want to maintain correct aspect ratio keep in mind that the length of a degree of longitude depends on the latitude: longitudes get shorter as you approach a pole. If you assume a spherical Earth the length of a longitude is multiplied by the cosine of the latitude, e.g. if a degree is 110km on the equator, on 60°N it's 110*cos(60) = 55km.

The earth is pretty flat over distances of less than 100km. Constant scale factors are OK unless you need really high precision, or have to work with geography of Antarctica.

0
votes

If you care about projection (see comments of question) and you use swing to draw on the screen you can use:

http://docs.geotools.org/stable/userguide/unsupported/swing/jmappane.html

Be warned, it is a very heavy library. It is probably faster to use a web page with leaflet (javascript) to get something geographical on the screen.