Skip to content

Instantly share code, notes, and snippets.

View keum's full-sized avatar

Peter Keum keum

  • King County - Wastewater Treatment Division
  • Seattle, WA
  • 17:39 (UTC -08:00)
View GitHub Profile
@keum
keum / list_comprehension from mattmakesmap
Last active December 23, 2015 01:49
Python - list comprehension and string formatting procedure to take a list and add specific string to all the list.
"""
Question One:
Why does the join method not add ".cso" to "king"
"""
a=('seattle','chelan','king')
print ".cso ".join(a) # returns "seattle.cso chelan.cso king"
"""
Answer:
@keum
keum / Import CSV file from URL
Last active July 5, 2019 18:46
Python Code using CSV & urllib for import csv STEP 1.
#Import CSV file from URL that has latest CSO status with location names and status
#This script only displays on the screen. Need to create list data into a file format.
#STEP 1
import csv
import urllib
#URL address that contains cso status with location name. This includes king county and SPU's data
url = "http://your.kingcounty.gov/dnrp/library/wastewater/cso/img/CSO.CSV"
webpage = urllib.urlopen(url)
@keum
keum / CSV to JSON format in python
Last active December 23, 2015 07:59
Python example on converting CSV into JSON format
This example came from Tom MacWright
Python standard library (plus simplejson for decimal encoding support) has all you need:
import csv, simplejson, decimal, codecs
data = open("in.csv")
reader = csv.DictReader(data, delimiter=",", quotechar='"')
with codecs.open("out.json", "w", encoding="utf-8") as out:
@keum
keum / sys.argv
Created September 18, 2013 04:40
Explains sys.argv
sys.argv is a list in Python, which contains the command-line arguments passed to the script.
With the len(sys.argv) function you can count the number of arguments.
If you are gonna work with command line arguments, you probably want to
use sys.argv.
To use sys.argv, you will first have to import the sys module.
@keum
keum / List combine
Created September 18, 2013 18:13
Question: How to combine two list into one?
#How to combine two separate list below into a one list?
#Have dictionary data within list
a = [{'A':23},{'B':50}]
b = [{'A':50},{'B':100},{'C':150}]
#Result i need
@keum
keum / Basic Git usage
Last active December 24, 2015 10:09
Command line git usage
Using GitHub
1.Sign up for Github - make yourself an account with a cool name!
2. Start - from your GitHub account, create a new repositiories by clicking Tab then click "New" green button. Or you can "fork" (dirty sounding, isn't it?) from someone elses page. This is like making your own copy. Under this Repository, you can create multiple files by clicking plus button next to your repository(folder) name.
3. Give a name that will becomes your repository(repo), equalvent to "directory folder in explorer".
4. After creating account and repository, you need to download actual git in your local machine or you can start with the link.
1. Install Anaconda to get your python 2.7.
2. Install .Net Framework - dotNetFx45_Full_setup.exe
3. Uninstall the Microsoft Visual C++ 2010 instances.
4. Install the Microsoft SDK - winsdk_web.exe #http://www.microsoft.com/en-us/download/details.aspx?id=8279
5. Install Node.js - http://nodejs.org/download/
6. Open your command prompt as an administrator
>Start
>"cmd" in Search for All Programs
>Ctrl-RightClick on CMD and "Run as Administrator"
7. Set your environment for the SDK (this was tricky to figure out!)
@keum
keum / Difference between EPSG 4326 & 3857
Last active September 8, 2023 18:26
EPSG 4326 and EPSG 3857 of Web Mercator
EPSG: 4326 uses a coordinate system on the surface of a sphere or ellipsoid of reference.
WGS 84 - Earth as Geoid. -Mercator
EPSG: 3857 uses a coordinate system PROJECTED from the surface of the
sphere. Earth as perfectly sphere. -Web Mercator
Think of it as this way:
EPSG 4326 uses a coordinate system the same as a GLOBE (curved surface).
EPSG 3857 uses a coordinate system the same as a MAP (flat surface).
@keum
keum / How to: shape2geojson
Last active November 26, 2018 22:49
How to: Converting Shape file into geojson format
WORK FLOW:Convert Shape files into GeoJSON using GDAl library
Two step process.
Step 1.Convert Data in WGS 84 projection --> 2. Convert shp into Geojson using ogr2ogr
STEP 1. Make sure your data is in EPSG 4326 (Geographic projection WGS 84) is NOT Web Mercator projection
(most commonly used projection that can be use to post onto GitHub page is web mercator is EPSG:3857).
Before geoJSON conversion, make sure data isn't in WGS 84 projection already by checking for projection meta using ogrinfo command.
Convert WA State Plane EPSG 2926 to WGS 84 - EPSG 4326 (Geographic Projection WGS 84)
--Use ogrinfo to check the projection of data, example : sewer.shp
@keum
keum / Data portal_geojson
Last active December 31, 2015 03:59
Reason and usability of converting data into geojson format
But the focus has been desktop users, not addressing the shift towards web maps and people
using it in “non-conventional” ways. But my belief is cost to build the data is
returned when users actually start using it, so let’s look to ALL the users.
Reason for geojson:
Aaron:
it is plain text (not binary like shapefile
json is a native format that is easily consumable by Javascript... which is more and more popular