/// <summary> /// </summary> /// <param name="objectClass"></param> /// <returns></returns> private ICursor FilterAndSortResults(ReportObjectClasses objectClass) { ITable tableFromDatasetName = GetTableFromDatasetName(objectClass.ObjectClass.name); if (tableFromDatasetName != null) { string str = null; Results.Reset(); for (object obj2 = Results.Next(); obj2 != null; obj2 = Results.Next()) { if (!(obj2 is IFeature)) continue; var feature = (IFeature) obj2; var dataset = (IDataset) feature.Class; if (dataset.Name != objectClass.ObjectClass.name) continue; if (str == null) str = Convert.ToString(feature.OID); else str = str + "," + Convert.ToString(feature.OID); } if (str != null) { IQueryFilter filter = new QueryFilterClass(); AddSubFields(objectClass, filter); filter.WhereClause = tableFromDatasetName.OIDFieldName + " IN (" + str + ")"; return tableFromDatasetName.Search(filter, true); } } const ICursor cursor = null; return cursor; }
///////////////////////////////////////////////////////////////////// /// <summary> /// Adds fields to the filter query object for selecting features /// for the feature cursor. Cursor is used to process the elements /// attributes into xml. Objects identified are by field.name /// </summary> /// <param name="objectClass"></param> /// <param name="filter"></param> private static void AddSubFields(ReportObjectClasses objectClass, IQueryFilter filter) { if (objectClass.ObjectClass.Fields == null) return; string name = null; foreach (Field field in objectClass.ObjectClass.Fields) { if (name == null) name = field.name; else name = name + "," + field.name; } if (name != null) filter.SubFields = name; }
/// <summary> /// </summary> /// <param name="objectClass"></param> /// <param name="geom"></param> /// <returns></returns> private ICursor GetFeaturesFromGeometry(ReportObjectClasses objectClass, IGeometry geom) { ITable tableFromDatasetName = GetTableFromDatasetName(objectClass.ObjectClass.name); if (tableFromDatasetName != null) { ISpatialFilter filter = new SpatialFilterClass { Geometry = geom, SpatialRel = esriSpatialRelEnum.esriSpatialRelContains }; AddSubFields(objectClass, filter); filter.WhereClause = getWhereClause(objectClass.ObjectClass.name); return tableFromDatasetName.Search(filter, true); } return null; }
/// <summary> /// </summary> /// <param name="reportObjectClass"></param> /// <returns></returns> private ICursor GetFeatureCursor(ReportObjectClasses reportObjectClass) { ICursor featuresFromGeometry = null; if (Geometry == null && Results == null) { var fc = GetFeatureClassFromDatasetName(reportObjectClass.ObjectClass.name); if (fc != null) { IQueryFilter filter = new QueryFilterClass(); filter.WhereClause = Where[0].Where; featuresFromGeometry = (ICursor) fc.Search(filter, false); } } if (Geometry != null) featuresFromGeometry = GetFeaturesFromGeometry(reportObjectClass, Geometry); else if (Results != null) featuresFromGeometry = FilterAndSortResults(reportObjectClass); return featuresFromGeometry; }
/// <summary> /// Export all report object classes /// </summary> /// <param name="writer"></param> /// <param name="reportObjectClass"></param> private void ExportReportObjectClass(XmlWriter writer, ReportObjectClasses reportObjectClass) { try { IFeatureLayer featureLayerFromDatasetName = GetFeatureLayerFromDatasetName(reportObjectClass.ObjectClass.name); ICursor featureCursor = GetFeatureCursor(reportObjectClass); if (featureCursor != null) { writer.WriteStartElement("ReportObject"); if (!string.IsNullOrEmpty(reportObjectClass.name)) writer.WriteAttributeString("name", reportObjectClass.name); ExportObjectClass(writer, reportObjectClass.ObjectClass, featureCursor, featureLayerFromDatasetName as IDisplayTable); if (reportObjectClass.SpatialRelationships != null) { writer.WriteStartElement("SpatialRelationships"); foreach (SpatialRelationship relationship in reportObjectClass.SpatialRelationships) { featureCursor = GetFeatureCursor(reportObjectClass); ExportSpatialRelatedObjects(writer, relationship, featureCursor as IFeatureCursor); } writer.WriteEndElement(); } if (reportObjectClass.BufferRelationships != null) { writer.WriteStartElement("BufferRelationships"); foreach (BufferRelationship relationship2 in reportObjectClass.BufferRelationships) { featureCursor = GetFeatureCursor(reportObjectClass); ExportBufferRelatedObjects(writer, relationship2, featureCursor as IFeatureCursor); } writer.WriteEndElement(); } if (reportObjectClass.GeodatabaseRelationships != null) { writer.WriteStartElement("GeodatabaseRelationships"); foreach (GeodatabaseRelationship relationship3 in reportObjectClass.GeodatabaseRelationships) { featureCursor = GetFeatureCursor(reportObjectClass); ExportGeodatabaseRelatedObjects(writer, featureLayerFromDatasetName.FeatureClass, relationship3, featureCursor); } writer.WriteEndElement(); } if (reportObjectClass.MapDocumentRelationships != null) { writer.WriteStartElement("MapDocumentRelationships"); foreach (MapDocumentRelationship relationship4 in reportObjectClass.MapDocumentRelationships) { featureCursor = GetFeatureCursor(reportObjectClass); ExportMapDocumentRelatedObjects(writer, featureLayerFromDatasetName, relationship4, featureCursor); } writer.WriteEndElement(); } writer.WriteEndElement(); } } catch (Exception exception) { HandleError(exception); } }