Skip to content

Commit e3945eb

Browse files
authored
Merge pull request #12199 from dbaston/python-create-vector
SWIG: Add Driver.CreateVector
2 parents f9b1d3c + 0d792b7 commit e3945eb

File tree

3 files changed

+33
-3
lines changed

3 files changed

+33
-3
lines changed

autotest/ogr/ogr_shape.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6129,9 +6129,7 @@ def test_ogr_shape_arrow_stream_fid_optim(tmp_vsimem):
61296129
def test_ogr_shape_logical_field(tmp_vsimem):
61306130

61316131
filename = tmp_vsimem / "test_ogr_shape_logical_field.shp"
6132-
ds = gdal.GetDriverByName("ESRI Shapefile").Create(
6133-
filename, 0, 0, 0, gdal.GDT_Unknown
6134-
)
6132+
ds = gdal.GetDriverByName("ESRI Shapefile").CreateVector(filename)
61356133
lyr = ds.CreateLayer("test")
61366134
fld_defn = ogr.FieldDefn("bool_field", ogr.OFTInteger)
61376135
fld_defn.SetSubType(ogr.OFSTBoolean)

swig/include/Driver.i

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,15 @@ public:
5757
return ds;
5858
}
5959

60+
%newobject Create;
61+
#ifndef SWIGJAVA
62+
%feature( "kwargs" ) CreateVector;
63+
#endif
64+
GDALDatasetShadow *CreateVector(const char *utf8_path, char **options = 0) {
65+
GDALDatasetShadow* ds = (GDALDatasetShadow*) GDALCreate(self, utf8_path, 0, 0, 0, GDT_Unknown, options);
66+
return ds;
67+
}
68+
6069
%newobject CreateMultiDimensional;
6170
#ifndef SWIGJAVA
6271
%feature( "kwargs" ) CreateMultiDimensional;

swig/include/python/docs/gdal_driver_docs.i

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,29 @@ Examples
125125
126126
";
127127

128+
%feature("docstring") CreateVector "
129+
130+
Create a new vector :py:class:`Dataset` with this driver.
131+
This method is an alias for ``Create(name, 0, 0, 0, gdal.GDT_Unknown)``.
132+
133+
Parameters
134+
----------
135+
utf8_path : str
136+
Path of the dataset to create.
137+
138+
Returns
139+
-------
140+
Dataset
141+
142+
Examples
143+
--------
144+
>>> with gdal.GetDriverByName('ESRI Shapefile').CreateVector('test.shp') as ds:
145+
... print(ds.GetLayerCount())
146+
...
147+
0
148+
149+
";
150+
128151
%feature("docstring") Delete "
129152
Delete a :py:class:`Dataset`.
130153
See :cpp:func:`GDALDriver::Delete`.

0 commit comments

Comments
 (0)