Skip to content

Instantly share code, notes, and snippets.

View datagistips's full-sized avatar

mathieu rajerison datagistips

View GitHub Profile
@datagistips
datagistips / Sloppy gradient colored lines
Last active February 18, 2021 17:56
Color gradient lines based on their slopes
-- NOTE :
-- This gist has two separate parts : one for the geometry generator, one for the filling color
-- inputs : lines, slope raster
-- STEP 1/2 - On geometry generator, set this expression to have interpolated points :
collect_geometries(
array_foreach(
generate_series(0, length($geometry), 5), -- we add lines every 5 meters
line_interpolate_point($geometry, @element)
Use symbology > centroid > geometry generator
# Main spikes :
with_variable(
'coords',
array(x(centroid($geometry)),y(centroid($geometry))),
make_triangle(
make_point(@coords[0] - 8000,
@coords[1]),
@datagistips
datagistips / print_layout_extents_to_map_for_processing.py
Last active February 27, 2020 11:01
Processing python code to get the print layout extents as a layer in qgis map
# -*- coding: utf-8 -*-
from PyQt5.QtCore import QCoreApplication, QVariant
from qgis.core import (QgsVectorLayer, QgsFields, QgsField, QgsProject,QgsLayoutItemMap,QgsFeature,QgsGeometry,QgsCoordinateReferenceSystem,
QgsProcessing,
QgsFeatureSink,
QgsProcessingAlgorithm,
QgsProcessingParameterFeatureSource,
QgsProcessingParameterFeatureSink)
@datagistips
datagistips / print_layout_extents_to_map.py
Last active February 16, 2019 11:26
Python code to get print layout extents as a layer in qgis map
def getCompositionExtents(crsCode=2154) :
# layer
vl = QgsVectorLayer("Polygon?crs=EPSG:%s"%(crsCode), "Extent Polygons", "memory")
# defining CRS
crs = vl.crs()
crs.createFromId(crsCode)
vl.setCrs(crs)
library(rgdal)
library(maptools)
library(spdep)
library(bezier)
library(rgeos)
bati = readOGR("D:/DATAS/APUR", "EMPRISE_BATIE")
coords.total = coordinates(bati)
creerGrille = function(pol, size=50000) {
r = raster(extend(extent(pol), size)); res(r) = size; r[]=1
grille = rasterToPolygons(r)
grille = grille[which(gIntersects(grille, pol, byid=T)), ]
grille = grille[-which(gTouches(grille, reg, byid=T)), ]
return(grille)
}
extractFrequencies = function(grille, r, values) {
# code used for the following map : http://datagistips.blogspot.fr/
library(raster)
library(rgdal)
library(rgeos)
clc = raster("DATAS/CLC12_RIDF_RGF.tif") # here is the 200m Corine Land Cover GeoTiff
reg = readOGR("DATAS", "idf_geofla") # ile de france GéoFla Departments
# RECLASS
library(rgdal)
library(spatstat)
library(maptools)
library(raster)
f <- readOGR("IN_NYC/sample_nyc.shp", "sample_nyc")
# CREATE SEGMENTS
segmts <- as.psp(as(f, "SpatialLines")) # coercing SpatialLines objects to psp Line Segment Pattern objects splits polylines to lines
library(RCurl)
library(rjson)
whatGoogleSuggestsFor <- function(question, domain="fr") {
# Domain : here, just France or USA
# You could add URLs for some other countries
if (domain == "fr") {
baseU <- "https://www.google.fr/s?gs_rn=45&sclient=psy-ab"
} else {
library(XML)
library(RCurl)
library(rgdal)
source("DORLING.R")
# GEOGLA DEPARTEMENTS
deps <- readOGR(".", "DEPARTEMENT.shp")
# LIST URLS