private static double DefaultIndexGridPoint(ref ESRI.ArcGIS.Geodatabase.IFeatureClass InFC) { ESRI.ArcGIS.Geodatabase.IGeoDataset pGeoDataSet; pGeoDataSet = InFC as IGeoDataset; ESRI.ArcGIS.Geometry.IEnvelope pEnvelope; pEnvelope = pGeoDataSet.Extent; int lngNumFeat; double dblArea; lngNumFeat = InFC.FeatureCount(null); if (lngNumFeat == 0 | pEnvelope.IsEmpty) { return(1000); } else { dblArea = pEnvelope.Height * pEnvelope.Width; return(System.Math.Sqrt(dblArea / lngNumFeat)); } }
private void cboTargetLayer_SelectedIndexChanged(object sender, EventArgs e) { try { string strLayerName = cboTargetLayer.Text; int intLIndex = m_pSnippet.GetIndexNumberFromLayerName(m_pActiveView, strLayerName); if (intLIndex == -1) { MessageBox.Show("Please select proper layer"); return; } ILayer pLayer = m_pForm.axMapControl1.get_Layer(intLIndex); IFeatureLayer pFLayer = pLayer as IFeatureLayer; ESRI.ArcGIS.Geodatabase.IFeatureClass pFClass = pFLayer.FeatureClass; IFields fields = pFClass.Fields; cboFieldName.Items.Clear(); for (int i = 0; i < fields.FieldCount; i++) { if (m_pSnippet.FindNumberFieldType(fields.get_Field(i))) { cboFieldName.Items.Add(fields.get_Field(i).Name); } } int intNfeatureCount = pFClass.FeatureCount(null); double dblBinCnt = Math.Ceiling(Math.Pow(intNfeatureCount, 1.0f / 3.0f) * 2.0); nudBinsCnt.Value = Convert.ToDecimal(dblBinCnt); } catch (Exception ex) { frmErrorLog pfrmErrorLog = new frmErrorLog(); pfrmErrorLog.ex = ex; pfrmErrorLog.ShowDialog(); return; } }
private void btnRun_Click(object sender, EventArgs e) { try { string strLayerName = cboTargetLayer.Text; string strIDFldName = cboFieldName.Text; string strOutputName = txtOutput.Text; bool blnRook = true; if (strLayerName == "" || strIDFldName == "" || strOutputName == "") { MessageBox.Show("Please select layer or fields"); return; } clsSnippet pSnippet = new clsSnippet(); int intLIndex = pSnippet.GetIndexNumberFromLayerName(pActiveView, strLayerName); ILayer pLayer = mForm.axMapControl1.get_Layer(intLIndex); IFeatureLayer pFLayer = pLayer as IFeatureLayer; ESRI.ArcGIS.Geodatabase.IFeatureClass pFClass = pFLayer.FeatureClass; IFields fields = pFClass.Fields; IFeatureCursor pFCursor = pFClass.Search(null, false); IFeature pFeature = pFCursor.NextFeature(); int intIDIdx = pFCursor.FindField(strIDFldName); ISpatialFilter pSF = new SpatialFilterClass(); IFeatureCursor pNBCursor = null; IFeature pNBFeature = null; int NBNumber = 0; string strNBIDs = null; ITopologicalOperator pTopoOp = (ITopologicalOperator)pFeature.Shape; pSF.Geometry = pFeature.ShapeCopy; pSF.SpatialRel = esriSpatialRelEnum.esriSpatialRelIntersects; IPointCollection pPointCol; System.IO.StreamWriter pSW = new System.IO.StreamWriter(strOutputName); pSW.WriteLine("0 " + pFClass.FeatureCount(null).ToString() + " " + pFClass.AliasName + " " + strIDFldName); while (pFeature != null) { NBNumber = 0; strNBIDs = null; pSF.Geometry = pFeature.ShapeCopy; pSF.SpatialRel = ESRI.ArcGIS.Geodatabase.esriSpatialRelEnum.esriSpatialRelIntersects; pNBCursor = pFClass.Search(pSF, true); pNBFeature = pNBCursor.NextFeature(); while (pNBFeature != null) { if (pFeature.get_Value(intIDIdx).Equals(pNBFeature.get_Value(intIDIdx))) { //if(pFeature.get_Value(intIDIdx) == pNBFeature.get_Value(intIDIdx)) pNBFeature = pNBCursor.NextFeature(); } else { NBNumber = NBNumber + 1; pPointCol = (IPointCollection)pTopoOp.Intersect(pNBFeature.Shape, esriGeometryDimension.esriGeometry0Dimension); if (blnRook) { if (pPointCol.PointCount != 1) { strNBIDs = strNBIDs + " " + pNBFeature.get_Value(intIDIdx); } else { NBNumber -= 1; } } else { strNBIDs = strNBIDs + " " + pNBFeature.get_Value(intIDIdx); } pNBFeature = pNBCursor.NextFeature(); } } pNBCursor.Flush(); if (NBNumber > 0) { pSW.WriteLine(pFeature.get_Value(intIDIdx).ToString() + " " + NBNumber.ToString()); pSW.WriteLine(strNBIDs.Substring(1)); } else { pSW.WriteLine(pFeature.get_Value(intIDIdx).ToString() + " " + NBNumber.ToString()); pSW.WriteLine(""); } pFeature = pFCursor.NextFeature(); } pSW.Close(); pSW.Dispose(); MessageBox.Show(strOutputName + " is generated."); //this.Close(); } catch (Exception ex) { frmErrorLog pfrmErrorLog = new frmErrorLog(); pfrmErrorLog.ex = ex; pfrmErrorLog.ShowDialog(); return; } }
public static double DefaultIndexGrid(ref ESRI.ArcGIS.Geodatabase.IFeatureClass InFC) { int lngNumFeat; int lngSampleSize; ESRI.ArcGIS.Geodatabase.IFields pFields; ESRI.ArcGIS.Geodatabase.IField pField; string strFIDName; string strWhereClause; //int lngCurrFID; ESRI.ArcGIS.Geodatabase.IFeature pFeat; ESRI.ArcGIS.Geodatabase.IFeatureCursor pFeatCursor; ESRI.ArcGIS.Geometry.IEnvelope pFeatEnv; ESRI.ArcGIS.Geodatabase.IQueryFilter pQueryFilter; List <int> pNewCol = new List <int>(); int lngKMax; double dblMaxDelta; dblMaxDelta = 0; double dblMinDelta; dblMinDelta = 1000000000000; double dblSquareness; dblSquareness = 1; const short SampleSize = 1; const short Factor = 1; object[] ColInfo = new object[1]; object[] c0 = new object[4]; c0[0] = "minext"; c0[1] = System.Convert.ToInt16(5); c0[2] = System.Convert.ToInt16(-1); c0[3] = false; ColInfo[0] = c0; lngNumFeat = InFC.FeatureCount(null) - 1; if (lngNumFeat <= 0) { return(1000); } if (InFC.ShapeType == ESRI.ArcGIS.Geometry.esriGeometryType.esriGeometryMultipoint | InFC.ShapeType == ESRI.ArcGIS.Geometry.esriGeometryType.esriGeometryPoint) { return(DefaultIndexGridPoint(ref InFC)); } lngSampleSize = lngNumFeat * SampleSize; if (lngSampleSize > 1000) { lngSampleSize = 1000; } pFields = InFC.Fields; // GET the OBJECTID field pField = pFields.get_Field(0); for (int m = 0; m < pFields.FieldCount; m++) { if (pFields.get_Field(m).Name == InFC.OIDFieldName) { pField = pFields.get_Field(m); break; } } strFIDName = pField.Name; for (int i = 1; i <= lngNumFeat; i += System.Convert.ToInt32(lngNumFeat / lngSampleSize)) { pNewCol.Add(i); } for (int j = 0; j <= pNewCol.Count - 1; j += 250) { lngKMax = Min(pNewCol.Count - j, 250); strWhereClause = strFIDName + " IN("; for (int k = 0; k < lngKMax; k++) { strWhereClause = strWhereClause + System.Convert.ToString(pNewCol[(j + k)]) + ","; } //strWhereClause = Mid(strWhereClause, 1, strWhereClause.Length - 1) + ")"; strWhereClause = strWhereClause.Substring(0, strWhereClause.Length - 1) + ")"; pQueryFilter = new ESRI.ArcGIS.Geodatabase.QueryFilter(); pQueryFilter.WhereClause = strWhereClause; pFeatCursor = InFC.Search(pQueryFilter, true); pFeat = pFeatCursor.NextFeature(); while (!(pFeat == null)) { pFeatEnv = pFeat.Extent; if (!pFeatEnv.IsEmpty) { dblMaxDelta = Max(dblMaxDelta, Max((pFeatEnv.Width), (pFeatEnv.Height))); dblMinDelta = Min(dblMinDelta, Min((pFeatEnv.Width), (pFeatEnv.Height))); if (dblMinDelta != 0) { dblSquareness = dblSquareness + ((Min((pFeatEnv.Width), (pFeatEnv.Height)) / (Max((pFeatEnv.Width), (pFeatEnv.Height))))); } else { dblSquareness = dblSquareness + 0.0001; } } pFeat = pFeatCursor.NextFeature(); } } if (((dblSquareness / lngSampleSize) > 0.5)) { return((dblMinDelta + ((dblMaxDelta - dblMinDelta) / 2)) * Factor); } else { return((dblMaxDelta / 2) * Factor); } }