This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# The MIT License (MIT) | |
# Copyright (c) 2016 Vladimir Ignatev | |
# | |
# Permission is hereby granted, free of charge, to any person obtaining | |
# a copy of this software and associated documentation files (the "Software"), | |
# to deal in the Software without restriction, including without limitation | |
# the rights to use, copy, modify, merge, publish, distribute, sublicense, | |
# and/or sell copies of the Software, and to permit persons to whom the Software | |
# is furnished to do so, subject to the following conditions: | |
# |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Check out the full post at http://beneathdata.com/how-to/visualizing-my-location-history/ | |
# to utilize the code below | |
# We'll only use a handful of distinct colors for our choropleth. So pick where | |
# you want your cutoffs to occur. Leave zero and ~infinity alone. | |
breaks = [0.] + [4., 24., 64., 135.] + [1e20] | |
def self_categorize(entry, breaks): | |
for i in range(len(breaks)-1): | |
if entry > breaks[i] and entry <= breaks[i+1]: | |
return i |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import multiprocessing | |
import multiprocessing.queues | |
from flask import Flask | |
from flask import request | |
class Backend(object): | |
def __init__(self, command_queue, host='0.0.0.0', port=8000, debug=True): | |
self.command_queue = command_queue | |
self.flask_app = Flask('Backend') | |
self.flask_app.add_url_rule('/', "handleRequest", self.handleRequest, methods=['GET']) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 -*- | |
# Many thanks to http://stackoverflow.com/users/400617/davidism | |
# This code under "I don't care" license | |
# Take it, use it, learn from it, make it better. | |
# Start this from cmd or shell or whatever | |
# Go to favourite browser and type localhost:5000/admin | |
import sys | |
from flask import Flask | |
from flask.ext.sqlalchemy import SQLAlchemy | |
from flask.ext.admin import Admin |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os, urllib, urllib2, datetime, arcpy, json | |
## ============================================================================== ## | |
## function to update a field - basically converts longs to dates for date fields ## | |
## since json has dates as a long (milliseconds since unix epoch) and geodb wants ## | |
## a proper date, not a long. | |
## ============================================================================== ## | |
def updateValue(row,field_to_update,value): | |
outputfield=next((f for f in fields if f.name ==field_to_update),None) #find the output field |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from .user import User | |
def init_db(db): | |
"""Add a save() function to db.Model""" | |
def save(model): | |
db.session.add(model) | |
db.session.commit() | |
db.Model.save = save |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!flask/bin/python | |
from flask import Flask, jsonify, abort, request, make_response, url_for | |
from flask_httpauth import HTTPBasicAuth | |
app = Flask(__name__, static_url_path = "") | |
auth = HTTPBasicAuth() | |
@auth.get_password | |
def get_password(username): | |
if username == 'miguel': |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pickle | |
import gzip | |
def save(object, filename, protocol = 0): | |
"""Saves a compressed object to disk | |
""" | |
file = gzip.GzipFile(filename, 'wb') | |
file.write(pickle.dumps(object, protocol)) | |
file.close() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
Web Mercator Scale and Resolution Calculations | |
Python implementation of the formulas at http://msdn.microsoft.com/en-us/library/bb259689.aspx | |
""" | |
import math | |
def meters_per_pixel(zoom, lat): | |
""" | |
ground resolution = cos(latitude * pi/180) * earth circumference / map width | |
""" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#Inspired by the code present in this answer: | |
#http://gis.stackexchange.com/a/26944/2043 | |
import arcpy,os | |
def main(): | |
InFolder = arcpy.GetParameterAsText(0) | |
Dest=arcpy.GetParameterAsText(1) | |
arcpy.env.workspace=InFolder |