This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from datetime import datetime | |
# https://register.geonorge.no/data/documents/sosi-standard-del-1-generell-del_Realisering%20i%20SOSI-format%20og%20GML_v1_del1-2-realiseringsosigml-4_0_.pdf | |
# De følgende parameterene må kunne settes utenifra | |
dataeier = 'NORSAR' | |
dataprodusent = 'NORSAR' | |
oppdateringsdato = '20240815' | |
objtype = 'Kabelgrøft' | |
objektkatalog = '' | |
datauttaksdato = datetime.now().strftime("%Y%m%d%H%M%S") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# From a layer with a timestamp as an epoch number, | |
# adds in fields for year, day of year and decimal hour if they do not exist yet | |
# goes through the dataset, calculate the year, doy and hour and populates the fields | |
import datetime | |
epochfield = 'acqtime' | |
layer = qgis.utils.iface.activeLayer() | |
if layer.dataProvider().fieldNameIndex(epochfield) == -1: | |
# Do not want to do anything on a layer without an epoch field | |
print(f'Data layer does not have an "{epochfield}" field') | |
else: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python3 | |
""" | |
This script reads the nagios status.dat file and exports it as a csv-file | |
the output can be read directly by postgresql file_fdw foreign data wrapper. | |
To set this up, make sure fdw_file is ready to use and define the following table: | |
create foreign table nagiosstatus( | |
statustype text, | |
hostname text, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys | |
from html.parser import HTMLParser | |
"""Download the specific lists from https://www.johnstonsarchive.net/nuclear/tests/index.html. | |
Save them with the same file name as the header (e.g. | |
"Database of nuclear tests, United States: part 1, 1945-1963") | |
run the script with the filename as argument and it will make a tab delimited text file.""" | |
filename=sys.argv[1] | |
outfile = filename+'.dat' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def rendercats(searchstring): | |
layer = iface.activeLayer() | |
renderer = layer.renderer() | |
categories = renderer.categories() | |
new_renderer = QgsCategorizedSymbolRenderer(attrName=renderer.classAttribute()) | |
for cat in categories: | |
value = cat.value() | |
if value is None: | |
cat.setRenderState(False) | |
else: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python3 | |
""" | |
Data are downloaded hourly from api.met.no using | |
/usr/bin/curl -s -A "<email>" "https://api.met.no/weatherapi/locationforecast/2.0/complete?lat=59&lon=10" > /var/www/html/homelog2/weather.json 2>/dev/null | |
check https://api.met.no/ for terms and usage | |
After being downloaded, the data are available on a local http-server. The reason I am not reading the file directly in | |
this script is that I am also using it for other purposes that need the http | |
schema for table: https://gist.github.com/sickel/9ae88a47f665c0962120078ed93e103a |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
create table forecast( | |
parameter varchar not null, | |
value numeric not null, | |
unit varchar, | |
timestamp timestamp not null); | |
alter table forecast add primary key(parameter,timestamp); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def measureline(search,reverse=False,offset=0): | |
""" | |
To be run in the QGIS python console. Select a line, run measureline(<search>) and it will put a marker at the point | |
<search> mapunits along the line from the start of the line and print out the lat,lon of the point. | |
By either setting a negative search length or setting reverse to True, it will measure from the end of the line instead. | |
A number given as <offset> will be subtracted from <search>. If an offset is given, search should be a positive value. | |
Developed in QGIS 3.20, will probably run in other 3.X version, will probably not work in QGIS 2.X | |
""" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python3 | |
"""Reads lightning data from frost.met.no. Inserts all points and auxilliary data into a PostGIS database. After allt | |
the points are inserted, uncertainty ellipses are calculated for each point and stored in the same record. In QGIS it is | |
then possible to use a calculated geometry for either the point or the ellipse""" | |
# Using format strings, so needs python >= 3.6 | |
# If this file is stored in a version control system, rewrite the next two lines to | |
# read clientid and connection parameters from a file that is not checked in in the VCS | |
client_id="FROSTCLIENTID" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python3 | |
from openpyxl import load_workbook | |
import sys | |
filenames=[] | |
for i in range(1,len(sys.argv)): | |
print(sys.argv[i]) | |
filenames.append(sys.argv[i]) | |
NewerOlder