Plot GeoIP data on a World Map

随声附和 提交于 2019-12-04 17:42:11

问题


I need a library (preferably written in Python) which is able to take a series of IP addresses (or geographic coordinates) and plots them on a World Map.

I already found this one, but it outputs data as a .svg file and it's simply unable to cope with large data sets.

Please note that I need something which can be downloaded and run locally, so no data uploading to 3rd party web services.

Thanks!


回答1:


Perhaps Basemap in Matplotlib for the plotting.

It can do all sorts of projections (don't mind the ugly default colours). And you have good control over what/how you plot. You can even use NASA Blue Marble imagery. And of course, you can plot markers, lines, etc on the map using the plot command.

I haven't put huge datasets through it, but being that it is a part of Matplotlib I suspect it will do well.

If I remember right, despite being part of the library, by default it doesn't ship with Matplotlib.




回答2:


The google maps API can support all of the above if you would be willing to set up a local web environment for testing. There is a wrapper around the API for Python called pymaps.

The API documentation has an example on how to use Google's geocoder to plot points on a map given a particular input address:

Google Maps API Example: Simple Geocoding




回答3:


You might want to have a look at mapsplotlib.

Installation

ONLY PYTHON 2.7!

$ pip install mapsplotlib
$ pip install pandas

You'll then need to have a Google Static Maps API key, go to https://console.developers.google.com

Usage

import pandas as pd
from mapsplotlib import mapsplot as mplt

df = pd.read_csv("data.csv")

mplt.register_api_key('your_google_api_key_here')
mplt.density_plot(df['latitude'], df['longitude'])

Example output




回答4:


I recently used gmplot.

Simply install it with

pip install gmplot

It is extremely easy to use. All you have to do is plug in the longitude and latitude values and gmplot will put out a map in html-form.

Here's a minimal example. Let lat_values and lon_values be lists of latitude and longitude values.

from gmplot import gmplot
import numpy as np

center_lat = np.mean(lat_values)
center_lon = np.mean(lon_values)
zoom = 15

gmap = gmplot.GoogleMapPlotter(center_lat, center_lon, zoom) 
gmap.scatter(lat_values, lon_values)
gmap.draw('my_map.html')

That's it! Of course, you can tune parameters to enhance the visuals. See the crash course here.



来源:https://stackoverflow.com/questions/1565555/plot-geoip-data-on-a-world-map

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!