Class TagTranslator

  • All Implemented Interfaces:
    AutoCloseable

    public class TagTranslator
    extends Object
    implements AutoCloseable
    Easily translate your textual tags and roles to OSHDB's internal representation (encoded as integers) and vice versa.

    This class handles missing/not-found data in the following ways:

    • for (tag/role) strings that cannot be found in a keytable, the tagtranslator will generate a (temporary, internal and negative) id which can afterwards be resolved back to the input string when using the same tagtranslator object.
    • for ids that are not found neither in the keytable nor the tagtranslator's cache, a runtime exception is thrown
    • Constructor Detail

      • TagTranslator

        public TagTranslator​(Connection conn)
                      throws OSHDBKeytablesNotFoundException
        A TagTranslator for a specific DB-Connection. It has its own internal cache to speed up searching.
        Parameters:
        conn - a connection to a database (containing oshdb keytables).
        Throws:
        OSHDBKeytablesNotFoundException - if the supplied database doesn't contain the required "keyTables" tables
    • Method Detail

      • getOSHDBTagKeyOf

        public OSHDBTagKey getOSHDBTagKeyOf​(String key)
        Get oshdb's internal representation of a tag key (string).
        Parameters:
        key - the tag key as a string
        Returns:
        the corresponding oshdb representation of this key
      • getOSHDBTagKeyOf

        public OSHDBTagKey getOSHDBTagKeyOf​(OSMTagKey key)
        Get oshdb's internal representation of a tag key.
        Parameters:
        key - the tag key as an OSMTagKey object
        Returns:
        the corresponding oshdb representation of this key
      • getOSMTagKeyOf

        public OSMTagKey getOSMTagKeyOf​(int key)
        Get a tag key's string representation from oshdb's internal data format.
        Parameters:
        key - the tag key (represented as an integer)
        Returns:
        the textual representation of this tag key
        Throws:
        OSHDBTagOrRoleNotFoundException - if the given tag key cannot be found
      • getOSMTagKeyOf

        public OSMTagKey getOSMTagKeyOf​(OSHDBTagKey key)
        Get a tag key's string representation from oshdb's internal data format.
        Parameters:
        key - the tag key (as an OSHDBTagKey object)
        Returns:
        the textual representation of this tag key
        Throws:
        OSHDBTagOrRoleNotFoundException - if the given tag key cannot be found
      • getOSHDBTagOf

        public OSHDBTag getOSHDBTagOf​(String key,
                                      String value)
        Get oshdb's internal representation of a tag (key-value string pair).
        Parameters:
        key - the (string) key of the tag
        value - the (string) value of the tag
        Returns:
        the corresponding oshdb representation of this tag
      • getOSHDBTagOf

        public OSHDBTag getOSHDBTagOf​(OSMTag tag)
        Get oshdb's internal representation of a tag (key-value pair).
        Parameters:
        tag - a key-value pair as an OSMTag object
        Returns:
        the corresponding oshdb representation of this tag
      • getOSMTagOf

        public OSMTag getOSMTagOf​(int key,
                                  int value)
        Get a tag's string representation from oshdb's internal data format.
        Parameters:
        key - the key of the tag (represented as an integer)
        value - the value of the tag (represented as an integer)
        Returns:
        the textual representation of this tag
        Throws:
        OSHDBTagOrRoleNotFoundException - if the given tag cannot be found
      • getOSMTagOf

        public OSMTag getOSMTagOf​(OSHDBTag tag)
        Get a tag's string representation from oshdb's internal data format.
        Parameters:
        tag - the tag (as an OSHDBTag object)
        Returns:
        the textual representation of this tag
        Throws:
        OSHDBTagOrRoleNotFoundException - if the given tag cannot be found
      • getOSHDBRoleOf

        public OSHDBRole getOSHDBRoleOf​(String role)
        Get oshdb's internal representation of a role (string).
        Parameters:
        role - the role string to fetch
        Returns:
        the corresponding oshdb representation of this role
      • getOSHDBRoleOf

        public OSHDBRole getOSHDBRoleOf​(OSMRole role)
        Get oshdb's internal representation of a role.
        Parameters:
        role - the role to fetch as an OSMRole object
        Returns:
        the corresponding oshdb representation of this role
      • getOSMRoleOf

        public OSMRole getOSMRoleOf​(int role)
        Get a role's string representation from oshdb's internal data format.
        Parameters:
        role - the role ID (represented as an integer)
        Returns:
        the textual representation of this role
        Throws:
        OSHDBTagOrRoleNotFoundException - if the given role cannot be found
      • getOSMRoleOf

        public OSMRole getOSMRoleOf​(OSHDBRole role)
        Get a role's string representation from oshdb's internal data format.
        Parameters:
        role - the role ID (as an OSHDBRole object)
        Returns:
        the textual representation of this role
        Throws:
        OSHDBTagOrRoleNotFoundException - if the given role cannot be found
      • getConnection

        public Connection getConnection()