/// <summary> /// Gets a cursor helper given a filter /// </summary> /// <param name="classIndex">ignore - feature datasets unsupported</param> /// <param name="env">Optional bounding box</param> /// <param name="strictSearch">ignore this parameter</param> /// <param name="whereClause">Optional where clause - unsupported</param> /// <param name="fidSet">Optional list of OIDs to select</param> /// <param name="fieldMap">Which fields are included in results</param> /// <returns></returns> public IPlugInCursorHelper FetchWithFilter(int classIndex, IEnvelope env, bool strictSearch, string WhereClause, IFIDSet fidSet, object fieldMap) { // without a OID list perform fetch by envelope if (null == fidSet) { return(this.FetchByEnvelope(classIndex, env, strictSearch, WhereClause, fieldMap)); } //to-do write SQL to IMongoQuery translator and assign to conditions if where clause is non-null IMongoQuery conditions = null; // build a mongo IN query of all OIDs int count = fidSet.Count(); BsonArray ba = new BsonArray(count); fidSet.Reset(); for (int i = 0; i < count; i++) { int oid; fidSet.Next(out oid); ba.Add(BsonValue.Create(oid)); } if (conditions == null) { conditions = Query.In(CommonConst.OID, ba); } else { conditions = Query.And(new IMongoQuery[] { Query.In(CommonConst.OID, ba), conditions }); } return(new MongoDBCursor(m_Connection[m_Entry.Name], env, conditions, CommonConst.SHAPEFIELD, (System.Array)fieldMap, m_Entry.Fields)); }
/// <summary> /// Creates an <see cref="IEnumerable{T}" /> from an <see cref="IFIDSet" /> /// </summary> /// <param name="source">An <see cref="IFIDSet" /> to create an <see cref="IEnumerable{T}" /> from.</param> /// <returns>An <see cref="IEnumerable{T}" /> that contains the IDs from the input source.</returns> public static IEnumerable <int> AsEnumerable(this IFIDSet source) { if (source != null) { source.Reset(); int objectId; source.Next(out objectId); while (objectId >= 0) { yield return(objectId); source.Next(out objectId); } } }
public void FIDsetToLongArray(IFIDSet InFIDSet, ref ILongArray OutLongArray, IStepProgressor StepProgressor) { Int32 pfID = -1; InFIDSet.Reset(); double dMax = InFIDSet.Count(); int iMax = (int)(dMax); for (Int32 pCnt = 0; pCnt <= (InFIDSet.Count() - 1); pCnt++) { InFIDSet.Next(out pfID); OutLongArray.Add(pfID); if (StepProgressor != null) { if (StepProgressor.Position < StepProgressor.MaxRange) StepProgressor.Step(); } } return; }
public bool DeleteRowsUnversioned(IWorkspace TheWorkSpace, ITable inTable, IFIDSet pFIDSet, IStepProgressor StepProgressor, ITrackCancel TrackCancel) { IMouseCursor pMouseCursor = new MouseCursorClass(); pMouseCursor.SetCursor(2); if (StepProgressor != null) { StepProgressor.MinRange = StepProgressor.Position; //reset the progress bar position StepProgressor.MaxRange = StepProgressor.Position + pFIDSet.Count(); if (StepProgressor.Position < StepProgressor.MaxRange) { StepProgressor.Step(); } } IQueryFilter pQF = new QueryFilterClass(); ISQLSyntax pSQLSyntax = (ISQLSyntax)TheWorkSpace; string sPref = pSQLSyntax.GetSpecialCharacter(esriSQLSpecialCharacters.esriSQL_DelimitedIdentifierPrefix); string sSuff = pSQLSyntax.GetSpecialCharacter(esriSQLSpecialCharacters.esriSQL_DelimitedIdentifierSuffix); ICursor ipCursor = null; IRow pRow = null; //make sure that there are no more then 999 tokens for the in clause(ORA- query will otherwise error on an Oracle database) int iTokenLimit = 995; int iTokenSet = 0; //the index of the set of 995 tokens string sWhereClauseLHS = sPref + inTable.OIDFieldName + sSuff + " in ("; string[] ids = { sWhereClauseLHS }; try { ITableWrite pTableWr = (ITableWrite)inTable; pFIDSet.Reset(); bool bCont = true; Int32 iID; Int32 count = pFIDSet.Count(); int j = 0; //inner count for each set of IDs for (int k = 0; k < count; k++) { if (j > iTokenLimit) { //over the limit for this Token set, time to create a new set ids[iTokenSet] += ")"; //close the previous set RedimPreserveString(ref ids, 1); //make space in the string array for the next token set iTokenSet++; //increment the index ids[iTokenSet] = sWhereClauseLHS; //left-hand side of the where clause j = 0; //reset the inner count back to zero } pFIDSet.Next(out iID); if (j > 0) //write a comma if this is not the first ID { ids[iTokenSet] += ","; } ids[iTokenSet] += iID.ToString(); j++; //increment the inner count } ids[iTokenSet] += ")"; if (count > 0) { for (int k = 0; k <= iTokenSet; k++) { pQF.WhereClause = ids[k]; ipCursor = pTableWr.UpdateRows(pQF, false); pRow = ipCursor.NextRow(); while (pRow != null) { ipCursor.DeleteRow(); Marshal.ReleaseComObject(pRow); if (StepProgressor != null) { //Check if the cancel button was pressed. If so, stop process if (TrackCancel != null) { bCont = TrackCancel.Continue(); } if (!bCont) { break; } if (StepProgressor.Position < StepProgressor.MaxRange) { StepProgressor.Step(); } } pRow = ipCursor.NextRow(); } if (!bCont) { AbortEditing(TheWorkSpace); if (ipCursor != null) { Marshal.ReleaseComObject(ipCursor); } if (pRow != null) { Marshal.ReleaseComObject(pRow); } if (pQF != null) { Marshal.ReleaseComObject(pQF); } if (pMouseCursor != null) { Marshal.ReleaseComObject(pMouseCursor); } return(false); } Marshal.ReleaseComObject(ipCursor); } Marshal.ReleaseComObject(pQF); } Marshal.ReleaseComObject(pMouseCursor); return(true); } catch (COMException ex) { if (ipCursor != null) { Marshal.ReleaseComObject(ipCursor); } if (pRow != null) { Marshal.ReleaseComObject(pRow); } if (pQF != null) { Marshal.ReleaseComObject(pQF); } if (pMouseCursor != null) { Marshal.ReleaseComObject(pMouseCursor); } MessageBox.Show(Convert.ToString(ex.ErrorCode)); return(false); } }
public bool DeleteRowsByFIDSet(ITable inTable, IFIDSet pFIDSet, IStepProgressor StepProgressor, ITrackCancel TrackCancel) {//this routine uses the GetRows method, avoids the need to break up the InClause. IMouseCursor pMouseCursor = new MouseCursorClass(); pMouseCursor.SetCursor(2); try { pFIDSet.Reset(); int[] iID = { }; bool bCont = true; iID = RedimPreserveInt(ref iID, pFIDSet.Count()); for (int iCount = 0; iCount <= pFIDSet.Count() - 1; iCount++) { pFIDSet.Next(out iID[iCount]); } ICursor pCursor = inTable.GetRows(iID, false); IRow row = pCursor.NextRow(); if (StepProgressor != null) { StepProgressor.MinRange = StepProgressor.Position; //reset the progress bar position StepProgressor.MaxRange = StepProgressor.Position + pFIDSet.Count(); if (StepProgressor.Position < StepProgressor.MaxRange) { StepProgressor.Step(); } } while (row != null) { //Check if the cancel button was pressed. If so, stop process if (StepProgressor != null) { if (TrackCancel != null) { bCont = TrackCancel.Continue(); } if (!bCont) { break; } } row.Delete(); Marshal.ReleaseComObject(row); row = pCursor.NextRow(); if (StepProgressor != null) { if (StepProgressor.Position < StepProgressor.MaxRange) { StepProgressor.Step(); } } } Marshal.ReleaseComObject(pCursor); inTable = null; iID = null; if (!bCont) { return(false); } return(true); } catch (COMException ex) { StepProgressor = null; MessageBox.Show(ex.Message); return(false); } }
public void EmptyGeometriesUnversioned(IWorkspace TheWorkSpace, IFeatureClass inTable, IFIDSet pFIDSet) { IMouseCursor pMouseCursor = new MouseCursorClass(); pMouseCursor.SetCursor(2); IQueryFilter pQF = new QueryFilterClass(); ISQLSyntax pSQLSyntax = (ISQLSyntax)TheWorkSpace; string sPref = pSQLSyntax.GetSpecialCharacter(esriSQLSpecialCharacters.esriSQL_DelimitedIdentifierPrefix); string sSuff = pSQLSyntax.GetSpecialCharacter(esriSQLSpecialCharacters.esriSQL_DelimitedIdentifierSuffix); ICursor ipCursor = null; IRow pRow = null; //make sure that there are no more then 999 tokens for the in clause(ORA- query will otherwise error on an Oracle database) int iTokenLimit = 995; int iTokenSet = 0; //the index of the set of 995 tokens string sWhereClauseLHS = sPref + inTable.OIDFieldName + sSuff + " in ("; string[] ids = { sWhereClauseLHS }; try { ITableWrite pTableWr = (ITableWrite)inTable; pFIDSet.Reset(); bool bCont = true; Int32 iID; Int32 count = pFIDSet.Count(); int j = 0; //inner count for each set of IDs for (int k = 0; k < count; k++) { if (j > iTokenLimit) {//over the limit for this Token set, time to create a new set ids[iTokenSet] += ")";//close the previous set RedimPreserveString(ref ids, 1);//make space in the string array for the next token set iTokenSet++;//increment the index ids[iTokenSet] = sWhereClauseLHS; //left-hand side of the where clause j = 0;//reset the inner count back to zero } pFIDSet.Next(out iID); if (j > 0) //write a comma if this is not the first ID ids[iTokenSet] += ","; ids[iTokenSet] += iID.ToString(); j++; //increment the inner count } ids[iTokenSet] += ")"; if (count > 0) { IFeature pFeat = null; ISet pRowSet = new SetClass(); for (int k = 0; k <= iTokenSet; k++) { pRowSet.RemoveAll(); pQF.WhereClause = ids[k]; ipCursor = pTableWr.UpdateRows(pQF, false); pRow = ipCursor.NextRow(); while (pRow != null) { pFeat = (IFeature)pRow; IGeometry pGeo = pFeat.ShapeCopy; pGeo.SetEmpty(); pFeat.Shape = pGeo; ipCursor.UpdateRow(pRow); Marshal.ReleaseComObject(pRow); pRow = ipCursor.NextRow(); } if (!bCont) { AbortEditing(TheWorkSpace); if (ipCursor != null) Marshal.ReleaseComObject(ipCursor); if (pRow != null) Marshal.ReleaseComObject(pRow); //if (pQF != null) // Marshal.ReleaseComObject(pQF); return; } } Marshal.ReleaseComObject(ipCursor); //Marshal.ReleaseComObject(pQF); } return; } catch (COMException ex) { if (ipCursor != null) Marshal.ReleaseComObject(ipCursor); if (pRow != null) Marshal.ReleaseComObject(pRow); //if (pQF != null) // Marshal.ReleaseComObject(pQF); MessageBox.Show(Convert.ToString(ex.ErrorCode)); return; } }
public void EmptyGeometries(IFeatureClass inFeatureClass, IFIDSet pFIDSet) { try { if (pFIDSet.Count() < 1) return; pFIDSet.Reset(); int[] iID = { }; iID = RedimPreserveInt(ref iID, pFIDSet.Count()); for (int iCount = 0; iCount <= pFIDSet.Count() - 1; iCount++) pFIDSet.Next(out iID[iCount]); IFeatureCursor pFeatCursor = inFeatureClass.GetFeatures(iID, false); IFeature pFeat = pFeatCursor.NextFeature(); while (pFeat != null) { IGeometry pGeo = pFeat.ShapeCopy; pGeo.SetEmpty(); pFeat.Shape = pGeo; pFeat.Store(); Marshal.ReleaseComObject(pFeat); pFeat = pFeatCursor.NextFeature(); } Marshal.ReleaseComObject(pFeatCursor); iID = null; return; } catch (Exception ex) { MessageBox.Show(ex.Message); return; } }
public bool DeleteRowsUnversioned(IWorkspace TheWorkSpace, ITable inTable, IFIDSet pFIDSet, IStepProgressor StepProgressor, ITrackCancel TrackCancel) { IMouseCursor pMouseCursor = new MouseCursorClass(); pMouseCursor.SetCursor(2); Debug.WriteLine(StepProgressor.Position); Debug.WriteLine(StepProgressor.MaxRange); IQueryFilter pQF = new QueryFilterClass(); ISQLSyntax pSQLSyntax = (ISQLSyntax)TheWorkSpace; string sPref = pSQLSyntax.GetSpecialCharacter(esriSQLSpecialCharacters.esriSQL_DelimitedIdentifierPrefix); string sSuff = pSQLSyntax.GetSpecialCharacter(esriSQLSpecialCharacters.esriSQL_DelimitedIdentifierSuffix); ICursor ipCursor = null; IRow pRow = null; //make sure that there are no more then 999 tokens for the in clause(ORA- query will otherwise error on an Oracle database) int iTokenLimit = 995; int iTokenSet = 0; //the index of the set of 995 tokens string sWhereClauseLHS = sPref + inTable.OIDFieldName + sSuff + " in ("; string[] ids = { sWhereClauseLHS }; try { ITableWrite pTableWr = (ITableWrite)inTable; pFIDSet.Reset(); bool bCont = true; Int32 iID; Int32 count = pFIDSet.Count(); int j = 0; //inner count for each set of IDs for (int k = 0; k < count; k++) { if (j > iTokenLimit) {//over the limit for this Token set, time to create a new set ids[iTokenSet] += ")";//close the previous set RedimPreserveString(ref ids, 1);//make space in the string array for the next token set iTokenSet++;//increment the index ids[iTokenSet] = sWhereClauseLHS; //left-hand side of the where clause j = 0;//reset the inner count back to zero } pFIDSet.Next(out iID); if (j > 0) //write a comma if this is not the first ID ids[iTokenSet] += ","; ids[iTokenSet] += iID.ToString(); j++; //increment the inner count } ids[iTokenSet] += ")"; if (count > 0) { for (int k = 0; k <= iTokenSet; k++) { pQF.WhereClause = ids[k]; ipCursor = pTableWr.UpdateRows(pQF, false); pRow = ipCursor.NextRow(); while (pRow != null) { ipCursor.DeleteRow(); Marshal.ReleaseComObject(pRow); if (StepProgressor != null) { //Check if the cancel button was pressed. If so, stop process if (TrackCancel != null) bCont = TrackCancel.Continue(); if (!bCont) break; if (StepProgressor.Position < StepProgressor.MaxRange) StepProgressor.Step(); } pRow = ipCursor.NextRow(); } if (!bCont) { AbortEditing(TheWorkSpace); if (ipCursor != null) Marshal.ReleaseComObject(ipCursor); if (pRow != null) Marshal.ReleaseComObject(pRow); //if (pQF != null) // Marshal.ReleaseComObject(pQF); return false; } Marshal.ReleaseComObject(ipCursor); } //Marshal.ReleaseComObject(pQF); } Debug.WriteLine(StepProgressor.Position); return true; } catch (Exception ex) { if (ipCursor != null) Marshal.ReleaseComObject(ipCursor); if (pRow != null) Marshal.ReleaseComObject(pRow); //if (pQF != null) // Marshal.ReleaseComObject(pQF); MessageBox.Show(Convert.ToString(ex.Message)); return false; } }
public bool DeleteRowsByFIDSetReturnGeomCollection(ITable inTable, IFIDSet pFIDSet, IStepProgressor StepProgressor, ITrackCancel TrackCancel, ref IGeometryCollection GeomCollection) { //this routine uses the GetRows method, avoids the need to break up the InClause. if (pFIDSet == null) return false; IMouseCursor pMouseCursor = new MouseCursorClass(); pMouseCursor.SetCursor(2); try { pFIDSet.Reset(); int[] iID = { }; bool bCont = true; iID = RedimPreserveInt(ref iID, pFIDSet.Count()); for (int iCount = 0; iCount <= pFIDSet.Count() - 1; iCount++) pFIDSet.Next(out iID[iCount]); ICursor pCursor = inTable.GetRows(iID, false); IRow row = pCursor.NextRow(); if (StepProgressor != null) { if (StepProgressor.Position < StepProgressor.MaxRange) StepProgressor.Step(); } while (row != null) { IFeature pFeat = row as IFeature; IGeometry pGeom = pFeat.ShapeCopy; if (pGeom != null) { if (!pGeom.IsEmpty) { object obj = Type.Missing; IEnvelope2 pEnv = (IEnvelope2)pGeom.Envelope; pEnv.Expand(0.1, 0.1, false); GeomCollection.AddGeometry(pEnv, ref obj, ref obj); } } //Check if the cancel button was pressed. If so, stop process if (StepProgressor != null) { if (TrackCancel != null) bCont = TrackCancel.Continue(); if (!bCont) break; } row.Delete(); Marshal.ReleaseComObject(row); row = pCursor.NextRow(); if (StepProgressor != null) { if (StepProgressor.Position < StepProgressor.MaxRange) StepProgressor.Step(); } } Marshal.ReleaseComObject(pCursor); inTable = null; iID = null; if (!bCont) return false; return true; } catch (COMException ex) { StepProgressor = null; if (ex.ErrorCode == -2147217400) //MessageBox.Show(ex.ErrorCode + Environment.NewLine + ex.Message + // Environment.NewLine + "This error indicates that the fabric may not have been correctly upgraded."); //TODO: need to confirm this. m_LastErrorCode = ex.ErrorCode; else MessageBox.Show(ex.Message + Environment.NewLine + ex.ErrorCode); m_LastErrorCode = ex.ErrorCode; return false; } }
public void IntersectFIDSetCommonIDs(IFIDSet InFIDSet1, IFIDSet InFIDSet2, out IFIDSet OutFIDSet) { IFIDSet OutFIDSet2 = new FIDSetClass(); Int32 pfID = -1; bool bExists = false; InFIDSet1.Reset(); for (Int32 i = 0; i <= (InFIDSet1.Count() - 1); i++) { InFIDSet1.Next(out pfID); InFIDSet2.Find(pfID, out bExists); if (bExists) OutFIDSet2.Add(pfID); } OutFIDSet = OutFIDSet2; return; }
/// <summary> /// Gets the differences between the <paramref name="source" /> and <paramref name="target" /> versions that need to be /// checked-in or exported. /// </summary> /// <param name="source">The source (or child) version.</param> /// <param name="target">The target (or parent) version.</param> /// <param name="predicate"> /// The predicate that defines a set of criteria and determines whether the specified differences /// will be loaded. /// </param> /// <param name="dataChangeTypes">The data change types.</param> /// <returns> /// Returns a <see cref="Dictionary{String, DeltaRow}" /> representing the differences for the table (or /// key). /// </returns> /// <exception cref="System.ArgumentNullException"> /// target /// or /// predicate /// or /// dataChangeTypes /// </exception> public static Dictionary <string, DeltaRowCollection> GetDataChanges(this IVersion source, IVersion target, Func <IModifiedClassInfo, bool> predicate, params esriDataChangeType[] dataChangeTypes) { if (source == null) { return(null); } if (target == null) { throw new ArgumentNullException("target"); } if (predicate == null) { throw new ArgumentNullException("predicate"); } if (dataChangeTypes == null) { throw new ArgumentNullException("dataChangeTypes"); } var list = new Dictionary <string, DeltaRowCollection>(StringComparer.Create(CultureInfo.InvariantCulture, true)); IVersionDataChangesInit vdci = new VersionDataChangesClass(); IWorkspaceName wsNameSource = (IWorkspaceName)((IDataset)source).FullName; IWorkspaceName wsNameTarget = (IWorkspaceName)((IDataset)target).FullName; vdci.Init(wsNameSource, wsNameTarget); IDataChanges dataChanges = (IDataChanges)vdci; IDataChangesInfo dci = (IDataChangesInfo)vdci; var tasks = new List <Action>(); IEnumModifiedClassInfo enumMci = dataChanges.GetModifiedClassesInfo(); foreach (var mci in enumMci.AsEnumerable()) { // Validate that the table needs to be loaded. if (predicate(mci)) { string tableName = mci.ChildClassName; tasks.Add(() => { var rows = new DeltaRowCollection(mci, source, target); var actions = new List <Action>(); // Determines if the table represents a feature class. bool isFeatureClass = mci.DatasetType == esriDatasetType.esriDTFeatureClass; // Iterate through all of the data change types. foreach (var dataChangeType in dataChangeTypes) { actions.Add(() => { // IRow objects returned from a difference cursor are meant to be a read only. Thus, only the OIDs are being loaded and // the rows are hydrated from the struct. IFIDSet set = dci.ChangedIDs[tableName, dataChangeType]; set.Reset(); int oid; set.Next(out oid); while (oid != -1) { var row = new DeltaRow(dataChangeType, oid, tableName, isFeatureClass); rows.Add(row); set.Next(out oid); } }); } if (actions.Any()) { Task.WaitAll(actions); } list.Add(tableName, rows); }); } } if (tasks.Any()) { Task.WaitAll(tasks); } return(list); }