I eventually managed to do it myself.
import sys
import os
from qgis.core import *
import matplotlib.pyplot as plt
from matplotlib.path import Path
import matplotlib.patches as patches
LATITUDE = 1.29306
LONGITUDE = 103.856
QgsApplication.setPrefixPath("/usr", True)
QgsApplication.initQgis()
layer=QgsVectorLayer("/home/shubham/SMART/zones/mtz1092p.shp", "mtz1092p", "ogr")
if not layer.isValid():
print "Layer failed to load!"
provider = layer.dataProvider()
def findFeatureId(point):
feat = QgsFeature()
allAttrs = provider.attributeIndexes()
provider.select(allAttrs)
while provider.nextFeature(feat):
geom = feat.geometry()
x = geom.asPolygon()
if len(x) == 0:
print "Feature ID %d has no ring" % feat.id()
else:
codes = []
codes.append(Path.MOVETO)
for i in range (0, len(x[0]) - 2):
codes.append(Path.LINETO)
codes.append(Path.CLOSEPOLY)
path = Path(x[0], codes)
if (path.contains_point(point, None, 0.0)):
print "Point contained in feature ID %d" %feat.id()
if __name__ == "__main__":
crsSrc = QgsCoordinateReferenceSystem(4326) # WGS84
crsDest = QgsCoordinateReferenceSystem(3414)# SVY21
xform = QgsCoordinateTransform(crsSrc, crsDest)
pt = xform.transform(QgsPoint(LONGITUDE, LATITUDE))
findFeatureId(pt)