Skip to content

Instantly share code, notes, and snippets.

View ragnarheidar's full-sized avatar

Ragnar Thrastarson ragnarheidar

View GitHub Profile
@ragnarheidar
ragnarheidar / ChangeCSVdelimiter.py
Last active July 8, 2021 17:59
A python script that reads a CSV file and writes it out with a different delimiter.
# -*- coding: utf-8 -*-
import csv
from tempfile import NamedTemporaryFile
import shutil
readfile = "SOME\\PATH\\input.csv"
writefile = "SOME\\PATH\\output.csv"
tempfile = NamedTemporaryFile(delete=False)
with open(readfile, 'rb') as csvfilein, tempfile:
@ragnarheidar
ragnarheidar / PlotWeatherStations.py
Last active October 1, 2017 08:36
Leaflet map created with folium and GeoJSON
"""
And example of a python code that uses the folium library to create a lightweight
leaflet web map. The example uses a GeoJSON file that is added to the map.
Folium documentation:
http://python-visualization.github.io/folium/docs-master/
How to add popups and cluster markers:
https://ocefpaf.github.io/python4oceanographers/blog/2015/12/14/geopandas_folium/
Leaflet maps from leaflet-providers:
https://leaflet-extras.github.io/leaflet-providers/preview/
@ragnarheidar
ragnarheidar / GetBottleTimeAndCoordinates.py
Created August 17, 2017 12:33
Python code to parse a KML file XML notation) and write data to a CSV table
import xml.etree.ElementTree as ET
from datetime import datetime
StartTime = datetime.now()
Tree = ET.parse('Bottles.kml')
root = Tree.getroot()
OutFileName = "Bottles.csv"
f = open(OutFileName, "w")
f.write('bottle_id, time, lat, lon' + '\n')
@ragnarheidar
ragnarheidar / Ask128.mp3
Last active June 15, 2017 21:08
Learn how to pronounce Icelandic Volcanos
@ragnarheidar
ragnarheidar / README.md
Last active June 14, 2017 08:37
Leaflet Map showing NYC 311 complaints on loud music in the Bronx

Leaflet map for a Geovisualization class at Lehman Collage/CUNY (GEP-660, Instructor: Gretchen Culp). Base map provided by Stamen and icons by Font Awesome.

@ragnarheidar
ragnarheidar / index.html
Last active October 6, 2016 14:03
A simple Leaflet map created with Python using the folium library
<!DOCTYPE html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/leaflet/0.7.3/leaflet.js"></script>
@ragnarheidar
ragnarheidar / README.md
Last active October 6, 2016 14:00
Earthquake map for Iceland
@ragnarheidar
ragnarheidar / IcelandicEarthquakes.py
Last active February 24, 2016 14:09
Python code that scrapes earthquake data and sends it to a CartoDB map
"""
Icelandic earthquakes in Iceland for the past 48 hours into CartoDB.
This script will:
1. Scrape earthquakes from the Iceland Met Office (past 48 hrs.)
2. Parse the resaults into a csv table and save it
3. Create a Python list from csv file
4. Use CartoDB SQL API to:
a) Truncate a table in CartoDB
b) Insert new records into the same table by wrapping Python list into SQL query
@ragnarheidar
ragnarheidar / FilenameAsAttribute.py
Last active February 10, 2016 09:07
A script that uses the arcpy site-package to read the filename of a feature class, create a field called Name and writes the filename as an attribute in the newly created field.
"""
A script that uses the arcpy site-package to read the filename
of a feature class, create a field called Name and wirites the
filename as an attribute in the newly create filed.
"""
import arcpy
from arcpy import env
arcpy.env.workspace = "SOME/PATH"
@ragnarheidar
ragnarheidar / PolygonToSAMOS_ArcGIS.py
Last active February 10, 2016 08:49
A python script tool that uses the ArcPy site-package to convert a polygon feature class to a specific text based output. Output includes parameters, number of vertices in each feature and X and Y coordinates of each vertex for each feature. The output is specific for the avalanche simulation software SAMOS.
# -*- coding: utf-8 -*-
""""
Tool Name: Starting Zones to SAMOS
Source Name: StartingZonesToSamos.py
Version: ArcGIS 10.3.1
Author: Icelandic Meteorology Office/Ragnar H. Thrastarson
Created: 2015-07-20
Description: A python script tool that uses the ArcPy site-package
to convert a polygon feature class to a specific text based
output. Output includes parameters, number of vertices in each