/// <summary> /// Validates the attributes in a Feature Class/Table or its subtype for domain constraints /// </summary> /// <param name="ipErrorCollection">Collection of validation results</param> /// <param name="ipTable">Feature class/Table whose attributes will be validated for domain constraints</param> /// <param name="ipDomain">Domain for which attributes need to be validated</param> /// <param name="strDomainFieldName">Name of the domain field</param> /// <param name="bHasSubtype">input true if the feature class/table has subype else false</param> /// <param name="strSubtypeFieldName">Name of the subtype field</param> /// <param name="iSubtypeCode">Subtype code for the subtype that need to be validated for the domain constraints</param> private void ValidateAttributes(IPLTSErrorCollection ipErrorCollection, ITable ipTable, IDomain ipDomain, string strDomainFieldName, bool bHasSubtype, string strSubtypeFieldName, int iSubtypeCode) { string strErrorConditionQueryString = ""; //Get the query string for searching records that violate domain constraints if (ipDomain.Type == esriDomainType.esriDTRange) { strErrorConditionQueryString = GetQueryStringForRangeDomain(ipDomain as IRangeDomain, strDomainFieldName); } else if (ipDomain.Type == esriDomainType.esriDTCodedValue) { strErrorConditionQueryString = GetQueryStringForCodedDomain(ipDomain as ICodedValueDomain, strDomainFieldName); } if (!string.IsNullOrEmpty(strErrorConditionQueryString)) { //Apply subtype filter if needed if (bHasSubtype && !string.IsNullOrEmpty(strSubtypeFieldName)) { strErrorConditionQueryString += " AND " + strSubtypeFieldName + " = " + iSubtypeCode; } //Use the query string to search records that violate domain constraints IQueryFilter ipQF = new QueryFilter(); ipQF.WhereClause = strErrorConditionQueryString; ICursor ipCursor = ipTable.Search(ipQF, true); if (null != ipCursor) { IRow ipRow = ipCursor.NextRow(); while (null != ipRow) { //Create a Reviewer result IPLTSError2 ipReviewerResult = new PLTSErrorClass() as IPLTSError2; ipReviewerResult.ErrorKind = pltsValErrorKind.pltsValErrorKindStandard; ipReviewerResult.OID = ipRow.OID; ipReviewerResult.LongDescription = "Domain constraints violated for " + strDomainFieldName + " field"; ipReviewerResult.QualifiedTableName = (ipTable as IDataset).Name; //If the record is a feature then use the feature geometry as Result's error geometry IFeature ipFeature = ipRow as IFeature; if (null != ipFeature) { IGeometry ipErrorGeometry = ipFeature.ShapeCopy; if (!ipErrorGeometry.IsEmpty) { ipReviewerResult.ErrorGeometry = ipErrorGeometry; } } //Add the result to the collection of results ipErrorCollection.AddError(ipReviewerResult); ipRow = ipCursor.NextRow(); } //release cursor System.Runtime.InteropServices.Marshal.ReleaseComObject(ipCursor); ipCursor = null; } } return; }
/// <summary> /// Excecute is called by Data Reviewer engine and passed the appropriate parameters. /// </summary> /// <param name="ipSelectionToValidate">ISelectionSet of features/rows to validate</param> /// <param name="arguments">comma delimited string of arguments</param> /// <returns> /// Collection of validation results. /// </returns> public IPLTSErrorCollection Execute(ISelectionSet ipSelectionToValidate, string arguments) { if (null == ipSelectionToValidate) { throw new ArgumentNullException("ISelectionSet parameter is null"); } if (String.IsNullOrEmpty(arguments)) { throw new ArgumentNullException("string parameter is null or empty"); } //Exit if there is nothing to check if (0 == ipSelectionToValidate.Count) { return new PLTSErrorCollectionClass(); } //Arguments and default values string strTargetFeatureClassName = ""; string strTargetSubtypeNumber = ""; string strSourceWhereClause = ""; string strTargetWhereClause = ""; esriSpatialRelEnum eSpatialOperation = esriSpatialRelEnum.esriSpatialRelIntersects; string strSpatialRelDescription = ""; string strUserMessage = ""; //Split comma delimited string into array string[] arrayOfArguments = arguments.Split(new char[] { ',' }, StringSplitOptions.None); //Parse arguments for (int i = 0; i < arrayOfArguments.Length; i++) { if (0 == i) { strTargetFeatureClassName = arrayOfArguments[i]; } else if (1 == i) { strTargetSubtypeNumber = arrayOfArguments[i]; } else if (2 == i) { try { eSpatialOperation = (esriSpatialRelEnum)Convert.ToInt32(arrayOfArguments[i]); } catch (Exception ex) { throw new Exception(String.Format("Error converting spatial operation parameter to esriSpatialRelEnum. Parameter value {0}", arrayOfArguments[i]), ex); } } else if (3 == i) { strTargetWhereClause = arrayOfArguments[i]; } else if (4 == i) { strSourceWhereClause = arrayOfArguments[i]; } else if (5 == i) { strSpatialRelDescription = arrayOfArguments[i]; } else if (6 == i) { strUserMessage = arrayOfArguments[i]; } else { throw new Exception("Invalid number of arguments. Only seven arguments are allowed. Arguments: (" + arguments + ")"); } } //Get handle to workspace IDataset ipSourceDataset = ipSelectionToValidate.Target as IDataset; IFeatureWorkspace ipFeatureWorkspace = ipSourceDataset.Workspace as IFeatureWorkspace; //Open the target feature class. Feature class name passed in should be fully qualified. IFeatureClass ipTargetFeatureClass = ipFeatureWorkspace.OpenFeatureClass(strTargetFeatureClassName); if (null == ipTargetFeatureClass) { throw new Exception(String.Format("Unable to open feature class {0} from workspace {1}", strTargetFeatureClassName, (ipFeatureWorkspace as IWorkspace).PathName)); } string strTargetSubtypeFieldName = (ipTargetFeatureClass as ISubtypes).SubtypeFieldName; //Setup spatial filter to apply to target feature class ISpatialFilter ipTargetSF = new SpatialFilterClass(); ipTargetSF.SpatialRel = eSpatialOperation; if ("*" == strTargetSubtypeNumber || String.IsNullOrEmpty(strTargetSubtypeNumber)) { if (strTargetWhereClause.Length > 0) { ipTargetSF.WhereClause = strTargetWhereClause; } } else { if (strTargetWhereClause.Length > 0) { ipTargetSF.WhereClause = strTargetSubtypeFieldName + " = " + strTargetSubtypeNumber + " AND " + strTargetWhereClause; } else { ipTargetSF.WhereClause = strTargetSubtypeFieldName + " = " + strTargetSubtypeNumber; } } if (eSpatialOperation == esriSpatialRelEnum.esriSpatialRelRelation) { ipTargetSF.SpatialRelDescription = strSpatialRelDescription; } //Prepare source where clause IQueryFilter ipSourceQF = new QueryFilterClass(); if (strSourceWhereClause.Length > 0) { ipSourceQF.WhereClause = strSourceWhereClause; } IPLTSErrorCollection ipRevResultCollection = new PLTSErrorCollectionClass(); //Loop through source geometries and perform a spatial query againts the target Feature Class. //For each geometry that does not satisfy the spatial relationship add a Reviewer result. ICursor ipCursor = null; ipSelectionToValidate.Search(ipSourceQF, false, out ipCursor); IFeatureCursor ipFeatureCursor = ipCursor as IFeatureCursor; IFeature ipSourceFeature = ipFeatureCursor.NextFeature(); while (null != ipSourceFeature) { Application.DoEvents(); IGeometry ipSourceGeometry = ipSourceFeature.ShapeCopy; ipTargetSF.Geometry = ipSourceGeometry; //If spatial filter returns zero records create a Reviewer result. if (ipTargetFeatureClass.FeatureCount(ipTargetSF) == 0) { //Create a Reviewer result IPLTSError2 ipReviewerResult = new PLTSErrorClass() as IPLTSError2; ipReviewerResult.ErrorKind = pltsValErrorKind.pltsValErrorKindStandard; ipReviewerResult.OID = ipSourceFeature.OID; ipReviewerResult.LongDescription = strUserMessage; ipReviewerResult.QualifiedTableName = ipSourceDataset.Name; ipReviewerResult.ErrorGeometry = ipSourceGeometry; ipRevResultCollection.AddError(ipReviewerResult); } ipSourceFeature = ipFeatureCursor.NextFeature(); }//end while loop //Release cursor Marshal.ReleaseComObject(ipFeatureCursor); ipFeatureCursor = null; Marshal.ReleaseComObject(ipCursor); ipCursor = null; //Return the collection of results return ipRevResultCollection; }
/// <summary> /// Excecute is called by Data Reviewer engine and passed the appropriate parameters. /// </summary> /// <param name="ipSelectionToValidate">ISelectionSet of features/rows to validate</param> /// <param name="arguments">comma delimited string of arguments</param> /// <returns> /// Collection of validation results. /// </returns> public IPLTSErrorCollection Execute(ISelectionSet ipSelectionToValidate, string arguments) { if (null == ipSelectionToValidate) { throw new ArgumentNullException("ISelectionSet parameter is null"); } if (String.IsNullOrEmpty(arguments)) { throw new ArgumentNullException("string parameter is null or empty"); } //Get cursor of selected features/rows ICursor ipCursor = null; ipSelectionToValidate.Search(null, true, out ipCursor); IDataset ipSourceDataset = ipSelectionToValidate.Target as IDataset; IFeatureClass ipSourceFeatureClass = null; //Setup reference to feature class to be used when creating results if (ipSourceDataset.Type == esriDatasetType.esriDTFeatureClass) { ipSourceFeatureClass = ipSourceDataset as IFeatureClass; } //Get the index of the field we are checking int iIndexOfField = -1; iIndexOfField = ipCursor.FindField(arguments); //arguments is the name of the field we are checking if (-1 == iIndexOfField) { throw new Exception(String.Format("Field {0} was not found in Dataset {1}", arguments, ipSourceDataset.Name)); } //Collection of results passed back to Data Reviewer IPLTSErrorCollection ipRevResultCollection = new PLTSErrorCollectionClass(); //Loop through rows and check if field is numeric IRow ipRow = ipCursor.NextRow(); while (null != ipRow) { object oValue = ipRow.get_Value(iIndexOfField); bool bIsNumeric = false; if (null != oValue) { double dOutValue; bIsNumeric = double.TryParse(oValue.ToString().Trim(), System.Globalization.NumberStyles.Any, System.Globalization.CultureInfo.CurrentCulture, out dOutValue); } if (!bIsNumeric) { //Create Reviewer result and add to collection IPLTSError2 ipRevResult = new PLTSErrorClass() as IPLTSError2; ipRevResult.ErrorKind = pltsValErrorKind.pltsValErrorKindStandard; ipRevResult.OID = ipRow.OID; ipRevResult.QualifiedTableName = ipSourceDataset.Name; ipRevResult.ShortDescription = "Field does not contain a number"; ipRevResult.LongDescription = oValue.ToString() + " in " + arguments + " is not a number."; if (null != ipSourceFeatureClass) { IFeature ipFeature = ipSourceFeatureClass.GetFeature(ipRow.OID); if (null != ipFeature) { ipRevResult.ErrorGeometry = ipFeature.ShapeCopy; } } ipRevResultCollection.AddError(ipRevResult); } ipRow = ipCursor.NextRow(); }//end while //Release cursor Marshal.ReleaseComObject(ipCursor); ipCursor = null; //Return the collection of results return(ipRevResultCollection); }
/// <summary> /// Excecute is called by Data Reviewer engine and passed the appropriate parameters. /// </summary> /// <param name="ipSelectionToValidate">ISelectionSet of features/rows to validate</param> /// <param name="arguments">comma delimited string of arguments</param> /// <returns> /// Collection of validation results. /// </returns> public IPLTSErrorCollection Execute(ISelectionSet ipSelectionToValidate, string arguments) { if (null == ipSelectionToValidate) { throw new ArgumentNullException("ISelectionSet parameter is null"); } if (String.IsNullOrEmpty(arguments)) { throw new ArgumentNullException("string parameter is null or empty"); } //Get cursor of selected features/rows ICursor ipCursor = null; ipSelectionToValidate.Search(null, true, out ipCursor); IDataset ipSourceDataset = ipSelectionToValidate.Target as IDataset; IFeatureClass ipSourceFeatureClass = null; //Setup reference to feature class to be used when creating results if (ipSourceDataset.Type == esriDatasetType.esriDTFeatureClass) { ipSourceFeatureClass = ipSourceDataset as IFeatureClass; } //Get the index of the field we are checking int iIndexOfField = -1; iIndexOfField = ipCursor.FindField(arguments); //arguments is the name of the field we are checking if (-1 == iIndexOfField) { throw new Exception(String.Format("Field {0} was not found in Dataset {1}", arguments, ipSourceDataset.Name)); } //Collection of results passed back to Data Reviewer IPLTSErrorCollection ipRevResultCollection = new PLTSErrorCollectionClass(); //Loop through rows and check if field is numeric IRow ipRow = ipCursor.NextRow(); while (null != ipRow) { object oValue = ipRow.get_Value(iIndexOfField); bool bIsNumeric = false; if (null != oValue) { double dOutValue; bIsNumeric = double.TryParse(oValue.ToString().Trim(), System.Globalization.NumberStyles.Any, System.Globalization.CultureInfo.CurrentCulture, out dOutValue); } if (!bIsNumeric) { //Create Reviewer result and add to collection IPLTSError2 ipRevResult = new PLTSErrorClass() as IPLTSError2; ipRevResult.ErrorKind = pltsValErrorKind.pltsValErrorKindStandard; ipRevResult.OID = ipRow.OID; ipRevResult.QualifiedTableName = ipSourceDataset.Name; ipRevResult.ShortDescription = "Field does not contain a number"; ipRevResult.LongDescription = oValue.ToString() + " in " + arguments + " is not a number."; if (null != ipSourceFeatureClass) { IFeature ipFeature = ipSourceFeatureClass.GetFeature(ipRow.OID); if (null != ipFeature) { ipRevResult.ErrorGeometry = ipFeature.ShapeCopy; } } ipRevResultCollection.AddError(ipRevResult); } ipRow = ipCursor.NextRow(); }//end while //Release cursor Marshal.ReleaseComObject(ipCursor); ipCursor = null; //Return the collection of results return ipRevResultCollection; }
/// <summary> /// Validates the attributes in a Feature Class/Table or its subtype for domain constraints /// </summary> /// <param name="ipErrorCollection">Collection of validation results</param> /// <param name="ipTable">Feature class/Table whose attributes will be validated for domain constraints</param> /// <param name="ipDomain">Domain for which attributes need to be validated</param> /// <param name="strDomainFieldName">Name of the domain field</param> /// <param name="bHasSubtype">input true if the feature class/table has subype else false</param> /// <param name="strSubtypeFieldName">Name of the subtype field</param> /// <param name="iSubtypeCode">Subtype code for the subtype that need to be validated for the domain constraints</param> private void ValidateAttributes(IPLTSErrorCollection ipErrorCollection, ITable ipTable, IDomain ipDomain, string strDomainFieldName, bool bHasSubtype, string strSubtypeFieldName, int iSubtypeCode) { string strErrorConditionQueryString = ""; //Get the query string for searching records that violate domain constraints if (ipDomain.Type == esriDomainType.esriDTRange) { strErrorConditionQueryString = GetQueryStringForRangeDomain(ipDomain as IRangeDomain, strDomainFieldName); } else if (ipDomain.Type == esriDomainType.esriDTCodedValue) { strErrorConditionQueryString = GetQueryStringForCodedDomain(ipDomain as ICodedValueDomain, strDomainFieldName); } if (!string.IsNullOrEmpty(strErrorConditionQueryString)) { //Apply subtype filter if needed if(bHasSubtype && !string.IsNullOrEmpty(strSubtypeFieldName)) strErrorConditionQueryString += " AND " + strSubtypeFieldName + " = " + iSubtypeCode; //Use the query string to search records that violate domain constraints IQueryFilter ipQF = new QueryFilter(); ipQF.WhereClause = strErrorConditionQueryString; ICursor ipCursor = ipTable.Search(ipQF, true); if (null != ipCursor) { IRow ipRow = ipCursor.NextRow(); while (null != ipRow) { //Create a Reviewer result IPLTSError2 ipReviewerResult = new PLTSErrorClass() as IPLTSError2; ipReviewerResult.ErrorKind = pltsValErrorKind.pltsValErrorKindStandard; ipReviewerResult.OID = ipRow.OID; ipReviewerResult.LongDescription = "Domain constraints violated for " + strDomainFieldName + " field"; ipReviewerResult.QualifiedTableName = (ipTable as IDataset).Name; //If the record is a feature then use the feature geometry as Result's error geometry IFeature ipFeature = ipRow as IFeature; if (null != ipFeature) { IGeometry ipErrorGeometry = ipFeature.ShapeCopy; if (!ipErrorGeometry.IsEmpty) ipReviewerResult.ErrorGeometry = ipErrorGeometry; } //Add the result to the collection of results ipErrorCollection.AddError(ipReviewerResult); ipRow = ipCursor.NextRow(); } //release cursor System.Runtime.InteropServices.Marshal.ReleaseComObject(ipCursor); ipCursor = null; } } return; }
/// <summary> /// Excecute is called by Data Reviewer engine and passed the appropriate parameters. /// </summary> /// <param name="ipSelectionToValidate">ISelectionSet of features/rows to validate</param> /// <param name="arguments">comma delimited string of arguments</param> /// <returns> /// Collection of validation results. /// </returns> public IPLTSErrorCollection Execute(ISelectionSet ipSelectionToValidate, string arguments) { if (null == ipSelectionToValidate) { throw new ArgumentNullException("ISelectionSet parameter is null"); } if (String.IsNullOrEmpty(arguments)) { throw new ArgumentNullException("string parameter is null or empty"); } //Exit if there is nothing to check if (0 == ipSelectionToValidate.Count) { return(new PLTSErrorCollectionClass()); } //Arguments and default values string strTargetFeatureClassName = ""; string strTargetSubtypeNumber = ""; string strSourceWhereClause = ""; string strTargetWhereClause = ""; esriSpatialRelEnum eSpatialOperation = esriSpatialRelEnum.esriSpatialRelIntersects; string strSpatialRelDescription = ""; string strUserMessage = ""; //Split comma delimited string into array string[] arrayOfArguments = arguments.Split(new char[] { ',' }, StringSplitOptions.None); //Parse arguments for (int i = 0; i < arrayOfArguments.Length; i++) { if (0 == i) { strTargetFeatureClassName = arrayOfArguments[i]; } else if (1 == i) { strTargetSubtypeNumber = arrayOfArguments[i]; } else if (2 == i) { try { eSpatialOperation = (esriSpatialRelEnum)Convert.ToInt32(arrayOfArguments[i]); } catch (Exception ex) { throw new Exception(String.Format("Error converting spatial operation parameter to esriSpatialRelEnum. Parameter value {0}", arrayOfArguments[i]), ex); } } else if (3 == i) { strTargetWhereClause = arrayOfArguments[i]; } else if (4 == i) { strSourceWhereClause = arrayOfArguments[i]; } else if (5 == i) { strSpatialRelDescription = arrayOfArguments[i]; } else if (6 == i) { strUserMessage = arrayOfArguments[i]; } else { throw new Exception("Invalid number of arguments. Only seven arguments are allowed. Arguments: (" + arguments + ")"); } } //Get handle to workspace IDataset ipSourceDataset = ipSelectionToValidate.Target as IDataset; IFeatureWorkspace ipFeatureWorkspace = ipSourceDataset.Workspace as IFeatureWorkspace; //Open the target feature class. Feature class name passed in should be fully qualified. IFeatureClass ipTargetFeatureClass = ipFeatureWorkspace.OpenFeatureClass(strTargetFeatureClassName); if (null == ipTargetFeatureClass) { throw new Exception(String.Format("Unable to open feature class {0} from workspace {1}", strTargetFeatureClassName, (ipFeatureWorkspace as IWorkspace).PathName)); } string strTargetSubtypeFieldName = (ipTargetFeatureClass as ISubtypes).SubtypeFieldName; //Setup spatial filter to apply to target feature class ISpatialFilter ipTargetSF = new SpatialFilterClass(); ipTargetSF.SpatialRel = eSpatialOperation; if ("*" == strTargetSubtypeNumber || String.IsNullOrEmpty(strTargetSubtypeNumber)) { if (strTargetWhereClause.Length > 0) { ipTargetSF.WhereClause = strTargetWhereClause; } } else { if (strTargetWhereClause.Length > 0) { ipTargetSF.WhereClause = strTargetSubtypeFieldName + " = " + strTargetSubtypeNumber + " AND " + strTargetWhereClause; } else { ipTargetSF.WhereClause = strTargetSubtypeFieldName + " = " + strTargetSubtypeNumber; } } if (eSpatialOperation == esriSpatialRelEnum.esriSpatialRelRelation) { ipTargetSF.SpatialRelDescription = strSpatialRelDescription; } //Prepare source where clause IQueryFilter ipSourceQF = new QueryFilterClass(); if (strSourceWhereClause.Length > 0) { ipSourceQF.WhereClause = strSourceWhereClause; } IPLTSErrorCollection ipRevResultCollection = new PLTSErrorCollectionClass(); //Loop through source geometries and perform a spatial query againts the target Feature Class. //For each geometry that does not satisfy the spatial relationship add a Reviewer result. ICursor ipCursor = null; ipSelectionToValidate.Search(ipSourceQF, false, out ipCursor); IFeatureCursor ipFeatureCursor = ipCursor as IFeatureCursor; IFeature ipSourceFeature = ipFeatureCursor.NextFeature(); while (null != ipSourceFeature) { Application.DoEvents(); IGeometry ipSourceGeometry = ipSourceFeature.ShapeCopy; ipTargetSF.Geometry = ipSourceGeometry; //If spatial filter returns zero records create a Reviewer result. if (ipTargetFeatureClass.FeatureCount(ipTargetSF) == 0) { //Create a Reviewer result IPLTSError2 ipReviewerResult = new PLTSErrorClass() as IPLTSError2; ipReviewerResult.ErrorKind = pltsValErrorKind.pltsValErrorKindStandard; ipReviewerResult.OID = ipSourceFeature.OID; ipReviewerResult.LongDescription = strUserMessage; ipReviewerResult.QualifiedTableName = ipSourceDataset.Name; ipReviewerResult.ErrorGeometry = ipSourceGeometry; ipRevResultCollection.AddError(ipReviewerResult); } ipSourceFeature = ipFeatureCursor.NextFeature(); }//end while loop //Release cursor Marshal.ReleaseComObject(ipFeatureCursor); ipFeatureCursor = null; Marshal.ReleaseComObject(ipCursor); ipCursor = null; //Return the collection of results return(ipRevResultCollection); }