User:Kannix/ENC iENC

From OpenStreetMap Wiki
Jump to navigation Jump to search

Some info about ENC and i(nland)ENC:

basics

  • "IHO S-57 format is a vector interchange format used for maritime charts. The only currently common profile is known as ENC (Electronic Nautical Chart). The format is promulgated by the IHO (International Hydrographic Organization)." [1]
  • iENC extend the standard S-57 objects/attribute-set by features starting with Code>= 17000. As further distinction, these feature's and attribute's acronyms are written in lowercase letters.

viewing

extracting data

  • ogr command line tool
  • for convenience, FWTools suite and OSGeo4W contain the ogr-tools
  • to extract iENC features, replace the original ogr-translation-tables with an (iENC)extended version like openCPN source:
    • s57attributes.csv
    • s57expectedinput.csv
    • s57objectclasses.csv
  • some ogr2ogr formats support georeferencing, some do not

Ogr2osm

ienc_bridge.py

 from osgeo import ogr
 import re
 import urllib

 #A translation function for ienc bridge

 def filterLayer(layer):
     if not layer:
         return
     if layer.GetName() in ('bridge'):
         print 'processing layer: ' + layer.GetName()
         return layer
     else:
         print 'ignored layer: ' + layer.GetName()
         return

 def filterTags(attrs):
     if not attrs:
         return
     tags = {}

     if attrs['OBJL'] == '17011':
       if 'OBJNAM' in attrs:
         tags['seamark:name'] = attrs['OBJNAM']

       if 'HORCLR' in attrs:
         tags['seamark:bridge:clearance_width'] = attrs['HORCLR']

       if 'VERCLR' in attrs:
         tags['seamark:bridge:clearance_height'] = attrs['VERCLR']

       if 'VERCCL' in attrs:
         tags['seamark:bridge:clearance_height_closed'] = attrs['VERCCL']

       if 'VERCOP' in attrs:
         tags['seamark:bridge:clearance_height_open'] = attrs['VERCOP']

       if attrs['OBJL'] == '17011':
         tags['seamark:type'] = 'bridge'

       if attrs['CATBRG'] == '1':
         tags['seamark:bridge:category'] = 'fixed'
       elif attrs['CATBRG'] == '3':
         tags['seamark:bridge:category'] = 'swing'
       elif attrs['CATBRG'] == '4':
         tags['seamark:bridge:category'] = 'lifting'
       elif attrs['CATBRG'] == '5':
         tags['seamark:bridge:category'] = 'bascule'
       elif attrs['CATBRG'] == '9':
         tags['seamark:bridge:category'] = 'foot'
       elif attrs['CATBRG'] == '12':
         tags['seamark:bridge:category'] = 'suspension'

     #print(attrs)
     return tags
  • place both .py-files (ogr2osm.py and SimpleXMLWriter.py), 'test.000'-iENC-file and ienc_bridge.py-translation-file in your OSGeo4W working-directory
  • start OSGeo4W shell
  • command:
python ogr2osm.py -o test.osm -t ienc_bridge.py test.000
  • works on NL-iENC files
  • on DE-iENCs, there are decoding errors:
Line 998 in ogr2osm.py workaround:
decode(options.encoding) > decode(options.encoding, 'ignore')

ienc_notmrk.py

 from osgeo import ogr
 import re
 import urllib
 
 # A translation function for ienc notmrk
 # ver. 2013-01-29
 # bnkwtw and CONDTN not openCPN s57*.csv!
 
 def filterLayer(layer):
     if not layer:
         return
     if layer.GetName() in ('notmrk'):
         print 'processing layer: ' + layer.GetName()
         return layer
     else:
         print 'ignored layer: ' + layer.GetName()
         return
 
 def filterTags(attrs):
     if not attrs:
         return
     tags = {}
 
     if attrs['OBJL'] == '17050':
 
       if attrs['OBJL'] == '17050':
         tags['seamark:type'] = 'notice'
 
       if attrs['addmrk'] != :
         listTempAddition = []
         tempAddMrk =attrs['addmrk'].split(',')
         for t in tempAddMrk:
           if t == '1':
             tempAddition = 'top_board'
           elif t == '2':
             tempAddition = 'bottom_board'
           elif t == '3':
             tempAddition = 'right_triangle'
           elif t == '4':
             tempAddition = 'left_triangle'
           elif t == '5':
             tempAddition = 'bottom_triangle'
           listTempAddition.append(tempAddition)
         tags['seamark:notice:addition'] = ';'.join(listTempAddition)
 
       if attrs['catnmk'] == '1':
         tags['seamark:notice:category'] = 'no_entry'
       elif attrs['catnmk'] == '2':
         tags['seamark:notice:category'] = 'closed_area'
       elif attrs['catnmk'] == '3':
         tags['seamark:notice:category'] = 'no_overtaking'
       elif attrs['catnmk'] == '4':
         tags['seamark:notice:category'] = 'no_convoy_overtaking'
       elif attrs['catnmk'] == '5':
         tags['seamark:notice:category'] = 'no_passing'
       elif attrs['catnmk'] == '6':
         tags['seamark:notice:category'] = 'no_berthing'
       elif attrs['catnmk'] == '7':
         tags['seamark:notice:category'] = 'no_berthing_lateral_limit'
       elif attrs['catnmk'] == '8':
         tags['seamark:notice:category'] = 'no_anchoring'
       elif attrs['catnmk'] == '9':
         tags['seamark:notice:category'] = 'no_mooring'
       elif attrs['catnmk'] == '10':
         tags['seamark:notice:category'] = 'no_turning'
       elif attrs['catnmk'] == '11':
         tags['seamark:notice:category'] = 'no_wash'
       elif attrs['catnmk'] == '12':
         tags['seamark:notice:category'] = 'no_passage_left'
       elif attrs['catnmk'] == '13':
         tags['seamark:notice:category'] = 'no_passage_right'
       elif attrs['catnmk'] == '14':
         tags['seamark:notice:category'] = 'no_motor_craft'
       elif attrs['catnmk'] == '15':
         tags['seamark:notice:category'] = 'no_sport_craft'
       elif attrs['catnmk'] == '16':
         tags['seamark:notice:category'] = 'no_waterskiing'
       elif attrs['catnmk'] == '17':
         tags['seamark:notice:category'] = 'no_sailing_craft'
       elif attrs['catnmk'] == '18':
         tags['seamark:notice:category'] = 'no_unpowered_craft'
       elif attrs['catnmk'] == '19':
         tags['seamark:notice:category'] = 'no_sailboards'
       elif attrs['catnmk'] == '20':
         tags['seamark:notice:category'] = 'no_waterbikes'
       elif attrs['catnmk'] == '21':
         tags['seamark:notice:category'] = 'no_high_speeds'
       elif attrs['catnmk'] == '22':
         tags['seamark:notice:category'] = 'no_launching_beaching'
       elif attrs['catnmk'] == '23':
         tags['seamark:notice:category'] = 'move_to_left'
       elif attrs['catnmk'] == '24':
         tags['seamark:notice:category'] = 'move_to_right'
       elif attrs['catnmk'] == '25':
         tags['seamark:notice:category'] = 'move_to_port'
       elif attrs['catnmk'] == '26':
         tags['seamark:notice:category'] = 'move_to_starboard'
       elif attrs['catnmk'] == '27':
         tags['seamark:notice:category'] = 'keep_to_port'
       elif attrs['catnmk'] == '28':
         tags['seamark:notice:category'] = 'keep_to_starboard'
       elif attrs['catnmk'] == '29':
         tags['seamark:notice:category'] = 'cross_to_port'
       elif attrs['catnmk'] == '30':
         tags['seamark:notice:category'] = 'cross_to_starboard'
       elif attrs['catnmk'] == '31':
         tags['seamark:notice:category'] = 'stop'
       elif attrs['catnmk'] == '32':
         tags['seamark:notice:category'] = 'speed_limit'
       elif attrs['catnmk'] == '33':
         tags['seamark:notice:category'] = 'sound_horn'
       elif attrs['catnmk'] == '34':
         tags['seamark:notice:category'] = 'keep_lookout'
       elif attrs['catnmk'] == '35':
         tags['seamark:notice:category'] = 'give_way_junction'
       elif attrs['catnmk'] == '36':
         tags['seamark:notice:category'] = 'give_way_crossing'
       elif attrs['catnmk'] == '37':
         tags['seamark:notice:category'] = 'make_radio_contact'
       elif attrs['catnmk'] == '38':
         tags['seamark:notice:category'] = 'limited_depth'
       elif attrs['catnmk'] == '39':
         tags['seamark:notice:category'] = 'limited_headroom'
       elif attrs['catnmk'] == '40':
         tags['seamark:notice:category'] = 'limited_width'
       elif attrs['catnmk'] == '41':
         tags['seamark:notice:category'] = 'navigation_restrictions'
       elif attrs['catnmk'] == '42':
         tags['seamark:notice:category'] = 'channel_distance_left'
       elif attrs['catnmk'] == '43':
         tags['seamark:notice:category'] = 'channel_distance_right'
       elif attrs['catnmk'] == '44':
         tags['seamark:notice:category'] = 'channel_two_way'
       elif attrs['catnmk'] == '45':
         tags['seamark:notice:category'] = 'channel_one_way'
       elif attrs['catnmk'] == '46':
         tags['seamark:notice:category'] = 'opening_to_right'
       elif attrs['catnmk'] == '47':
         tags['seamark:notice:category'] = 'opening_to_left'
       elif attrs['catnmk'] == '48':
         tags['seamark:notice:category'] = 'proceed_to_left'
       elif attrs['catnmk'] == '49':
         tags['seamark:notice:category'] = 'proceed_to_right'
       elif attrs['catnmk'] == '50':
         tags['seamark:notice:category'] = 'entry_permitted'
       elif attrs['catnmk'] == '51':
         tags['seamark:notice:category'] = 'overhead_cable'
       elif attrs['catnmk'] == '52':
         tags['seamark:notice:category'] = 'weir'
       elif attrs['catnmk'] == '53':
         tags['seamark:notice:category'] = 'ferry_non_independent'
       elif attrs['catnmk'] == '54':
         tags['seamark:notice:category'] = 'ferry_independent'
       elif attrs['catnmk'] == '55':
         tags['seamark:notice:category'] = 'berthing_permitted '
       elif attrs['catnmk'] == '56':
         tags['seamark:notice:category'] = 'berthing_lateral_limit'
       elif attrs['catnmk'] == '57':
         tags['seamark:notice:category'] = 'berthing_lateral_limits'
       elif attrs['catnmk'] == '58':
         tags['seamark:notice:category'] = 'berthing_rafting_limit'
       elif attrs['catnmk'] == '59':
         tags['seamark:notice:category'] = 'berthing_unmarked_pushing'
       elif attrs['catnmk'] == '60':
         tags['seamark:notice:category'] = 'berthing_marked_pushing_1'
       elif attrs['catnmk'] == '61':
         tags['seamark:notice:category'] = 'berthing_marked_pushing_2'
       elif attrs['catnmk'] == '62':
         tags['seamark:notice:category'] = 'berthing_marked_pushing_3'
       elif attrs['catnmk'] == '63':
         tags['seamark:notice:category'] = 'berthing_unmarked_non_pushing'
       elif attrs['catnmk'] == '64':
         tags['seamark:notice:category'] = 'berthing_marked_non_pushing_1'
       elif attrs['catnmk'] == '65':
         tags['seamark:notice:category'] = 'berthing_marked_non_pushing_2'
       elif attrs['catnmk'] == '66':
         tags['seamark:notice:category'] = 'berthing_marked_non_pushing_3'
       elif attrs['catnmk'] == '67':
         tags['seamark:notice:category'] = 'berthing_unmarked'
       elif attrs['catnmk'] == '68':
         tags['seamark:notice:category'] = 'berthing_marked_1 '
       elif attrs['catnmk'] == '69':
         tags['seamark:notice:category'] = 'berthing_marked_2'
       elif attrs['catnmk'] == '70':
         tags['seamark:notice:category'] = 'berthing_marked_3 '
       elif attrs['catnmk'] == '71':
         tags['seamark:notice:category'] = 'anchoring_permitted'
       elif attrs['catnmk'] == '72':
         tags['seamark:notice:category'] = 'mooring_permitted'
       elif attrs['catnmk'] == '73':
         tags['seamark:notice:category'] = 'vehicle_loading_berth'
       elif attrs['catnmk'] == '74':
         tags['seamark:notice:category'] = 'turning_area'
       elif attrs['catnmk'] == '75':
         tags['seamark:notice:category'] = 'secondary_waterway_crossing'
       elif attrs['catnmk'] == '76':
         tags['seamark:notice:category'] = 'secondary_waterway_right'
       elif attrs['catnmk'] == '77':
         tags['seamark:notice:category'] = 'secondary_waterway_left'
       elif attrs['catnmk'] == '78':
         tags['seamark:notice:category'] = 'main_waterway_right_secondary_ahead'
       elif attrs['catnmk'] == '79':
         tags['seamark:notice:category'] = 'main_waterway_left_secondary_ahead'
       elif attrs['catnmk'] == '80':
         tags['seamark:notice:category'] = 'main_waterway_right_secondary_left'
       elif attrs['catnmk'] == '81':
         tags['seamark:notice:category'] = 'main_waterway_left_secondary_right'
       elif attrs['catnmk'] == '82':
         tags['seamark:notice:category'] = 'main_waterway_right_secondary_ahead_left'
       elif attrs['catnmk'] == '83':
         tags['seamark:notice:category'] = 'main_waterway_left_secondary_ahead_right'
       elif attrs['catnmk'] == '84':
         tags['seamark:notice:category'] = 'main_waterway_crossing'
       elif attrs['catnmk'] == '85':
         tags['seamark:notice:category'] = 'main_waterway_junction'
       elif attrs['catnmk'] == '86':
         tags['seamark:notice:category'] = 'main_waterway_ahead_right'
       elif attrs['catnmk'] == '87':
         tags['seamark:notice:category'] = 'main_waterway_ahead_left'
       elif attrs['catnmk'] == '88':
         tags['seamark:notice:category'] = 'main_waterway_ahead_right_secondary_left'
       elif attrs['catnmk'] == '89':
         tags['seamark:notice:category'] = 'main_waterway_ahead_left_secondary_right'
       elif attrs['catnmk'] == '90':
         tags['seamark:notice:category'] = 'prohibition_ends'
       elif attrs['catnmk'] == '91':
         tags['seamark:notice:category'] = 'drinking_water'
       elif attrs['catnmk'] == '92':
         tags['seamark:notice:category'] = 'telephone'
       elif attrs['catnmk'] == '93':
         tags['seamark:notice:category'] = 'motor_craft_permitted'
       elif attrs['catnmk'] == '94':
         tags['seamark:notice:category'] = 'sport_craft_permitted'
       elif attrs['catnmk'] == '95':
         tags['seamark:notice:category'] = 'waterskiing_permitted'
       elif attrs['catnmk'] == '96':
         tags['seamark:notice:category'] = 'sailing_craft_permitted'
       elif attrs['catnmk'] == '97':
         tags['seamark:notice:category'] = 'unpowered_craft_permitted'
       elif attrs['catnmk'] == '98':
         tags['seamark:notice:category'] = 'sailboards_permitted'
       elif attrs['catnmk'] == '99':
         tags['seamark:notice:category'] = 'radio_information'
       elif attrs['catnmk'] == '100':
         tags['seamark:notice:category'] = 'waterbikes_permitted'
       elif attrs['catnmk'] == '101':
         tags['seamark:notice:category'] = 'high_speeds_permitted'
       elif attrs['catnmk'] == '102':
         tags['seamark:notice:category'] = 'launching_beaching_permitted'
 
       if attrs['dirimp'] == '1':
         tags['seamark:notice:direction'] = 'upstream'
       elif attrs['dirimp'] == '2':
         tags['seamark:notice:direction'] = 'downstream'
       elif attrs['dirimp'] == '3':
         tags['seamark:notice:direction'] = 'left_bank'
       elif attrs['dirimp'] == '4':
         tags['seamark:notice:direction'] = 'right_bank'
       elif attrs['dirimp'] == '5':
         tags['seamark:notice:direction'] = 'to_harbor'
 
       if attrs['disipd'] != :
         tags['seamark:notice:distance_down'] = attrs['disipd']
 
       if attrs['disipu'] != :
         tags['seamark:notice:distance_up'] = attrs['disipu']
 
       if attrs['disbk1'] != :
         tags['seamark:notice:distance_start'] = attrs['disbk1']
 
       if attrs['disbk2'] != :
         tags['seamark:notice:distance_end'] = attrs['disbk2']
 
       if attrs['fnctnm'] == '1':
         tags['seamark:notice:function'] = 'prohibition'
       elif attrs['fnctnm'] == '2':
         tags['seamark:notice:function'] = 'regulation'
       elif attrs['fnctnm'] == '3':
         tags['seamark:notice:function'] = 'restriction'
       elif attrs['fnctnm'] == '4':
         tags['seamark:notice:function'] = 'recommendation'
       elif attrs['fnctnm'] == '5':
         tags['seamark:notice:function'] = 'information'
 
       if attrs['marsys'] == '1':
         tags['seamark:notice:system'] = 'iala-a'
       elif attrs['marsys'] == '2':
         tags['seamark:notice:system'] = 'iala-b'
       elif attrs['marsys'] == '9':
         tags['seamark:notice:system'] = 'none'
       elif attrs['marsys'] == '10':
         tags['seamark:notice:system'] = 'other'
       elif attrs['marsys'] == '11':
         tags['seamark:notice:system'] = 'cevni'
       elif attrs['marsys'] == '12':
         tags['seamark:notice:system'] = 'riwr'
       elif attrs['marsys'] == '13':
         tags['seamark:notice:system'] = 'bniwr2'
       elif attrs['marsys'] == '14':
         tags['seamark:notice:system'] = 'bniwr'
       elif attrs['marsys'] == '15':
         tags['seamark:notice:system'] = 'ppwbc'
 
       if attrs['ORIENT'] != :
         tags['seamark:notice:orientation'] = attrs['ORIENT']
 
       if attrs['STATUS'] == '2':
         tags['seamark:notice:status'] = 'occasional'
       elif attrs['STATUS'] == '3':
         tags['seamark:notice:status'] = 'recommended'
       elif attrs['STATUS'] == '4':
         tags['seamark:notice:status'] = 'not_in_use'
       elif attrs['STATUS'] == '8':
         tags['seamark:notice:status'] = 'private'
       elif attrs['STATUS'] == '9':
         tags['seamark:notice:status'] = 'mandatory'
       elif attrs['STATUS'] == '12':
         tags['seamark:notice:status'] = 'illuminated'
       elif attrs['STATUS'] == '14':
         tags['seamark:notice:status'] = 'public'
       elif attrs['STATUS'] == '16':
         tags['seamark:notice:status'] = 'watched'
       elif attrs['STATUS'] == '17':
         tags['seamark:notice:status'] = 'un-watched'
       elif attrs['STATUS'] == '18':
         tags['seamark:notice:status'] = 'existence_doubtful'
 
       if attrs['bnkwtw'] == '1':
         tags['seamark:notice:bank'] = 'left'
       elif attrs['bnkwtw'] == '2':
         tags['seamark:notice:bank'] = 'right'
 
       if attrs['CONDTN'] == '1':
         tags['seamark:notice:condition'] = 'under_construction'
       elif attrs['CONDTN'] == '2':
         tags['seamark:notice:condition'] = 'ruined'
       elif attrs['CONDTN'] == '3':
         tags['seamark:notice:condition'] = 'under_reclamation'
       elif attrs['CONDTN'] == '4':
         tags['seamark:notice:condition'] = 'wingless'
       elif attrs['CONDTN'] == '5':
         tags['seamark:notice:condition'] = 'planned_construction'
 
       if attrs['OBJNAM'] != :
         tags['seamark:notice:name'] = attrs['OBJNAM']
 
       if attrs['INFORM'] != :
         tags['seamark:notice:information'] = attrs['INFORM']
 
     #print(attrs)
     return tags


  • place both .py-files (ogr2osm.py and SimpleXMLWriter.py), 'test.000'-iENC-file and ienc_notmrk.py-translation-file in your OSGeo4W working-directory
  • start OSGeo4W shell
  • command:
python ogr2osm.py -o test.osm -t ienc_notmrk.py test.000
  • works on NL-iENC files
  • not tested on DE iENC-files yet

references