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*
@ncimino
ncimino / zip_content.sh
Created November 19, 2012 18:39
Bash loop through files - show zip contents
rm contents.txt
ls *.zip > filelist
for FILENAME in `cat filelist`
do
unzip -l $FILENAME >> contents.txt
done
rm filelist
@tjmgis
tjmgis / OS VectorMap Local QGIS Text Recipe
Last active December 18, 2015 21:38
OS VectorMap Local QGIS Text Recipe - guide to how to post process OS VectorMap Local so that you can use QGIS data driven styling to create cartographic text styling.
The following is a guide for post processing OS VectorMap Local so that it can be rendered within QGIS.
We need X Y coordinates so we can use the anchor position
ALTER TABLE vml.text ADD COLUMN x_coordinate NUMERIC;
COMMIT;
update vml.text set x_coordinate = ST_X(wkb_geometry);
COMMIT;
ALTER TABLE vml.text ADD COLUMN y_coordinate NUMERIC;
@tjmgis
tjmgis / OS VectorMap District Cartographic Rendering
Created June 24, 2013 16:48
OS VectorMap District guide for cartographic rendering
Background
OS VectorMap District is made up of 23 layers of data ranging from woodland to tidal water to POI features.
Ordnance Survey released a number of Style Layer Descriptors (SLDs). These SLDs although they can be imported and used to style the data within QGIS several of the SLDs need editing. There also needs to be some post processing applied to the data in order to render as a cartographic product.
Firstly, I want to use the Dft NUmber and the Road name as a label so I added a new column and created a concatenated string using the SQL commands below.
ALTER TABLE vmd.road ADD COLUMN roadinfo VARCHAR;
COMMIT;
@graydon
graydon / country-bounding-boxes.py
Created April 23, 2014 00:03
country bounding boxes
# extracted from http//www.naturalearthdata.com/download/110m/cultural/ne_110m_admin_0_countries.zip
# under public domain terms
country_bounding_boxes = {
'AF': ('Afghanistan', (60.5284298033, 29.318572496, 75.1580277851, 38.4862816432)),
'AO': ('Angola', (11.6400960629, -17.9306364885, 24.0799052263, -4.43802336998)),
'AL': ('Albania', (19.3044861183, 39.624997667, 21.0200403175, 42.6882473822)),
'AE': ('United Arab Emirates', (51.5795186705, 22.4969475367, 56.3968473651, 26.055464179)),
'AR': ('Argentina', (-73.4154357571, -55.25, -53.628348965, -21.8323104794)),
'AM': ('Armenia', (43.5827458026, 38.7412014837, 46.5057198423, 41.2481285671)),
@drmalex07
drmalex07 / convert-geojson-to-wkt.py
Created May 12, 2014 22:13
Convert GeoJSON to/from WKT in Python. #python #geojson #geometry
import json
import geojson
from shapely.geometry import shape
o = {
"coordinates": [[[23.314208, 37.768469], [24.039306, 37.768469], [24.039306, 38.214372], [23.314208, 38.214372], [23.314208, 37.768469]]],
"type": "Polygon"
}
s = json.dumps(o)
@lukeplausin
lukeplausin / bash_aws_jq_cheatsheet.sh
Last active January 4, 2025 17:42
AWS, JQ and bash command cheat sheet. How to query, cut and munge things in JSON generally.
# Count total EBS based storage in AWS
aws ec2 describe-volumes | jq "[.Volumes[].Size] | add"
# Count total EBS storage with a tag filter
aws ec2 describe-volumes --filters "Name=tag:Name,Values=CloudEndure Volume qjenc" | jq "[.Volumes[].Size] | add"
# Describe instances concisely
aws ec2 describe-instances | jq '[.Reservations | .[] | .Instances | .[] | {InstanceId: .InstanceId, State: .State, SubnetId: .SubnetId, VpcId: .VpcId, Name: (.Tags[]|select(.Key=="Name")|.Value)}]'
# Wait until $instance_id is running and then immediately stop it again
aws ec2 wait instance-running --instance-id $instance_id && aws ec2 stop-instances --instance-id $instance_id
# Get 10th instance in the account
@iacovlev-pavel
iacovlev-pavel / geoserver-install.sh
Last active May 8, 2022 06:55
Install GeoServer on Ubuntu 18.04
#
apt-get install openjdk-8-jre
# PostgreSQL and PostGIS
apt-get install postgresql postgresql-contrib postgis postgresql-10-postgis-2.4
# Create "geoserver" database
sudo -u postgres createuser -P geoserver
sudo -u postgres createdb -O geoserver geoserver
sudo -u postgres psql -c "CREATE EXTENSION postgis; CREATE EXTENSION postgis_topology;" geoserver
@reyemtm
reyemtm / index.html
Last active November 15, 2024 09:44
Leaflet Vector Grid with Interactivity
<!DOCTYPE html>
<html>
<head>
<meta charset=utf-8 />
<title>Leaflet Vector Grid</title>
<meta name='viewport' content='initial-scale=1,maximum-scale=1,user-scalable=no' />
<link rel="stylesheet" href="https://unpkg.com/[email protected]/dist/leaflet.css" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/leaflet/1.3.1/leaflet.js"></script>
<script src="https://unpkg.com/leaflet.vectorgrid@latest/dist/Leaflet.VectorGrid.bundled.js"></script>
@ghandic
ghandic / pandas_s3.py
Last active June 5, 2023 11:40
Load csv from S3 directly into memory and write to S3 directly from memory by extending pd.DataFrame class
import boto3
import pandas as pd
from io import StringIO
class S3DataFrame(pd.DataFrame):
"""
# Make a dataframe and upload it as csv
s3df = S3DataFrame({'h1':[1], 'h2':[2]})
s3df.to_s3(Bucket='bucket-name',