public static string ToGeoJson(this Esri.FileGDB.Row row) { try { StringBuilder sb = new StringBuilder("{ \"type\": \"Feature\", "); var geom = row.GetGeometry(); sb.Append("\"geometry\": "); sb.Append(geom.ToGeoJson()); sb.Append(", "); sb.Append(processFields(row)); sb.Append("}"); return sb.ToString(); } catch (Exception ex) { throw new Exception("Error processing row", ex); } }
private static string processFields(Esri.FileGDB.Row row) { try { StringBuilder sb = new StringBuilder("\"properties\": {"); List<string> props = new List<string>(); string proptemplate = "\"{0}\": \"{1}\""; for (int fldnum = 0; fldnum < row.FieldInformation.Count; fldnum++) { string fldname = row.FieldInformation.GetFieldName(fldnum); string fldval = ""; if (row.IsNull(fldname)) { fldval = "null"; } else { switch (row.FieldInformation.GetFieldType(fldnum)) { case FieldType.Geometry: fldval = "geometry"; break; case FieldType.Blob: fldval = "blob"; break; case FieldType.SmallInteger: fldval = row.GetShort(fldname).ToString(); break; case FieldType.Integer: fldval = row.GetInteger(fldname).ToString(); break; case FieldType.Single: fldval = row.GetFloat(fldname).ToString(); break; case FieldType.Double: fldval = row.GetDouble(fldname).ToString(); break; case FieldType.String: fldval = row.GetString(fldname); break; case FieldType.Date: fldval = row.GetDate(fldname).ToLongTimeString(); break; case FieldType.OID: fldval = row.GetOID().ToString(); break; case FieldType.GUID: fldval = row.GetGUID(fldname).ToString(); break; case FieldType.GlobalID: fldval = row.GetGlobalID().ToString(); break; default: break; } } string propval = string.Format(proptemplate, fldname, fldval); props.Add(propval); } var proparray = props.ToArray(); string propsjoin = string.Join(",", proparray); sb.Append(propsjoin); sb.Append("}"); return sb.ToString(); } catch (Exception ex) { throw new Exception("Error processing attributes", ex); } }