Geographic Information Systems Asked by Brandon Hoffmann on November 30, 2020
I wrote a python script that updates the values in a dataset and then returns a static image of the map it’s connected to.
The problem is if I download the image too soon after updating the dataset, one of the visualization layers on the map that requires a lot of calculations won’t show up.
I don’t want to have to set a manual wait time in the code because the size of the data I’m uploading could range from 100 to 10,000 data points.
Is there an API url I could call that would know when a layer is being updated and when it has finished?
I have tried using vizualization url but could not find anything in the JSON data about an update status.
img_url1 = 'https://%s.carto.com/api/v2/viz/%s/viz.json/?api_key=%s&' %(self.options['u'], map_id, self.options['k'])
r1 = requests.get(img_url1)
print(json.dumps(r4.json(), indent=2))
On a similar thread someone sugested using this to refresh the the_geom data but I had no luck there either:
refresh_url = "https://{username}.carto.com/api/v2/sql?q=UPDATE table SET the_geom = cdb_latlng(latitude, longitude)&api_key={api_key}".format(username=self.options['u'], api_key=self.options['k'])
r4 = requests.get(refresh_url)
print(json.dumps(r4.json(), indent=2))
I have tried using the named map API but the ‘Last Updated’ field shows the time when the update started not finished, and the ‘Date’ field just shows the current time.
img_url2 = 'https://{user}.carto.com/api/v1/map/named/{template}/jsonp?auth_token={auth_token}&callback=callback'.format(user=self.options['u'], template=tpl_name, auth_token=self.options['k'])
r2 = requests.get(img_url2)
print(r2.headers)
'Date': 'Mon, 10 Feb 2020 20:27:14 GMT',
'Content-Type': 'text/javascript; charset=utf-8',
'Transfer-Encoding': 'chunked',
'Connection': 'keep-alive',
'Vary': 'Accept-Encoding, Authorization',
'Access-Control-Allow-Origin': '*',
'Access-Control-Allow-Headers': 'X-Requested-With, X-Prototype-Version, X-CSRF-Token, Authorization',
'Carto-Rate-Limit-Limit': '21',
'Carto-Rate-Limit-Remaining': '20',
'Carto-Rate-Limit-Reset': '0',
'Cache-Control': 'public,max-age=5,must-revalidate',
'Surrogate-Key': '{removed for privacy}',
'Last-Modified': 'Mon, 10 Feb 2020 20:14:40 GMT',
'X-Layergroup-Id': '{removed for privacy}',
'X-Content-Type-Options': 'nosniff',
'X-Varnish': '47747576',
'Age': '0',
'X-Cache': 'MISS',
'Content-Encoding': 'gzip'
From the postgresql side there are system tables that tell you if a query is running but these are not queryable via the Carto API for obvious security reasons.
You could try seeing if the batch API provides the query status see: https://carto.com/developers/sql-api/guides/batch-queries/
Answered by Shoaib Burq on November 30, 2020
Get help from others!
Recent Questions
Recent Answers
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP