105 |
PyErr_Format(PyExc_TypeError, "shapelib.SHPObject.__init__ takes no keyword arguments"); |
PyErr_Format(PyExc_TypeError, "shapelib.SHPObject.__init__ takes no keyword arguments"); |
106 |
return -1; |
return -1; |
107 |
} |
} |
108 |
if (!PyArg_ParseTuple(args, "iiO|O", &type, &id, &parts, &part_type_list)) return -1; |
if (!PyArg_ParseTuple(args, "iiO|O:__init__", &type, &id, &parts, &part_type_list)) return -1; |
109 |
|
|
110 |
/* check parts */ |
/* check parts */ |
111 |
if (!PySequence_Check(parts)) |
if (!PySequence_Check(parts)) |
205 |
switch (vertex_type) |
switch (vertex_type) |
206 |
{ |
{ |
207 |
case vtXY: |
case vtXY: |
208 |
ok = PyArg_ParseTuple(vertex, "dd", xs + part_start + j, ys + part_start + j); |
ok = PyArg_ParseTuple(vertex, "dd:__init__", xs + part_start + j, ys + part_start + j); |
209 |
break; |
break; |
210 |
case vtXYM: |
case vtXYM: |
211 |
ok = PyArg_ParseTuple(vertex, "ddd", xs + part_start + j, ys + part_start + j, ms + part_start + j); |
ok = PyArg_ParseTuple(vertex, "ddd:__init__", xs + part_start + j, ys + part_start + j, ms + part_start + j); |
212 |
break; |
break; |
213 |
case vtXYZM: |
case vtXYZM: |
214 |
ms[part_start + j] = 0.; |
ms[part_start + j] = 0.; |
215 |
ok = PyArg_ParseTuple(vertex, "ddd|d", xs + part_start + j, ys + part_start + j, zs + part_start + j, |
ok = PyArg_ParseTuple(vertex, "ddd|d:__init__", xs + part_start + j, ys + part_start + j, zs + part_start + j, |
216 |
ms + part_start + j); |
ms + part_start + j); |
217 |
break; |
break; |
218 |
} |
} |
436 |
|
|
437 |
static struct PyMethodDef shpobject_methods[] = |
static struct PyMethodDef shpobject_methods[] = |
438 |
{ |
{ |
439 |
{"extents", (PyCFunction)shpobject_extents, METH_NOARGS, NULL}, |
{"extents", (PyCFunction)shpobject_extents, METH_NOARGS, |
440 |
{"vertices", (PyCFunction)shpobject_vertices, METH_NOARGS, NULL}, |
"extents()\n" |
441 |
{"part_types", (PyCFunction)shpobject_part_types, METH_NOARGS, NULL}, |
"returns ((x_min, y_min, z_min, m_min), (x_max, y_max, z_max, m_max)), the 4D bounding box of the SHPObject"}, |
442 |
|
{"vertices", (PyCFunction)shpobject_vertices, METH_NOARGS, |
443 |
|
"vertices()\n" |
444 |
|
"returns [[(x, y, ...), ...], ...], a list of object parts, where each part is again a list of vertices.\n" |
445 |
|
"each vertex is a tuple of two to four doubles, depending on the object type."}, |
446 |
|
{"part_types", (PyCFunction)shpobject_part_types, METH_NOARGS, |
447 |
|
"part_types()\n" |
448 |
|
"returns a tuple of integers, each integer indicating the type of the corresponding part in vertices()"}, |
449 |
{NULL} |
{NULL} |
450 |
}; |
}; |
451 |
|
|
452 |
static struct PyGetSetDef shpobject_getsetters[] = |
static struct PyGetSetDef shpobject_getsetters[] = |
453 |
{ |
{ |
454 |
{"type", (getter)shpobject_type, NULL, NULL }, |
{"type", (getter)shpobject_type, NULL, "type of the object (read-only)" }, |
455 |
{"id", (getter)shpobject_id, NULL, NULL }, |
{"id", (getter)shpobject_id, NULL, "id of the object (read-only)" }, |
456 |
{NULL} |
{NULL} |
457 |
}; |
}; |
458 |
|
|
497 |
PyErr_Format(PyExc_TypeError, "shapelib.ShapeFile.__init__ takes no keyword arguments"); |
PyErr_Format(PyExc_TypeError, "shapelib.ShapeFile.__init__ takes no keyword arguments"); |
498 |
return -1; |
return -1; |
499 |
} |
} |
500 |
if (!PyArg_ParseTuple(args, "s|s", &file, &mode)) return -1; |
if (!PyArg_ParseTuple(args, "et|s:__init__", Py_FileSystemDefaultEncoding, &file, &mode)) return -1; |
501 |
|
|
502 |
self->handle = SHPOpen(file, mode); |
self->handle = SHPOpen(file, mode); |
503 |
return self->handle ? 0 : -1; |
return self->handle ? 0 : -1; |
525 |
SHPObject* object; |
SHPObject* object; |
526 |
SHPObjectObject* result; |
SHPObjectObject* result; |
527 |
|
|
528 |
if (!PyArg_ParseTuple(args, "i", &index)) return NULL; |
if (!PyArg_ParseTuple(args, "i:read_object", &index)) return NULL; |
529 |
|
|
530 |
object = SHPReadObject(self->handle, index); |
object = SHPReadObject(self->handle, index); |
531 |
if (!object) |
if (!object) |
549 |
int index, result; |
int index, result; |
550 |
PyObject* object; |
PyObject* object; |
551 |
|
|
552 |
if (!PyArg_ParseTuple(args, "iO", &index, &object)) return NULL; |
if (!PyArg_ParseTuple(args, "iO:write_object", &index, &object)) return NULL; |
553 |
|
|
554 |
if (!PyObject_IsInstance(object, (PyObject*)&SHPObjectType)) |
if (!PyObject_IsInstance(object, (PyObject*)&SHPObjectType)) |
555 |
{ |
{ |
579 |
|
|
580 |
static struct PyMethodDef shapefile_methods[] = |
static struct PyMethodDef shapefile_methods[] = |
581 |
{ |
{ |
582 |
{"close", (PyCFunction)shapefile_close, METH_NOARGS, "close the shape file" }, |
{"close", (PyCFunction)shapefile_close, METH_NOARGS, |
583 |
{"info", (PyCFunction)shapefile_info, METH_NOARGS, |
"close()\n" |
584 |
"Return a tuple (NUM_SHAPES, TYPE, MIN, MAX) where NUM_SHAPES is the number of shapes in the file, TYPE is the " |
"close the shape file" }, |
585 |
"shape type and MIN and MAX are 4-element tuples with the min. and max. values of the data." }, |
{"info", (PyCFunction)shapefile_info, METH_NOARGS, |
586 |
{"read_object", (PyCFunction)shapefile_read_object, METH_VARARGS, "Return object number i" }, |
"info()\n" |
587 |
{"write_object", (PyCFunction)shapefile_write_object, METH_VARARGS, "Write an object"}, |
"returns (num_shapes, type, (x_min, y_min, z_min, m_min), (x_max, y_max, z_max, m_max)) with:\n" |
588 |
{"cobject", (PyCFunction)shapefile_cobject, METH_NOARGS, "Return the shapelib SHPHandle as a Python CObject"}, |
"-num_shapes: the number of the objects in the file\n" |
589 |
|
"-type: the type of the shape file (SHPT_POINT, SHPT_POLYGON, ...)\n" |
590 |
|
"-(x_min, y_min, z_min, m_min), (x_max, y_max, z_max, m_max): 4D bounding box of the data in the shape file" }, |
591 |
|
{"read_object", (PyCFunction)shapefile_read_object, METH_VARARGS, |
592 |
|
"read_object(id)\n" |
593 |
|
"Return object indexed by id" }, |
594 |
|
{"write_object", (PyCFunction)shapefile_write_object, METH_VARARGS, |
595 |
|
"write_object(id, object)\n" |
596 |
|
"Write an object at index id.\n" |
597 |
|
"If id == -1, the object is appended at the end of the shape file"}, |
598 |
|
{"cobject", (PyCFunction)shapefile_cobject, METH_NOARGS, |
599 |
|
"cobject()\n" |
600 |
|
"Return the shapelib SHPHandle as a Python CObject"}, |
601 |
{NULL} |
{NULL} |
602 |
}; |
}; |
603 |
|
|
621 |
int type; |
int type; |
622 |
ShapeFileObject* result; |
ShapeFileObject* result; |
623 |
|
|
624 |
if (!PyArg_ParseTuple(args, "si", &file, &type)) return NULL; |
if (!PyArg_ParseTuple(args, "eti:create", Py_FileSystemDefaultEncoding, &file, &type)) return NULL; |
625 |
|
|
626 |
result = PyObject_New(ShapeFileObject, &ShapeFileType); |
result = PyObject_New(ShapeFileObject, &ShapeFileType); |
627 |
if (!result) |
if (!result) |
657 |
static PyObject* shapelib_type_name(PyObject* module, PyObject* args) |
static PyObject* shapelib_type_name(PyObject* module, PyObject* args) |
658 |
{ |
{ |
659 |
int type; |
int type; |
660 |
if (!PyArg_ParseTuple(args, "i", &type)) return NULL; |
if (!PyArg_ParseTuple(args, "i:type_name", &type)) return NULL; |
661 |
return PyString_FromString(SHPTypeName(type)); |
return PyString_FromString(SHPTypeName(type)); |
662 |
} |
} |
663 |
|
|
664 |
static PyObject* shapelib_part_type_name(PyObject* module, PyObject* args) |
static PyObject* shapelib_part_type_name(PyObject* module, PyObject* args) |
665 |
{ |
{ |
666 |
int type; |
int type; |
667 |
if (!PyArg_ParseTuple(args, "i", &type)) return NULL; |
if (!PyArg_ParseTuple(args, "i:part_type_name", &type)) return NULL; |
668 |
return PyString_FromString(SHPPartTypeName(type)); |
return PyString_FromString(SHPPartTypeName(type)); |
669 |
} |
} |
670 |
|
|
671 |
static struct PyMethodDef shapelib_methods[] = |
static struct PyMethodDef shapelib_methods[] = |
672 |
{ |
{ |
673 |
{"open", (PyCFunction)shapelib_open, METH_VARARGS, "open a ShapeFile" }, |
{"open", (PyCFunction)shapelib_open, METH_VARARGS, |
674 |
{"create", (PyCFunction)shapelib_create, METH_VARARGS, "create a ShapeFile" }, |
"open(filename [, mode='rb'])\n" |
675 |
{"c_api", (PyCFunction)shapelib_c_api, METH_NOARGS, "get C API of shapelib" }, |
"open a ShapeFile" }, |
676 |
{"type_name", (PyCFunction)shapelib_type_name, METH_VARARGS, "return type as string" }, |
{"create", (PyCFunction)shapelib_create, METH_VARARGS, |
677 |
{"part_type_name", (PyCFunction)shapelib_part_type_name, METH_VARARGS, "return part type as string" }, |
"create(filename, type)\n" |
678 |
|
"create a ShapeFile of a certain type (one of SHPT_POINT, SHPT_POLYGON)" }, |
679 |
|
{"c_api", (PyCFunction)shapelib_c_api, METH_NOARGS, |
680 |
|
"c_api()\n" |
681 |
|
"get C API of shapelib" }, |
682 |
|
{"type_name", (PyCFunction)shapelib_type_name, METH_VARARGS, |
683 |
|
"type_name(type)\n" |
684 |
|
"return type as string" }, |
685 |
|
{"part_type_name", (PyCFunction)shapelib_part_type_name, METH_VARARGS, |
686 |
|
"part_type_name(part_type)\n" |
687 |
|
"return part type as string" }, |
688 |
{NULL} |
{NULL} |
689 |
}; |
}; |
690 |
|
|