public static void aoFieldsToPostGisFields(ref string fields, Layer postGisLayer, int outSrid) { // We want to load every field so we can easily // interoperate with the rest of the framework. // However, load nulls for the fields that aren't specified. log.enterFunc("aoFieldsToPostGisFields"); bool loadAll = (fields == "*"); log.Debug("outSrid = " + outSrid.ToString()); string[] fieldArray = fields.Split(','); Hashtable fieldMap = new Hashtable(fieldArray.Length); foreach (string f in fieldArray) fieldMap.Add(f.ToLower().Trim(), true); // Use a dummy value. (Paolo: I added a Trim) string name; bool load; StringBuilder sb = new StringBuilder(); DataTable dataFields = postGisLayer.getDataFields(false); foreach (DataRow r in dataFields.Rows) { name = ((string)r["ColumnName"]).ToLower(); // Are we loading the data? // (if the field is found in the Hashtable // then the field was supplied to this // function, therefore we load its data) // We also load if we are loading all. load = (fieldMap[name] != null || loadAll); // Geometry fields are special - add the asbinary() func. // Plus, we *always* load the geometry data. // DONE: apply correct coordinate transformation here if (name == postGisLayer.geometryField) name = postGisLayer.transformGeometryFieldAsBinary(outSrid) + " as " + name; else if (!load) { sb.Append("null as "); } sb.Append(name); sb.Append(","); } sb.Remove(sb.Length - 1, 1); fields = sb.ToString(); log.leaveFunc(); }
internal PostGisFields(Layer postGisLayer) { log.enterFunc("ctor"); try { bool hasGIDField = false; if (log.IsDebugEnabled) log.Debug("1"); DataTable dataFields = postGisLayer.getDataFields(false); if (log.IsDebugEnabled) log.Debug("2"); m_flds = new PostGisField[dataFields.Rows.Count]; m_ids = new Hashtable(fields.Length); PostGisField pgisFld; int i = 0; foreach (DataRow r in dataFields.Rows) { pgisFld = new PostGisField(postGisLayer, r, i); m_flds[i] = pgisFld; m_ids.Add(pgisFld.Name, i); if(pgisFld.Name.ToLower()=="gid") { hasGIDField=true; } ++i; } //gid (int4 or int8) is mandatory as GDB unique OID if (hasGIDField==false) { System.Windows.Forms.MessageBox.Show("This PostGis layer will be added in ArcMap but will not correctly work for some funcitonality (selections, rendering, ...): it misses a mandatory gid (int) field as unique OID for each feature. This gid field is necessary for the Esri Geodatabase model."); } } catch (Exception e) { log.Error("", e); throw; } finally { log.leaveFunc(); } }