This repository has been archived by the owner on Jun 14, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 41
Using your own data with GeoBases
Alex Prengère edited this page Sep 29, 2015
·
6 revisions
How to use your own data with GeoBases? Well, it depends on your data, mainly it is formatted using CSV or not.
If you have a CSV file, this should work:
$ cat file.csv | GeoBase -i delimiter headers indices
With:
- delimiter for, well, the column delimiter
- headers for column names separated by a '/'
- indices for columns used for key generation, also separated by a '/'
In our case:
$ cat file.csv
d1 48.22 2.33
d2 49.33 2.24
$ cat file.csv | GeoBase -i ' ' name/lat/lng name
To add file.csv as a permanent new data source, you have to use the admin
mode to modify the YAML configuration file:
$ GeoBase --admin
Just answer the questions!
If your data source is not CSV formatted, fear not. You just have to use the Python API to create the GeoBase. If you can manage to transform your data source into a Python file-like object, you can load it in one line (let's take the same file for example):
from GeoBases import GeoBase
g = GeoBase(data='feed',
source=open('file.csv'),
delimiter=' ',
headers=['name', 'lat', 'lng'],
key_fields=['name'])
g.getLocation('d1') # (48.22, 2.33)
g.visualize()
If it is not possible to have a file-like, fear not! You just have to feed the object this way:
from GeoBases import GeoBase
g = GeoBase('feed')
g.set('d1', lat=48.2, lng=2.4) # this data may come from anywhere
g.get('d1', 'lng') # 2.4
g.visualize()