Copy

Copying a LayersSet is straightforward. Without parameters, a copy in ‘Memory’ is created.

lrs0 = LayersReader('D:/tmp/DEU_adm_shp/DEU_adm4.shp')
lrs1 = lrs0.copy()  # the copy can be modified
lrs1.show(max_rows=6)
          geom ID_0  ISO   NAME_0 ID_1             NAME_1 ID_2           NAME_2  ID_3            NAME_3   ID_4             NAME_4 VARNAME_4 CCN_4         CCA_4    TYPE_4 ENGTYPE_4
0      Polygon   86  DEU  Germany    1  Baden-Württemberg    1  Alb-Donau-Kreis     1      Allmendingen      1       Allmendingen      None     0  084255001002  Gemeinde      Town
1      Polygon   86  DEU  Germany    1  Baden-Württemberg    1  Alb-Donau-Kreis     1      Allmendingen      2            Altheim      None     0  084255001004  Gemeinde      Town
2      Polygon   86  DEU  Germany    1  Baden-Württemberg    1  Alb-Donau-Kreis     2        Blaubeuren      3          Berghülen      None     0  084255002017  Gemeinde      Town
...        ...  ...  ...      ...  ...                ...  ...              ...   ...               ...    ...                ...       ...   ...           ...       ...       ...
11299  Polygon   86  DEU  Germany   16          Thüringen  402    Weimarer Land  4672  Nordkreis Weimar  11300  Vippachedelhausen      None     0  160715013092  Gemeinde      Town
11300  Polygon   86  DEU  Germany   16          Thüringen  402    Weimarer Land  4672  Nordkreis Weimar  11301          Wohlsborn      None     0  160715013097  Gemeinde      Town
11301  Polygon   86  DEU  Germany   16          Thüringen  403           Weimar  4673            Weimar  11302             Weimar      None     0  160550000000     Stadt      Town

You can select fields to copy with the parameter ofields (output fields) followed by the layer number. ofields has a list field names.

In the following example, all fields from all layers are copied (in this case there is only one layer, since it is a shapefile):

lrs0 = LayersReader('D:/tmp/girs/DEU_adm_shp/DEU_adm4.shp')
lrs1 = lrs0.copy()  # the copy can be modified

In the next example, only fields ‘NAME_4’ and ‘TYPE_4’ from the first layer are copied. If there were other layers, all their fields would be copied:

lrs0 = LayersReader('D:/tmp/girs/DEU_adm_shp/DEU_adm4.shp')
lrs1 = lrs0.copy(target='', ofields0=['NAME_4', 'TYPE_4'])  # fields to keep
lrs1.show(max_rows=10)
          geom             NAME_4    TYPE_4
0      Polygon       Allmendingen  Gemeinde
1      Polygon            Altheim  Gemeinde
2      Polygon          Berghülen  Gemeinde
...        ...                ...       ...
11299  Polygon  Vippachedelhausen  Gemeinde
11300  Polygon          Wohlsborn  Gemeinde
11301  Polygon             Weimar     Stadt

The copy is an instance of LayersWriter, which can be further modified. In order to save the copy, a target must be defined:

lrs0 = LayersReader('D:/tmp/DEU_adm_shp/DEU_adm4.shp')
lrs1 = lrs0.copy(target='D:/tmp/DEU_adm_shp/DEU_adm4_copy.shp')  # the copy can be modified