<div dir="ltr">Hi,<div><br></div><div>I'm trying to convert data from one format to another using ogr with python (Postgis->SHP) using the following code:</div><div><div><br></div><div>conn=ogr.Open("PG: host=host dbname=db user=user password=password")</div><div>if conn is None:</div><div>    print 'Could not open a database or GDAL is not correctly installed!'</div><div>    sys.exit(1)</div><div><br></div><div>output = "out.shp"</div><div><br></div><div># Schema definition of SHP file</div><div>#out_driver = ogr.GetDriverByName('Memory')</div><div>#out_ds = out_driver.CreateDataSource('out') </div><div>out_driver = ogr.GetDriverByName( 'ESRI Shapefile' )</div><div>out_ds = out_driver.CreateDataSource(output)</div><div>out_srs = None</div><div>out_layer = out_ds.CreateLayer("name", out_srs, ogr.wkbMultiLineString)</div><div>fd = ogr.FieldDefn('name',ogr.OFTString)</div><div>out_layer.CreateField(fd)</div><div><br></div><div>layer = conn.ExecuteSQL("select *,'' as TITLE from table")</div><div><br></div><div>feat = layer.GetNextFeature()</div><div>while feat is not None:</div><div>    featDef = ogr.Feature(out_layer.GetLayerDefn())</div><div>    featDef.SetGeometry(feat.GetGeometryRef())</div><div>    featDef.SetField('name',feat.TITLE)</div><div>    out_layer.CreateFeature(featDef)</div><div>    feat.Destroy()</div><div>    feat = layer.GetNextFeature()</div><div><br></div><div>conn.Destroy()</div><div>out_ds.Destroy()</div></div><div><br></div><div>That code works corrctly and generates the shape file, but this isn't adecuate for the program that I'm writing because it's an HTTP service.</div><div>There is any way to get the shapefile data without writing and reading it latter(it's inefficient)? I missed to check somthing from the documentation  or it's not possible to get the file data as an string?</div><div><br></div><div>If it's not possible would it be a good improvment? </div><div><br></div><div><br></div><div>Best reggards</div></div>