Skip to content

Instantly share code, notes, and snippets.

View gist:b719344c6170ea2504a7
In [1]: from plotly.offline import download_plotlyjs, init_notebook_mode, iplot
In [2]: init_notebook_mode()
<IPython.core.display.HTML object>
In [3]: iplot([{"x": [1, 2, 3], "y": [3, 1, 6]}])
<IPython.core.display.HTML object>
<IPython.core.display.HTML object>
View viewshed.py
# -*- coding: utf-8 -*-
from PyQt5.QtCore import QCoreApplication, QVariant
from qgis.core import (QgsProcessing,
QgsFeatureSink,
QgsField,
QgsFields,
QgsProcessingUtils,
QgsProcessingException,
QgsProcessingAlgorithm,
@ghtmtt
ghtmtt / geocoding.py
Last active Sep 14, 2021
Geocoding in QGIS Field Calculator
View geocoding.py
# 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")
View qgis_network_analysis.py
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,
View layer_to_df.py
# -*- 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
View gee_qgis.py
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')
View pandas_melt.py
# -*- 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. *
* *
View example.py
# -*- coding: utf-8 -*-
from PyQt5.QtCore import QCoreApplication
from qgis.core import (QgsProcessing,
QgsFeatureSink,
QgsProcessingAlgorithm,
QgsProcessingParameterFeatureSource,
QgsProcessingParameterFeatureSink)
import processing
View covid-pandas.py
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,
View 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