Skip to content

Instantly share code, notes, and snippets.

# -*- coding: utf-8 -*-
"""
***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
@ghtmtt
ghtmtt / qgis_network_analysis.py
Created July 8, 2021 06:48
qgis_network_analysis
project = QgsProject.instance()
start_points = project.mapLayersByName('start_points')[0] # start
end_points = project.mapLayersByName('end_points')[0] # end
network = project.mapLayersByName('network')[0] # network
## from polyline to director
director = QgsVectorLayerDirector(
source=network,
# -*- coding: utf-8 -*-
"""
/***************************************************************************
DataPlotlyDialog
A QGIS plugin
D3 Plots for QGIS
-------------------
begin : 2020-08-17
git sha : $Format:%H$
copyright : (C) 2017 by matteo ghetta
import ee
from ee_plugin import Map
# Sentinel data
collection = ee.ImageCollection('COPERNICUS/S5P/OFFL/L3_NO2')
# Band of NO2
collection = collection.select('tropospheric_NO2_column_number_density')
# 2019 data
collection2019 = collection.filterDate('2019-03-01', '2019-04-30')
# -*- coding: utf-8 -*-
"""
***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
import pandas as pd
import plotly.express as px
df = pd.read_csv("https://gist.github.com/ghtmtt/66164cc25a7b160cef99fa61b2feca59/raw/3034facfdecf7358934d9f0a78341c4d13f2af47/covid-pandas.csv")
col = [col for col in df.columns if '20' in col]
dfm = pd.melt(
df,
id_vars=["Province/State", "Country/Region", "continent", "Lat", "Long"],
value_vars=col,
@ghtmtt
ghtmtt / covid-pandas.csv
Created April 15, 2020 05:49
covid-pandas.csv
We can make this file beautiful and searchable if this error is corrected: Unclosed quoted field in line 2.
Province/State,Country/Region,Lat,Long,1/22/20,1/23/20,1/24/20,1/25/20,1/26/20,1/27/20,1/28/20,1/29/20,1/30/20,1/31/20,2/1/20,2/2/20,2/3/20,2/4/20,2/5/20,2/6/20,2/7/20,2/8/20,2/9/20,2/10/20,2/11/20,2/12/20,2/13/20,2/14/20,2/15/20,2/16/20,2/17/20,2/18/20,2/19/20,2/20/20,2/21/20,2/22/20,2/23/20,2/24/20,2/25/20,2/26/20,2/27/20,2/28/20,2/29/20,3/1/20,3/2/20,3/3/20,3/4/20,3/5/20,3/6/20,3/7/20,3/8/20,3/9/20,3/10/20,3/11/20,3/12/20,3/13/20,3/14/20,3/15/20,3/16/20,3/17/20,3/18/20,3/19/20,3/20/20,3/21/20,3/22/20,3/23/20,3/24/20,3/25/20,3/26/20,3/27/20,3/28/20,3/29/20,3/30/20,3/31/20,4/1/20,4/2/20,4/3/20,4/4/20,4/5/20,4/6/20,4/7/20,4/8/20,4/9/20,4/10/20,4/11/20,4/12/20,4/13/20,continent
,Afghanistan,33,65,"0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","1","1","1","1","1","1","1","1","1","1","1","1","1","4","4","5","7","7","7","11","16","21","22","22","22","24","24","40","40","74","84","94","110","110","120","170","174","237","273","281
----------------------------------------
Compiled translation files to .qm files.
----------------------------------------
Processing: DataPlotly/i18n/DataPlotly_en.ts
Updating 'DataPlotly/i18n/DataPlotly_en.qm'...
Generated 0 translation(s) (0 finished and 0 unfinished)
Ignored 164 untranslated source text(s)
Processing: DataPlotly/i18n/DataPlotly_it.ts
Updating 'DataPlotly/i18n/DataPlotly_it.qm'...
@ghtmtt
ghtmtt / geocoding.py
Last active September 14, 2021 04:40
Geocoding in QGIS Field Calculator
# the function needs geopy
# for Windows users, to install geopy, open the OSGEO4W Shell and type:
# py3_env
# pip3 install geopy
from qgis.core import *
from qgis.gui import *
from geopy.geocoders import Nominatim
locator = Nominatim(user_agent="myGeocoder")
from plotly import graph_objs as go
a = [go.Scatter({
#'customdata': [so4],
'hoverinfo': 'all',
'ids': [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20,
21, 22, 23, 24, 25, 26, 27, 28, 29, 30],
'line': {'dash': 'solid', 'width': 1.0},
'marker': {'color': [203, 151, 350, 137, 319, 329, 267, 88, 98, 84, 100, 627, 306, 513, 267,
457, 683, 791, 788, 265, 296, 680, 536, 1122, 632, 1055, 1322, 1485,