Skip to content

Instantly share code, notes, and snippets.

View jsanz's full-sized avatar
🗺️
Mapping

Jorge Sanz jsanz

🗺️
Mapping
View GitHub Profile
@jsanz
jsanz / query.sql
Created September 5, 2016 18:24
SQL: Draw max circles that cross the date line
/*
All the details on how this work here, all credit to PRamsey :-)
https://carto.com/blog/jets-and-datelines/
*/
with
-- data preparation you need rows with origin and destination
-- and any number of associated data
pairs as (
@jsanz
jsanz / README.md
Last active February 10, 2017 22:02
SQL: Postgis workshop

Postgis queries workshop

With this viewer you will have a sandbox space to try different PostGIS capabilities using several datasets. Change the SQL and press Control+S or Command+S and check the results on the map on the right.

You can also play with the styles on the CartoCSS pane.

Contents

@jsanz
jsanz / README.md
Created September 14, 2016 09:23
SQL: ring buffers with several distances

Query to produce a series of rings using buffers:

  • First you get a generate_series with the number of rings you want to produce
  • Then produce the 80km buffers multiplying by the radius for a number of cities
  • Finally use the lag function to remove for every ring the previous one so you get the ring

@jsanz
jsanz / README.md
Last active February 10, 2017 22:01
JavaScritpt: bind event to custom infowindow visibility change in carto.js

On this simple carto.js example we add a custom infowindow using Mustache and bind to its model an event when the change:visibility property changes.

Open the console for the Hi! and Bye! messages when showing and closing an infowindow.

@jsanz
jsanz / README.md
Last active February 10, 2017 21:53
CARTO: Aggregating data on SQL and infowindows

CARTO: Aggregating data on SQL and infowindows

Example on how to aggregate data using spatial SQL and then show the also attributes on CARTO BUILDER infowindow.

Based on a sample dataset with images I will first reduce the geographical precission so they collide into a grid. After that using the json_agg function we join the urls into a single field along with the counts.

WITH data as (
@jsanz
jsanz / README.md
Created March 3, 2017 12:16
JavaScript: load a mapnik and torque layer with CARTO.js

When you need to load a Torque layer along with other CARTO normal layers (Mapnik type) you need to call createLayer twice and load them into the map in the correct order.

@jsanz
jsanz / README.md
Last active March 9, 2017 17:18
Debugging CARTO.js

Doesn't throw errors, nor does it enable the intended functionality. Question is not what's specifically wrong with this script, but how do we debug these requests that ping the CARTO server but don't seem to return errors.

@jsanz
jsanz / README.md
Last active March 31, 2017 13:50
Javascript: Center a CARTO BUILDER embed

Text by Álvaro Arredondo

You can do it in the URL, but it's a little bit tricky. When you move the view in an embed, you'll see the URL changes. The thing is, that URL is encoded, but is actually showing a bounding box (NE and SW coordinates). This is the structure:

https://{{map_url}}/embed?state={"map":{"ne":[x, y],"sw":[x, y]}}

Let's take your URL:

@jsanz
jsanz / README.md
Last active May 8, 2017 18:02
CARTO & OSM: Using Overpass Turbo to create CARTO Sync Tables

Steps to create a synchronized table in CARTO that queries OSM for specific data.

  1. Navigate to Overpass Turbo web interface and put on the map on the right the area you wnat to query
  2. You can use the wizard or simply put this code and adapt it to your desired tags. Use the Map Features page from the OSM wiki to look for your desired tags.
[out:xml][timeout:25];
(
  node["amenity"="school"]({{bbox}});
);
@jsanz
jsanz / lines.sql
Created May 15, 2017 14:02
SQL: Get the angles of segment breaks of a line table
with
-- dump the geometries
dumps as (
select cartodb_id,
st_dumppoints(the_geom) as dp
from ne_50m_rivers_lake_centerlines
),
-- get the points
points as (
select cartodb_id,