gntools.protocol module

This module can be used to write text and features to the GEONIS Protocol (XML). The Protocol is typically used to report issues (e.g. validation) with certain features.

class gntools.protocol.Feature(table, global_id, {geometry}, {globalid_field})

Bases: object

Creates a Feature for GEONIS Protocol logging purposes.

Params:

  • table (str, unicode):

    The full path to the table or feature class that contains the logged feature.

  • global_id (str, unicode, gpf.tools.guids.Guid):

    GlobalID value of the logged feature.

  • geometry (str, arcpy.Geometry):

    Esri Geometry instance or EsriJSON string.

Keyword params:

  • globalid_field (str, unicode):

    If the GlobalID field has a different name, specify it using this option.

fid

Returns the (validated) GlobalID of the current Feature feature.

Return type:str
write_elements(parent_element)

Adds a <feature> XML element to the parent_element based on the current Feature values.

Parameters:parent_element – Element
class gntools.protocol.Logger

Bases: object

Logger class to write GEONIS XML protocols (e.g. for validations, reporting etc.).

Note

Because Logger is a singleton, instantiating it multiple times will always refer to the same object. The Logger stores an XML root element, to which all Logger instances write. Once an instance has called the flush() method, the XML root element will be reset. Calling flush() will set the project name and path and write out the XML file. After this call, remaining Logger instances or new ones will simply write into a new XML root element.

blank()

Logs a blank Entry to the GEONIS XML protocol (appears as a blank line in the protocol window).

error(message, gn_feature=None)

Logs an error to the GEONIS XML protocol, optionally accompanied by a feature.

Parameters:
  • message (str, unicode) – Text message to log.
  • gn_feature (gntools.protocol.Feature) – Feature object to add to the log entry.
flush(output_path, project_path, encoding=None)

Flushes the root element buffer and writes the GEONIS Protocol to an XML file.

Once this function is called, the root element has been reset and you can reuse the Logger for another project or the same one, or you can exit your application.

Parameters:
  • output_path (str, unicode) – The full path to the output protocol XML that should be written.
  • project_path (str, unicode) – The full path to the GEONIS project to which the protocol applies.
  • encoding (str, unicode) – Optional encoding to use for the protocol file (default = ISO-8859-1).

Warning

The user must have write access in the specified output directory.

header(message, gn_feature=None)

Logs a header to the GEONIS XML protocol, optionally accompanied by a feature.

Parameters:
  • message (str, unicode) – Text message to log.
  • gn_feature (gntools.protocol.Feature) – Feature object to add to the log entry.
info(message, gn_feature=None)

Logs an info notice to the GEONIS XML protocol, optionally accompanied by a feature.

Parameters:
  • message (str, unicode) – Text message to log.
  • gn_feature (gntools.protocol.Feature) – Feature object to add to the log entry.
message(message, gn_feature=None)

Logs a basic message to the GEONIS XML protocol, optionally accompanied by a feature.

Parameters:
  • message (str, unicode) – Text message to log.
  • gn_feature (gntools.protocol.Feature) – Feature object to add to the log entry.
subheader(message, gn_feature=None)

Logs a subheader to the GEONIS XML protocol, optionally accompanied by a feature.

Parameters:
  • message (str, unicode) – Text message to log.
  • gn_feature (gntools.protocol.Feature) – Feature object to add to the log entry.
warn(message, gn_feature=None)

Logs a warning to the GEONIS XML protocol, optionally accompanied by a feature.

Parameters:
  • message (str, unicode) – Text message to log.
  • gn_feature (gntools.protocol.Feature) – Feature object to add to the log entry.