Index: applications/editors/josm/plugins/seachart/josmtos57/src/josmtos57/Josmtos57.java
===================================================================
--- applications/editors/josm/plugins/seachart/josmtos57/src/josmtos57/Josmtos57.java	(revision 31721)
+++ applications/editors/josm/plugins/seachart/josmtos57/src/josmtos57/Josmtos57.java	(revision 31722)
@@ -11,4 +11,5 @@
 
 import java.io.*;
+import java.util.HashMap;
 import java.util.Scanner;
 import java.util.zip.CRC32;
@@ -60,4 +61,5 @@
 	static S57map map;
 	static byte[] buf;
+	static HashMap<String, String> meta;
 	
 	public static void main(String[] args) throws IOException {
@@ -72,7 +74,10 @@
 		try {
 			Scanner min = new Scanner(new FileInputStream(args[1]));
-			while (min.hasNext()) {
-				min.next();
-			}
+			meta = new HashMap<String, String>();
+			meta.put("FILE", args[3]);
+//			while (min.hasNext()) {
+//				String[] tokens = min.next().split("=");
+//				meta.put(tokens[0], tokens[1]);
+//			}
 			min.close();
 		} catch (IOException e) {
@@ -91,7 +96,10 @@
 		try {
 			buf = new byte[5242880];
-			idx = S57enc.encodeChart(map, buf);
+			idx = S57enc.encodeChart(map, meta, buf);
 		} catch (IndexOutOfBoundsException e) {
-			System.err.println("Output file too big (limit 5 MB)");
+			System.err.println("Output file too big (limit 5 MB) - try smaller areas");
+			System.exit(-1);
+		} catch (UnsupportedEncodingException e) {
+			System.err.println("Input data error" + e.getMessage());
 			System.exit(-1);
 		}
Index: applications/editors/josm/plugins/seachart/src/render/Rules.java
===================================================================
--- applications/editors/josm/plugins/seachart/src/render/Rules.java	(revision 31721)
+++ applications/editors/josm/plugins/seachart/src/render/Rules.java	(revision 31722)
@@ -119,4 +119,5 @@
 	}
 	
+	@SuppressWarnings("unchecked")
 	public static Enum<?> getAttEnum(Feature feature, Obj obj, int idx, Att att) {
 		ArrayList<?> list = (ArrayList<?>)getAttVal(feature, obj, idx, att);
@@ -127,4 +128,5 @@
 	}
 	
+	@SuppressWarnings("unchecked")
 	public static ArrayList<?> getAttList(Feature feature, Obj obj, int idx, Att att) {
 		ArrayList<Enum<?>> list = (ArrayList<Enum<?>>)getAttVal(feature, obj, idx, att);
@@ -137,4 +139,5 @@
 	}
 	
+	@SuppressWarnings("unchecked")
 	static Scheme getScheme(Feature feature, Obj obj) {
 		ArrayList<Color> colours = new ArrayList<Color>();
@@ -406,4 +409,5 @@
 	}
 	
+	@SuppressWarnings("unchecked")
 	private static void beacons() {
 		if ((Renderer.zoom >= 14) || ((Renderer.zoom >= 12) && ((feature.type == Obj.BCNLAT) || (feature.type == Obj.BCNCAR)))) {
@@ -451,4 +455,5 @@
 	}
 	
+	@SuppressWarnings("unchecked")
 	private static void buoys() {
 		if ((Renderer.zoom >= 14) || ((Renderer.zoom >= 12) && ((feature.type == Obj.BOYLAT) || (feature.type == Obj.BOYCAR)))) {
@@ -620,4 +625,5 @@
 	}
 	
+	@SuppressWarnings("unchecked")
 	private static void harbours() {
 		String name = getName();
@@ -737,4 +743,5 @@
 	}
 	
+	@SuppressWarnings("unchecked")
 	private static void highways() {
 		switch (feature.type) {
@@ -767,4 +774,5 @@
 	}
 	
+	@SuppressWarnings("unchecked")
 	private static void landmarks() {
 		ArrayList<CatLMK> cats = (ArrayList<CatLMK>) getAttList(feature, feature.type, 0, Att.CATLMK);
@@ -814,4 +822,5 @@
 	}
 
+	@SuppressWarnings("unchecked")
 	private static void marinas() {
 		if (Renderer.zoom >= 16) {
@@ -870,6 +879,6 @@
 			}
 			MarSYS sys = MarSYS.SYS_CEVN;
-			BnkWTW bnk = BnkWTW.BWW_UNKN;
-			AttVal att = feature.atts.get(Att.MARSYS);
+//			BnkWTW bnk = BnkWTW.BWW_UNKN;
+			AttVal<?> att = feature.atts.get(Att.MARSYS);
 			if (att != null) sys = (MarSYS)att.val;
 			ObjTab objs = feature.objs.get(Obj.NOTMRK);
@@ -968,4 +977,5 @@
 	}
 
+	@SuppressWarnings("unchecked")
 	private static void platforms() {
 		ArrayList<CatOFP> cats = (ArrayList<CatOFP>) getAttList(feature, Obj.OFSPLF, 0, Att.CATOFP);
@@ -1020,4 +1030,5 @@
 	}
 
+	@SuppressWarnings("unchecked")
 	private static void shoreline() {
 		CatSLC cat = (CatSLC) getAttEnum(feature, feature.type, 0, Att.CATSLC);
@@ -1060,4 +1071,5 @@
 	}
 
+	@SuppressWarnings("unchecked")
 	private static void stations() {
 		if (Renderer.zoom >= 14) {
Index: applications/editors/josm/plugins/seachart/src/render/Signals.java
===================================================================
--- applications/editors/josm/plugins/seachart/src/render/Signals.java	(revision 31721)
+++ applications/editors/josm/plugins/seachart/src/render/Signals.java	(revision 31722)
@@ -167,4 +167,5 @@
 	}
 
+	@SuppressWarnings("unchecked")
 	public static void radioStations(Feature feature) {
 		Renderer.symbol(feature, Beacons.RadarStation);
Index: applications/editors/josm/plugins/seachart/src/s57/S57dat.java
===================================================================
--- applications/editors/josm/plugins/seachart/src/s57/S57dat.java	(revision 31721)
+++ applications/editors/josm/plugins/seachart/src/s57/S57dat.java	(revision 31722)
@@ -32,5 +32,5 @@
 	static {
 		convs.put(S57subf.I8RN, new S57conv(5,2));
-		convs.put(S57subf.RCNM, new S57conv(2,1)); convs.put(S57subf.RCID, new S57conv(10,32)); convs.put(S57subf.EXPP, new S57conv(1,1));
+		convs.put(S57subf.RCNM, new S57conv(2,1)); convs.put(S57subf.RCID, new S57conv(10,4)); convs.put(S57subf.EXPP, new S57conv(1,1));
 		convs.put(S57subf.INTU, new S57conv(1,1)); convs.put(S57subf.DSNM, new S57conv(0,0)); convs.put(S57subf.EDTN, new S57conv(0,0));
 		convs.put(S57subf.UPDN, new S57conv(0,0)); convs.put(S57subf.UADT, new S57conv(8,0)); convs.put(S57subf.ISDT, new S57conv(8,0));
@@ -78,5 +78,5 @@
 	
 	public enum S57field { I8RI, DSID, DSSI, DSPM, DSPR, DSRC, DSHT, DSAC, CATD, CATX, DDDF, DDDR, DDDI, DDOM, DDRF, DDSI, DDSC,
-		FRID, FOID, ATTF, NATF, FFPC, FFPT, FSPC, FSPT, VRID, ATTV, VRPC, VRPT, SGCC, SG2D, SG3D, ARCC, AR2D, EL2D, CT2D }
+		FRID, FOID, LNAM, ATTF, NATF, FFPC, FFPT, FSPC, FSPT, VRID, ATTV, VRPC, VRPT, SGCC, SG2D, SG3D, ARCC, AR2D, EL2D, CT2D }
 	
 	private static ArrayList<S57subf> S57i8ri = new ArrayList<S57subf>(Arrays.asList(S57subf.I8RN));
@@ -105,6 +105,6 @@
 	private static ArrayList<S57subf> S57ddsc = new ArrayList<S57subf>(Arrays.asList(S57subf.ATLB, S57subf.ASET, S57subf.AUTH ));
 	private static ArrayList<S57subf> S57frid = new ArrayList<S57subf>(Arrays.asList(S57subf.RCNM, S57subf.RCID, S57subf.PRIM, S57subf.GRUP, S57subf.OBJL, S57subf.RVER, S57subf.RUIN ));
-//	private static ArrayList<S57subf> S57foid = new ArrayList<S57subf>(Arrays.asList(S57subf.AGEN, S57subf.FIDN, S57subf.FIDS ));
-	private static ArrayList<S57subf> S57foid = new ArrayList<S57subf>(Arrays.asList(S57subf.LNAM));
+	private static ArrayList<S57subf> S57foid = new ArrayList<S57subf>(Arrays.asList(S57subf.AGEN, S57subf.FIDN, S57subf.FIDS ));
+	private static ArrayList<S57subf> S57lnam = new ArrayList<S57subf>(Arrays.asList(S57subf.LNAM));
 	private static ArrayList<S57subf> S57attf = new ArrayList<S57subf>(Arrays.asList(S57subf.ATTL, S57subf.ATVL ));
 	private static ArrayList<S57subf> S57natf = new ArrayList<S57subf>(Arrays.asList(S57subf.ATTL, S57subf.ATVL ));
@@ -132,11 +132,44 @@
 		fields.put(S57field.CATX, S57catx); fields.put(S57field.DDDF, S57dddf); fields.put(S57field.DDDR, S57dddr); fields.put(S57field.DDDI, S57dddi);
 		fields.put(S57field.DDOM, S57ddom); fields.put(S57field.DDRF, S57ddrf); fields.put(S57field.DDSI, S57ddsi); fields.put(S57field.DDSC, S57ddsc);
-		fields.put(S57field.FRID, S57frid); fields.put(S57field.FOID, S57foid); fields.put(S57field.ATTF, S57attf); fields.put(S57field.NATF, S57natf);
-		fields.put(S57field.FFPC, S57ffpc); fields.put(S57field.FFPT, S57ffpt); fields.put(S57field.FFPC, S57fspc); fields.put(S57field.FSPT, S57fspt);
-		fields.put(S57field.VRID, S57vrid); fields.put(S57field.ATTV, S57attv); fields.put(S57field.VRPC, S57vrpc); fields.put(S57field.VRPT, S57vrpt);
-		fields.put(S57field.SGCC, S57sgcc); fields.put(S57field.SG2D, S57sg2d); fields.put(S57field.SG3D, S57sg3d); fields.put(S57field.ARCC, S57arcc);
-		fields.put(S57field.AR2D, S57ar2d); fields.put(S57field.EL2D, S57el2d); fields.put(S57field.CT2D, S57ct2d); 
-	}
-
+		fields.put(S57field.FRID, S57frid); fields.put(S57field.FOID, S57foid); fields.put(S57field.LNAM, S57lnam); fields.put(S57field.ATTF, S57attf);
+		fields.put(S57field.NATF, S57natf); fields.put(S57field.FFPC, S57ffpc); fields.put(S57field.FFPT, S57ffpt); fields.put(S57field.FFPC, S57fspc);
+		fields.put(S57field.FSPT, S57fspt); fields.put(S57field.VRID, S57vrid); fields.put(S57field.ATTV, S57attv); fields.put(S57field.VRPC, S57vrpc);
+		fields.put(S57field.VRPT, S57vrpt); fields.put(S57field.SGCC, S57sgcc); fields.put(S57field.SG2D, S57sg2d); fields.put(S57field.SG3D, S57sg3d);
+		fields.put(S57field.ARCC, S57arcc); fields.put(S57field.AR2D, S57ar2d); fields.put(S57field.EL2D, S57el2d); fields.put(S57field.CT2D, S57ct2d); 
+	}
+
+	public enum S57record { DS, DP, DH, DA, CD, CR, ID, IO, IS, FE, VS, VI, VC, VE }
+	
+	private static ArrayList<S57field> S57ds = new ArrayList<S57field>(Arrays.asList(S57field.I8RI, S57field.DSID, S57field.DSSI ));
+	private static ArrayList<S57field> S57dp = new ArrayList<S57field>(Arrays.asList(S57field.I8RI, S57field.DSPM, S57field.DSPR, S57field.DSRC ));
+	private static ArrayList<S57field> S57dh = new ArrayList<S57field>(Arrays.asList(S57field.I8RI, S57field.DSHT ));
+	private static ArrayList<S57field> S57da = new ArrayList<S57field>(Arrays.asList(S57field.I8RI, S57field.DSAC ));
+	private static ArrayList<S57field> S57cd = new ArrayList<S57field>(Arrays.asList(S57field.I8RI, S57field.CATD ));
+	private static ArrayList<S57field> S57cr = new ArrayList<S57field>(Arrays.asList(S57field.I8RI, S57field.CATX ));
+	private static ArrayList<S57field> S57id = new ArrayList<S57field>(Arrays.asList(S57field.I8RI, S57field.DDDF, S57field.DDDR ));
+	private static ArrayList<S57field> S57io = new ArrayList<S57field>(Arrays.asList(S57field.I8RI, S57field.DDDI, null, S57field.DDOM, S57field.DDRF, null ));
+	private static ArrayList<S57field> S57is = new ArrayList<S57field>(Arrays.asList(S57field.I8RI, S57field.DDSI, S57field.DDSC ));
+	private static ArrayList<S57field> S57fe = new ArrayList<S57field>(Arrays.asList(S57field.I8RI, S57field.FRID, S57field.FOID, null, S57field.ATTF, null,
+			null, S57field.NATF, null, null, S57field.FFPT, null, null, S57field.FSPT, null ));
+	private static ArrayList<S57field> S57vs = new ArrayList<S57field>(Arrays.asList(S57field.I8RI, S57field.VRID, null, S57field.SG3D, null));
+	private static ArrayList<S57field> S57vi = new ArrayList<S57field>(Arrays.asList(S57field.I8RI, S57field.VRID, S57field.SG2D));
+	private static ArrayList<S57field> S57vc = new ArrayList<S57field>(Arrays.asList(S57field.I8RI, S57field.VRID, S57field.SG2D));
+	private static ArrayList<S57field> S57ve = new ArrayList<S57field>(Arrays.asList(S57field.I8RI, S57field.VRID, null, S57field.VRPT, null, null, S57field.SG3D, null));
+	
+	private static final EnumMap<S57record, ArrayList<S57field>> records = new EnumMap<S57record, ArrayList<S57field>>(S57record.class);
+	static {
+		records.put(S57record.DS, S57ds); records.put(S57record.DP, S57dp); records.put(S57record.DH, S57dh); records.put(S57record.DA, S57da); records.put(S57record.CD, S57cd);
+		records.put(S57record.CR, S57cr); records.put(S57record.ID, S57id); records.put(S57record.IO, S57io); records.put(S57record.IS, S57is); records.put(S57record.FE, S57fe);
+		records.put(S57record.VS, S57vs); records.put(S57record.VI, S57vi); records.put(S57record.VC, S57vc); records.put(S57record.VE, S57ve);
+	}
+	
+	private static final EnumMap<S57record, Integer> rcnms = new EnumMap<S57record, Integer>(S57record.class);
+	static {
+		rcnms.put(S57record.DS, 10); rcnms.put(S57record.DP, 20); rcnms.put(S57record.DH, 30); rcnms.put(S57record.DA, 40); rcnms.put(S57record.CD, 50);
+		rcnms.put(S57record.CR, 60); rcnms.put(S57record.ID, 70); rcnms.put(S57record.IO, 80); rcnms.put(S57record.IS, 90); rcnms.put(S57record.FE, 100);
+		rcnms.put(S57record.VS, 110); rcnms.put(S57record.VI, 110); rcnms.put(S57record.VC, 120); rcnms.put(S57record.VE, 130);
+	}
+	
+	private static byte[] leader = {'0', '0', '0', '0', '0', ' ', 'D', ' ', ' ', ' ', ' ', ' ', '0', '0', '0', '0', '0', ' ', ' ', ' ', '0', '0', '0', '4'};
 	private static byte[] buffer;
 	private static int offset;
@@ -259,9 +292,23 @@
 	}
 
-	public static byte[] encSubf(S57subf subf, Object val) throws UnsupportedEncodingException {
-		S57conv conv = findSubf(subf);
-		if ((conv.bin == 0) && (val instanceof String)) {
-			index = ((String)val).length();
-			buffer = ((String)val + " ").getBytes("ISO-8859-1");
+	public static byte[] encSubf(S57subf subf, Object val) {
+		if (val instanceof S57record) val = rcnms.get(val);
+		S57conv conv = convs.get(subf);
+		if (conv.bin == 0) {
+			String sval = "";
+			if (val instanceof String) {
+				sval = (String) val;
+			} else if (val instanceof Long) {
+				sval = ((Long)val).toString();
+			} else if (val instanceof Double) {
+				sval = ((Double)val).toString();
+			}
+			index = sval.length();
+			try {
+				buffer = ((String) sval + " ").getBytes("ISO-8859-1");
+			} catch (Exception e) {
+				System.err.println(e.getMessage());
+				System.exit(-1);
+			}
 			if (conv.asc == 0) {
 				buffer[index] = 0x01f;
@@ -274,5 +321,15 @@
 		} else {
 			int f = Math.abs(conv.bin);
-			long lval = (long) val;
+			long lval;
+			if (val instanceof String) {
+				lval = Long.parseLong((String)val);
+			} else	if (val instanceof Double) {
+				double dval = (double) val;
+				lval = (long) dval;
+			} else	if (val instanceof Integer) {
+				lval = (int) val;
+			} else {
+				lval = (long) val;
+			}
 			if (f < 8) {
 				buffer = new byte[f];
@@ -284,5 +341,5 @@
 				f /= 8;
 				buffer = new byte[f];
-				for (int i = f-1; i <= 0; i++) {
+				for (int i = f-1; i >= 0; i--) {
 					buffer[i] = (byte) (lval & 0xff);
 					lval >>= 8;
@@ -292,4 +349,73 @@
 		return buffer;
 	}
-	
+
+	static class Index {
+		byte[] field;
+		int length;
+		int offset;
+		Index (byte[] id, int l, int o) {
+			field = id;
+			length = l;
+			offset = o;
+		}
+	}
+	
+	public static byte[] encRecord(Object...params) {
+		ArrayList<Index> index = new ArrayList<Index>();
+		offset = 0;
+		int maxlen = 0;
+		ArrayList<S57field> record = records.get(params[1]);
+		byte[] buf = new byte[0];
+		int ip = 0;
+		for (S57field field : record) {
+			for (S57subf subf : fields.get(field)) {
+				byte[] next = encSubf(subf, params[ip++]);
+				buf = Arrays.copyOf(buf, (buf.length + next.length));
+				System.arraycopy(next, 0, buf, (buf.length - next.length), next.length);
+				if (ip >= params.length)
+					break;
+			}
+			buf = Arrays.copyOf(buf, (buf.length + 1));
+			buf[buf.length-1] = 0x1e;
+			int flen = buf.length - offset;
+			if (field == S57field.I8RI) {
+				index.add(new Index("0001".getBytes(), flen, offset));
+			} else {
+				index.add(new Index(field.toString().getBytes(), flen, offset));
+			}
+			maxlen = (flen > maxlen) ? flen : maxlen;
+			offset += flen;
+		}
+		int mlen = String.valueOf(maxlen).length();
+		String ffmt = "%0" + mlen + "d";
+		int olen = String.valueOf(offset).length();
+		String ofmt = "%0" + olen + "d";
+		int ilen = 4 + mlen + olen;
+		int isiz = (ilen * index.size()) + 1;
+		byte[] ibuf = new byte[isiz];
+		int i = 0;
+		for (Index item : index) {
+			for (byte ch : item.field) {
+				ibuf[i++] = ch;
+			}
+			byte[] digits = String.format(ffmt, item.length).getBytes();
+			for (byte ch : digits) {
+				ibuf[i++] = ch;
+			}
+			digits = String.format(ofmt, item.offset).getBytes();
+			for (byte ch : digits) {
+				ibuf[i++] = ch;
+			}
+		}
+		ibuf[i] = 0x1e;
+		byte[] fbuf = Arrays.copyOf(leader, (leader.length + ibuf.length + buf.length));
+		System.arraycopy(ibuf, 0, fbuf, leader.length, ibuf.length);
+		System.arraycopy(buf, 0, fbuf, (leader.length + ibuf.length), buf.length);
+		fbuf[20] = (byte)(mlen + 0x30);
+		fbuf[21] = (byte)(olen + 0x30);
+		System.arraycopy(String.format("%05d", fbuf.length).getBytes(), 0, fbuf, 0, 5);
+		System.arraycopy(String.format("%05d", (leader.length + ibuf.length)).getBytes(), 0, fbuf, 12, 5);
+		return fbuf;
+	}
+
 }
Index: applications/editors/josm/plugins/seachart/src/s57/S57dec.java
===================================================================
--- applications/editors/josm/plugins/seachart/src/s57/S57dec.java	(revision 31721)
+++ applications/editors/josm/plugins/seachart/src/s57/S57dec.java	(revision 31722)
@@ -93,5 +93,5 @@
 						break;
 					case "FOID":
-						name = (Long) S57dat.decSubf(record, fields + pos, S57field.FOID, S57subf.LNAM);
+						name = (Long) S57dat.decSubf(record, fields + pos, S57field.LNAM, S57subf.LNAM);
 						map.newFeature(name, pflag, objl);
 						break;
Index: applications/editors/josm/plugins/seachart/src/s57/S57enc.java
===================================================================
--- applications/editors/josm/plugins/seachart/src/s57/S57enc.java	(revision 31721)
+++ applications/editors/josm/plugins/seachart/src/s57/S57enc.java	(revision 31722)
@@ -9,4 +9,11 @@
 
 package s57;
+
+import java.io.UnsupportedEncodingException;
+import java.util.HashMap;
+import java.util.Map;
+
+import s57.S57dat.*;
+import s57.S57map.*;
 
 public class S57enc { // S57 ENC file generation
@@ -120,5 +127,5 @@
 		'1', 0x1f, '0', 0x1f,
 		//*** 2035
-		'0', '0', '0', '0', '0', '0', '0', '0',   '0', '0', '0', '0', '0', '0', '0', '0', // Date x2
+		'0', '0', '0', '0', '0', '0', '0', '0',   '0', '0', '0', '0', '0', '0', '0', '0', // Date x2 (from system)
 		'0', '3', '.', '1', 0x14, 0x1f, 0x1f, 0x01, 0x26, 0x0f, 'G', 'e', 'n', 'e', 'r', 'a', 't', 'e', 'd', ' ', 'b', 'y', ' ', 
 		'O', 'p', 'e', 'n', 'S', 'e', 'a', 'M', 'a', 'p', '.', 'o', 'r', 'g', 0x1f, 0x1e,
@@ -126,11 +133,11 @@
 		0x02, 0x01, 0x02,
 		//*** 2093
-		0x02, 0x00, 0x00, 0x00, // # of meta records
+		0x00, 0x00, 0x00, 0x00, // # of meta records (from metas counter)
 		0x00, 0x00, 0x00, 0x00,
-		0x00, 0x00, 0x00, 0x00, // # of geo records
+		0x00, 0x00, 0x00, 0x00, // # of geo records (from geos counter)
 		0x00, 0x00, 0x00, 0x00,
-		0x00, 0x00, 0x00, 0x00, // # of isolated node records
-		0x00, 0x00, 0x00, 0x00, // # of connected node records
-		0x00, 0x00, 0x00, 0x00, // # of edge records
+		0x00, 0x00, 0x00, 0x00, // # of isolated node records (from isols counter)
+		0x00, 0x00, 0x00, 0x00, // # of connected node records (from conns counter)
+		0x00, 0x00, 0x00, 0x00, // # of edge records (from edges counter)
 		0x00, 0x00, 0x00, 0x00, 0x1e,
 
@@ -143,19 +150,54 @@
 		0x14, 0x01, 0x00, 0x00, 0x00, 0x02, 0x17, 0x17,
 		//*** 2176
-		0x00, 0x00, 0x00, 0x00, // Scale
-		0x01, // Depth units
-		0x01, // Height units
-		0x01, 0x01,	(byte)0x80, (byte)0x96, (byte)0x98, 0x00, 0x0a, 0x00, 0x00, 0x00, 0x1f, 0x1e
+		0x00, 0x00, 0x00, 0x00, // Scale (from meta list)
+		0x01, // Depth units (from meta list)
+		0x01, // Height units (from meta list)
+		0x01, 0x01,
+		(byte)0x80, (byte)0x96, (byte)0x98, 0x00, // COMF=10000000
+		0x0a, // SOMF=10
+		0x00, 0x00, 0x00, 0x1f, 0x1e
 	};
 	
-	private static byte[] leader = {'0', '0', '0', '0', '0', ' ', 'D', ' ', ' ', ' ', ' ', ' ', '0', '0', '0', '0', '0', ' ', ' ', ' ', '0', '0', '0', '0'};
+	static final double COMF=10000000;
+	static final double SOMF=10;
+	
 	static int idx;
-
-	public static int encodeChart(S57map map, byte[] buf) throws IndexOutOfBoundsException {
+	static int recs;
+	static int isols;
+	static int conns;
+	static int metas;
+	static int geos;
+	static int rcid;
+
+	public static int encodeChart(S57map map, HashMap<String, String> meta, byte[] buf) throws IndexOutOfBoundsException, UnsupportedEncodingException {
+
+		/*
+		 * Encoding order:
+		 * 1. Copy records 0-3 & fill in meta attributes.
+		 * 2. Depth isolated nodes.
+		 * 3. All other isolated nodes.
+		 * 4. Connected nodes.
+		 * 5. Edges.
+		 * 6. Meta objects.
+		 * 7. Geo objects.
+		 */
 		
-		int idx = leader.length;
+		recs = rcid = 3;
+		isols = conns = metas = geos = 0;
 		for (idx = 0; idx < header.length; idx++) {
 			buf[idx] = header[idx];
 		}
+//		byte[] file = S57dat.encSubf(S57subf.FILE, meta.get("FILE"));
+		
+		for (Map.Entry<Long, S57map.Snode> entry : map.nodes.entrySet()) {
+			S57map.Snode node = entry.getValue();
+			if (node.flg == Nflag.ISOL) {
+				byte[] record = S57dat.encRecord(recs++, S57record.VI, rcid++, 1, 1, (Math.toDegrees(node.lat) * COMF), (Math.toDegrees(node.lon) * COMF));
+				System.arraycopy(record, 0, buf, idx, record.length);
+				idx += record.length;
+				isols++;
+				recs++;
+			}
+		}
 
 	return idx;
@@ -164,10 +206,4 @@
 	public static int encodeCatalogue(S57map map, byte[] buf) throws IndexOutOfBoundsException {
 		
-		
-		int idx = leader.length;
-		for (int i = 0; i < idx; i++) {
-			buf[i] = leader[i];
-		}
-
 	return idx;
 }
Index: applications/editors/josm/plugins/seachart/src/s57/S57map.java
===================================================================
--- applications/editors/josm/plugins/seachart/src/s57/S57map.java	(revision 31721)
+++ applications/editors/josm/plugins/seachart/src/s57/S57map.java	(revision 31722)
@@ -44,6 +44,6 @@
 
 	public class Snode {	// All coordinates in map
-		public double lat;	// Latitude
-		public double lon;	// Longitude
+		public double lat;	// Latitude in radians
+		public double lon;	// Longitude in radians
 		public Nflag flg;		// Role of node
 
Index: applications/editors/josm/plugins/seachart/src/s57/S57osm.java
===================================================================
--- applications/editors/josm/plugins/seachart/src/s57/S57osm.java	(revision 31721)
+++ applications/editors/josm/plugins/seachart/src/s57/S57osm.java	(revision 31722)
@@ -37,5 +37,5 @@
 	static {
 		OSMtags.put("natural=coastline", new KeyVal<>(Obj.COALNE, Att.UNKATT, null, null)); OSMtags.put("natural=water", new KeyVal<>(Obj.LAKARE, Att.UNKATT, null, null));
-		OSMtags.put("waterway=river", new KeyVal<>(Obj.RIVERS, Att.UNKATT, null, null)); OSMtags.put("waterway=riverbank", new KeyVal<>(Obj.COALNE, Att.UNKATT, null, null));
+		OSMtags.put("waterway=river", new KeyVal<>(Obj.RIVERS, Att.UNKATT, null, null)); OSMtags.put("waterway=riverbank", new KeyVal<>(Obj.LAKARE, Att.UNKATT, null, null));
 		OSMtags.put("waterway=canal", new KeyVal<>(Obj.CANALS, Att.UNKATT, null, null)); OSMtags.put("waterway=dock", new KeyVal<>(Obj.HRBBSN, Att.UNKATT, null, null));
 		OSMtags.put("waterway=lock", new KeyVal<>(Obj.HRBBSN, Att.UNKATT, null, null)); OSMtags.put("landuse=basin", new KeyVal<>(Obj.LAKARE, Att.UNKATT, null, null));
