Skip to content

Instantly share code, notes, and snippets.

View geobabbler's full-sized avatar
💭
Working

William Dollins geobabbler

💭
Working
View GitHub Profile
if (ImageFormat.Jpeg.Equals(image.RawFormat))
{
// JPEG
}
else if (ImageFormat.Png.Equals(image.RawFormat))
{
// PNG
}
else if (ImageFormat.Gif.Equals(image.RawFormat))
{
@geobabbler
geobabbler / globamaptiles.py
Created April 21, 2014 13:19
Update of globalmaptiles.py from http://www.maptiler.org to include functions to generate ArcGIS tile addresses (using hex notation) and to generate world file (affine transformation) parameters for a given TMS tile.
#!/usr/bin/env python
###############################################################################
# $Id$
#
# Project: GDAL2Tiles, Google Summer of Code 2007 & 2008
# Global Map Tiles Classes
# Purpose: Convert a raster into TMS tiles, create KML SuperOverlay EPSG:4326,
# generate a simple HTML viewers based on Google Maps and OpenLayers
# Author: Klokan Petr Pridal, klokan at klokan dot cz
# Web: http://www.klokan.cz/projects/gdal2tiles/
@geobabbler
geobabbler / worlddfile.py
Last active August 29, 2015 14:00
Function to generate world file parameters for any TMS tile. Useful for building virtual rasters. Add to globalmaptiles.py
def WorldFileParameters(self, tx, ty, zoom):
"Returns world file (affine transofrmation) parameters of the given tile."
bounds = self.TileBounds( tx, ty, zoom)
moriginx = bounds[3] + (self.Resolution(zoom) / 2)
moriginy = bounds[0] - (self.Resolution(zoom) / 2)
return (self.Resolution(zoom), 0.0, 0.0, self.Resolution(zoom) * -1, moriginy, moriginx)
var express = require('express'),
geo = require('./routes/geo');
var app = express();
app.get('/countries/:id/bbox', geo.bbox);
app.get('/countries/:id/bbox/:srid', geo.bboxSrid);
app.get('/countries/:id/polygon', geo.polygon);
app.get('/countries/:id/polygon/:srid', geo.polygonSrid);
var pg = require('pg');
var conString = "postgres://username:password@hostname.rds.amazonaws.com:5432/database"; //TODO: point to RDS instance
exports.bbox = function(req, res) {
var client = new pg.Client(conString);
client.connect();
var crsobj = {"type": "name","properties": {"name": "urn:ogc:def:crs:EPSG:6.3:4326"}};
var idformat = "'" + req.params.id + "'";
idformat = idformat.toUpperCase();
var query = client.query("select st_asgeojson(st_envelope(shape)) as geojson from ne_countries where iso_a3 = " + idformat + ";");
{
"type": "feature",
"crs": {
"type": "name",
"properties": {
"name": "urn:ogc:def:crs:EPSG:6.3:4326"
}
},
"geometry": {
"type": "Polygon",
// dynamically include routes (Controller)
fs.readdirSync('./controllers').forEach(function (file) {
if(file.substr(-3) == '.js') {
route = require('./controllers/' + file);
route.controller(app);
}
});
var meta = client.query("select * from geometry_columns where f_table_name = '" + tablename + "' and f_table_schema = '" + schemaname + "';");
meta.on('row', function (row) {
var query;
var coll;
spatialcol = row.f_geometry_column;
if (geom == "features") {
query = client.query("select st_asgeojson(st_transform(" + spatialcol + ",4326)) as geojson, * from " + fullname + ";");
coll = {
type : "FeatureCollection",
features : []
};
/roll up the results
query.on('row', function (result) {
if (!result) {
return res.send('No data found');
} else {
if (geom == "features") {
coll.features.push(geojson.getFeatureResult(result, spatialcol)); //use helper function
} else if (geom == "geometry") {
var shape = JSON.parse(result.geojson);
coll.geometries.push(shape);