/// <summary>Create the the fields for teh gipod Shapefile</summary> private List <IField> gipodIFields(dataHandler.gipodtype gtype, bool shp = true) { List <IField> fields = new List <IField>(); IField gipodID = geopuntHelper.createField("gipodID", esriFieldType.esriFieldTypeInteger); fields.Add(gipodID); IField eigenaar = geopuntHelper.createField("owner", esriFieldType.esriFieldTypeString, 254); fields.Add(eigenaar); int descriptLen = 1600; if (shp) { descriptLen = 254; } IField descript = geopuntHelper.createField("info", esriFieldType.esriFieldTypeString, descriptLen); fields.Add(descript); IField startDate = geopuntHelper.createField("beginDate", esriFieldType.esriFieldTypeDate); fields.Add(startDate); IField endDate = geopuntHelper.createField("endDate", esriFieldType.esriFieldTypeDate); fields.Add(endDate); IField hinder = geopuntHelper.createField("hinder", esriFieldType.esriFieldTypeSmallInteger); fields.Add(hinder); IField detail = geopuntHelper.createField("link", esriFieldType.esriFieldTypeString, 254); fields.Add(detail); IField cities = geopuntHelper.createField("cities", esriFieldType.esriFieldTypeString, 254); fields.Add(cities); if (gtype == dataHandler.gipodtype.manifestation) { IField initiator = geopuntHelper.createField("initiatief", esriFieldType.esriFieldTypeString, 254); fields.Add(initiator); IField eventType = geopuntHelper.createField("eventType", esriFieldType.esriFieldTypeString, 254); fields.Add(eventType); IField recurrencePattern = geopuntHelper.createField("patroon", esriFieldType.esriFieldTypeString, 254); fields.Add(recurrencePattern); } return(fields); }
/// <summary>insert the records from the GIPOD service into the shapefile </summary> private void populateGipodShape(IFeatureClass gipodFC, List <datacontract.gipodResponse> gipodRecords, dataHandler.gipodtype gtype) { //return if something is null if (gipodFC == null || gipodRecords == null) { return; } //get the srs ISpatialReference srs = view.FocusMap.SpatialReference; using (ComReleaser comReleaser = new ComReleaser()) { // Create a feature buffer. IFeatureBuffer featureBuffer = gipodFC.CreateFeatureBuffer(); comReleaser.ManageLifetime(featureBuffer); // Create an insert cursor. IFeatureCursor insertCursor = gipodFC.Insert(true); comReleaser.ManageLifetime(insertCursor); foreach (datacontract.gipodResponse row in gipodRecords) { Double x = row.coordinate.coordinates[0]; Double y = row.coordinate.coordinates[1]; IPoint pt = new PointClass() { X = x, Y = y, SpatialReference = lam72 }; IPoint toPt = geopuntHelper.Transform(pt, srs) as IPoint; featureBuffer.Shape = toPt; int id = row.gipodId; int idIdx = gipodFC.FindField("gipodID"); featureBuffer.set_Value(idIdx, id); string owner = row.owner; if (owner.Length > 254) { owner = owner.Substring(0, 254); } int ownerIdx = gipodFC.FindField("owner"); featureBuffer.set_Value(ownerIdx, owner); //sometime very long, handle that string description = row.description.Replace("\n", " ").Replace("\r", ""); int descriptionIdx = gipodFC.FindField("info"); int maxLen = featureBuffer.Fields.get_Field(descriptionIdx).Length; if (description.Length > maxLen) { description = description.Substring(0, maxLen); } featureBuffer.set_Value(descriptionIdx, description); DateTime startDate = row.startDateTime; int startDateIdx = gipodFC.FindField("beginDate"); featureBuffer.set_Value(startDateIdx, startDate); DateTime endDate = row.endDateTime; int endDateIdx = gipodFC.FindField("endDate"); featureBuffer.set_Value(endDateIdx, endDate); int hinder = row.importantHindrance ? 1 : 0; int hinderIdx = gipodFC.FindField("hinder"); featureBuffer.set_Value(hinderIdx, hinder); string detail = String.Format("http://www.geopunt.be/kaart?app=Hinder_in_kaart_app&GIPODID={0}&maximize=1", row.gipodId);//row.detail; if (detail.Length > 254) { detail = detail.Substring(0, 254); } int detailIdx = gipodFC.FindField("link"); featureBuffer.set_Value(detailIdx, detail); string cities = string.Join(", ", row.cities.ToArray()); if (cities.Length > 254) { cities = cities.Substring(0, 254); } int citiesIdx = gipodFC.FindField("cities"); featureBuffer.set_Value(citiesIdx, cities); if (gtype == dataHandler.gipodtype.manifestation) { string initiator = row.initiator; if (initiator != null) { if (initiator.Length > 254) { initiator = initiator.Substring(0, 254); } int initiatorIdx = gipodFC.FindField("initiatief"); featureBuffer.set_Value(initiatorIdx, initiator); } string eventType = row.eventType; if (eventType != null) { if (eventType.Length > 254) { eventType = eventType.Substring(0, 254); } int eventTypeIdx = gipodFC.FindField("eventType"); featureBuffer.set_Value(eventTypeIdx, eventType); } string recurrencePattern = row.recurrencePattern; if (recurrencePattern != null) { if (recurrencePattern.Length > 254) { recurrencePattern = recurrencePattern.Substring(0, 254); } int recurrencePatternIdx = gipodFC.FindField("patroon"); featureBuffer.set_Value(recurrencePatternIdx, recurrencePattern); } } insertCursor.InsertFeature(featureBuffer); } insertCursor.Flush(); } }