Skip to content

Instantly share code, notes, and snippets.

View rclark's full-sized avatar

Ryan Clark rclark

View GitHub Profile
@rclark
rclark / Issues.md
Last active January 28, 2024 01:18
Leaflet WMS + GetFeatureInfo

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 / _readme.md
Last active April 4, 2023 19:05
Pre-commit hook for Golang formatting and linting

Pre-commit git hook to require Golang formatting and linting

  1. Add this file in a local repo at .githooks/pre-commit.
  2. git config core.hooksPath .githooks sets up the hook
@rclark
rclark / readme.md
Last active February 18, 2023 20:27
satisfactory dedicated server on aws

Satisfactory dedicated server on AWS ECS

A CloudFormation stack that you can run in your AWS account to host up a dedicated Satisfactory server.

Thanks to https://github.com/wolveix/satisfactory-server for the Docker image!

Runs on AWS ECS

The dedicated server application runs on ECS Fargate, so you get a more-or-less "serverless" setup. It uses Fargate Spot, which allows you to get the cheapest possible setup, though AWS may choose to stop and restart your server. FWIW I've never actually observed that happening.

@rclark
rclark / map.js
Created October 29, 2013 22:46
little code review
function onEachFeature(feature, layer) {
/* From the perspective of reading this function, it would be easier if you think about it in a linear fashion
What does this function do?
1) get a single feature
2) parse some specific properties out of the feature
3) use those properties to generate a string of HTML
4) build a popup from that HTML
Right now its a little hard to read because you're jumping around between those steps a bit
*/
@rclark
rclark / L.TopoJSON.js
Last active December 7, 2022 00:23
TopoJSON-aware Leaflet layer
/*
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 / L.Composite.js
Last active March 18, 2020 03:14
Composite Leaflet Layer
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 / owslib-metadata-mapping.json
Last active September 18, 2019 09:35
Mapping from ISO19139XML to owslib.iso:MD_Metadata
{
"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 / lines2polysNoder.js
Created August 6, 2013 21:34
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
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 March 12, 2018 04:18
Access dynamic ESRI service layers via "export"
/* 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 March 11, 2018 19:41
Example of "cleaning" a line network using JSTS to create a properly noded segment network (i.e. nodes at every intersection between segments).
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)",