Skip to content

Instantly share code, notes, and snippets.

View nygeog's full-sized avatar

Danny S. nygeog

View GitHub Profile
@nygeog
nygeog / bash_profile
Created December 10, 2019 01:33
Bash Profile Question on how to make Alias for Anaconda
# added by Anaconda3 2019.10 installer
# >>> conda init >>>
# !! Contents within this block are managed by 'conda init' !!
__conda_setup="$(CONDA_REPORT_ERRORS=false '/Users/{...username...}/opt/anaconda3/bin/conda' shell.bash hook 2> /dev/null)"
if [ $? -eq 0 ]; then
\eval "$__conda_setup"
else
if [ -f "/Users/{...username...}/opt/anaconda3/etc/profile.d/conda.sh" ]; then
. "/Users/{...username...}/opt/anaconda3/etc/profile.d/conda.sh"
CONDA_CHANGEPS1=false conda activate base
@nygeog
nygeog / csv-to-shapefile-geopandas.py
Last active July 18, 2024 00:31
Read a CSV with Pandas and set as GeoDataFrame with geopandas and save as Shapefile with fiona
import pandas as pd
from geopandas import GeoDataFrame
from shapely.geometry import Point
import fiona
df = pd.read_csv('data.csv')
geometry = [Point(xy) for xy in zip(df.x, df.y)]
crs = {'init': 'epsg:2263'} #http://www.spatialreference.org/ref/epsg/2263/
geo_df = GeoDataFrame(df, crs=crs, geometry=geometry)
@nygeog
nygeog / cartodb-import-api-example.py
Created April 21, 2017 17:06
CartoDB Import API Example w/ Python
from cartodb import CartoDBAPIKey, CartoDBException, FileImport
from _secret_info import cartodb_domain, API_KEY
cl = CartoDBAPIKey(API_KEY, cartodb_domain)
fi = FileImport('nyctrees2015.csv', cl, create_vis='true', privacy='public') # Import csv file, set privacy as 'link' and create a default viz
fi.run() #https://github.com/CartoDB/cartodb-python
import json
inFileName = 'data/cartojsontest1.carto.json'
ouFileName = 'data/cartojsontest1_change_zoom10.carto.json'
newMapName = 'THIS IS A TEST10'
zoomLevel = 12
lat = '40.7127'
lng = '-75.0059'
oldDatasetName = 'infogroup_bus_2012_is_mcdonalds'
newDatasetName = 'infogroup_bus_2012_like_exxon'
import json
def oneTest():
return 'so'
def openJSON(inFile):
with open(inFile) as json_data:
data = json.load(json_data)
return data
@nygeog
nygeog / classify-for-cartodb-torque-for-gradauted-symbols-w-sql.py
Created December 21, 2016 15:08
Classify for Cartodb Torque for Graduated Symbols with SQL
ALTER TABLE table_name ADD COLUMN torque_class INTEGER;
UPDATE table_name SET torque_class = ROUND(((input_col - (SELECT MIN(input_col) FROM table_name)) / (( (SELECT MAX(input_col) FROM table_name) - (SELECT MIN(input_col) FROM table_name))) * 255))
import urllib2
import json
import csv
import pandas as pd
import numpy as np
import decimal
D = decimal.Decimal
url = "https://www.wework.com/locations/all"
data = urllib2.urlopen(url).read()
@nygeog
nygeog / classify-for-cartodb-torque-for-gradauted-symbols-w-pandas.py
Last active December 21, 2016 15:09
Classify for Cartodb Torque for Graduated Symbols with Pandas
df['col'] = ((((df['col']-df['col'].min()) / (df['col'].max() - df['col'].min()))*255).round()).astype(int)
@nygeog
nygeog / carto-html-file-template
Last active September 24, 2016 14:55
Carto JS html template
<!DOCTYPE html>
<html>
<head>
<title>Map Title</title>
<meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
<meta http-equiv="content-type" content="text/html; charset=UTF-8"/>
<link rel="shortcut icon" href="https://cartodb.com/assets/favicon.ico" />
<style>
html, body, #map {
height: 100%;
@nygeog
nygeog / sql-add-thousands-sep.sql
Created September 23, 2016 01:35
Add a column in CartoDB for creating thousands separator's in SQL
ALTER TABLE tablename ADD COLUMN new_col TEXT
UPDATE tablename SET new_col = to_char(old_col, '9,999,999')