Skip to content

Instantly share code, notes, and snippets.

from osgeo import ogr
# Open shapefile and count features
source = ogr.Open('building-means.shp', update=True)
layer = source.GetLayer()
features_count = layer.GetFeatureCount()
# Create new field
new_field = ogr.FieldDefn('mean_rnd', ogr.OFTReal) # Define new floating-point field
{"nodes":[{"name":"US"},{"name":"JP"},{"name":"DE"},{"name":"GB"},{"name":"FR"},{"name":"IT"},{"name":"CA"},{"name":"G7"},{"name":"CN"},{"name":"HK"},{"name":"MY"},{"name":"VN"},{"name":"IN"},{"name":"TW"},{"name":"ID"},{"name":"TR"},{"name":"TH"},{"name":"Asia Other"},{"name":"NL"},{"name":"Europe Other"},{"name":"Americas Other"},{"name":"Africa Other"},{"name":"Oceania Other"}],"links":[{"source":"CA","target":"Africa Other","value_h1_17":113.932,"value_h1_18":48.166},{"source":"CA","target":"Americas Other","value_h1_17":55.823,"value_h1_18":39.946},{"source":"CA","target":"Asia Other","value_h1_17":176.256,"value_h1_18":1266.557},{"source":"CA","target":"CN","value_h1_17":20398.059,"value_h1_18":874.396},{"source":"CA","target":"Europe Other","value_h1_17":540.634,"value_h1_18":258.634},{"source":"CA","target":"G7","value_h1_17":56895.946,"value_h1_18":57902.149},{"source":"CA","target":"HK","value_h1_17":17859.425,"value_h1_18":2566.798},{"source":"CA","target":"ID","value_h1_17":null,"value_h1_18":346.

Keybase proof

I hereby claim:

  • I am davidbjourno on github.
  • I am davidcblood (https://keybase.io/davidcblood) on keybase.
  • I have a public key ASCPqRS7wa5cMJ2azRpOL_K3y9ol3xK2Hql06eCzm58T-go

To claim this, I am signing this object:

@davidbjourno
davidbjourno / batch-ocr-pdfs.md
Last active March 9, 2022 16:08
Batch OCR PDFs

Batch OCR PDFs

In PDFs directory:

  1. Replace additional . in filenames with _: zmv '(*.*)(.*)' '${1//./_}$2
  2. mkdir jpg && mkdir txt
  3. mogrify -format jpg -density 200 -quality 100 -alpha off -path jpg/ -verbose *.pdf
  4. for file in jpg/*.jpg; do tesseract $file ${file%%.*}; done
  5. mv jpg/*.txt txt/
@davidbjourno
davidbjourno / spec.json
Last active August 18, 2022 16:11
Vega-Lite spec from Wed Aug 17 2022
{
"config": {"view": {"continuousWidth": 400, "continuousHeight": 300}},
"layer": [
{
"data": {"name": "data-1a9dea4ba8b8849e4235562cc245ac37"},
"mark": {"type": "rect", "opacity": 0.5},
"encoding": {
"color": {
"field": "ann_diff",
"legend": {"direction": "horizontal"},