Skip to content

Instantly share code, notes, and snippets.

SELECT avg(mindist) AS avgNND
FROM
( SELECT aname, min(dist) AS mindist
FROM
( SELECT a.geometry, ST_Distance(a.geometry, b.geometry)*0.00062 AS dist,
a.name AS aname, b.name AS bname
FROM parks AS a, parks AS b
WHERE a.name <> b.name
ORDER BY aname, dist ASC ) AS distances
SELECT name FROM upstate ORDER BY name;
SELECT * FROM
Crosstab('SELECT row.name::text, col.name::text, (ST_Distance(row.geometry, col.geometry, true)*0.00062)::text AS dist
FROM upstate AS row, upstate AS col
ORDER BY 1, 2;'
) AS
ct(row_name text, Auburn text, Binghamton text, Elmira text, Ithaca text, Rochester text, Syracuse text);
DROP TABLE qlayer;
SELECT distances.dist, parcels.parcel_id, parcels.geometry INTO qlayer FROM
( SELECT min(ST_Distance(parcels.geometry,firm.geometry)::integer) AS dist, parcels.parcel_id
FROM parcels,firm
WHERE firm.zone = 'X500'
GROUP BY parcels.parcel_id
ORDER BY dist DESC
) AS distances,
@aaronpdennis
aaronpdennis / PostGIS_cheatsheet.md
Last active March 27, 2017 22:12
useful notes, commands, queries for PostGIS
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Zoom Tile size at equator (km) Resolution at equator (m)
0 22568 88155
1 11284 44078
2 7656 29904
3 4577 17881
4 2443 9544
5 1244 4861
6 625 2442
7 313 1223
@aaronpdennis
aaronpdennis / congressional-district-maps.md
Last active October 2, 2016 16:08
Blog post for GovTrack.us about creating congressional district maps.

Every ten years, after the decennial census and as mandated by the U.S. Constitution, states are subdivided into sets of congressional districts for representation in the U.S. House of Representatives. GovTrack provides maps of these congressional boundaries for your reference and makes the maps available for embedding on other sites. Beyond looking up the district for a specific address, maps introduce a geographic context that tells us about the demographics and rural/urban nature of a district, as well as whether that district's boundaries show signs of gerrymandering.

Recently, we redesigned GovTrack's map of congressional districts to be more responsive, more legible, and easier to reproduce. To create these maps, we used data from the U.S. Census Bureau, a few cartographic tricks and tools, and web map hosting from Mapbox. I'll explain the process here, and you can reference the exact workflow [on GitHub](https://github.com/aaron

@aaronpdennis
aaronpdennis / cb_2014_500k.json
Last active September 9, 2018 11:53
Congressional Districts Map with TopoJSON and Mapbox GL JS
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
HTML:
<link rel="stylesheet" type="text/css" href="//fonts.googleapis.com/css?family=Open+Sans" />CSS:
h1 {
font-family: 'Open Sans';
font-size: 36px;
font-style: normal;
font-variant: normal;
font-weight: bold;
line-height: 54px;
}