catatom2osm.geo.layer.base module

class catatom2osm.geo.layer.base.BaseLayer(path, baseName, providerLib='ogr')[fuente]

Bases: qgis._core.QgsVectorLayer

Base class for application layers.

append(layer, rename=None, resolve=None, query=None, **kwargs)[fuente]

Copy all features from layer.

Parámetros
  • layer (QgsVectorLayer) – Source layer

  • rename (dict) – Translation of attributes names

  • resolve (dict) – xlink reference fields

  • query (func) – function with args feature and kwargs that returns a boolean deciding if each feature will be included or not

  • kwargs – aditional arguments for query function

Ejemplos

>>> query = lambda feat, kwargs: feat['foo']=='bar'
Will copy only features with a value 'bar' in the field 'foo'.
>>> query = lambda feat, kwargs: layer.is_inside(feat, kwargs['zone'])
Will copy only features inside zone.

See also copy_feature().

bounding_box(expression=None)[fuente]

Return bounding box in overpass format.

Use features matching expression or all features if expression is None.

copy_feature(feature, rename=None, resolve=None)[fuente]

Return a copy of feature renaming attributes or resolving xlink references.

Parámetros
  • feature (QgsFeature) – Source feature

  • rename (dict) – Translation of attributes names

  • resolve (dict) – xlink reference fields

Ejemplos

With this:

>>> rename = {'spec': 'specification'}
>>> resolve = {
...     'PD_id': ('component_href', r'[\w\.]+PD[\.0-9]+'),
...     'TN_id': ('component_href', r'[\w\.]+TN[\.0-9]+'),
...     'AU_id': ('component_href', r'[\w\.]+AU[\.0-9]+')
... }

You get:

>>> original_attributes = ['localId', 'specification', 'component_href']
>>> original_values = [
...     '38.012.1.12.0295603CS6109N',
...     'Parcel', (
...         '(3:#ES.SDGC.PD.38.012.38570,'
...         '#ES.SDGC.TN.38.012.1,'
...         '#ES.SDGC.AU.38.012)'
...     )
... ]
>>> final_attributes = ['localId', 'spec', 'PD_id', 'TN_id', 'AU_id']
>>> final_values = [
...     '38.012.1.12.0295603CS6109N',
...     'Parcel',
...     'ES.SDGC.PD.38.012.38570',
...     'ES.SDGC.TN.38.012.1',
...     'ES.SDGC.AU.38.012'
... ]
count(expression='', unique='')[fuente]

Return number of features for this search expression.

static create_shp(name, crs, fields=<qgis._core.QgsFields object>, geom_type=6)[fuente]
static delete_shp(path)[fuente]
export(path, driver_name='ESRI Shapefile', overwrite=True, target_crs_id=None)[fuente]

Write layer to file.

Parámetros
  • path (str) – Path of the output file

  • driver_name (str) – Defaults to ESRI Shapefile.

  • overwrite (bool) – Defaults to True

  • target_crs_id (int) – Defaults to source CRS

static get_crs_transform(source_crs, target_crs)[fuente]
get_index()[fuente]

Return a QgsSpatialIndex of all features in this layer.

get_overpass_bbox(bbox)[fuente]

Transform bbox to EPSG 4326 and returns str in overpass format.

get_progressbar(description, total=None)[fuente]

Return progress bar with “description” for “total” iterations.

static get_writer(name, crs, fields=<qgis._core.QgsFields object>, geom_type=6)[fuente]
join_field(source_layer, target_field_name, join_field_name, field_names_subset, prefix='')[fuente]

Replace qgis table join mechanism.

I’m not able to work with it in standalone script mode (without GUI).

Parámetros
  • source_layer (QgsVectorLayer) – Source layer.

  • target_field_name (str) – Join field in the target layer.

  • join_fieldsName (str) – Join field in the source layer.

  • field_names_subset (list) – List of field name strings for the target layer.

  • prefix (str) – An optional prefix to add to the target fields names

reproject(target_crs=None)[fuente]

Reproject all features in this layer to a new CRS.

Parámetros

target_crs (QgsCoordinateReferenceSystem) – New CRS to apply.

search(expression='')[fuente]

Return a features iterator for this search expression.

to_osm(tags_translation=<function all_tags>, data=None, tags={}, upload='never')[fuente]

Export this layer to an Osm data set.

Parámetros
  • tags_translation (function) – Function to translate fields to tags. By defaults convert all fields.

  • data (Osm) – OSM data set to append. By default creates a new one.

  • upload (str) – upload attribute of the osm dataset, default “never”

  • tags (dict) – tags to update config.changeset_tags

Devuelve

OSM data set

Tipo del valor devuelto

Osm

translate_field(field_name, translations, clean=True)[fuente]

Transform the values of a field.

Parámetros
  • field_name (str) – Name of the field to transform

  • translations (dict) – A dictionary used to transform field values

  • clean (bool) – If true (default), delete features without translation

writeAsVectorFormat(name, driver_name, target_crs=None)[fuente]