1

I have done following steps, so how I open that created shp file in Qgis

driver=ogr.GetDriverByName('ESRI Shapefile')
out=driver.CreateDataSource('pts.shp')
outL=out.CreateLayer('lake',geom_type=ogr.wkbPolygon)
farea=ogr.FieldDefn('ara',ogr.OFTString)
farea.SetWidth(16)
outL.CreateField(farea)
sr=osr.SpatialReference()
sr.ImportFromEPSG(4326)
featDef=outL.GetLayerDefn()
ring=ogr.Geometry(ogr.wkbLinearRing)

# gave points correctly 
poly=ogr.Geometry(ogr.wkbPolygon)
poly.AddGeometry(ring)

... likewise I follow the all steps, Now I want to open the created file in QGis. However, I could not find the path of the file. where I can find it?

1

Since you have not specified any path, Python will put your file in the same directory as the Python EXE. This is not good practice. It is much better to specify a known path. You could maybe pick that up from some environment variable to make it relative to the project or hard code a proper path into your python e.g.:

out=driver.CreateDataSource(r'C:\myfolder\pts.shp') 

The litle r before the path make Windows handle the slashes correctly and not mistake them for escaped characters (which could cause you a problem).

  • I am using Ubuntu, then how the path should be given? – Niroshan Oct 3 '14 at 16:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.