Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I know how to do this:

nodes = driver.Open(node_nav,0)
node_lyr = nodes.GetLayer()  

But how do can use the layer methods on a geometry I created from scratch?

for n in nodes:
    x,y = n.node
    x = float(x)/dim
    y = float(y)/dim


This is the traceback for this attempt:

File "/usr/lib/python2.7/dist-packages/osgeo/", line 2927, in <lambda>
 __getattr__ = lambda self, name: _swig_getattr(self, Geometry, name)
File "/usr/lib/python2.7/dist-packages/osgeo/", line 55, in _swig_getattr
raise AttributeError(name)
AttributeError: SetSpatialFilter

I don't want to save the geometry in a shape file (like it is described here for example).

share|improve this question
AttributeError: SetSpatialFilter This just means the attribute isn't found on the object. – Nathan W Jul 26 '13 at 12:53
up vote 2 down vote accepted

You could write the geometry to an in-memory dataset using the '/vsimem/path_file.shp' virtual file system.


drv = ogr.GetDriverByName( 'ESRI Shapefile' )
ds = drv.CreateDataSource( "/vsimem/blahblah.shp" )
share|improve this answer
This looks interesting. Have you any experience using it? Can you provide some example code? – LarsVegas Aug 15 '13 at 5:26
@LarsVegas - yes, I use /vsimem regularly with GDAL, seems to work just as well with OGR. There's example code in your link and the OGR API tutorial. The only difference is instead of calling ds = drv.CreateDataSource( r"c:\somedir\blahblah.shp" ) you call ds = drv.CreateDataSource( "/vsimem/blahblah.shp" ) – Luke Aug 15 '13 at 6:12
Ok, thanks for the edit. – LarsVegas Aug 15 '13 at 7:03
This works great! Very useful information you provided here. I created a point shape file with ~300.000 geometries and two attribute fields in less than a second. Impressive. – LarsVegas Aug 23 '13 at 11:11

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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