Skip to content

Instantly share code, notes, and snippets.

@bmcbride
bmcbride / postgis_geojson.php
Created February 26, 2012 05:43
PHP PostGIS to GeoJSON
<?php
/**
* PostGIS to GeoJSON
* Query a PostGIS table or view and return the results in GeoJSON format, suitable for use in OpenLayers, Leaflet, etc.
*
* @param string $geotable The PostGIS layer name *REQUIRED*
* @param string $geomfield The PostGIS geometry field *REQUIRED*
* @param string $srid The SRID of the returned GeoJSON *OPTIONAL (If omitted, EPSG: 4326 will be used)*
* @param string $fields Fields to be returned *OPTIONAL (If omitted, all fields will be returned)* NOTE- Uppercase field names should be wrapped in double quotes
* @param string $parameters SQL WHERE clause parameters *OPTIONAL*
@bmcbride
bmcbride / sqlite_geojson.php
Created February 27, 2012 02:08
PHP SQLite to GeoJSON
<?php
/**
* SQLite to GeoJSON (Requires https://github.com/phayes/geoPHP)
* Query a SQLite table or view (with a WKB GEOMETRY field) and return the results in GeoJSON format, suitable for use in OpenLayers, Leaflet, etc.
*
* @param string $geotable The SQLite table name *REQUIRED*
* @param string $geomfield The WKB GEOMETRY field *REQUIRED*
* @param string $fields Fields to be returned *OPTIONAL (If omitted, all fields will be returned)*
* @param string $parameters SQL WHERE clause parameters *OPTIONAL*
* @param string $orderby SQL ORDER BY constraint *OPTIONAL*
@bmcbride
bmcbride / osm2pgsql-to-imposm-schema.sql
Created October 22, 2012 21:11
osm2pgsql-to-imposm-schema.sql Modified for use in TileMill open-streets-dc project
/*********************************************************************
Original Source: https://github.com/jmckenna/basemaps/blob/master/contrib/osm2pgsql-to-imposm-schema.sql
Modified for use in creating shapefiles to replace in TileMill Open Streets, DC project
Purpose: This script will modify tables generated through the osm2pgsql
utilility [1] into tables similar to those as generated from the
imposm utility [2]. The generated tables can then be used
by the mapserver-utils utility [3].
This is most likely useful for the Windows platform.
@bmcbride
bmcbride / LeafletToWKT.js
Last active June 7, 2022 02:17
Leaflet layer to WKT
function toWKT(layer) {
var lng, lat, coords = [];
if (layer instanceof L.Polygon || layer instanceof L.Polyline) {
var latlngs = layer.getLatLngs();
for (var i = 0; i < latlngs.length; i++) {
latlngs[i]
coords.push(latlngs[i].lng + " " + latlngs[i].lat);
if (i === 0) {
lng = latlngs[i].lng;
lat = latlngs[i].lat;
@bmcbride
bmcbride / RedistributeData
Last active December 20, 2015 00:28
Excel macro to redistribute a delimited column of data into separate rows (keeping other data as is). Modification of http://www.excelfox.com/forum/f22/redistribute-a-delimited-column-of-data-into-separate-rows-keeping-other-data-as-is-420/
Sub RedistributeData()
Dim X As Long, LastRow As Long, A As Range, Table As Range, Data() As String
Const Delimiter As String = ", "
Const DelimitedColumn As String = "B"
Const TableColumns As String = "A:B"
Const StartRow As Long = 2
Application.ScreenUpdating = False
LastRow = Columns(TableColumns).Find(What:="*", SearchOrder:=xlRows, _
SearchDirection:=xlPrevious, LookIn:=xlFormulas).Row
For X = LastRow To StartRow Step -1
@bmcbride
bmcbride / LeafletLayerOrder.js
Last active December 20, 2015 19:58
jQuery form layer toggling logic for Leaflet maps.
$('input[name="basemapLayers"]').change(function () {
// Remove unchecked layers
$('input:radio[name="basemapLayers"]:not(:checked)').each(function () {
map.removeLayer(window[$(this).attr('id')]);
});
// Add checked layer
$('input:radio[name="basemapLayers"]:checked').each(function () {
map.addLayer(window[$(this).attr('id')]);
});
});
@bmcbride
bmcbride / ogr2ogr.txt
Created September 4, 2013 04:44
ogr2ogr Append shapefile to existing SQLite database
ogr2ogr -update -append -f SQLite mydb.sqlite -nln "newtable" -a_srs "EPSG:4326" shapefile.shp
@bmcbride
bmcbride / proxy.php
Created September 18, 2013 19:35
Simple PHP proxy
<?php
$ch = curl_init($_GET['url']);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$output = curl_exec($ch);
curl_close($ch);
echo $output;
?>
@bmcbride
bmcbride / ImageMagick
Last active October 5, 2016 15:30
Use ImageMagick to convert black glyphicon icon to light gray color that matches inverted glyphish icon
convert glyphicons_195_circle_info.png -fuzz 100% -fill "rgb(187,187,187)" -opaque black glyphicons_195_circle_info-gray.png
@bmcbride
bmcbride / gdal.txt
Last active January 11, 2021 17:48
GDAL commands to convert NYSDOP orthoimagery JPEG2000 files to GeoTiff & PDF
SINGLE FILE CONVERT
gdal_translate input_nysdop_ortho.jp2 output.tif -b 1 -b 2 -b 3 -mask 4 -co COMPRESS=JPEG -co JPEG_QUALITY=25 -co PHOTOMETRIC=YCBCR --config GDAL_TIFF_INTERNAL_MASK YES -a_srs EPSG:2260
BATCH CONVERT
for /r %g in (*.jp2) do gdal_translate -of GTiff "%g" "%~dpng.tif" -b 1 -b 2 -b 3 -mask 4 -co COMPRESS=JPEG -co JPEG_QUALITY=25 -co PHOTOMETRIC=YCBCR --config GDAL_TIFF_INTERNAL_MASK YES -a_srs EPSG:2260
BUILT VIRTUAL RASTER (CATALOG)
gdalbuildvrt catalog.vrt e_06811416_06_05000_4bd_2011.jp2 e_06811414_06_05000_4bd_2011.jp2 e_06781416_06_05000_4bd_2011.jp2 e_06781414_06_05000_4bd_2011.jp2
gdalbuildvrt -allow_projection_difference -hidenodata -vrtnodata "255 255 255" nysdop.vrt *.jp2 -a_srs EPSG:2260