-
Notifications
You must be signed in to change notification settings - Fork 96
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add iterator for fields in feature add accessors for additional ogr field types. FieldValueIterator skip unknown types but does not terminate until field count reached
- Loading branch information
Showing
9 changed files
with
354 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
#!/usr/bin/env python3 | ||
|
||
from osgeo import ogr, osr | ||
import os.path | ||
|
||
c_dir = os.path.dirname(os.path.realpath(__file__)) | ||
|
||
|
||
def create_n_layer_sqlite_ds(name: str, n_layers: int, n_features: int): | ||
driver_name = "SQLite" | ||
driver = ogr.GetDriverByName(driver_name) | ||
|
||
file_name = os.path.join(c_dir, name) | ||
if os.path.exists(file_name): | ||
os.remove(file_name) | ||
|
||
source = driver.CreateDataSource(file_name) | ||
|
||
srs = osr.SpatialReference() | ||
srs.ImportFromEPSG(4326) | ||
|
||
for nl in range(0, n_layers): | ||
# create a layer | ||
layer = source.CreateLayer("layer_{}".format(nl), srs, geom_type=ogr.wkbPoint) | ||
|
||
# create a field "id" in the layer | ||
id_field = ogr.FieldDefn("id", ogr.OFTInteger) | ||
layer.CreateField(id_field) | ||
|
||
for ni in range(0, n_features): | ||
# add a feature to the layer | ||
feature_def = layer.GetLayerDefn() | ||
feature = ogr.Feature(feature_def) | ||
|
||
# add a point to the feature | ||
point = ogr.Geometry(ogr.wkbPoint) | ||
point.AddPoint(x=47.0 + nl, y=-122.0 + nl) | ||
feature.SetGeometry(point) | ||
|
||
# add the feature to the layer | ||
layer.CreateFeature(feature) | ||
|
||
# add a field | ||
feature.SetField("id", nl) | ||
|
||
source.Destroy() | ||
|
||
|
||
if __name__ == '__main__': | ||
create_n_layer_sqlite_ds(name="three_layer_ds.s3db", n_layers=3, n_features=3) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
{ | ||
"features": [ | ||
{ | ||
"geometry": { | ||
"coordinates": [ -122.4335161, 47.3136322 ], | ||
"type": "Point" | ||
}, | ||
"properties": { | ||
"a_string_list": [ "a", "list", "of", "strings"], | ||
"a_real_list": [ 0.1, 0.2 ], | ||
"an_int_list": [ 1, 2 ], | ||
"a_long_list": [ 5000000000, 6000000000 ] | ||
}, | ||
"type": "Feature" | ||
} | ||
], | ||
"type": "FeatureCollection" | ||
} |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.