﻿{"id":6243,"date":"2018-09-05T04:30:37","date_gmt":"2018-09-05T02:30:37","guid":{"rendered":"http:\/\/www.sigterritoires.fr\/?p=6243"},"modified":"2018-10-17T12:04:15","modified_gmt":"2018-10-17T10:04:15","slug":"python-methods-for-qgis-how-to-examine-vector-data","status":"publish","type":"post","link":"https:\/\/www.sigterritoires.fr\/index.php\/en\/python-methods-for-qgis-how-to-examine-vector-data\/","title":{"rendered":"Python Methods for QGis: how to examine vector data"},"content":{"rendered":"\r\n\r\n\r\n<p>Once a layer is loaded, usually we want to access the data included in the layer, whether the geometries or the attributes. Now, we will discuss how to code in Python the access to these two types of data.<!--more--><\/p>\r\n\r\n\r\n\r\n<h2><strong>How to access<\/strong> <strong>the<\/strong> <strong>geometry<\/strong><strong> of<\/strong> <strong>a<\/strong> <strong>vector layer<\/strong><\/h2>\r\n\r\n\r\n\r\n<p>We will resume the loading of a <a href=\"https:\/\/www.sigterritoires.fr\/index.php\/en\/shapefile-vs-geopackage\/\">shapefile<\/a> script previously created (load_vector.py)<\/p>\r\n\r\n\r\n\r\n<p>&nbsp;<\/p>\r\n\r\n\r\n\r\n\r\n\r\n<p>\u00a0\u00bb \u00a0\u00a0 \u00a0\u00bb \u00a0 \u00bbYour description of the script goes here\u00ab \u00a0\u00a0 \u00a0\u00bb \u00a0 \u00ab\u00a0<\/p>\r\n\r\n\r\n\r\n<p># Some commonly used imports<\/p>\r\n\r\n\r\n\r\n<p>from PyQt4.QtCore import * <br \/>from PyQt4.QtGui import * <br \/>from qgis.core import * <br \/>from qgis.gui import *<\/p>\r\n\r\n\r\n\r\n<p>def run_script ( iface ): <br \/>qfd = QFileDialog () <br \/>title = &lsquo; Open a file &lsquo; <br \/>path = \u00a0\u00bb \u00a0 C: \/ \u00a0 \u00a0\u00bb <br \/>f = QFileDialog.getOpenFileName ( qfd , title, path) <br \/>layer = QgsVectorLayer (f, \u00a0\u00bb \u00a0 Museums in New York City \u00a0 \u00bb,\u00ab \u00a0 ogr \u00a0 \u00ab\u00a0) <br \/>if not layer.isValid (): <br \/>print \u00ab \u00a0 loading error of% s layer \u00a0 \u00bb% Layer.name () <br \/>QgsMapLayerRegistry.instance (). addMapLayers ([layer])<\/p>\r\n[\/stextbox]<\/figure>\r\n\r\n\r\n\r\n\r\n\r\n<p>Replace the last line<\/p>\r\n\r\n\r\n\r\n<p><strong><em>QgsMapLayerRegistry.instance<\/em><\/strong> <strong><em>().<\/em><\/strong> <strong><em>addMapLayers<\/em><\/strong> <strong><em>([layer])<\/em><\/strong><\/p>\r\n\r\n\r\n\r\n<p>by\u00a0<\/p>\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n<div class='stb-container stb-style-grey'><div class='stb-caption'><div class='stb-logo'><img class='stb-logo__image' src='data:image\/png;base64,iVBORw0KGgoAAAANSUhEUgAAADIAAAAyCAYAAAAeP4ixAAAACXBIWXMAAAsTAAALEwEAmpwYAAAKT2lDQ1BQaG90b3Nob3AgSUNDIHByb2ZpbGUAAHjanVNnVFPpFj333vRCS4iAlEtvUhUIIFJCi4AUkSYqIQkQSoghodkVUcERRUUEG8igiAOOjoCMFVEsDIoK2AfkIaKOg6OIisr74Xuja9a89+bN\/rXXPues852zzwfACAyWSDNRNYAMqUIeEeCDx8TG4eQuQIEKJHAAEAizZCFz\/SMBAPh+PDwrIsAHvgABeNMLCADATZvAMByH\/w\/qQplcAYCEAcB0kThLCIAUAEB6jkKmAEBGAYCdmCZTAKAEAGDLY2LjAFAtAGAnf+bTAICd+Jl7AQBblCEVAaCRACATZYhEAGg7AKzPVopFAFgwABRmS8Q5ANgtADBJV2ZIALC3AMDOEAuyAAgMADBRiIUpAAR7AGDIIyN4AISZABRG8lc88SuuEOcqAAB4mbI8uSQ5RYFbCC1xB1dXLh4ozkkXKxQ2YQJhmkAuwnmZGTKBNA\/g88wAAKCRFRHgg\/P9eM4Ors7ONo62Dl8t6r8G\/yJiYuP+5c+rcEAAAOF0ftH+LC+zGoA7BoBt\/qIl7gRoXgug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NzI8FgiJk3zGLM2JGo1RqcTqfcvJCoqzuHz+ePzPrqjFt1Ou2OT5sjaVnqokCvHGohoEf2Qj7gAqwylEPOI1EUxSQgVr+7OQmoas+cEVKplABIe\/fukcLhMIDC4XCMvvOuJYq5X5vDiZOH8AdCGIxmotEQsWgIf1CBLTObFCkaG+s4deoUI0aMqNPptBc\/6xElLVs8LANcAE4Ce4Ed8vV94JIMefkU4JD3FQExlUqJslHS4XA4LRtvUCgUGltUmG91u1tpbr7E6Iqx5Lhy6PZ4qGtoI9M1kD5fmAMHDrF7zy5UKjXFJUUHN2x4p\/Gz5MjHYZXyD9AAesAsF8xsefaXPXTZO0a5+6GVp0reQ7isiEajUX377bdb9AaDsrioFHOGkcOHDmPQm5l38zzCsQDZmS6OHz+Gw5GJ290ZjEZD3\/nFo794SxTFz\/Wom5ZvnpItG5e95JHDTC9DWWQhyLgCVCuvq+SckmQ1TITD4axXXnllwn333ZdfPrKMynXr6OkL8M0pM9i4uZJeTy\/\/etcyTtW8z6KFd7KhqvL0unXrW+S9kp+3HSRdMa8Eisoe65Etrr5iauT3tJefRuXvxuVrARDzeDymdWvXOg1anbDg27fR7e6gpqaG225bxNGjx5g0cSrPrF4V3bRpY6fsUeHzhtYnVX6u2Fj42NrfM8TlG2YAo4GvARNXrVo1PJVMalrb2jSTJk0Rurs7EUWJ7du2uHfu2nkI2AjsAtzSVX705wX5JLArX0tXgfl47hlkOS\/Nzc0d0eV2Z40dNz6voCA\/c\/v27b12uz3a2Nh4GtgHnAO8H7XQJL4okGsZSvkclyELhEnOsdgV8t9zZRH8vwpytZIgXCUU+cwgX\/7z4UuQL0H++UD+awDc\/MMFLMO8WgAAAABJRU5ErkJggg==' alt='img'\/><\/div><div class='stb-caption-content'><\/div><div class='stb-tool'><\/div><\/div><div class='stb-content'>features = layer.getFeatures () <br \/>feat = features.next () <br \/>g = feat.geometry () <br \/>print g.asPoint ()<\/div><\/div>\r\n\r\n\r\n\r\n<p>We avoid loading the layer in QGis and we display in the Python console the x and y coordinates of the first point of the layer.<\/p>\r\n\r\n\r\n\r\n<p>The script must look like this:<\/p>\r\n\r\n\r\n\r\n\r\n\r\n<figure class=\"wp-block-image\"><a href=\"https:\/\/i1.wp.com\/www.sigterritoires.fr\/wp-content\/uploads\/2016\/08\/pv12.png\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"640\" height=\"462\" data-attachment-id=\"6247\" data-permalink=\"https:\/\/www.sigterritoires.fr\/index.php\/en\/python-methods-for-qgis-how-to-examine-vector-data\/py31-2\/\" data-orig-file=\"https:\/\/i0.wp.com\/www.sigterritoires.fr\/wp-content\/uploads\/2018\/09\/py31.png?fit=777%2C561&amp;ssl=1\" data-orig-size=\"777,561\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"py31\" data-image-description=\"\" data-image-caption=\"\" data-large-file=\"https:\/\/i0.wp.com\/www.sigterritoires.fr\/wp-content\/uploads\/2018\/09\/py31.png?fit=640%2C462&amp;ssl=1\" class=\"wp-image-6247\" src=\"https:\/\/i0.wp.com\/www.sigterritoires.fr\/wp-content\/uploads\/2018\/09\/py31.png?resize=640%2C462&#038;ssl=1\" alt=\"\" srcset=\"https:\/\/i0.wp.com\/www.sigterritoires.fr\/wp-content\/uploads\/2018\/09\/py31.png?w=777&amp;ssl=1 777w, https:\/\/i0.wp.com\/www.sigterritoires.fr\/wp-content\/uploads\/2018\/09\/py31.png?resize=300%2C217&amp;ssl=1 300w, https:\/\/i0.wp.com\/www.sigterritoires.fr\/wp-content\/uploads\/2018\/09\/py31.png?resize=768%2C555&amp;ssl=1 768w\" sizes=\"auto, (max-width: 640px) 100vw, 640px\" \/><\/a><\/figure>\r\n\r\n\r\n\r\n<p>The procedure is the following :<\/p>\r\n\r\n\r\n\r\n<p><strong><em>features =<\/em><\/strong> <strong><em>layer.getFeatures<\/em><\/strong> <strong><em>()<\/em><\/strong><\/p>\r\n\r\n\r\n\r\n<p>Create a pointer named \u00a0<strong><em>features<\/em><\/strong> on the layer <strong><em>layer<\/em><\/strong><\/p>\r\n\r\n\r\n\r\n<p><strong><em>feat =<\/em><\/strong> <strong><em>features.next<\/em><\/strong> <strong><em>()<\/em><\/strong><\/p>\r\n\r\n\r\n\r\n<p>Moving the cursor on the next entity, here this is the first entity of the table and charge this entity in the object <strong><em>feat<\/em><\/strong> .<\/p>\r\n\r\n\r\n\r\n<p><strong><em>g =<\/em><\/strong> <strong><em>feat.geometry<\/em><\/strong> <strong><em>()<\/em><\/strong><\/p>\r\n\r\n\r\n\r\n<p>Load the geometry of the current cursor entity in subject <strong><em>g<\/em><\/strong>.<\/p>\r\n\r\n\r\n\r\n<p>Once executed , we get the result in the Python console: <\/p>\r\n\r\n\r\n\r\n<figure class=\"wp-block-image\"><a href=\"https:\/\/i2.wp.com\/www.sigterritoires.fr\/wp-content\/uploads\/2016\/08\/pv13.png\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"640\" height=\"131\" data-attachment-id=\"6248\" data-permalink=\"https:\/\/www.sigterritoires.fr\/index.php\/en\/python-methods-for-qgis-how-to-examine-vector-data\/py32-2\/\" data-orig-file=\"https:\/\/i0.wp.com\/www.sigterritoires.fr\/wp-content\/uploads\/2018\/09\/py32.png?fit=786%2C161&amp;ssl=1\" data-orig-size=\"786,161\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"py32\" data-image-description=\"\" data-image-caption=\"\" data-large-file=\"https:\/\/i0.wp.com\/www.sigterritoires.fr\/wp-content\/uploads\/2018\/09\/py32.png?fit=640%2C131&amp;ssl=1\" class=\"wp-image-6248\" src=\"https:\/\/i0.wp.com\/www.sigterritoires.fr\/wp-content\/uploads\/2018\/09\/py32.png?resize=640%2C131&#038;ssl=1\" alt=\"\" srcset=\"https:\/\/i0.wp.com\/www.sigterritoires.fr\/wp-content\/uploads\/2018\/09\/py32.png?w=786&amp;ssl=1 786w, https:\/\/i0.wp.com\/www.sigterritoires.fr\/wp-content\/uploads\/2018\/09\/py32.png?resize=300%2C61&amp;ssl=1 300w, https:\/\/i0.wp.com\/www.sigterritoires.fr\/wp-content\/uploads\/2018\/09\/py32.png?resize=768%2C157&amp;ssl=1 768w\" sizes=\"auto, (max-width: 640px) 100vw, 640px\" \/><\/a><\/figure>\r\n\r\n\r\n\r\n<p><strong>NOTES:<\/strong><\/p>\r\n\r\n\r\n\r\n<p>We could access by others means to geometry of an entity but the use of pointers in Python allows working with very important data loads without having to load the entire table into the memory.<\/p>\r\n\r\n\r\n\r\n<p>Here we have loaded a shapefile, but regardless of the data source, once the layer is created the Python code does not change.<\/p>\r\n\r\n\r\n\r\n<h2><strong>How to access<\/strong> <strong>attributes<\/strong> <strong>of a<\/strong> <strong>vector<\/strong><strong> layer<\/strong><\/h2>\r\n\r\n\r\n\r\n<p>To access the non-geometric attributes of the entities, we will modify the previous script<\/p>\r\n\r\n\r\n\r\n<p>Replace the last two lines<\/p>\r\n\r\n\r\n\r\n<p><strong><em>g =<\/em><\/strong> <strong><em>feat.geometry<\/em><\/strong> <strong><em>()<\/em><\/strong> <br \/><strong><em>print<\/em><\/strong> <strong><em>g.asPoint<\/em><\/strong> <strong><em>()<\/em><\/strong><\/p>\r\n\r\n\r\n\r\n<p>by<\/p>\r\n\r\n\r\n\r\n<p><strong><em>print<\/em><\/strong> <strong><em>feat.attributes<\/em><\/strong> <strong><em>()<\/em><\/strong><\/p>\r\n\r\n\r\n\r\n<p>The script must look like this: <\/p>\r\n\r\n\r\n\r\n<figure class=\"wp-block-image\"><a href=\"https:\/\/i2.wp.com\/www.sigterritoires.fr\/wp-content\/uploads\/2016\/08\/pv14.png\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"640\" height=\"456\" data-attachment-id=\"6249\" data-permalink=\"https:\/\/www.sigterritoires.fr\/index.php\/en\/python-methods-for-qgis-how-to-examine-vector-data\/py33-2\/\" data-orig-file=\"https:\/\/i0.wp.com\/www.sigterritoires.fr\/wp-content\/uploads\/2018\/09\/py33.png?fit=767%2C546&amp;ssl=1\" data-orig-size=\"767,546\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"py33\" data-image-description=\"\" data-image-caption=\"\" data-large-file=\"https:\/\/i0.wp.com\/www.sigterritoires.fr\/wp-content\/uploads\/2018\/09\/py33.png?fit=640%2C456&amp;ssl=1\" class=\"wp-image-6249\" src=\"https:\/\/i0.wp.com\/www.sigterritoires.fr\/wp-content\/uploads\/2018\/09\/py33.png?resize=640%2C456&#038;ssl=1\" alt=\"\" srcset=\"https:\/\/i0.wp.com\/www.sigterritoires.fr\/wp-content\/uploads\/2018\/09\/py33.png?w=767&amp;ssl=1 767w, https:\/\/i0.wp.com\/www.sigterritoires.fr\/wp-content\/uploads\/2018\/09\/py33.png?resize=300%2C214&amp;ssl=1 300w\" sizes=\"auto, (max-width: 640px) 100vw, 640px\" \/><\/a><\/figure>\r\n\r\n\r\n\r\n<p>And its execution gives the following result in the Python console: <\/p>\r\n\r\n\r\n\r\n<figure class=\"wp-block-image\"><a href=\"https:\/\/i1.wp.com\/www.sigterritoires.fr\/wp-content\/uploads\/2016\/08\/pv15.png\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"640\" height=\"155\" data-attachment-id=\"6250\" data-permalink=\"https:\/\/www.sigterritoires.fr\/index.php\/en\/python-methods-for-qgis-how-to-examine-vector-data\/py34-2\/\" data-orig-file=\"https:\/\/i0.wp.com\/www.sigterritoires.fr\/wp-content\/uploads\/2018\/09\/py34.png?fit=768%2C186&amp;ssl=1\" data-orig-size=\"768,186\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"py34\" data-image-description=\"\" data-image-caption=\"\" data-large-file=\"https:\/\/i0.wp.com\/www.sigterritoires.fr\/wp-content\/uploads\/2018\/09\/py34.png?fit=640%2C155&amp;ssl=1\" class=\"wp-image-6250\" src=\"https:\/\/i0.wp.com\/www.sigterritoires.fr\/wp-content\/uploads\/2018\/09\/py34.png?resize=640%2C155&#038;ssl=1\" alt=\"\" srcset=\"https:\/\/i0.wp.com\/www.sigterritoires.fr\/wp-content\/uploads\/2018\/09\/py34.png?w=768&amp;ssl=1 768w, https:\/\/i0.wp.com\/www.sigterritoires.fr\/wp-content\/uploads\/2018\/09\/py34.png?resize=300%2C73&amp;ssl=1 300w\" sizes=\"auto, (max-width: 640px) 100vw, 640px\" \/><\/a><\/figure>\r\n\r\n\r\n\r\n<p>The result is a Python list with the set of attributes of the first entity of the table.<\/p>\r\n\r\n\r\n\r\n<p>This information is usually related to the names of the fields in the table. For a list of field names, replace in the previous script the following line<\/p>\r\n\r\n\r\n\r\n<p><strong><em>print<\/em><\/strong> <strong><em>feat.attributes<\/em><\/strong> <strong><em>()<\/em><\/strong><\/p>\r\n\r\n\r\n\r\n<p>by<\/p>\r\n\r\n\r\n\r\n<p><strong><em>print [c.name () for c in<\/em><\/strong> <strong><em>feat.fields<\/em><\/strong> <strong><em>().<\/em><\/strong> <strong><em>toList<\/em><\/strong> <strong><em>()]<\/em><\/strong><\/p>\r\n\r\n\r\n\r\n<p>The script must look like this: <\/p>\r\n\r\n\r\n\r\n<figure class=\"wp-block-image\"><a href=\"https:\/\/i1.wp.com\/www.sigterritoires.fr\/wp-content\/uploads\/2016\/08\/pv16.png\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"640\" height=\"436\" data-attachment-id=\"6251\" data-permalink=\"https:\/\/www.sigterritoires.fr\/index.php\/en\/python-methods-for-qgis-how-to-examine-vector-data\/py35-2\/\" data-orig-file=\"https:\/\/i0.wp.com\/www.sigterritoires.fr\/wp-content\/uploads\/2018\/09\/py35.png?fit=762%2C519&amp;ssl=1\" data-orig-size=\"762,519\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"py35\" data-image-description=\"\" data-image-caption=\"\" data-large-file=\"https:\/\/i0.wp.com\/www.sigterritoires.fr\/wp-content\/uploads\/2018\/09\/py35.png?fit=640%2C436&amp;ssl=1\" class=\"wp-image-6251\" src=\"https:\/\/i0.wp.com\/www.sigterritoires.fr\/wp-content\/uploads\/2018\/09\/py35.png?resize=640%2C436&#038;ssl=1\" alt=\"\" srcset=\"https:\/\/i0.wp.com\/www.sigterritoires.fr\/wp-content\/uploads\/2018\/09\/py35.png?w=762&amp;ssl=1 762w, https:\/\/i0.wp.com\/www.sigterritoires.fr\/wp-content\/uploads\/2018\/09\/py35.png?resize=300%2C204&amp;ssl=1 300w\" sizes=\"auto, (max-width: 640px) 100vw, 640px\" \/><\/a><\/figure>\r\n\r\n\r\n\r\n<p>And its execution gives the following result in the Python console <\/p>\r\n\r\n\r\n\r\n<figure class=\"wp-block-image\"><a href=\"https:\/\/i2.wp.com\/www.sigterritoires.fr\/wp-content\/uploads\/2016\/08\/pv17.png\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"640\" height=\"146\" data-attachment-id=\"6252\" data-permalink=\"https:\/\/www.sigterritoires.fr\/index.php\/en\/python-methods-for-qgis-how-to-examine-vector-data\/py36-2\/\" data-orig-file=\"https:\/\/i0.wp.com\/www.sigterritoires.fr\/wp-content\/uploads\/2018\/09\/py36.png?fit=766%2C175&amp;ssl=1\" data-orig-size=\"766,175\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"py36\" data-image-description=\"\" data-image-caption=\"\" data-large-file=\"https:\/\/i0.wp.com\/www.sigterritoires.fr\/wp-content\/uploads\/2018\/09\/py36.png?fit=640%2C146&amp;ssl=1\" class=\"wp-image-6252\" src=\"https:\/\/i0.wp.com\/www.sigterritoires.fr\/wp-content\/uploads\/2018\/09\/py36.png?resize=640%2C146&#038;ssl=1\" alt=\"\" srcset=\"https:\/\/i0.wp.com\/www.sigterritoires.fr\/wp-content\/uploads\/2018\/09\/py36.png?w=766&amp;ssl=1 766w, https:\/\/i0.wp.com\/www.sigterritoires.fr\/wp-content\/uploads\/2018\/09\/py36.png?resize=300%2C69&amp;ssl=1 300w\" sizes=\"auto, (max-width: 640px) 100vw, 640px\" \/><\/a><\/figure>\r\n","protected":false},"excerpt":{"rendered":"<p>Once a layer is loaded, usually we want to access the data included in the layer, whether the geometries or the attributes. Now, we will discuss how to code in Python the access to these two&hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"give_campaign_id":0,"_bbp_topic_count":0,"_bbp_reply_count":0,"_bbp_total_topic_count":0,"_bbp_total_reply_count":0,"_bbp_voice_count":0,"_bbp_anonymous_reply_count":0,"_bbp_topic_count_hidden":0,"_bbp_reply_count_hidden":0,"_bbp_forum_subforum_count":0,"sfsi_plus_gutenberg_text_before_share":"","sfsi_plus_gutenberg_show_text_before_share":"","sfsi_plus_gutenberg_icon_type":"","sfsi_plus_gutenberg_icon_alignemt":"","sfsi_plus_gutenburg_max_per_row":"","_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[1296,1401,1377],"tags":[1449,1386,1447],"class_list":["post-6243","post","type-post","status-publish","format-standard","hentry","category-posts-en","category-gis-and-management","category-qgis-en","tag-python-en","tag-qgis-en","tag-vector-data"],"aioseo_notices":[],"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/p6XU0A-1CH","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/www.sigterritoires.fr\/index.php\/wp-json\/wp\/v2\/posts\/6243","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.sigterritoires.fr\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.sigterritoires.fr\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.sigterritoires.fr\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.sigterritoires.fr\/index.php\/wp-json\/wp\/v2\/comments?post=6243"}],"version-history":[{"count":0,"href":"https:\/\/www.sigterritoires.fr\/index.php\/wp-json\/wp\/v2\/posts\/6243\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.sigterritoires.fr\/index.php\/wp-json\/wp\/v2\/media?parent=6243"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.sigterritoires.fr\/index.php\/wp-json\/wp\/v2\/categories?post=6243"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.sigterritoires.fr\/index.php\/wp-json\/wp\/v2\/tags?post=6243"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}