Skip to main content
Tweeted twitter.com/StackGIS/status/1539805443454910466
deleted 302 characters in body; edited tags
Source Link
Taras
  • 34k
  • 4
  • 73
  • 148

Selecting only 10000N records from layer using PyQGIS

from qgis.core import *
from qgis.utils import *
from qgis.analysis import QgsNativeAlgorithms
from PyQt5.QtCore import QVariant
from qgis.core import QgsApplication, QgsProcessingFeedback, QgsRasterLayer
import sys

sys.path.append('/usr/lib/qgis')
sys.path.append('/usr/share/qgis/python/plugins')
os.environ["QT_QPA_PLATFORM"] = "offscreen"

QgsApplication.setPrefixPath(r'/usr/bin/qgis', True)
qgs = QgsApplication([], False)
qgs.initQgis()

import processing
from processing.core.Processing import Processing

Processing.initialize()
QgsApplication.processingRegistry().addProvider(QgsNativeAlgorithms())
feedback = QgsProcessingFeedback()

processing.run("native:joinattributesbylocation", {'INPUT':r'/home/gis/budynki_opolskie/budynki_opolskie/bdot10k_bubd_a_opolskie.gpkg|layername=bubd_a',
                                                   'JOIN':r'/home/gis/adresypolska/PRG_PunktyAdresowe_POLSKA.shp',
                                                   'PREDICATE':[1,5],
                                                   'JOIN_FIELDS':['PNA','SIMC_id','SIMC_nazwa','ULIC_nazwa','Numer'],
                                                   'METHOD':0,
                                                   'DISCARD_NONMATCHING':True,
                                                   'PREFIX':'',
                                                   'OUTPUT':r'/home/gis/zlaczoneopolskie.shp'})
import sys
from qgis.core import *
from qgis.utils import *
from qgis.analysis import QgsNativeAlgorithms
from PyQt5.QtCore import QVariant
from qgis.core import QgsApplication, QgsProcessingFeedback, QgsRasterLayer

sys.path.append('/usr/lib/qgis')
sys.path.append('/usr/share/qgis/python/plugins')
os.environ["QT_QPA_PLATFORM"] = "offscreen"

QgsApplication.setPrefixPath(r'/usr/bin/qgis', True)
qgs = QgsApplication([], False)
qgs.initQgis()

import processing
from processing.core.Processing import Processing

Processing.initialize()
QgsApplication.processingRegistry().addProvider(QgsNativeAlgorithms())
feedback = QgsProcessingFeedback()

processing.run("native:joinattributesbylocation", {
                'INPUT': r'/home/gis/budynki_opolskie/budynki_opolskie/bdot10k_bubd_a_opolskie.gpkg|layername=bubd_a',
                'JOIN': r'/home/gis/adresypolska/PRG_PunktyAdresowe_POLSKA.shp',
                'PREDICATE': [1,5],
                'JOIN_FIELDS': ['PNA','SIMC_id','SIMC_nazwa','ULIC_nazwa','Numer'],
                'METHOD': 0,
                'DISCARD_NONMATCHING': True,
                'PREFIX': '',
                'OUTPUT': r'/home/gis/zlaczoneopolskie.shp'
                })

Selecting only 10000 records from layer using PyQGIS

from qgis.core import *
from qgis.utils import *
from qgis.analysis import QgsNativeAlgorithms
from PyQt5.QtCore import QVariant
from qgis.core import QgsApplication, QgsProcessingFeedback, QgsRasterLayer
import sys

sys.path.append('/usr/lib/qgis')
sys.path.append('/usr/share/qgis/python/plugins')
os.environ["QT_QPA_PLATFORM"] = "offscreen"

QgsApplication.setPrefixPath(r'/usr/bin/qgis', True)
qgs = QgsApplication([], False)
qgs.initQgis()

import processing
from processing.core.Processing import Processing

Processing.initialize()
QgsApplication.processingRegistry().addProvider(QgsNativeAlgorithms())
feedback = QgsProcessingFeedback()

processing.run("native:joinattributesbylocation", {'INPUT':r'/home/gis/budynki_opolskie/budynki_opolskie/bdot10k_bubd_a_opolskie.gpkg|layername=bubd_a',
                                                   'JOIN':r'/home/gis/adresypolska/PRG_PunktyAdresowe_POLSKA.shp',
                                                   'PREDICATE':[1,5],
                                                   'JOIN_FIELDS':['PNA','SIMC_id','SIMC_nazwa','ULIC_nazwa','Numer'],
                                                   'METHOD':0,
                                                   'DISCARD_NONMATCHING':True,
                                                   'PREFIX':'',
                                                   'OUTPUT':r'/home/gis/zlaczoneopolskie.shp'})

Selecting only N records from layer using PyQGIS

import sys
from qgis.core import *
from qgis.utils import *
from qgis.analysis import QgsNativeAlgorithms
from PyQt5.QtCore import QVariant
from qgis.core import QgsApplication, QgsProcessingFeedback, QgsRasterLayer

sys.path.append('/usr/lib/qgis')
sys.path.append('/usr/share/qgis/python/plugins')
os.environ["QT_QPA_PLATFORM"] = "offscreen"

QgsApplication.setPrefixPath(r'/usr/bin/qgis', True)
qgs = QgsApplication([], False)
qgs.initQgis()

import processing
from processing.core.Processing import Processing

Processing.initialize()
QgsApplication.processingRegistry().addProvider(QgsNativeAlgorithms())
feedback = QgsProcessingFeedback()

processing.run("native:joinattributesbylocation", {
                'INPUT': r'/home/gis/budynki_opolskie/budynki_opolskie/bdot10k_bubd_a_opolskie.gpkg|layername=bubd_a',
                'JOIN': r'/home/gis/adresypolska/PRG_PunktyAdresowe_POLSKA.shp',
                'PREDICATE': [1,5],
                'JOIN_FIELDS': ['PNA','SIMC_id','SIMC_nazwa','ULIC_nazwa','Numer'],
                'METHOD': 0,
                'DISCARD_NONMATCHING': True,
                'PREFIX': '',
                'OUTPUT': r'/home/gis/zlaczoneopolskie.shp'
                })
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
added 94 characters in body
Source Link

I would like to join attributes by location of 2 layers. My INPUT layer has 446k records and it is too many. I would like to divide my layer and select for example 10000 records.

For example in Python if I have a list I can select by data[:10000]. How can i do thatI select x records from layer?

My code:

from qgis.core import *
from qgis.utils import *
from qgis.analysis import QgsNativeAlgorithms
from PyQt5.QtCore import QVariant
from qgis.core import QgsApplication, QgsProcessingFeedback, QgsRasterLayer
import sys

sys.path.append('/usr/lib/qgis')
sys.path.append('/usr/share/qgis/python/plugins')
os.environ["QT_QPA_PLATFORM"] = "offscreen"

QgsApplication.setPrefixPath(r'/usr/bin/qgis', True)
qgs = QgsApplication([], False)
qgs.initQgis()

import processing
from processing.core.Processing import Processing

Processing.initialize()
QgsApplication.processingRegistry().addProvider(QgsNativeAlgorithms())
feedback = QgsProcessingFeedback()

processing.run("native:joinattributesbylocation", {'INPUT':r'/home/gis/budynki_opolskie/budynki_opolskie/bdot10k_bubd_a_opolskie.gpkg|layername=bubd_a',
                                                   'JOIN':r'/home/gis/adresypolska/PRG_PunktyAdresowe_POLSKA.shp',
                                                   'PREDICATE':[1,5],
                                                   'JOIN_FIELDS':['PNA','SIMC_id','SIMC_nazwa','ULIC_nazwa','Numer'],
                                                   'METHOD':0,
                                                   'DISCARD_NONMATCHING':True,
                                                   'PREFIX':'',
                                                   'OUTPUT':r'/home/gis/zlaczoneopolskie.shp'})

I would like to join attributes by location of 2 layers. My INPUT layer has 446k records and it is too many. I would like to divide my layer and select for example 10000 records.

How can i do that?

My code:

from qgis.core import *
from qgis.utils import *
from qgis.analysis import QgsNativeAlgorithms
from PyQt5.QtCore import QVariant
from qgis.core import QgsApplication, QgsProcessingFeedback, QgsRasterLayer
import sys

sys.path.append('/usr/lib/qgis')
sys.path.append('/usr/share/qgis/python/plugins')
os.environ["QT_QPA_PLATFORM"] = "offscreen"

QgsApplication.setPrefixPath(r'/usr/bin/qgis', True)
qgs = QgsApplication([], False)
qgs.initQgis()

import processing
from processing.core.Processing import Processing

Processing.initialize()
QgsApplication.processingRegistry().addProvider(QgsNativeAlgorithms())
feedback = QgsProcessingFeedback()

processing.run("native:joinattributesbylocation", {'INPUT':r'/home/gis/budynki_opolskie/budynki_opolskie/bdot10k_bubd_a_opolskie.gpkg|layername=bubd_a',
                                                   'JOIN':r'/home/gis/adresypolska/PRG_PunktyAdresowe_POLSKA.shp',
                                                   'PREDICATE':[1,5],
                                                   'JOIN_FIELDS':['PNA','SIMC_id','SIMC_nazwa','ULIC_nazwa','Numer'],
                                                   'METHOD':0,
                                                   'DISCARD_NONMATCHING':True,
                                                   'PREFIX':'',
                                                   'OUTPUT':r'/home/gis/zlaczoneopolskie.shp'})

I would like to join attributes by location of 2 layers. My INPUT layer has 446k records and it is too many. I would like to divide my layer and select for example 10000 records.

For example in Python if I have a list I can select by data[:10000]. How can I select x records from layer?

My code:

from qgis.core import *
from qgis.utils import *
from qgis.analysis import QgsNativeAlgorithms
from PyQt5.QtCore import QVariant
from qgis.core import QgsApplication, QgsProcessingFeedback, QgsRasterLayer
import sys

sys.path.append('/usr/lib/qgis')
sys.path.append('/usr/share/qgis/python/plugins')
os.environ["QT_QPA_PLATFORM"] = "offscreen"

QgsApplication.setPrefixPath(r'/usr/bin/qgis', True)
qgs = QgsApplication([], False)
qgs.initQgis()

import processing
from processing.core.Processing import Processing

Processing.initialize()
QgsApplication.processingRegistry().addProvider(QgsNativeAlgorithms())
feedback = QgsProcessingFeedback()

processing.run("native:joinattributesbylocation", {'INPUT':r'/home/gis/budynki_opolskie/budynki_opolskie/bdot10k_bubd_a_opolskie.gpkg|layername=bubd_a',
                                                   'JOIN':r'/home/gis/adresypolska/PRG_PunktyAdresowe_POLSKA.shp',
                                                   'PREDICATE':[1,5],
                                                   'JOIN_FIELDS':['PNA','SIMC_id','SIMC_nazwa','ULIC_nazwa','Numer'],
                                                   'METHOD':0,
                                                   'DISCARD_NONMATCHING':True,
                                                   'PREFIX':'',
                                                   'OUTPUT':r'/home/gis/zlaczoneopolskie.shp'})
added 4 characters in body; edited tags; edited title
Source Link
PolyGeo
  • 65.4k
  • 29
  • 114
  • 345

PyQGIS: How to select Selecting only 10000 records from layer? using PyQGIS

I would like to join attributes by location of 2 layers. My INPUT layer has 446k records and it is too many. I would like to divide my layer and select for example 10000 records. 

How can i do that? 

My code:

from qgis.core import *
from qgis.utils import *
from qgis.analysis import QgsNativeAlgorithms
from PyQt5.QtCore import QVariant
from qgis.core import QgsApplication, QgsProcessingFeedback, QgsRasterLayer
import sys

sys.path.append('/usr/lib/qgis')
sys.path.append('/usr/share/qgis/python/plugins')
os.environ["QT_QPA_PLATFORM"] = "offscreen"

QgsApplication.setPrefixPath(r'/usr/bin/qgis', True)
qgs = QgsApplication([], False)
qgs.initQgis()

import processing
from processing.core.Processing import Processing

Processing.initialize()
QgsApplication.processingRegistry().addProvider(QgsNativeAlgorithms())
feedback = QgsProcessingFeedback()

processing.run("native:joinattributesbylocation", {'INPUT':r'/home/gis/budynki_opolskie/budynki_opolskie/bdot10k_bubd_a_opolskie.gpkg|layername=bubd_a',
                                                   'JOIN':r'/home/gis/adresypolska/PRG_PunktyAdresowe_POLSKA.shp',
                                                   'PREDICATE':[1,5],
                                                   'JOIN_FIELDS':['PNA','SIMC_id','SIMC_nazwa','ULIC_nazwa','Numer'],
                                                   'METHOD':0,
                                                   'DISCARD_NONMATCHING':True,
                                                   'PREFIX':'',
                                                   'OUTPUT':r'/home/gis/zlaczoneopolskie.shp'})

PyQGIS: How to select only 10000 records from layer?

I would like to join attributes by location of 2 layers. My INPUT layer has 446k records and it is too many. I would like to divide my layer and select for example 10000 records. How can i do that? My code:

from qgis.core import *
from qgis.utils import *
from qgis.analysis import QgsNativeAlgorithms
from PyQt5.QtCore import QVariant
from qgis.core import QgsApplication, QgsProcessingFeedback, QgsRasterLayer
import sys

sys.path.append('/usr/lib/qgis')
sys.path.append('/usr/share/qgis/python/plugins')
os.environ["QT_QPA_PLATFORM"] = "offscreen"

QgsApplication.setPrefixPath(r'/usr/bin/qgis', True)
qgs = QgsApplication([], False)
qgs.initQgis()

import processing
from processing.core.Processing import Processing

Processing.initialize()
QgsApplication.processingRegistry().addProvider(QgsNativeAlgorithms())
feedback = QgsProcessingFeedback()

processing.run("native:joinattributesbylocation", {'INPUT':r'/home/gis/budynki_opolskie/budynki_opolskie/bdot10k_bubd_a_opolskie.gpkg|layername=bubd_a',
                                                   'JOIN':r'/home/gis/adresypolska/PRG_PunktyAdresowe_POLSKA.shp',
                                                   'PREDICATE':[1,5],
                                                   'JOIN_FIELDS':['PNA','SIMC_id','SIMC_nazwa','ULIC_nazwa','Numer'],
                                                   'METHOD':0,
                                                   'DISCARD_NONMATCHING':True,
                                                   'PREFIX':'',
                                                   'OUTPUT':r'/home/gis/zlaczoneopolskie.shp'})

Selecting only 10000 records from layer using PyQGIS

I would like to join attributes by location of 2 layers. My INPUT layer has 446k records and it is too many. I would like to divide my layer and select for example 10000 records. 

How can i do that? 

My code:

from qgis.core import *
from qgis.utils import *
from qgis.analysis import QgsNativeAlgorithms
from PyQt5.QtCore import QVariant
from qgis.core import QgsApplication, QgsProcessingFeedback, QgsRasterLayer
import sys

sys.path.append('/usr/lib/qgis')
sys.path.append('/usr/share/qgis/python/plugins')
os.environ["QT_QPA_PLATFORM"] = "offscreen"

QgsApplication.setPrefixPath(r'/usr/bin/qgis', True)
qgs = QgsApplication([], False)
qgs.initQgis()

import processing
from processing.core.Processing import Processing

Processing.initialize()
QgsApplication.processingRegistry().addProvider(QgsNativeAlgorithms())
feedback = QgsProcessingFeedback()

processing.run("native:joinattributesbylocation", {'INPUT':r'/home/gis/budynki_opolskie/budynki_opolskie/bdot10k_bubd_a_opolskie.gpkg|layername=bubd_a',
                                                   'JOIN':r'/home/gis/adresypolska/PRG_PunktyAdresowe_POLSKA.shp',
                                                   'PREDICATE':[1,5],
                                                   'JOIN_FIELDS':['PNA','SIMC_id','SIMC_nazwa','ULIC_nazwa','Numer'],
                                                   'METHOD':0,
                                                   'DISCARD_NONMATCHING':True,
                                                   'PREFIX':'',
                                                   'OUTPUT':r'/home/gis/zlaczoneopolskie.shp'})
Source Link
Loading