ImportEpanetInpFiles #QGIS

Older Videos:

QGIS Open Day – QHF March 2021

Join in on the QGIS INTEGRATED open day. Our amazing lineup of presenters will show you how QGIS can work in a network with other software and programs to create dynamic and sharable spatial data, maps, and systems.

If you would like to discuss topics on our QGISOpenDay, please add sections below for each discussion along with the proposed time and agenda.

Simply join the meeting on Jitsi and say hi! https://meet.jit.si/QGISOpenDay

To keep up to date with QGIS Open Day events, please join the Telegram channel

Programme overview:

Virtual events will be taking place online (see links below) and in the telegram chat room, and with many events also being live-streamed on YouTube. See the individual event descriptions below for an indication of where to join each event.

QGISOpenDay 26th March 2021

No Name Time Coordinator Language
1 Input and Mergin: collect data, sync, and collaborate with ease 08h00 UTC Saber Razmjooei English
2 Using QGIS, Input, Mergin, and Metabase to map the Waterberg 09h00 UTC Gavin Fleming English
3 Using QGIS and a laser cutter to make 3D contour models 10h30 UTC Raymond Nijssen English
4 Seamless fieldwork with QField & QFieldCloud 12h00 UTC Marco Bernasocchi English

Using basemaps with QGIS temporal controller

QGIS 3.14

Old version:

for i, layer in enumerate(QgsProject.instance().mapLayers().values()):
    if isinstance(layer, QgsRasterLayer):
        mode = QgsRasterLayerTemporalProperties.ModeFixedTemporalRange
        tprops = layer.temporalProperties()
        tprops.setFixedTemporalRange(QgsDateTimeRange(QDateTime(QDate(2020, 1, 1), QTime(1, i, 0, 0), Qt.UTC),
                                                   QDateTime(QDate(2020, 1, 1), QTime(1, 1+i, 0, 0), Qt.UTC)))

        tprops.setMode(mode)
        tprops.setIsActive(True)
https://github.com/Mariosmsk/qgis-python

Example code: layer.setSubsetString(“‘4′ LIKE “dist_code””’)

# Show every province features (postcodes) one by one

from time import sleep

def stopped(task):
    pass
def completed(exception, result=None):
    pass
def run(task, wait_time):

    # main code
    postcodes = QgsProject.instance().mapLayersByName('postcodes')[0]
    wait_time = wait_time / 100
    prov = [1, 3, 4, 5, 6]
    for i, m in enumerate(prov):
        task.setProgress(i)
        sleep(wait_time)
        postcodes.setSubsetString("'" + str(m) + "'" + ''' LIKE "dist_code"''')

        if task.isCanceled():
            stopped(task)
            return None
    postcodes.setSubsetString("")

task = QgsTask.fromFunction(u'Task', run,
                            on_finished=completed, wait_time=150)
QgsApplication.taskManager().addTask(task)

Or by right click on layer and go to Source and Query Builder:

Filter features on a layer #QGIS #PyQGIS

Year, Winner
1956, Switzerland
1957, Netherlands
1958, France
1959, Netherlands
1960, France
1961, Luxembourg
1962, France
1963, Denmark
1964, Italy
1965, Luxembourg
1966, Austria
1967, United Kingdom
1968, Spain
1969, Spain
1970, Ireland
1971, Monaco
1972, Luxembourg
1973, Luxembourg
1974, Sweden
1975, Netherlands
1976, United Kingdom
1977, France
1978, Israel
1979, Israel
1980, Ireland
1981, United Kingdom
1982, Germany
1983, Luxembourg
1984, Sweden
1985, Norway
1986, Belgium
1987, Ireland
1988, Switzerland
1989, Yugoslavia
1990, Italy
1991, Sweden
1992, Ireland
1993, Ireland
1994, Ireland
1995, Norway
1996, Ireland
1997, United Kingdom
1998, Israel
1999, Sweden
2000, Denmark
2001, Estonia
2002, Latvia
2003, Turkey
2004, Ukraine
2005, Greece
2006, Finland
2007, Serbia
2008, Russia
2009, Norway
2010, Germany
2011, Azerbaijan
2012, Sweden
2013, Denmark
2014, Austria
2015, Sweden
2016, Ukraine
2017, Portugal
2018, Israel
2019, Netherlands

Example: HERE

Eurovision Winners 1956 – 2019 #QGIS #Maps #Eurovision

Sample code:

from time import sleep
def stopped(task):
	QgsMessageLog.logMessage(
		'Task "{name}" was canceled'.format(
			name=task.description()),
		'task', Qgis.Info)

def completed(exception, result=None):

    buildings=result['buildings']
    finalFeature=result['finalFeature']
    buildings.startEditing()

    for i, featBuilds in enumerate(finalFeature):
        buildings.updateFeature(featBuilds) 
    buildings.commitChanges()
    
def run(task, wait_time):
    QgsMessageLog.logMessage('Started task {}'.format(task.description()),
                                 'Add post code on buildings', Qgis.Info)

    postcodes = QgsProject.instance().mapLayersByName('ex_postCodes')[0]
    buildings = QgsProject.instance().mapLayersByName('ex_buildings')[0]

    fields = []
    [fields.append(f.name()) for f in buildings.fields()]
    newfield = 'post_code'
    if newfield not in fields:
        postcode_field = QgsField(newfield, QVariant.Int)
        prov = buildings.dataProvider()
        prov.addAttributes([postcode_field])
        buildings.updateFields()

    wait_time = wait_time / 100

    # Create a column for post codes in buildings
    total_features = buildings.featureCount() + postcodes.featureCount()
    prc = 0

    new_postcode_index = buildings.fields().indexFromName(newfield)
    finalFeature = []
    for i, featBuilds in enumerate(buildings.selectedFeatures()):
        task.setProgress((prc/total_features)*100)
        #sleep(wait_time)
        overlapping = []
        check_IF_write_value = False
        for featPostc in postcodes.getFeatures():
            prc += 1
            num_post_code = featPostc.attribute(featPostc.fieldNameIndex(newfield))
            if featBuilds.geometry().within(featPostc.geometry()):
                featBuilds['post_code'] = num_post_code
                finalFeature.append(featBuilds)
                check_IF_write_value = True
            else:
                areaA = featBuilds.geometry().intersection(featPostc.geometry()).area()
                areaB = featBuilds.geometry().area()
                overlapping.append([(areaA/areaB)*100, num_post_code])
            if not check_IF_write_value:
                featBuilds.setAttribute(new_postcode_index, max(overlapping)[1])
                featBuilds['post_code'] = max(overlapping)[1]
                finalFeature.append(featBuilds)
        if task.isCanceled():
            stopped(task)
            return None
    return {'finalFeature': finalFeature, 'buildings': buildings,
            'task': task}

task = QgsTask.fromFunction(u'Task', run,
					on_finished=completed, wait_time=4)
QgsApplication.taskManager().addTask(task)

How to add postcode layer to selected buildings layer #QGIS