3

I am trying to plot some circle markers in bokeh, python on stamer toner map. I have locations from google map api in such format:

 latitude 41.552164 longitude 44.990961 

But the bokeh map plot gets data points in X and Y coordinate format. How can I transform these lat/long coordinates to X and Y?

Thank you in advance.

2
  • Please see if this can help you Commented May 13, 2017 at 17:22
  • 1
    I think it's close to my question but doesn't answer fully. They talk about distance and I want just point translation from lat/long to x,y. Commented May 13, 2017 at 17:56

2 Answers 2

5

your question is a little vague on what exactly you are trying to do and a code example would help give a better answer.

Generally when trying to plot geographical data obtained by online sources, you will have data in a coordinate system (WGS84) with latitude being the y and longitude being the x. Bokeh can plot longitude and latitude simply by specifying the proper names in the ColumnDataSource.

from bokeh.io import show from bokeh.models import ColumnDataSource from bokeh.plotting import figure longitude = [44.990961] latitude = [41.552164] source = ColumnDataSource(data=dict(longitude=longitude, latitude=latitude)) p = figure(plot_width=400, plot_height=400) p.circle(x='longitude', y='latitude', source=source) show(p) 

If truly your question is related to a coordinate transformation of your data, it will be difficult to answer your question without more details. I recommend you take a look at https://en.wikipedia.org/wiki/Map_projection to understand map projections.

If you need to convert the longitude/latitude coordinates into a different coordinates system. You can use the pyproj package.

import pyproj project_projection = pyproj.Proj("+init=EPSG:4326") # wgs84 google_projection = pyproj.Proj("+init=EPSG:3857") # default google projection longitude = [44.990961] latitude = [41.552164] x, y = pyproj.transform(google_projection, project_projection, longitude, latitude) print(x, y) 

Reference for the google projection Google map api v3 projection?

Sign up to request clarification or add additional context in comments.

1 Comment

If you don't want to have to us the pyproj library then it actually is pretty easy to convert the coordinates in pure python, as described here
1

in order to easily transform from longitude/latitude (EPSG:4326) into another projection (for example WebMercator EPSG:3857, used by GoogleMaps AFAIK), I would recommend pyproj package in combination with shapely, for example:

from functools import partial from shapely.geometry import Point from shapely.ops import transform import pyproj pnt = transform( partial( pyproj.transform, pyproj.Proj(init='EPSG:4326'), pyproj.Proj(init='EPSG:3857')), Point(44.990961, 41.552164)) print(pnt.x, pnt.y) 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.