Hi Viewers,
From this video, you will come to know how to use python(Python Interface) in QGIS. For better understanding, follow below program:
Python Interface
iface
help(iface)
##Add Vector layer:
iface.addVectorLayer("d:/.../points.shp","points", "ogr")
##Zoom
iface.zoomFull()
iface.zoomToPrevious()
iface.zoomToNext()
##Active Layer
layer = iface.activeLayer()
##Attribute Table
iface.showAttributeTable(layer)
##Layer Properties
iface.showLayerProperties(layer)
##New Project
iface.newProject()
##Add New Layer
help(iface.addVectorLayer)
iface.addVectorLayer("d:/.../points.shp","points", "ogr")
layer = iface.activeLayer()
dir(layer)
##Feature details (Attributes)
for f in layer.getFeatures():
print (f)
run python
..............................
for f in layer.getFeatures():
print(f['place'], f['amenity'])
run python
....................
##Coordinates (Lat, Long)
for f in layer.getFeatures():
geom = f.geometry()
print (geom.asPoint())
run python
..............
for f in layer.getFeatures():
geom = f.geometry()
print (geom.asPoint().x())
runpython
.............................
for f in layer.getFeatures():
geom = f.geometry()
print(geom.asPoint().y(), geom.asPoint().x()) (Lat (y)/Long(x))
run python
................................
##Coordinates along with Other Fields
for f in layer.getFeatures():
geom = f.geometry()
print ('%s, %s, %f, %f' % (f['place'], f['amenity'], geom.asPoint().y(), geom.asPoint().x()))
run python
.............................
18 сен 2020