Skip to content

Instantly share code, notes, and snippets.

View geobabbler's full-sized avatar
💭
Working

William Dollins geobabbler

💭
Working
View GitHub Profile
@geobabbler
geobabbler / anno_snippet1.cs
Created January 16, 2015 20:47
First code snippet for annotation post
if (_draw == null)
{
_draw = new Draw(BoundMap); //private class-level variable of type ESRI.ArcGIS.Client.Draw
_draw.DrawComplete += DrawCompleteHandler; //subscribe to the DrawComplete event
_activated = true;
_draw.IsEnabled = true; //enable the Draw object
}
_draw.DrawMode = DrawMode.Point; //set it to Point mode
@geobabbler
geobabbler / stack2csv.py
Created November 26, 2014 21:20
Import JSON from StackExchange tags API to CSV
import requests
from pprint import pprint
r = requests.get('https://api.stackexchange.com/2.2/tags?page=1&pagesize=100&order=desc&sort=popular&site=gis')
data = r.json()
print "tag,count"
for tag in data["items"]:
print tag["name"] + "," + str(tag["count"])
gdalbuildvrt 6.vrt 6/*.png
python tile_grab.py -b -158;21;-157;22 -d E:\tiles\oahu_img\a -i false -z 6 -u http://www.someserver.net/arcgis/rest/services/ImagerySvc/MapServer/tile/{z}/{y}/{x}.png
app.get('/leonardtown/buildings/:geom', function (req, res, next) {
var client = new pg.Client(app.conString);
var geom = req.params.geom.toLowerCase();
if ((geom != "features") && (geom != "geometry")) {
res.status(404).send("Resource '" + geom + "' not found");
return;
}
var tablename = "leonardtown_bldgs";
var schemaname = "public";
var fullname = schemaname + "." + tablename;
//SQL to retrieve schema
//var sql = "SELECT n.nspname as schemaname,c.relname as table_name,a.attname as column_name,format_type(a.atttypid, a.atttypmod) AS //type,col_description(a.attrelid, a.attnum) as comments";
//sql = sql + " FROM pg_class c INNER JOIN pg_namespace n ON c.relnamespace = n.oid LEFT JOIN pg_attribute a ON a.attrelid = c.oid";
//sql = sql + " WHERE a.attnum > 0 and c.relname = '" + tablename + "' and n.nspname = '" + schemaname + "';";
//SQL to retrieve layer list
//sql = "SELECT 'geometry' AS geotype, * FROM geometry_columns UNION SELECT 'geography' as geotype, * FROM geography_columns;";
/**
* retrieve all features that intersect the input GeoJSON geometry
*/
app.post('/vector/:schema/:table/:geom/intersect', function (req, res, next) {
//console.log(JSON.stringify(req.body));
var queryshape = JSON.stringify(req.body);
//continue with the rest of app.post
@geobabbler
geobabbler / snippet6.bat
Created November 23, 2014 14:33
Code snippet 6 for blog post
curl -X POST -d "{ \"type\": \"Point\", \"coordinates\": [-98.35, 39.7] }" -H "Content-Type: application/json" http://localhost:3000/vector/public/states_gen/features/intersect
exports.getFeatureResult = function(result, spatialcol) {
var props = new Object;
var crsobj = {
"type" : "name",
"properties" : {
"name" : "urn:ogc:def:crs:EPSG:6.3:4326"
}
};
//builds feature properties from database columns
for (var k in result) {
/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);