简体   繁体   中英

How to convert geo coordinates to pixels with fixed ratio?

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?

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, eg 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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM