Skip to content

Instantly share code, notes, and snippets.

@eliascotto
eliascotto / MathExpression.py
Last active April 8, 2021 06:35
Simple math parser for expressions evaluation in Python 3. Also includes a command line interface for use as a calculator.
'''
-> CONTEXT-FREE GRAMMAR <-
expr --> expr PLUS term | expr MINUS term | term
term --> term TIMES factor | term DIVIDE factor | factor
factor --> exponent POW factor | exponent
exponent --> MINUS exponent | final
final --> DIGIT | ( expr )
'''
@jqtrde
jqtrde / modern-geospatial-python.md
Last active August 1, 2023 14:50
Modern remote sensing image processing with Python
@lptorres
lptorres / multi2single_inplace.py
Last active September 14, 2021 06:16
This script is similar to multi2single.py, but it converts the shapefile in place, instead of creating a new shapefile.
from osgeo import gdal, ogr
import sys
def multipoly2poly(layer):
for feature in layer:
fid = feature.GetFID()
geom = feature.GetGeometryRef()
if geom.GetGeometryName() == 'MULTIPOLYGON':
@lptorres
lptorres / multi2single.py
Created December 4, 2013 01:55
A simple script that converts shapefiles with multipart polygons into singlepart polygons, and copies the fields of the source shapefile. This script is based on a script by Paolo Corti, found here: https://gist.github.com/anonymous/735330 The original script only converts multipolygons by creating a new feature for each part of a multipolygon. …
import os
from osgeo import gdal, ogr, osr
import sys
def initFields(in_lyr, out_lyr):
#Arbitrarily get the first feature
feat = in_lyr[0]
#loop over each field
@eskriett
eskriett / GoogleMapDownloader.py
Last active June 1, 2025 13:22
A python script to download high resolution Google map images given a longitude, latitude and zoom level.
#!/usr/bin/python
# GoogleMapDownloader.py
# Created by Hayden Eskriett [http://eskriett.com]
#
# A script which when given a longitude, latitude and zoom level downloads a
# high resolution google map
# Find the associated blog post at: http://blog.eskriett.com/2013/07/19/downloading-google-maps/
import urllib
import Image