public IField FindField(string name) { if (_fields != null) { foreach (IField field in _fields.ToEnumerable()) { if (field.name == name) { return(field); } } } return(null); }
private void FillJoinTableFieldsList() { lstJoinTableFields.Items.Clear(); if (String.IsNullOrEmpty(cmbTable.Text)) { return; } _fields = FilterFields(FieldType.unknown); if (_fields != null) { foreach (IField field in _fields.ToEnumerable()) { lstJoinTableFields.Items.Add(field); } } }
static private string CheckNameLength(IFields fields, IField field, string fieldname, int maxLength, int counter) { foreach (IField f in fields.ToEnumerable()) { if (f.Equals(field)) { return(fieldname.Substring(0, Math.Min(fieldname.Length, maxLength))); } if (f.name.Substring(0, Math.Min(f.name.Length, maxLength)).ToLower() == fieldname.Substring(0, Math.Min(fieldname.Length, maxLength)).ToLower()) { fieldname = fieldname.Substring(0, Math.Min(fieldname.Length, maxLength) - counter.ToString().Length) + counter.ToString(); return(CheckNameLength(fields, field, fieldname, maxLength, counter + 1)); } } return(fieldname.Substring(0, Math.Min(fieldname.Length, maxLength))); }
public Task <int> CreateFeatureClass(string dsname, string fcname, IGeometryDef geomDef, IFields fields) { if (geomDef == null || fields == null) { return(Task.FromResult(-1)); } string filename = _directoryName + @"/" + fcname; Fields f = new Fields(); foreach (IField field in fields.ToEnumerable()) { f.Add(field); } if (!SHPFile.Create(filename, geomDef, f)) { return(Task.FromResult(-1)); } return(Task.FromResult(0)); }
public int CreateFeatureClass(string dsname, string fcname, gView.Framework.Geometry.IGeometryDef geomDef, IFields fields) { if (geomDef == null || fields == null) { return(-1); } string filename = _directoryName + @"\" + fcname + ".gml"; Fields f = new Fields(); foreach (IField field in fields.ToEnumerable()) { f.Add(field); } if (!GMLFile.Create(filename, geomDef, f, _gmlVersion)) { return(-1); } return(0); }
public void AddFeature(IFeature feature, ISpatialReference sRef, IFeatureLayer layer, string Category, IFields fields, IField primaryDisplayField) { if (feature == null) { return; } if (layer != null) { if (fields == null) { fields = layer.Fields; } if (primaryDisplayField == null) { primaryDisplayField = layer.Fields.PrimaryDisplayField; } } if (Category == "") { Category = "Results"; } CategoryTreeNode parent = null; foreach (CategoryTreeNode node in treeObjects.Nodes) { if (node.Category == Category) { parent = node; break; } } if (parent == null) { parent = new CategoryTreeNode(Category); treeObjects.Nodes.Add(parent); } parent.Nodes.Add(new FeatureTreeNode(_doc, feature, sRef, layer, (primaryDisplayField != null) ? primaryDisplayField.name : "", 1)); if (fields != null && feature.Fields != null) { List <FieldValue> fvs = gView.Framework.system.ListOperations <FieldValue> .Clone(feature.Fields); feature.Fields.Clear(); foreach (IField field in fields.ToEnumerable()) { if (!field.visible) { continue; } for (int i = 0; i < fvs.Count; i++) { if (fvs[i].Name == field.name) { feature.Fields.Add(new FieldValue(field.aliasname, fvs[i].Value)); fvs.RemoveAt(i); break; } } } } if (treeObjects.SelectedNode == null) { treeObjects.SelectedNode = parent.Nodes[0]; if (_doc != null && _doc.FocusMap != null && _doc.FocusMap.Display != null) { IGeometry shape = feature.Shape; if (sRef != null && !sRef.Equals(_doc.FocusMap.Display.SpatialReference)) { shape = GeometricTransformer.Transform2D(shape, sRef, _doc.FocusMap.Display.SpatialReference); } _doc.FocusMap.HighlightGeometry(shape, 300); } //parent.ExpandAll(); parent.Expand(); if (parent.Nodes.Count > 0) { parent.Nodes[0].Expand(); } } }
virtual public int CreateFeatureClass(string dsname, string fcname, IGeometryDef geomDef, IFields Fields) { DatasetNameCase nameCase = DatasetNameCase.ignore; foreach (System.Attribute attribute in System.Attribute.GetCustomAttributes(this.GetType())) { if (attribute is UseDatasetNameCase) { nameCase = ((UseDatasetNameCase)attribute).Value; } } switch (nameCase) { case DatasetNameCase.lower: case DatasetNameCase.classNameLower: fcname = fcname.ToLower(); break; case DatasetNameCase.upper: case DatasetNameCase.classNameUpper: fcname = fcname.ToUpper(); break; } StringBuilder sb = new StringBuilder(); sb.Append("CREATE TABLE " + fcname + " \n(\n"); Field idField = new Field(OgcDictionary("gid"), FieldType.ID); sb.Append(OgcDictionary("gid") + " "); sb.Append(DbDictionary(idField)); Field shapeField = new Field(OgcDictionary("the_geom"), FieldType.Shape); if (!String.IsNullOrEmpty(DbDictionary(shapeField))) { sb.Append(",\n"); sb.Append(OgcDictionary("the_geom") + " "); sb.Append(DbDictionary(shapeField)); } foreach (IField field in Fields.ToEnumerable()) { if (field.type == FieldType.ID || field.type == FieldType.Shape) { continue; } string fieldName = field.name; switch (nameCase) { case DatasetNameCase.lower: case DatasetNameCase.classNameLower: fieldName = fieldName.ToLower(); break; case DatasetNameCase.upper: case DatasetNameCase.classNameUpper: fieldName = fieldName.ToUpper(); break; } sb.Append(",\n"); sb.Append(" \"" + fieldName + "\" "); sb.Append(DbDictionary(field)); } //sb.Append(" the_geom geometry,\n"); string geomTypeString = ""; switch (geomDef.GeometryType) { case geometryType.Point: geomTypeString = "POINT"; break; case geometryType.Polyline: geomTypeString = "MULTILINESTRING"; break; case geometryType.Polygon: geomTypeString = "MULTIPOLYGON"; break; default: _errMsg = "Geometrytype not implemented..."; return(-1); } sb.Append(")\n"); try { using (DbConnection connection = this.ProviderFactory.CreateConnection()) { connection.ConnectionString = _connectionString; connection.Open(); DbCommand command = this.ProviderFactory.CreateCommand(); command.CommandText = sb.ToString(); command.Connection = connection; command.ExecuteNonQuery(); command.CommandText = CreateGidSequence(fcname); if (!String.IsNullOrEmpty(command.CommandText)) { command.ExecuteNonQuery(); } command.CommandText = CreateGidTrigger(fcname, OgcDictionary("gid")); if (!String.IsNullOrEmpty(command.CommandText)) { command.ExecuteNonQuery(); } command.CommandText = AddGeometryColumn("", fcname, OgcDictionary("the_geom"), "-1", geomTypeString); if (!String.IsNullOrEmpty(command.CommandText)) { command.ExecuteNonQuery(); } } return(0); } catch (Exception ex) { _errMsg = ex.Message; return(-1); } }