forked from pnorman/ogr2osm-translations
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlayer.py
36 lines (26 loc) · 1019 Bytes
/
layer.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# -*- coding: utf-8 -*-
'''
This translation file adds a __LAYER field to a datasource before translating it
Copyright (c) 2012 Paul Norman
<penorman@mac.com>
Released under the MIT license: http://opensource.org/licenses/mit-license.php
'''
from osgeo import ogr
import ogr2osm
class LayerTranslation(ogr2osm.TranslationBase):
def filter_layer(self, layer):
if not layer:
return
layername = layer.GetName()
# Add a __LAYER field
field = ogr.FieldDefn('__LAYER', ogr.OFTString)
field.SetWidth(len(layername))
layer.CreateField(field)
# Set the __LAYER field to the name of the current layer
for j in range(layer.GetFeatureCount()):
ogrfeature = layer.GetNextFeature()
ogrfeature.SetField('__LAYER', layername)
layer.SetFeature(ogrfeature)
# Reset the layer's read position so features are read later on
layer.ResetReading()
return layer