本文整理汇总了C#中IFeatureClass.Update方法的典型用法代码示例。如果您正苦于以下问题:C# IFeatureClass.Update方法的具体用法?C# IFeatureClass.Update怎么用?C# IFeatureClass.Update使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IFeatureClass
的用法示例。
在下文中一共展示了IFeatureClass.Update方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: UpdateFeature
public static void UpdateFeature(IFeatureClass featureClass)
{
// Create a COM releaser for cursor management
using (ComReleaser comReleaser = new ComReleaser())
{
// Use IFeatureClass.Update to create an update cursor
IFeatureCursor featureCursor = featureClass.Update(null, true);
comReleaser.ManageLifetime(featureCursor);
// find the index of the field named "country"
int fieldIndex = featureClass.FindField("Country");
IFeature feature = null;
while ((feature = featureCursor.NextFeature()) != null)
{
feature.set_Value(fieldIndex, "USA");
featureCursor.UpdateFeature(feature); // Do not use IFeature.Store with UpdateCursors
}
}
}
示例2: summarizeBiomassPolygon
public static void summarizeBiomassPolygon(IFeatureClass pointFtr, IField[] fldsToSummarize, IFunctionRasterDataset strataRaster, IFeatureClass standsFtr, geoDatabaseUtility geoUtil = null, rasterUtil rsUtil = null)
{
if (geoUtil == null) geoUtil = new geoDatabaseUtility();
if(rsUtil == null) rsUtil = new rasterUtil();
int cnt = 0;
//need to work on calculating N
Dictionary<string,double[][]> vlDic = getDictionaryValues(pointFtr, fldsToSummarize, strataRaster, geoUtil, rsUtil); //Strata: SummaryFields [{sum,sum2,cnt},...]
int[] meanFldIndex = new int[fldsToSummarize.Length];
int[] varFldIndex = new int[fldsToSummarize.Length];
int[] cntFldIndex = new int[fldsToSummarize.Length];
//string cntName = geoUtil.createField(standsFtr, "n", esriFieldType.esriFieldTypeInteger, false);
//int cntIndex = standsFtr.FindField(cntName);
foreach (IField fld in fldsToSummarize)
{
string sName = geoUtil.createField(standsFtr, "v_" + fld.Name, esriFieldType.esriFieldTypeDouble, false);
varFldIndex[cnt] = standsFtr.FindField(sName);
string mName = geoUtil.createField(standsFtr, "m_" + fld.Name, esriFieldType.esriFieldTypeDouble, false);
meanFldIndex[cnt] = standsFtr.FindField(mName);
string cntName = geoUtil.createField(standsFtr, "n_" + fld.Name, esriFieldType.esriFieldTypeDouble, false);
cntFldIndex[cnt] = standsFtr.FindField(cntName);
cnt++;
}
IFeatureCursor uCur = standsFtr.Update(null, true);
IFeature uFtr = uCur.NextFeature();
while (uFtr != null)
{
ESRI.ArcGIS.Geometry.IGeometry geo = uFtr.Shape;
IFunctionRasterDataset cRs = rsUtil.clipRasterFunction(strataRaster, geo, esriRasterClippingType.esriRasterClippingOutside);
//Console.WriteLine("Clipping raster");
Dictionary<string, double> rsStrataPropDic = getStrataProportion(cRs,rsUtil); //Strata: proportion of area
//int tn = 0;
//double[] tn = new double[meanFldIndex.Length];
double[][] updateValuesArr = new double[meanFldIndex.Length][];
for (int i = 0; i < meanFldIndex.Length; i++)
{
updateValuesArr[i] = new double[3];
}
foreach (KeyValuePair<string, double> kvp in rsStrataPropDic)
{
string stratum = kvp.Key;
double proportion = kvp.Value;
//Console.WriteLine(stratum + " = " + proportion.ToString());
double[][] vlDicArr;
if (vlDic.TryGetValue(stratum, out vlDicArr))
{
//double n = vlDicArr[0][2];
//tn += System.Convert.ToInt32(n);
for (int i = 0; i < meanFldIndex.Length; i++)
{
double[] dArr = vlDicArr[i];
double n = dArr[2];
//tn[i] += n;
double s=dArr[0];
double s2=dArr[1];
updateValuesArr[i][0] += (s/n) * proportion;//mean
updateValuesArr[i][1] += (s2-Math.Pow(s,2)/n)/(n-1) * proportion;//variance
updateValuesArr[i][2] += n;
}
}
}
//uFtr.set_Value(cntIndex, tn);
for (int i = 0; i < meanFldIndex.Length; i++)
{
uFtr.set_Value(meanFldIndex[i], updateValuesArr[i][0]);
uFtr.set_Value(varFldIndex[i], updateValuesArr[i][1]);
uFtr.set_Value(cntFldIndex[i], updateValuesArr[i][2]);
}
uCur.UpdateFeature(uFtr);
uFtr = uCur.NextFeature();
}
System.Runtime.InteropServices.Marshal.ReleaseComObject(uCur);
}
开发者ID:GeospatialDaryl,项目名称:USFS_RMRS_FunctionalModeling_RasterModeling,代码行数:73,代码来源:fiaIntegration.cs
示例3: UpdateCircularArcValues
private bool UpdateCircularArcValues(IFeatureClass LineTable, IQueryFilter QueryFilter, bool Unversioned, IDictionary<int, InferredCurve> CurveLookup, myProgessor progressor, Dictionary<int, int> MaxSequenceCache)
{
IFeature pLineFeat = null;
IFeatureBuffer buffer = null;
IFeatureCursor pLineCurs = null;
IFeatureCursor pRadialCur = null;
IFeatureCursor maxCursor = null;
IDataStatistics dataStatistics = null;
IGeometryFactory3 geometryFactory = new GeometryEnvironmentClass();
IGeometry geometry = new PolylineClass();
geometryFactory.CreateEmptyGeometryByType(LineTable.ShapeType, out geometry);
IGeometryDef geometryDef = LineTable.Fields.get_Field(LineTable.FindField(LineTable.ShapeFieldName)).GeometryDef;
if (geometryDef.HasZ)
{
IZAware zAware = (IZAware)(geometry);
zAware.ZAware = true;
}
if (geometryDef.HasM)
{
IMAware mAware = (IMAware)(geometry);
mAware.MAware = true;
}
try
{
CurveByInferenceSettings.FieldPositions positions = new CurveByInferenceSettings.FieldPositions((ITable)LineTable);
buffer = LineTable.CreateFeatureBuffer();
pLineCurs = LineTable.Update(QueryFilter, false);
pRadialCur = LineTable.Insert(false);
while ((pLineFeat = pLineCurs.NextFeature()) != null)
{
//loop through all of the given lines, and update centerpoint ids, radius, and arc length values
if (!progressor.Continue())
return false;
progressor.Step();
InferredCurve curveInfo = CurveLookup[pLineFeat.OID];
pLineFeat.set_Value(positions.RadiusFieldIdx, curveInfo.InferredRadius);
pLineFeat.set_Value(positions.CenterpointIDFieldIdx, curveInfo.InferredCenterpointID);
IFeature feature = pLineFeat as IFeature;
double length = 0;
if (feature != null)
{
IPolyline polyline = feature.ShapeCopy as IPolyline;
if (polyline != null)
{
length = ((IProximityOperator)polyline.FromPoint).ReturnDistance(polyline.ToPoint);
pLineFeat.set_Value(positions.ArcLengthFieldIdx, length);
Marshal.ReleaseComObject(polyline);
}
}
if (Unversioned)
pLineCurs.UpdateFeature(pLineFeat);
else
pLineFeat.Store();
//fine the max sequence value
int maxSequence = -1;
if (MaxSequenceCache.ContainsKey(curveInfo.Parcel))
{
maxSequence = MaxSequenceCache[curveInfo.Parcel];
}
else
{
maxCursor = LineTable.Search(new QueryFilter() {
SubFields = String.Format("{0}, {1}, {2}", LineTable.OIDFieldName, CurveByInferenceSettings.Instance.SequenceFieldName, CurveByInferenceSettings.Instance.ParcelIDFieldName),
WhereClause = String.Format("{0} = {1}", CurveByInferenceSettings.Instance.ParcelIDFieldName, curveInfo.Parcel) }, true);
int seqenceIdx = maxCursor.Fields.FindField(CurveByInferenceSettings.Instance.SequenceFieldName);
IRow maxFeat = null;
while ((maxFeat = maxCursor.NextFeature()) != null)
{
maxSequence = Math.Max((int)maxFeat.get_Value(seqenceIdx), maxSequence);
Marshal.ReleaseComObject(maxFeat);
}
Marshal.ReleaseComObject(maxCursor);
MaxSequenceCache.Add(curveInfo.Parcel, maxSequence);
dataStatistics = null;
maxCursor = null;
}
if (maxSequence <= 0)
throw new Exception("Failed to find max sequence value");
//the chord bearing
double featureBearing = (double)pLineFeat.get_Value(positions.BearingFieldIdx);
//half the delta of the proposed curve would be:
double halfdelta = toDegrees(Math.Asin(length / 2 / curveInfo.InferredRadius.Value));
//perpendicular to the chord
//.........这里部分代码省略.........
示例4: MatchTable
/// <summary>
/// Geocodes a table of addresses
/// </summary>
/// <param name="addressTable">Input address table</param>
/// <param name="addressFieldNames">Fields defined in the table</param>
/// <param name="whereClause">Query filter where clause</param>
/// <param name="outputFeatureClass">Output feature class for matched addresses</param>
/// <param name="outputFieldNames">Output field names</param>
/// <param name="fieldsToCopy"></param>
/// <param name="cancelTracker"></param>
public virtual void MatchTable(ITable addressTable, String addressFieldNames, String whereClause,
IFeatureClass outputFeatureClass, String outputFieldNames, IPropertySet fieldsToCopy, ITrackCancel cancelTracker)
{
_log.Debug("IAddressGeocoding MatchTable");
// Obtain the read and insert cursors
IQueryFilter queryFilter = new QueryFilterClass();
queryFilter.WhereClause = whereClause;
ICursor readCursor = null;
IFeatureCursor insertCursor = null;
IFeatureCursor updateCursor = null;
// m_needToUpdate will be True when a Rematch is being preformed
if (m_needToUpdate)
{
// Create update cursor to update matched records
updateCursor = outputFeatureClass.Update(queryFilter, false);
if (isSameObject(addressTable, outputFeatureClass))
readCursor = updateCursor as ICursor;
else
readCursor = addressTable.Search(queryFilter, true);
}
else
{
// Create insert cursor to add new records
readCursor = addressTable.Search(queryFilter, true);
insertCursor = outputFeatureClass.Insert(true);
}
int count = addressTable.RowCount(queryFilter);
// Progress dialog setup
IStepProgressor progressor = null;
if (cancelTracker != null)
progressor = cancelTracker.Progressor as IStepProgressor;
IProgressStatistics progStats = cancelTracker as IProgressStatistics;
if (progressor != null)
{
progressor.StepValue = 1;
progressor.MaxRange = addressTable.RowCount(null);
}
// Separate the input field names
string[] multilineFields = addressFieldNames.Split(',');
// Read the first row and get the address field
IRow row = readCursor.NextRow();
Dictionary<int, string> addressFieldIndexes = new Dictionary<int, string>();
// Get the index of each valid field
for (int i = 0; i < multilineFields.Length; i++)
{
if (multilineFields[i].Trim().Length > 0)
addressFieldIndexes.Add(row.Fields.FindField(multilineFields[i].Trim()), multilineFields[i].Trim());
}
string address;
IPropertySet addressProperties = new PropertySetClass();
IPropertySet resultSet;
IFeatureBuffer featureBuffer;
object copyTo, copyFrom, key, value;
// Get the name and value of all the properties in the property set
fieldsToCopy.GetAllProperties(out copyTo, out copyFrom);
string[] copyToArray = copyTo as string[];
object[] copyFromArray = copyFrom as object[];
string matchStatus = "U";
// Populate the output feature class
while (row != null)
{
featureBuffer = outputFeatureClass.CreateFeatureBuffer();
foreach (KeyValuePair<int,string> entry in addressFieldIndexes)
{
if (entry.Key != -1)
address = row.get_Value(entry.Key) as string;
else
address = row.get_Value(0) as string;
addressProperties.SetProperty(entry.Value, address);
}
resultSet = MatchAddress(addressProperties);
// Get all of the fields and values of the result
resultSet.GetAllProperties(out key, out value);
string[] names = key as string[];
object[] items = value as object[];
//.........这里部分代码省略.........
示例5: TratarSubtiposDominiosShapefile
private static void TratarSubtiposDominiosShapefile(IFeatureLayer fLayer, string pasta, IFeatureWorkspace pFeatureWorkspace, IFeatureClass pFeatureClassShp)
{
List<String> camposAdicionados = new List<string>();
IWorkspace ws = (fLayer.FeatureClass as IDataset).Workspace;
IQueryFilter qf = new QueryFilterClass();
IFeatureCursor fcur = null;
IFeature ftr = null;
#region
for (int i = 0; i < fLayer.FeatureClass.Fields.FieldCount; i++)
{
IDomain domain = fLayer.FeatureClass.Fields.get_Field(i).Domain;
int totLinhas = (fLayer.FeatureClass as ITable).RowCount(qf);
if (domain != null)
{
AdicionarColuna(fLayer.FeatureClass.Fields.get_Field(i), fLayer, pFeatureClassShp, camposAdicionados);
#region Setando valores
fcur = pFeatureClassShp.Update(qf, true);
ftr = fcur.NextFeature();
while (ftr != null)
{
int idxNovoCampo = pFeatureClassShp.Fields.FieldCount - 1;
ftr.set_Value(idxNovoCampo, GetDescricaoDominio(domain.Name, ftr.get_Value(i + 1), ws));
fcur.UpdateFeature(ftr);
ftr = fcur.NextFeature();
}
#endregion
}
else
{
#region Tratamento para subtipos
if (CampoEhSubtipo(fLayer.FeatureClass.Fields.get_Field(i).Name, fLayer.FeatureClass))
{
AdicionarColuna(fLayer.FeatureClass.Fields.get_Field(i), fLayer, pFeatureClassShp, camposAdicionados);
ISubtypes subtipos = fLayer.FeatureClass as ISubtypes;
IEnumSubtype enumSub = subtipos.Subtypes;
int subtypeCode;
String descSubtipo = enumSub.Next(out subtypeCode);
fcur = pFeatureClassShp.Update(qf, true);
ftr = fcur.NextFeature();
while (ftr != null)
{
int idxNovoCampo = pFeatureClassShp.Fields.FieldCount - 1;
ftr.set_Value(idxNovoCampo, GetDescricaoSubtipo(subtipos, ftr.get_Value(i + 1)));
fcur.UpdateFeature(ftr);
ftr = fcur.NextFeature();
}
}
#endregion
}
}
pFeatureClassShp = null;
GC.Collect();
GC.WaitForPendingFinalizers();
#endregion
}
示例6: updateIsMemberOf
private void updateIsMemberOf(IFeatureClass osmLineFeatureClass, int osmMemberOfPolylineFieldIndex, string osmID, List<string> parentList)
{
using (ComReleaser comReleaserInternal = new ComReleaser())
{
IQueryFilter lineQueryFilter = new QueryFilterClass();
lineQueryFilter.WhereClause = osmLineFeatureClass.WhereClauseByExtensionVersion(osmID, "OSMID", 2);
IFeatureCursor searchCursor = osmLineFeatureClass.Update(lineQueryFilter, false);
comReleaserInternal.ManageLifetime(searchCursor);
IFeature featureToModify = searchCursor.NextFeature();
if (featureToModify != null)
{
List<string> isMemberOfList = _osmUtility.retrieveIsMemberOf(featureToModify, osmMemberOfPolylineFieldIndex);
// create a union of both lists
List<string> unionedMemberOfList = new List<string>(isMemberOfList.Union(parentList));
isMemberOfList.AddRange(unionedMemberOfList);
_osmUtility.insertIsMemberOf(osmMemberOfPolylineFieldIndex, unionedMemberOfList, featureToModify);
searchCursor.UpdateFeature(featureToModify);
if (featureToModify != null)
Marshal.ReleaseComObject(featureToModify);
}
}
}
示例7: loadOSMWays
//.........这里部分代码省略.........
wayPointCollection.AddPoint(new PointClass());
}
List<string> idRequests = SplitOSMIDRequests(currentWay, 2);
// build a list of node ids we can use to determine the point index in the line geometry
// as well as a dictionary to determine the position in the list in case of duplicates nodes
Dictionary<string, int> nodePositionDictionary = new Dictionary<string, int>(currentWay.nd.Length);
List<string> nodeIDs = new List<string>(currentWay.nd.Length);
foreach (nd wayNode in currentWay.nd)
{
nodeIDs.Add([email protected]);
if (nodePositionDictionary.ContainsKey([email protected]) == false)
{
nodePositionDictionary.Add([email protected], 0);
}
}
try
{
osmIDQueryFilter.SubFields = osmPointFeatureClass.ShapeFieldName + "," + osmPointFeatureClass.Fields.get_Field(osmPointIDFieldIndex).Name + "," + osmPointFeatureClass.Fields.get_Field(osmWayRefCountFieldIndex).Name;
}
catch
{ }
foreach (string request in idRequests)
{
string idCompareString = request;
osmIDQueryFilter.WhereClause = sqlPointOSMID + " IN " + request;
using (ComReleaser innerComReleaser = new ComReleaser())
{
updatePointCursor = osmPointFeatureClass.Update(osmIDQueryFilter, true);
innerComReleaser.ManageLifetime(updatePointCursor);
IFeature nodeFeature = updatePointCursor.NextFeature();
while (nodeFeature != null)
{
// determine the index of the point in with respect to the node position
string nodeOSMIDString = Convert.ToString(nodeFeature.get_Value(osmPointIDFieldIndex));
// remove the ID from the request string
idCompareString = idCompareString.Replace(nodeOSMIDString, String.Empty);
int nodePositionIndex = -1;
while ((nodePositionIndex = nodeIDs.IndexOf(nodeOSMIDString, nodePositionDictionary[nodeOSMIDString])) != -1)
{
//// update the new position start search index
nodePositionDictionary[nodeOSMIDString] = nodePositionIndex + 1;
wayPointCollection.UpdatePoint(nodePositionIndex, (IPoint)nodeFeature.Shape);
// increase the reference counter
if (osmWayRefCountFieldIndex != -1)
{
nodeFeature.set_Value(osmWayRefCountFieldIndex, ((int)nodeFeature.get_Value(osmWayRefCountFieldIndex)) + 1);
updatePointCursor.UpdateFeature(nodeFeature);
}
}
if (nodeFeature != null)
Marshal.ReleaseComObject(nodeFeature);
示例8: sampleRaster
/// <summary>
/// sample a raster using a given offset
/// </summary>
/// <param name="inFtrCls"></param>
/// <param name="sampleRst"></param>
/// <param name="inName"></param>
/// <param name="azmithDistance"></param>
/// <param name="typeOfCluster"></param>
/// <returns></returns>
public string[] sampleRaster(IFeatureClass inFtrCls, IRaster sampleRst, string inName, Dictionary<double,double> azmithDistance, clusterType typeOfCluster)
{
IRaster2 sr = (IRaster2)sampleRst;
IRasterBandCollection rsBC = (IRasterBandCollection)sr;
IEnumRasterBand rsBE = rsBC.Bands;
IRasterBand rsB = rsBE.Next();
string rsName = inName;
if (rsName == null)
{
rsName = ((IDataset)sr.RasterDataset).Name;
}
int cntB = 0;
int[] fldIndex = new int[rsBC.Count];
string[] fldNames = new string[rsBC.Count];
while (rsB != null)
{
string fldName = rsName + "_Band" + (cntB + 1).ToString();
//fldName = geoUtil.getSafeFieldName(inFtrCls, fldName);
esriFieldType fldType = esriFieldType.esriFieldTypeDouble;
fldName = geoUtil.createField(inFtrCls, fldName, fldType);
fldNames[cntB] = fldName;
fldIndex[cntB] = inFtrCls.FindField(fldName);
cntB++;
rsB = rsBE.Next();
}
System.Runtime.InteropServices.Marshal.ReleaseComObject(rsBE);
IGeometry geo = (IGeometry)((IRasterProps)sampleRst).Extent;
ISpatialFilter spFlt = new SpatialFilterClass();
spFlt.Geometry = geo;
spFlt.GeometryField = inFtrCls.ShapeFieldName;
spFlt.SpatialRel = esriSpatialRelEnum.esriSpatialRelIntersects;
IFeatureCursor sCur = inFtrCls.Update(spFlt, true);
IFeature sRow = sCur.NextFeature();
while (sRow != null)
{
geo = sRow.Shape;
IPoint pnt = (IPoint)geo;
int x, y;
x = 0;
y = 0;
for (int i = 0; i < ((IRasterBandCollection)sr).Count; i++)
{
double rsVl = 0;
List<double> rsVlLst = new List<double>();
try
{
sr.MapToPixel(pnt.X, pnt.Y, out x, out y);
rsVlLst.Add(System.Convert.ToDouble(sr.GetPixelValue(i, x, y)));
foreach (KeyValuePair<double, double> kVp in azmithDistance)
{
double az = kVp.Key;
double ds = kVp.Value;
double nX = pnt.X + (System.Math.Sin(az * Math.PI / 180) * ds);
double nY = pnt.Y + (System.Math.Cos(az * Math.PI / 180) * ds);
sr.MapToPixel(nX, nY, out x, out y);
rsVlLst.Add(System.Convert.ToDouble(sr.GetPixelValue(i, x, y)));
}
switch (typeOfCluster)
{
case clusterType.SUM:
rsVl = rsVlLst.Sum();
break;
case clusterType.MEAN:
rsVl = rsVlLst.Average();
break;
case clusterType.MEDIAN:
rsVlLst.Sort();
rsVl = rsVlLst[(rsVlLst.Count-1) / 2];
break;
case clusterType.MODE:
Dictionary<double, int> cntDic = new Dictionary<double, int>();
int maxLc = 0;
double maxKy = rsVlLst[0];
foreach (double d in rsVlLst)
{
if (cntDic.ContainsKey(d))
{
int cntVl = cntDic[d] + 1;
if(cntVl>maxLc)
{
maxLc = cntVl;
maxKy = d;
}
cntDic[d] = cntVl;
}
else
{
cntDic.Add(d, 1);
}
}
rsVl = maxKy;
//.........这里部分代码省略.........
示例9: RemoveBlankSpace
/// <summary>
/// 4.去除多边形内的空白区域
/// 多边形面积/空白面积>3
/// </summary>
/// <param name="radio"></param>
private void RemoveBlankSpace(IFeatureClass feacls,double radio)
{
//确定多边形内存在环,且环中无其他多边形
using(ComReleaser com=new ComReleaser())
{
IFeatureCursor cursor = feacls.Update(null, true);
com.ManageLifetime(cursor);
IFeature fea = cursor.NextFeature();
while (fea != null)
{
IPolygon3 poly = fea.Shape as IPolygon3;
IGeometryCollection geomCollection = poly as IGeometryCollection;
if (geomCollection.GeometryCount <= 1)
{
fea = cursor.NextFeature();
continue;
}
else
{
/* IRing ring = null;
IRing exRing = null;
List<IRing> rlist = new List<IRing>();
for (int i = 0; i < geomCollection.GeometryCount; i++)
{
ring = geomCollection.get_Geometry(i) as IRing;
if (ring.IsExterior)
{
exRing = ring;
continue;
}
rlist.Add(ring);
}
IArea area = exRing as IArea;
double extArea = area.Area;
foreach (IRing item in rlist)
{
double inArea = ((IArea)item).Area;
if(extArea/inArea>3)
{
item.SetEmpty();
}
}
geomCollection.GeometriesChanged();
fea.Store();
fea = cursor.NextFeature();*/
int i = 0;
while(i<geomCollection.GeometryCount)
{
IRing ring = geomCollection.get_Geometry(i) as IRing;
if(ring.IsExterior)
{
i++;
continue;
}
else
{
geomCollection.RemoveGeometries(i, 1);
geomCollection.GeometriesChanged();
continue;
}
}
fea.Store();
fea = cursor.NextFeature();
}
}
}
}
示例10: DeleteFeatures
/// <summary>
/// delete feature through cursor from specified featureclass
/// </summary>
public static void DeleteFeatures(IFeatureClass ThisFeatureClass, string WhereClause, ref string ErrorMessage)
{
NPSGlobal NPS;
IQueryFilter ThisQueryFilter;
IFeature ThisFeature;
IFeatureCursor ThisFCursor;
NPS = NPSGlobal.Instance;
ThisQueryFilter = new QueryFilterClass();
ThisQueryFilter.WhereClause = WhereClause;
try
{
ThisFCursor = ThisFeatureClass.Update(ThisQueryFilter, false);
while ((ThisFeature = ThisFCursor.NextFeature()) != null)
{
ThisFeature.Delete();
}
ThisFCursor = null;
}
catch (Exception ex)
{
ErrorMessage = "Error occured while deleting features in "
+ ((IDataset)ThisFeatureClass).Name + ". " + ex.Message;
}
}
示例11: weightFieldValuesByAreaLength
public void weightFieldValuesByAreaLength(IFeatureClass strataFtr, string[] fldNames, IFeatureClass standsFtr, bool length = false)
{
int[] meanFldIndex = new int[fldNames.Length];
int[] fldNamesIndex = new int[fldNames.Length];
for (int i = 0; i < fldNames.Length; i++)
{
string mName = geoUtil.createField(standsFtr, "m_" + fldNames[i], ESRI.ArcGIS.Geodatabase.esriFieldType.esriFieldTypeDouble, false);
meanFldIndex[i] = standsFtr.FindField(mName);
fldNamesIndex[i] = strataFtr.FindField(fldNames[i]);
}
IFeatureCursor uCur = standsFtr.Update(null, true);
IFeature uFtr = uCur.NextFeature();
while (uFtr != null)
{
ESRI.ArcGIS.Geometry.IGeometry geo = uFtr.Shape;
ISpatialFilter spFlt = new SpatialFilter();
spFlt.Geometry = geo;
spFlt.SpatialRel = esriSpatialRelEnum.esriSpatialRelIntersects;
double totalVl = 0;
IFeatureCursor sCur = strataFtr.Search(spFlt, true);
IFeature sFtr = sCur.NextFeature();
double[] vlArr = new double[meanFldIndex.Length];
while (sFtr != null)
{
ESRI.ArcGIS.Geometry.IGeometry sgeo = sFtr.Shape;
ESRI.ArcGIS.Geometry.ITopologicalOperator4 topo = (ESRI.ArcGIS.Geometry.ITopologicalOperator4)sgeo;
ESRI.ArcGIS.Geometry.IGeometry sgeo2 = topo.Intersect(geo, ESRI.ArcGIS.Geometry.esriGeometryDimension.esriGeometry2Dimension);
double subArea = 0;
if (length)
{
subArea = (((ESRI.ArcGIS.Geometry.IPolygon)sgeo2).Length);
totalVl += subArea;
}
else
{
subArea = ((ESRI.ArcGIS.Geometry.IArea)sgeo2).Area;
totalVl += subArea;
}
for (int i = 0; i < meanFldIndex.Length; i++)
{
vlArr[i] += System.Convert.ToDouble(sFtr.get_Value(fldNamesIndex[i])) * subArea;
}
sFtr = sCur.NextFeature();
}
System.Runtime.InteropServices.Marshal.ReleaseComObject(sCur);
if (totalVl != 0)
{
for (int i = 0; i < meanFldIndex.Length; i++)
{
uFtr.set_Value(meanFldIndex[i], vlArr[i] / totalVl);
}
uCur.UpdateFeature(uFtr);
}
uFtr = uCur.NextFeature();
}
System.Runtime.InteropServices.Marshal.ReleaseComObject(uCur);
}
示例12: HistoryRecoverInner
/// <summary>
/// 将现状恢复到上一次历史状态
/// </summary>
/// <param name="parentNo"></param>
/// <param name="fc"></param>
/// <param name="historyFC"></param>
/// <returns>上一次历史状态的id</returns>
private static bool HistoryRecoverInner(int parentNO, IFeatureClass fc, IFeatureClass historyFC, IFeatureClass crossFC)
{
// 历史表里没这个parentNo
var cursor = historyFC.Search(new QueryFilterClass { WhereClause = string.Format("{0} = {1}", IDFieldName, parentNO) }, true);
var historyf = cursor.NextFeature();
if (historyf == null)
{
Marshal.ReleaseComObject(cursor);
return false;
}
// 当前表的记录的直接历史并不是parentNo对应的历史
var cursor3 = fc.Update(new QueryFilter { WhereClause = string.Format("{0} = {1}", ParentIDFieldName, parentNO) }, true);
var f = cursor3.NextFeature();
if( f == null)
{
Marshal.ReleaseComObject(cursor3);
return false;
}
// 记录两端节点,不删除它们
var nodes = new List<int>();
var o = historyf.get_Value(historyf.Fields.FindField(FromNodeFieldName));
if(o != null && o != DBNull.Value) nodes.Add(Convert.ToInt32(o));
o = historyf.get_Value(historyf.Fields.FindField(ToNodeFieldName));
if(o != null && o != DBNull.Value) nodes.Add(Convert.ToInt32(o));
// 将记录从历史表拷贝到当前表,并删除历史表中的记录
var cursor2 = fc.Insert(true);
var buffer = fc.CreateFeatureBuffer();
buffer.Shape = historyf.ShapeCopy;
CopyFields(historyf, buffer);
buffer.set_Value(buffer.Fields.FindField(IDFieldName), parentNO);
cursor2.InsertFeature(buffer);
Marshal.ReleaseComObject(cursor2);
historyf.Delete();
Marshal.ReleaseComObject(cursor);
// 将当前表中的相关记录删除
var fromIndex = cursor3.FindField(FromNodeFieldName);
var toIndex = cursor3.FindField(ToNodeFieldName);
var nodesToRemove = new HashSet<int>();
while(f != null)
{
o = f.get_Value(fromIndex);
if(o!= null && o != DBNull.Value)
{
if(nodes.Contains(Convert.ToInt32(o)) == false) // 是中间节点,需要删除;否则是两端节点,需要保留
{
nodesToRemove.Add(Convert.ToInt32(o));
}
}
o = f.get_Value(toIndex);
if(o!= null && o != DBNull.Value)
{
if(nodes.Contains(Convert.ToInt32(o)) == false) // 是中间节点,需要删除;否则是两端节点,需要保留
{
nodesToRemove.Add(Convert.ToInt32(o));
}
}
cursor3.DeleteFeature();
f = cursor3.NextFeature();
}
Marshal.ReleaseComObject(cursor3);
// 删除相关节点
foreach(var i in nodesToRemove)
{
DeleteNode(i, parentNO, crossFC, fc);
}
return true;
}
示例13: updateAcetate
public static void updateAcetate(SEE see, IFeatureClass featureClass, ISDUTExtension ext)
{
if(see == null)
{
return;
}
Logger.Write("Update acetate");
IFeature feat = null;
if(featureClass.FeatureCount(null) < 1)
{
feat = featureClass.CreateFeature();
feat.Shape = see.Shape;
feat.Store();
}
else
{
feat = featureClass.Update(null,false).NextFeature();
feat.Shape = see.Shape;
feat.Store();
}
Logger.Write("Update acetate -- Refresh");
((IActiveView)ext.FocusMap).Refresh();
}
示例14: loadOSMNodes
//.........这里部分代码省略.........
}
}
currentNode = null;
}
}
}
if (stepProgressor != null)
{
stepProgressor.Hide();
}
pointInsertCursor.Flush();
osmFileXmlReader.Close();
message.AddMessage(String.Format(_resourceManager.GetString("GPTools_OSMGPFileReader_pointsloaded"), pointCount));
message.AddMessage(_resourceManager.GetString("GPTools_buildingpointidx"));
if (pointFeatureLoad != null)
{
pointFeatureLoad.LoadOnlyMode = false;
}
}
}
if (TrackCancel.Continue() == false)
{
return;
}
using (ComReleaser comReleaser = new ComReleaser())
{
IFeatureCursor updatePoints = osmPointFeatureClass.Update(null, false);
comReleaser.ManageLifetime(updatePoints);
IFeature feature2Update = updatePoints.NextFeature();
while (feature2Update != null)
{
IPoint pointGeometry = feature2Update.Shape as IPoint;
pointGeometry.ID = feature2Update.OID;
feature2Update.Shape = pointGeometry;
if (conserveMemory == false)
{
string osmid = Convert.ToString(feature2Update.get_Value(osmPointIDFieldIndex));
if (osmNodeDictionary.ContainsKey(osmid))
osmNodeDictionary[osmid].pointObjectID = feature2Update.OID;
}
updatePoints.UpdateFeature(feature2Update);
if (TrackCancel.Continue() == false)
{
return;
}
if (feature2Update != null)
Marshal.ReleaseComObject(feature2Update);
if (pointGeometry != null)
Marshal.ReleaseComObject(pointGeometry);
feature2Update = updatePoints.NextFeature();
}
示例15: calcStandMeans
private static void calcStandMeans(IFeatureClass strataFtr, IFeatureClass standsFtr, int[] meanStrataFldIndex, int[] varStrataFldIndex, int[] countFldStrataIndex, IField[] fldsToSummarize, geoDatabaseUtility geoUtil)
{
int cnt = 0;
int[] ptFldIndex = new int[fldsToSummarize.Length];
int[] meanFldIndex = new int[fldsToSummarize.Length];
int[] varFldIndex = new int[fldsToSummarize.Length];
int[] cntFldIndex = new int[fldsToSummarize.Length];
foreach (IField fld in fldsToSummarize)
{
string sName = geoUtil.createField(standsFtr, "v_" + fld.Name, esriFieldType.esriFieldTypeDouble, false);
varFldIndex[cnt] = standsFtr.FindField(sName);
string mName = geoUtil.createField(standsFtr, "m_" + fld.Name, esriFieldType.esriFieldTypeDouble, false);
meanFldIndex[cnt] = standsFtr.FindField(mName);
string cName = geoUtil.createField(standsFtr, "n_" + fld.Name, esriFieldType.esriFieldTypeDouble, false);
cntFldIndex[cnt] = standsFtr.FindField(cName);
cnt++;
}
IFeatureCursor uCur = standsFtr.Update(null, true);
IFeature uFtr = uCur.NextFeature();
while (uFtr != null)
{
ESRI.ArcGIS.Geometry.IGeometry geo = uFtr.Shape;
ISpatialFilter spFlt = new SpatialFilter();
spFlt.Geometry = geo;
spFlt.SpatialRel = esriSpatialRelEnum.esriSpatialRelIntersects;
double totalArea = 0;
IFeatureCursor sCur = strataFtr.Search(spFlt, true);
IFeature sFtr = sCur.NextFeature();
double[][] vlArr = new double[meanFldIndex.Length][];
for (int i = 0; i < meanFldIndex.Length; i++)
{
vlArr[i] = new double[3];
}
while (sFtr != null)
{
ESRI.ArcGIS.Geometry.IGeometry sgeo = sFtr.Shape;
ESRI.ArcGIS.Geometry.ITopologicalOperator4 topo = (ESRI.ArcGIS.Geometry.ITopologicalOperator4)sgeo;
ESRI.ArcGIS.Geometry.IGeometry sgeo2 = topo.Intersect(geo, ESRI.ArcGIS.Geometry.esriGeometryDimension.esriGeometry2Dimension);
double subArea = (((ESRI.ArcGIS.Geometry.IArea)sgeo2).Area);
totalArea += subArea;
for (int i = 0; i < meanFldIndex.Length; i++)
{
vlArr[i][0] += System.Convert.ToDouble(sFtr.get_Value(meanStrataFldIndex[i])) * subArea;
vlArr[i][1] += System.Convert.ToDouble(sFtr.get_Value(varStrataFldIndex[i])) * subArea;
vlArr[i][2] += System.Convert.ToDouble(sFtr.get_Value(countFldStrataIndex[i]));
}
sFtr = sCur.NextFeature();
}
System.Runtime.InteropServices.Marshal.ReleaseComObject(sCur);
if (totalArea != 0)
{
for (int i = 0; i < meanFldIndex.Length; i++)
{
uFtr.set_Value(meanFldIndex[i], vlArr[i][0]/totalArea);
uFtr.set_Value(varFldIndex[i], vlArr[i][1]/totalArea);
uFtr.set_Value(cntFldIndex[i], vlArr[i][2]);
}
uCur.UpdateFeature(uFtr);
}
uFtr = uCur.NextFeature();
}
System.Runtime.InteropServices.Marshal.ReleaseComObject(uCur);
}
开发者ID:GeospatialDaryl,项目名称:USFS_RMRS_FunctionalModeling_RasterModeling,代码行数:63,代码来源:fiaIntegration.cs