示例#1
0
        public void LoadAnalysisObjectsByGeometry(ESRI.ArcGIS.Geodatabase.IFeatureClass
                                                  inputFeatureClass, string naClassName, ESRI.ArcGIS.NetworkAnalyst.INAContext
                                                  naContext)
        {
            // Both Initialize and Load take a cursor from the input feature class
            ESRI.ArcGIS.Geodatabase.ICursor cursor = inputFeatureClass.Search(null, false) as
                                                     ESRI.ArcGIS.Geodatabase.ICursor;

            // Initialize the default field mappings.
            // If you want to specify field mappings beyond the default ones, use naClassLoader.FieldMap to retrieve
            //  and edit the mappings between the input class and the naclass.
            ESRI.ArcGIS.NetworkAnalyst.INAClassLoader2 naClassLoader = new
                                                                       ESRI.ArcGIS.NetworkAnalyst.NAClassLoaderClass();
            naClassLoader.Initialize(naContext, naClassName, cursor);

            // Use ExcludeRestrictedElements and CacheRestrictedElements to prevent locations from being placed on restricted elements.
            // Some ways to restrict elements include restriction barriers and restriction attributes.
            // If you are loading barriers into barrier classes, or not loading locations (for example, seedpoints)
            //  then you should not exclude the restricted elements.  Also, if you do have barriers in your analysis problem,
            //  then you should load those first, to make sure the restricted elements are established before loading
            //  non-barrier classes.
            ESRI.ArcGIS.NetworkAnalyst.INALocator3 naLocator3 = naClassLoader.Locator as
                                                                ESRI.ArcGIS.NetworkAnalyst.INALocator3;
            naLocator3.ExcludeRestrictedElements = true;
            naLocator3.CacheRestrictedElements(naContext);

            // After Loading is complete, the rowsIn and rowsLocated variable can be used to verify
            //  that every row from the input feature class has been loaded into the network analysis class
            int rowsIn      = 0;
            int rowsLocated = 0;

            naClassLoader.Load(cursor, null, ref rowsIn, ref rowsLocated);
        }
        /// <summary>
        /// Finds the connected device/port
        /// </summary>
        /// <param name="siblingFtClass">Any feature class from the workspace</param>
        /// <param name="cableId">Cable ID to check connx for</param>
        /// <param name="fiberNumber">Fiber Number to check connx for</param>
        /// <param name="isFromEnd">Whether to check the cable's from or to end</param>
        /// <param name="portRow">(out) result port</param>
        /// <param name="deviceFt">(out) result device</param>
        /// <returns>True if a connx was found</returns>
        private bool GetConnectedPort(ESRI.ArcGIS.Geodatabase.IFeatureClass siblingFtClass, string cableId, int fiberNumber, bool isFromEnd, out ESRI.ArcGIS.Geodatabase.IRow portRow, out ESRI.ArcGIS.Geodatabase.IFeature deviceFt)
        {
            portRow  = null;
            deviceFt = null;

            bool result = false;

            string[] portTableNames = ConfigUtil.PortTableNames;
            using (ESRI.ArcGIS.ADF.ComReleaser releaser = new ESRI.ArcGIS.ADF.ComReleaser())
            {
                ESRI.ArcGIS.Geodatabase.IQueryFilter filter = new ESRI.ArcGIS.Geodatabase.QueryFilterClass();
                filter.WhereClause = string.Format("{0}='{1}' AND {2}={3} AND {4}='{5}'",
                                                   ConfigUtil.ConnectedCableFieldName,
                                                   cableId,
                                                   ConfigUtil.ConnectedFiberFieldName,
                                                   fiberNumber,
                                                   ConfigUtil.ConnectedEndFieldName,
                                                   isFromEnd ? "T" : "F");
                releaser.ManageLifetime(filter);

                for (int i = 0; i < portTableNames.Length; i++)
                {
                    string portTableName = portTableNames[i];
                    ESRI.ArcGIS.Geodatabase.ITable  portTable = _wkspHelper.FindTable(portTableName);
                    ESRI.ArcGIS.Geodatabase.ICursor cursor    = portTable.Search(filter, false);
                    releaser.ManageLifetime(cursor);

                    portRow = cursor.NextRow();
                    if (null != portRow)
                    {
                        ESRI.ArcGIS.Geodatabase.IRelationshipClass deviceHasPorts = ConfigUtil.GetDeviceRelationship(portTable);
                        if (null == deviceHasPorts)
                        {
                            throw new Exception("Device to port relationship is missing or cannot be opened.");
                        }

                        ESRI.ArcGIS.Geodatabase.IFeatureClass deviceClass = deviceHasPorts.OriginClass as ESRI.ArcGIS.Geodatabase.IFeatureClass;
                        if (null == deviceClass)
                        {
                            throw new Exception("Device feature class is missing or cannot be opened.");
                        }

                        filter.WhereClause = string.Format("{0}='{1}'",
                                                           deviceHasPorts.OriginPrimaryKey,
                                                           portRow.get_Value(portTable.FindField(deviceHasPorts.OriginForeignKey)));
                        ESRI.ArcGIS.Geodatabase.IFeatureCursor deviceCursor = deviceClass.Search(filter, false);
                        deviceFt = deviceCursor.NextFeature();

                        result = true;
                        break;
                    }
                }
            }

            return(result);
        }
示例#3
0
        /// <summary>
        /// Returns all features from a given feature class that have a vertex or endpoint coincident with a given point
        /// </summary>
        /// <param name="point">IPoint to use as the spatial filter</param>
        /// <param name="searchFtClass">IFeatureClass to search in</param>
        /// <param name="linearEndpointsOnly">Flag to use only the endpoints of a line instead of all vertices</param>
        /// <param name="buffer">Search geometry buffer in map units</param>
        /// <returns>List of IFeature</returns>
        public static List <ESRI.ArcGIS.Geodatabase.IFeature> GetFeaturesWithCoincidentVertices(ESRI.ArcGIS.Geometry.IPoint point, ESRI.ArcGIS.Geodatabase.IFeatureClass searchFtClass, bool linearEndpointsOnly, double buffer)
        {
            List <ESRI.ArcGIS.Geodatabase.IFeature> result = new List <ESRI.ArcGIS.Geodatabase.IFeature>();

            using (ESRI.ArcGIS.ADF.ComReleaser releaser = new ESRI.ArcGIS.ADF.ComReleaser())
            {
                ESRI.ArcGIS.Geodatabase.ISpatialFilter filter = new ESRI.ArcGIS.Geodatabase.SpatialFilterClass();
                releaser.ManageLifetime(filter);

                ESRI.ArcGIS.Geometry.IEnvelope filterGeometry = point.Envelope;
                if (0 < buffer)
                {
                    filterGeometry.Expand(buffer, buffer, false);
                }

                filter.SpatialRel = ESRI.ArcGIS.Geodatabase.esriSpatialRelEnum.esriSpatialRelIntersects;
                filter.Geometry   = filterGeometry;

                ESRI.ArcGIS.Geodatabase.IFeatureCursor fts = searchFtClass.Search(filter, false);
                releaser.ManageLifetime(fts);

                ESRI.ArcGIS.Geodatabase.IFeature ft = fts.NextFeature();
                while (null != ft)
                {
                    if (searchFtClass.ShapeType == ESRI.ArcGIS.Geometry.esriGeometryType.esriGeometryPoint)
                    {
                        result.Add(ft);
                    }
                    else if (searchFtClass.ShapeType == ESRI.ArcGIS.Geometry.esriGeometryType.esriGeometryPolyline && linearEndpointsOnly)
                    {
                        ESRI.ArcGIS.Geometry.IPolyline           polyline  = (ESRI.ArcGIS.Geometry.IPolyline)ft.Shape;
                        ESRI.ArcGIS.Geometry.IRelationalOperator fromPoint = polyline.FromPoint as ESRI.ArcGIS.Geometry.IRelationalOperator;
                        ESRI.ArcGIS.Geometry.IRelationalOperator toPoint   = polyline.ToPoint as ESRI.ArcGIS.Geometry.IRelationalOperator;

                        if (fromPoint.Equals(point) || toPoint.Equals(point))
                        {
                            result.Add(ft);
                        }
                    }
                    else
                    {
                        ESRI.ArcGIS.Geometry.IPointCollection pointCollection = ft.Shape as ESRI.ArcGIS.Geometry.IPointCollection;
                        if (null != pointCollection)
                        {
                            for (int i = 0; i < pointCollection.PointCount; i++)
                            {
                                ESRI.ArcGIS.Geometry.IRelationalOperator testPoint = pointCollection.get_Point(i) as ESRI.ArcGIS.Geometry.IRelationalOperator;
                                if (testPoint.Equals(point))
                                {
                                    result.Add(ft);
                                    break;
                                }
                            }
                        }
                    }

                    ft = fts.NextFeature();
                }
            }

            return(result);
        }
示例#4
0
        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;
            }
        }
        private FiberCableWrapper GetConnectedFiber(DeviceWrapper device, int portId, PortType portType, out int fiberNumber)
        {
            FiberCableWrapper result = null;

            fiberNumber = -1;

            ESRI.ArcGIS.Geodatabase.IFeatureClass      deviceFtClass  = (ESRI.ArcGIS.Geodatabase.IFeatureClass)device.Feature.Class;
            ESRI.ArcGIS.Geodatabase.IRelationshipClass deviceHasPorts = ConfigUtil.GetPortRelationship(deviceFtClass);
            if (null == deviceHasPorts)
            {
                throw new Exception("Device to port relationship is missing or cannot be opened.");
            }

            ESRI.ArcGIS.Geodatabase.ITable portTable = deviceHasPorts.DestinationClass as ESRI.ArcGIS.Geodatabase.ITable;
            if (null == portTable)
            {
                throw new Exception("Port table is missing or cannot be opened.");
            }


            using (ESRI.ArcGIS.ADF.ComReleaser releaser = new ESRI.ArcGIS.ADF.ComReleaser())
            {
                ESRI.ArcGIS.Geodatabase.IQueryFilter filter = new ESRI.ArcGIS.Geodatabase.QueryFilterClass();
                releaser.ManageLifetime(filter);
                filter.WhereClause = string.Format("{0}='{1}' AND {2}={3} AND {4}='{5}'",
                                                   deviceHasPorts.OriginForeignKey,
                                                   device.Feature.get_Value(deviceFtClass.FindField(deviceHasPorts.OriginPrimaryKey)),
                                                   ConfigUtil.PortIdFieldName,
                                                   portId,
                                                   ConfigUtil.PortTypeFieldName,
                                                   PortType.Input == portType ? 1 : 2);

                ESRI.ArcGIS.Geodatabase.ICursor cursor = portTable.Search(filter, false);
                releaser.ManageLifetime(cursor);
                ESRI.ArcGIS.Geodatabase.IRow portRow = cursor.NextRow();

                if (null != portRow)
                {
                    //releaser.ManageLifetime(portRow);

                    object cableIdValue = portRow.get_Value(portTable.FindField(ConfigUtil.ConnectedCableFieldName));
                    if (DBNull.Value != cableIdValue)
                    {
                        ESRI.ArcGIS.Geodatabase.IFeatureClass cableFtClass = _wkspHelper.FindFeatureClass(ConfigUtil.FiberCableFtClassName);
                        filter.WhereClause = string.Format("{0}='{1}'", ConfigUtil.IpidFieldName, cableIdValue);
                        ESRI.ArcGIS.Geodatabase.IFeatureCursor cableCursor = cableFtClass.Search(filter, false);
                        releaser.ManageLifetime(cableCursor);

                        ESRI.ArcGIS.Geodatabase.IFeature cable = cableCursor.NextFeature();
                        if (null != cable)
                        {
                            result = new FiberCableWrapper(cable);
                            object fiberNumberValue = portRow.get_Value(portTable.FindField(ConfigUtil.ConnectedFiberFieldName));
                            if (DBNull.Value != fiberNumberValue)
                            {
                                int.TryParse(fiberNumberValue.ToString(), out fiberNumber);
                            }
                        }
                    }
                }
            }

            return(result);
        }
        ///// <summary>
        ///// The active view has refreshed. Redraw our results, if we have any
        ///// </summary>
        ///// <param name="Display">Display to draw on</param>
        ///// <param name="phase"></param>
        //private void _arcMapWrapper_ActiveViewAfterDraw(ESRI.ArcGIS.Display.IDisplay Display, ESRI.ArcGIS.Carto.esriViewDrawPhase phase)
        //{
        //    if (phase == ESRI.ArcGIS.Carto.esriViewDrawPhase.esriViewGeoSelection)
        //    {
        //        // Draw after the selection
        //        if (null != _currentResults)
        //        {
        //            ESRI.ArcGIS.Display.ILineSymbol lineSymbol = new ESRI.ArcGIS.Display.SimpleLineSymbol();
        //            ESRI.ArcGIS.Display.IRgbColor color = new ESRI.ArcGIS.Display.RgbColorClass();
        //            color.Red = 255;
        //            color.Green = 0;
        //            color.Blue = 0;

        //            lineSymbol.Color = color;
        //            lineSymbol.Width = 4;

        //            ESRI.ArcGIS.Display.ISimpleMarkerSymbol markerSymbol = new ESRI.ArcGIS.Display.SimpleMarkerSymbolClass();
        //            markerSymbol.Color = color;
        //            markerSymbol.Style = ESRI.ArcGIS.Display.esriSimpleMarkerStyle.esriSMSCircle;
        //            markerSymbol.Size = 6;

        //            for (int i = 0; i < _currentResults.Count; i++)
        //            {
        //                ESRI.ArcGIS.Geometry.IGeometry geometry = _currentResults[i];
        //                if (geometry is ESRI.ArcGIS.Geometry.IPolyline)
        //                {
        //                    Display.SetSymbol((ESRI.ArcGIS.Display.ISymbol)lineSymbol);
        //                    Display.DrawPolyline((ESRI.ArcGIS.Geometry.IPolyline)geometry);
        //                }
        //                else if (geometry is ESRI.ArcGIS.Geometry.IPoint)
        //                {
        //                    Display.SetSymbol((ESRI.ArcGIS.Display.ISymbol)markerSymbol);
        //                    Display.DrawPoint((ESRI.ArcGIS.Geometry.IPoint)geometry);
        //                }
        //            }
        //        }
        //    }
        //}

        private List <ESRI.ArcGIS.Geodatabase.IRow> TracePath(ESRI.ArcGIS.Geodatabase.IFeature cableFeature, int fiberNumber, bool isStartingAtFromEnd)
        {
            List <ESRI.ArcGIS.Geodatabase.IRow> result = new List <ESRI.ArcGIS.Geodatabase.IRow>();

            string ipid = cableFeature.get_Value(cableFeature.Fields.FindField(ConfigUtil.IpidFieldName)).ToString();

            ESRI.ArcGIS.Geodatabase.IFeatureClass cableFtClass = (ESRI.ArcGIS.Geodatabase.IFeatureClass)cableFeature.Class;

            ESRI.ArcGIS.Geodatabase.IFeatureClass spliceFtClass    = _wkspHelper.FindFeatureClass(ConfigUtil.SpliceClosureFtClassName);
            ESRI.ArcGIS.Geodatabase.ITable        fiberSpliceTable = _wkspHelper.FindTable(ConfigUtil.FiberSpliceTableName);

            ESRI.ArcGIS.Geodatabase.IFields spliceFields = fiberSpliceTable.Fields;

            string fiberClassName = ConfigUtil.FiberTableName;

            ESRI.ArcGIS.Geodatabase.IRelationshipClass fiberRelationship = GdbUtils.GetRelationshipClass(cableFtClass, ConfigUtil.FiberCableToFiberRelClassName);
            if (null != fiberRelationship && null != fiberRelationship.DestinationClass)
            {
                fiberClassName = GdbUtils.ParseTableName(fiberRelationship.DestinationClass as ESRI.ArcGIS.Geodatabase.IDataset);
            }

            ESRI.ArcGIS.Geodatabase.ITable fiberTable = _wkspHelper.FindTable(fiberClassName);

            _aCableIdx            = spliceFields.FindField(ConfigUtil.ACableIdFieldName);
            _bCableIdx            = spliceFields.FindField(ConfigUtil.BCableIdFieldName);
            _aFiberNumIdx         = spliceFields.FindField(ConfigUtil.AFiberNumberFieldName);
            _bFiberNumIdx         = spliceFields.FindField(ConfigUtil.BFiberNumberFieldName);
            _isAFromIdx           = spliceFields.FindField(ConfigUtil.IsAFromEndFieldName);
            _isBFromIdx           = spliceFields.FindField(ConfigUtil.IsBFromEndFieldName);
            _spliceClosureIpidIdx = spliceFields.FindField(ConfigUtil.SpliceClosureIpidFieldName);

            ESRI.ArcGIS.Geodatabase.IQueryFilter spliceFilter = new ESRI.ArcGIS.Geodatabase.QueryFilterClass();
            spliceFilter.WhereClause = string.Format("({0}='{1}' AND {2}={3})"
                                                     + " OR ({4}='{1}' AND {5}={3})",
                                                     ConfigUtil.ACableIdFieldName,
                                                     ipid,
                                                     ConfigUtil.AFiberNumberFieldName,
                                                     fiberNumber,
                                                     ConfigUtil.BCableIdFieldName,
                                                     ConfigUtil.BFiberNumberFieldName);

            int connections = fiberSpliceTable.RowCount(spliceFilter);

            if (2 < connections)
            {
                // TODO: warning?
                System.Windows.Forms.MessageBox.Show("Less than 2 connections were detected: " + fiberNumber, "Telecom Trace", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Information);
            }

            string spliceClosureIpid = string.Empty;
            string nextCableId       = string.Empty;
            int    nextFiberNumber   = -1;
            bool   isNextFromEnd     = false;

            // {{0}} causes the string.format to
            string cableWhereFormat  = string.Format("{0}='{{0}}'", ConfigUtil.IpidFieldName);
            string spliceWhereFormat = string.Format("{0}='{{0}}'", ConfigUtil.IpidFieldName);
            string fiberWhereFormat  = string.Format("{0}='{{0}}' AND {1}={{1}}", fiberRelationship.OriginForeignKey, ConfigUtil.Fiber_NumberFieldName);

            using (ESRI.ArcGIS.ADF.ComReleaser releaser = new ESRI.ArcGIS.ADF.ComReleaser())
            {
                ESRI.ArcGIS.Geodatabase.IQueryFilter filter = new ESRI.ArcGIS.Geodatabase.QueryFilterClass();
                releaser.ManageLifetime(filter);

                // Ripple down the start cable's to end
                ESRI.ArcGIS.Geodatabase.IRow spliceRow = GetNextSplice(fiberSpliceTable, ipid, fiberNumber, isStartingAtFromEnd, out nextCableId, out nextFiberNumber, out spliceClosureIpid, out isNextFromEnd);
                while (null != spliceRow)
                {
                    ESRI.ArcGIS.Geodatabase.IFeature spliceClosure = null;

                    if (spliceClosureIpid.Equals(""))
                    {
                        System.Windows.Forms.MessageBox.Show("Found Splice with no SpliceClosure (ID/#) " + nextCableId + "/" + nextFiberNumber, "Telecom Trace", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Warning);
                    }
                    else
                    {
                        filter.WhereClause = string.Format(spliceWhereFormat, spliceClosureIpid);
                        ESRI.ArcGIS.Geodatabase.IFeatureCursor spliceCursor = spliceFtClass.Search(filter, false);
                        releaser.ManageLifetime(spliceCursor);
                        spliceClosure = spliceCursor.NextFeature();
                        if (spliceClosure == null)
                        {
                            System.Windows.Forms.MessageBox.Show("Invalid SpliceClosure referenced: (IPID)" + spliceClosureIpid, "Telecom Trace", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Warning);
                        }
                    }

                    filter.WhereClause = string.Format(cableWhereFormat, nextCableId);
                    ESRI.ArcGIS.Geodatabase.IFeatureCursor cableCursor = cableFtClass.Search(filter, false);
                    releaser.ManageLifetime(cableCursor);
                    ESRI.ArcGIS.Geodatabase.IFeature cable = cableCursor.NextFeature();
                    if (cable == null)
                    {
                        System.Windows.Forms.MessageBox.Show("Invalid cable ID referenced: (ID)" + nextCableId, "Telecom Trace", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Warning);
                    }

                    filter.WhereClause = string.Format(fiberWhereFormat, nextCableId, nextFiberNumber);
                    ESRI.ArcGIS.Geodatabase.ICursor fiberCursor = fiberTable.Search(filter, false);
                    releaser.ManageLifetime(fiberCursor);
                    ESRI.ArcGIS.Geodatabase.IRow fiber = fiberCursor.NextRow();
                    if (fiber == null)
                    {
                        System.Windows.Forms.MessageBox.Show("Invalid Fiber Cable or # referenced: (ID/#) " + nextCableId + "/" + nextFiberNumber, "Telecom Trace", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Warning);
                    }

                    if (isStartingAtFromEnd)
                    {
                        if (spliceRow != null)
                        {
                            result.Add(spliceRow);
                        }
                        if (spliceClosure != null)
                        {
                            result.Add(spliceClosure);
                        }
                        if (fiber != null)
                        {
                            result.Add(fiber);
                        }
                        if (cable != null)
                        {
                            result.Add(cable);
                        }
                    }
                    else
                    {
                        if (spliceClosure != null)
                        {
                            result.Add(spliceClosure);
                        }
                        if (spliceRow != null)
                        {
                            result.Add(spliceRow);
                        }
                        if (cable != null)
                        {
                            result.Add(cable);
                        }
                        if (fiber != null)
                        {
                            result.Add(fiber);
                        }
                    }

                    spliceRow = GetNextSplice(fiberSpliceTable, nextCableId, nextFiberNumber, !isNextFromEnd, out nextCableId, out nextFiberNumber, out spliceClosureIpid, out isNextFromEnd);
                }

                // See if there is a port for this one
                ESRI.ArcGIS.Geodatabase.IRow     portRow  = null;
                ESRI.ArcGIS.Geodatabase.IFeature deviceFt = null;
                if (GetConnectedPort(cableFtClass, nextCableId, nextFiberNumber, isNextFromEnd, out portRow, out deviceFt))
                {
                    if (isStartingAtFromEnd)
                    {
                        result.Add(portRow);
                        result.Add(deviceFt);
                    }
                    else
                    {
                        result.Add(deviceFt);
                        result.Add(portRow);
                    }
                }

                return(result);
            }
        }
        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);
            }
        }
示例#8
0
        private static Dictionary <string, double[][]> getDictionaryValues(ESRI.ArcGIS.Geodatabase.IFeatureClass pointFtr, ESRI.ArcGIS.Geodatabase.IField[] fldsToSummarize, IFunctionRasterDataset strataRaster, geoDatabaseUtility geoUtil, rasterUtil rsUtil)
        {
            IRaster2 rs2 = (IRaster2)rsUtil.createRaster(strataRaster);

            int[] ptfldIndex = new int[fldsToSummarize.Length];
            for (int i = 0; i < ptfldIndex.Length; i++)
            {
                ptfldIndex[i] = pointFtr.FindField(fldsToSummarize[i].Name);
            }
            Dictionary <string, double[][]> outDic = new Dictionary <string, double[][]>();
            IFeatureCursor sCur = pointFtr.Search(null, true);
            IFeature       sFtr = sCur.NextFeature();

            while (sFtr != null)
            {
                IGeometry geo = sFtr.Shape;
                IPoint    pnt = (IPoint)geo;
                int       clm, rw;
                rs2.MapToPixel(pnt.X, pnt.Y, out clm, out rw);
                object strataVlObj = rs2.GetPixelValue(0, clm, rw);
                if (strataVlObj != null)
                {
                    string     strataVl = strataVlObj.ToString();
                    double[][] vlArr;
                    if (outDic.TryGetValue(strataVl, out vlArr))
                    {
                        for (int i = 0; i < ptfldIndex.Length; i++)
                        {
                            object vlObj = sFtr.get_Value(ptfldIndex[i]);
                            if (vlObj != null)
                            {
                                double vl = System.Convert.ToDouble(vlObj);
                                vlArr[i][0] += vl;
                                vlArr[i][1] += (vl * vl);
                                vlArr[i][2] += 1;
                            }
                        }
                    }
                    else
                    {
                        vlArr = new double[fldsToSummarize.Length][];
                        for (int i = 0; i < ptfldIndex.Length; i++)
                        {
                            double[] vlSumArr = new double[3];
                            object   vlObj    = sFtr.get_Value(ptfldIndex[i]);
                            if (vlObj != null && !System.Convert.IsDBNull(vlObj))
                            {
                                double vl = System.Convert.ToDouble(vlObj);
                                vlSumArr[0] = vl;
                                vlSumArr[1] = (vl * vl);
                                vlSumArr[2] = 1;
                            }
                            vlArr[i] = vlSumArr;
                        }
                        outDic[strataVl] = vlArr;
                    }
                }
                sFtr = sCur.NextFeature();
            }
            System.Runtime.InteropServices.Marshal.ReleaseComObject(sCur);
            return(outDic);
        }