Last active
December 11, 2015 18:39
-
-
Save lucasnad27/4643339 to your computer and use it in GitHub Desktop.
Create genealogical lines from nodes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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