Skip to content

Instantly share code, notes, and snippets.

@lucasnad27
Last active December 11, 2015 18:39
Show Gist options
  • Save lucasnad27/4643339 to your computer and use it in GitHub Desktop.
Save lucasnad27/4643339 to your computer and use it in GitHub Desktop.
Create genealogical lines from nodes
import urllib2
import urllib
base_url = 'http://lucasnad27.cartodb.com/api/v2/sql'
api_key = 'none of your business'
delete_sql = urllib.quote('delete from CONNECTORS')
insert_sql = urllib.quote('Insert into connectors (the_geom,person_id) select ST_MakeLine(points), c.person_id from (select n.the_geom as points, n.person_id from nodes as n order by start_date) c group by c.person_id')
req = urllib2.Request('%s/?q=%s&api_key=%s' % (base_url, delete_sql, api_key))
response = urllib2.urlopen(req)
print response.read()
req = urllib2.Request('%s/?q=%s&api_key=%s' % (base_url, insert_sql, api_key))
response = urllib2.urlopen(req)
print response.read()
Insert into connectors (
the_geom,
person_id
)
select ST_MakeLine(points), c.person_id
from (
select n.the_geom as points, n.person_id
from nodes as n order by start_date
) c
group by c.person_id
update nodes
set end_date =
to_date(end_time::varchar || ', 00:00:00.00', 'yyyy, HH24:MI:SS.MS');
update nodes
set start_date =
to_date(start_time::varchar || ', 00:00:00.00', 'yyyy, HH24:MI:SS.MS');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment