Skip to content

Instantly share code, notes, and snippets.

Ryan Clark rclark

  • Mapbox
  • Tucson, AZ
Block or report user

Report or block rclark

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@rclark
rclark / Issues.md
Last active Nov 30, 2019
Leaflet WMS + GetFeatureInfo
View Issues.md

There are a bunch of reasons why this is convoluted, mostly in building the URL to make the request:

  1. You have to rely on an AJAX request, this example uses jQuery
  2. To make a GetFeatureInfo request, you must provide a BBOX for a image, and the pixel coordinates for the part of the image that you want info from. A couple of squirrely lines of Leaflet code can give you that.
  3. Output formats. The info_format parameter in the request. We don't know a priori which will be supported by a WMS that we might make a request to. See Geoserver's docs for what formats are available from Geoserver. That won't be the same from WMS to WMS, however.
  4. WMS services return XML docs when there's a mistake in the request or in processing. This sends an HTTP 200, which jQuery doesn't think is an error.
@rclark
rclark / owslib-metadata-mapping.json
Last active Sep 18, 2019
Mapping from ISO19139XML to owslib.iso:MD_Metadata
View owslib-metadata-mapping.json
{
"identifier": "gmd:fileIdentifier/gco:CharacterString",
"parentidentifier": "gmd:parentIdentifier/gco:CharacterString",
"language": "gmd:language/gco:CharacterString",
"dataseturi": "gmd:dataSetURI/gco:CharacterString",
"languagecode": "gmd:language/gmd:LanguageCode",
"datestamp": "gmd:dateStamp/gco:Date or gmd:dateStamp/gco:DateTime",
"charset": "gmd:characterSet/gmd:MD_CharacterSetCode/@codeListValue",
"hierarchy": "gmd:hierarchyLevel/gmd:MD_ScopeCode/@codeListValue",
"contact": {
@rclark
rclark / L.Composite.js
Last active May 30, 2019
Composite Leaflet Layer
View L.Composite.js
L.Composite = L.Class.extend({
includes: L.Mixin.Events,
initialize: function (options) {
// options should include:
// - tileUrl: A URL template for this layer's visible representation
// - tileOptions (optional): Any [config options for the L.TileLayer](http://leafletjs.com/reference.html#tilelayer-options)
// - geojsonUrl: A URL that retrieves GeoJSON data for this layer as a FeatureCollection,
// or a [Github blob API call](http://developer.github.com/v3/git/blobs/#get-a-blob)
// - geojsonOptions (optional): [Config options for the L.GeoJSON layer](http://leafletjs.com/reference.html#geojson-options)
@rclark
rclark / L.TopoJSON.js
Last active May 22, 2019
TopoJSON-aware Leaflet layer
View L.TopoJSON.js
/*
You'll need something like this in your HTML:
<script src="http://d3js.org/topojson.v1.min.js"></script>
*/
L.TopoJSON = L.GeoJSON.extend({
addData: function(jsonData) {
if (jsonData.type === "Topology") {
for (key in jsonData.objects) {
geojson = topojson.feature(jsonData, jsonData.objects[key]);
@rclark
rclark / lines2polysNoder.js
Created Aug 6, 2013
JSTS to create polygons from a network of arbitrary, or "spaghetti" lines. This uses jsts.noding to "clean" or "planarize" the line network, which is crazy fast compared to the "Union" alternative here: https://gist.github.com/rclark/6123614
View lines2polysNoder.js
var jsts = require("jsts"),
u = require("underscore"),
fs = require("fs");
fs.readFile("/Users/ryan/Desktop/hv-lines.geojson", function (err, data) {
var geojson = JSON.parse(data),
writer = new jsts.io.GeoJSONWriter(),
polygonizer = new jsts.operation.polygonize.Polygonizer(),
noder = new jsts.noding.MCIndexNoder(),
intersector = new jsts.algorithm.RobustLineIntersector(),
@rclark
rclark / L.TileLayer.EsriImageExports.js
Last active Mar 12, 2018
Access dynamic ESRI service layers via "export"
View L.TileLayer.EsriImageExports.js
/* When creating a layer pass the ESRI Service's Export URL. e.g.:
* https://eia-ms.esri.com/arcgis/rest/services/20130301StateEnergyProfilesMap/MapServer/export
*/
L.TileLayer.EsriImageExports = L.TileLayer.WMS.extend({
getTileUrl: function (tilePoint) {
// Get the URL if this was just a WMS
var wmsUrl = L.TileLayer.WMS.prototype.call(this, tilePoint),
base = wmsUrl.split("?")[0],
params = wmsUrl.split("?")[1].split("&");
@rclark
rclark / testNoder.js
Last active Mar 11, 2018
Example of "cleaning" a line network using JSTS to create a properly noded segment network (i.e. nodes at every intersection between segments).
View testNoder.js
var jsts = require("jsts"),
fs = require("fs"),
javascript = require("javascript.util"),
assert = require("assert"),
lines = [
"LINESTRING(-110.5 32.1,-110.45 32.2,-110.4 32.1)",
"LINESTRING(-110.5 32.25,-110.45 32.2,-110.45 32.15,-110.4 32.25)"
],
expected = [
"LINESTRING(-110.5 32.1,-110.45 32.2)",
@rclark
rclark / lines2polysUnion.js
Last active Jun 10, 2017
JSTS to create polygons from spaghetti lines. Union on lines is the "planarize" step, and is extremely time-consuming for larg-ish numbers of lines (~300 it takes about 2 seconds per each new line to union).
View lines2polysUnion.js
var jsts = require("jsts"),
_ = require("underscore"),
fs = require("fs");
fs.readFile("/Users/ryan/Desktop/hv-lines.geojson", function (err, data) {
var geojson = JSON.parse(data),
reader = new jsts.io.GeoJSONReader(),
writer = new jsts.io.GeoJSONWriter(),
polygonizer = new jsts.operation.polygonize.Polygonizer(),
View backfill.md
      |                                           |                                       |                                                     |                                                         |
      |                                           |                                       |                                                     |                                                         |
      |--------- really no time at all -----------|------------ 7 to 14 days -------------|-------------- really no time at all ----------------|----------------- shouldn't be too long -----------------|
      |                                           |                                       |                                                     |                                                         |
      |                                           |                                       |                                                     |                                                         |
View rds-troubles.md

Import times with osm2pgsql

I imported tucson.osm.pbf, a 3.4MB OSM extract.

Where is PostgreSQL Machine Specs Import time
Local 4 CPU, 16GB RAM Macbook Pro 18 seconds
Local i2.4xlarge EC2 76 seconds
Remote m1.medium EC2 > db.m1.large 500GB : 2000 IOPS 112 seconds
Remote i2.4xlarge EC2 > db.m2.4xlarge 1000GB : 10000 IOPS 82 seconds
You can’t perform that action at this time.