IOHandlers.pyShpIO — Shapefile Plugin for PySAL’s FileIO System
The IOHandlers.pyShpIO Shapefile Plugin for PySAL’s FileIO System
New in version 1.0.
PySAL ShapeFile Reader and Writer based on pure python shapefile module.
-
class pysal.core.IOHandlers.pyShpIO.PurePyShpWrapper(*args, **kwargs)
FileIO handeler for ESRI ShapeFiles.
Notes
This class wraps _pyShpIO’s shp_file class with the PySAL FileIO API.
shp_file can be used without PySAL.
Examples
>>> import tempfile
>>> f = tempfile.NamedTemporaryFile(suffix='.shp'); fname = f.name; f.close()
>>> import pysal
>>> i = pysal.open('../../examples/10740.shp','r')
>>> o = pysal.open(fname,'w')
>>> for shp in i:
... o.write(shp)
>>> o.close()
>>> open('../../examples/10740.shp','rb').read() == open(fname,'rb').read()
True
>>> open('../../examples/10740.shx','rb').read() == open(fname[:-1]+'x','rb').read()
True
>>> import os
>>> os.remove(fname); os.remove(fname.replace('.shp','.shx'))
Attributes
| Formats |
list |
A list of support file extensions |
| Modes |
list |
A list of support file modes |
Methods
-
class by_row(parent)
-
PurePyShpWrapper.cast(key, typ)
- cast key as typ
-
classmethod PurePyShpWrapper.check()
- Prints the contents of the registry
-
PurePyShpWrapper.close()
-
PurePyShpWrapper.flush()
-
PurePyShpWrapper.get(n)
- Seeks the file to n and returns n
If .ids is set n should be an id,
else, n should be an offset
-
static PurePyShpWrapper.getType(dataPath)
- Parse the dataPath and return the data type
-
PurePyShpWrapper.ids
-
PurePyShpWrapper.next()
- A FileIO object is its own iterator, see StringIO
-
classmethod PurePyShpWrapper.open(*args, **kwargs)
- Alias for FileIO()
-
PurePyShpWrapper.rIds
-
PurePyShpWrapper.read(n=-1)
- Read at most n objects, less if read hits EOF
if size is negative or omitted read all objects until EOF
returns None if EOF is reached before any objects.
-
PurePyShpWrapper.seek(n)
- Seek the FileObj to the beginning of the n’th record,
if ids are set, seeks to the beginning of the record at id, n
-
PurePyShpWrapper.tell()
- Return id (or offset) of next object
-
PurePyShpWrapper.truncate(size=None)
- Should be implemented by subclasses
and redefine this doc string
-
PurePyShpWrapper.write(obj)
- Must be implemented by subclasses that support ‘w’
subclasses should increment .pos
subclasses should also check if obj is an instance of type(list)
and redefine this doc string