Skip to content

Instantly share code, notes, and snippets.

@benizar
benizar / empirical_semivariogram.R
Created October 11, 2013 11:15
This code creates the empirical semivariograms for three aerial images showing agricultural parcels. Want more info? Visit our www.gisandchips.org blog (http://www.gisandchips.org/2010/01/28/extraccion-de-caracteristicas-estructurales-de-una-imagen-ii-semi-variograma-de-una-imagen-usando-r-2/#more-1303).
# Instalo los packages necesarios:
#-------------------------------------------------
install.packages("pixmap", dependencies= T)
install.packages("fields", dependencies= T)
# Cargo las librerias:
#-------------------------------------------------
library(pixmap)
@benizar
benizar / plr_histogram.sql
Created October 11, 2013 11:20
This code creates a pl/R function for creating histograms directly from a PostgreSQL database. Want more info? Visit our www.gisandchips.org blog (http://www.gisandchips.org/2009/09/24/integracion-de-r-en-postgresql-mi-primera-funcion-en-plr/#more-165).
CREATE OR REPLACE FUNCTION _plr_hist(text, text)
RETURNS text AS
$BODY$
select = 'select '
campo = arg1
from = ' from '
tabla = arg2
selection = paste(select, campo, from, tabla, sep='');
## Ejecutamos la consulta y la almacenamos en el objeto "sql";
<?xml version="1.0" encoding="UTF-8"?>
<POLIGONO Sup_ha="18,4355531115" code="R(25PSTpc_22UDS(45SNE_20VAP_15EDFva_15ZAU_03OCT_02LAA)_18LFNsc_15LFCrr_10CHLrr_10LVIsc)" Id="00b1b9be-caa0-44b0-9c39-389d24cd81df">
<COBERTURA Sup="100" Desc="Mosaico Regular" ID="R">
<COBERTURA Sup="25" Desc="Pastizal" ID="PST">
<ATRIBUTO Desc="procedencia de cultivos" ID="pc"/>
</COBERTURA>
<COBERTURA Sup="22" Desc="Discontinuo" ID="UDS">
<COBERTURA Sup="45" Desc="Suelo No Edificado" ID="SNE"/>
<COBERTURA Sup="20" Desc="Vial, Aparcamiento o Zona Peatonal sin Vegetación" ID="VAP"/>
<COBERTURA Sup="15" Desc="Edificación" ID="EDF">
SELECT *, true AS resid FROM usos5 WHERE usos5.id_2009 IN (SELECT id_2009 FROM usos5
WHERE (xpath('//COBERTURA[@ID="EDF" and @Sup>20]/@ID', xml_2009::xml))[1]::text='EDF'
OR (xpath('//COBERTURA[@ID="UCS" and @Sup>20]/@ID', xml_2009::xml))[1]::text='UCS'
OR (xpath('//COBERTURA[@ID="UEN" and @Sup>20]/@ID', xml_2009::xml))[1]::text='UEN'
OR (xpath('//COBERTURA[@ID="UDS" and @Sup>20]/@ID', xml_2009::xml))[1]::text='UDS'
OR (xpath('//COBERTURA[@ID="TCO" and @Sup>20]/@ID', xml_2009::xml))[1]::text='TCO'
OR (xpath('//COBERTURA[@ID="TCH" and @Sup>20]/@ID', xml_2009::xml))[1]::text='TCH')
UNION
SELECT *, false AS resid FROM usos5 WHERE usos5.id_2009 NOT IN (SELECT id_2009 FROM usos5
WHERE (xpath('//COBERTURA[@ID="EDF" and @Sup>20]/@ID', xml_2009::xml))[1]::text='EDF'
"""Calculate building floors from the Spanish Cadastre GIS files (SHP).
Once logged, data can be downloaded from https://www.sedecatastro.gob.es/
and the data specification is at
http://www.catastro.minhap.gob.es/ayuda/manual_descriptivo_shapefile.pdf
This python script is to be used in the QGIS 2.x field calculator.
The "CONSTRU" field stores volumetric data and other attributes in the form
of a structured text code. Floor numbers are in roman numerals.
As for example, "-II+IV+TZA" is a building part with two underground floors,
@benizar
benizar / post-install-ubuntu-16.04.sh
Last active October 9, 2020 14:30
Ubuntu post installation script for installing some basics
#!/bin/bash
apt-get update && apt-get install -y \
build-essential \
ppa-purge \
curl \
p7zip-full \
git \
make \
brasero \
@benizar
benizar / multiple-git-clone.md
Last active May 3, 2024 21:45
Ubuntu post-installation script for cloning multiple git repositories.

multiple-git-clone.sh

Every time I install Ubuntu on a different computer, I need to clone again the same git repositories. This is why I use this bash script.

Usage

It clones the list of repositories to a convenient working directory in the home folder. I use the /home/git folder.

Arguments are lists of git repositories. One repo per line, one file per list. See the example:

@benizar
benizar / multiple-git-pull.sh
Last active October 8, 2020 15:35
Update all git repositories under a base directory
#!/bin/bash
# Based on https://gist.github.com/douglas/1287372
# But with a couple of changes
# store the current dir
CUR_DIR=$(pwd)
# Let the person running the script know what's going on.
echo "Pulling in latest changes for all repositories..."
@benizar
benizar / airbnb.r
Created June 29, 2018 22:24 — forked from t-andrew-do/airbnb.r
AirBnB Scraping Script
library(stringr)
library(purrr)
library(rvest)
#------------------------------------------------------------------------------#
# Author: Andrew Do
# Purpose: A bunch of utility functions for the main ScrapeCityToPage The goal
# is to be able to scrape up to a specified page number for a given city and
# then to store that information as a data frame. The resulting data frame will
# be raw and will require additional cleaning, but the structure is more or less
@benizar
benizar / README.md
Last active February 14, 2022 18:48
Extract images and text from a list of PDF files

Execute providing a list of files

bash pdf-break-down.sh folder/*