public void FindCurves(String Name, IFeatureClass pFabricLinesFC, ISelectionSet selSet, string whereClause, myProgessor progressor)
        {
            CurveByInferenceSettings.FieldPositions positions = new CurveByInferenceSettings.FieldPositions((ITable)pFabricLinesFC);
            if (!positions.ValidCheckFields)
            {
                messageBox.Show(string.Format("One or more of the following fields are missing ({0}, {1})", CurveByInferenceSettings.Instance.RadiusFieldName, CurveByInferenceSettings.Instance.CenterpointIDFieldName));
            }


            IQueryFilter qFilter = new QueryFilter();
            if (String.IsNullOrEmpty(whereClause))
            {
                qFilter.WhereClause = "CenterPointID is null and Radius is null";
            }
            else
            {
                qFilter.WhereClause = string.Concat(whereClause, " and CenterPointID is null and Radius is null");
            }

            IFeatureCursor cursor = null;
            if (selSet != null)
            {
                ICursor c;
                ISelectionSet subset = selSet.Select(qFilter, esriSelectionType.esriSelectionTypeIDSet, esriSelectionOption.esriSelectionOptionNormal, null);
                progressor.setStepProgressorProperties(subset.Count, String.Format("Layer {0}: Evaluating Selected Features", Name));

                subset.Search(null, true, out c);
                cursor = (IFeatureCursor)c;
            }
            else
            {
                progressor.setStepProgressorProperties(((ITable)pFabricLinesFC).RowCount(qFilter), String.Format("Layer {0}: Evaluating Features", Name));
                cursor = pFabricLinesFC.Search(qFilter, true);
            }

            //ISelectionSet pSelSet = pFabricLinesFC.Select(qFilter, esriSelectionType.esriSelectionTypeIDSet, esriSelectionOption.esriSelectionOptionNormal, null);
            //progressor.setStepProgressorProperties(pSelSet.Count, String.Format("Layer {0}: Evaluating Features", Name));
            //ICursor cursor = null;
            //pSelSet.Search(null, false, out cursor);


            IFeature pLineFeat = null;
            while ((pLineFeat = (IFeature)cursor.NextFeature() as IFeature) != null)
            {
                if (!progressor.Continue())
                    break;
                progressor.Step();

                if (!Curves.Any(w => w.ObjectID == pLineFeat.OID))
                {
                    IGeometry pGeom = pLineFeat.ShapeCopy;
                    ISegmentCollection pSegColl = pGeom as ISegmentCollection;
                    ISegment pSeg = null;
                    if (pSegColl != null && pSegColl.SegmentCount == 1)
                    {
                        pSeg = pSegColl.get_Segment(0);
                    }
                    else
                    {
                        if (pSegColl == null)
                            messageBox.Show(String.Format("The shape for objectid {0} could not be converted to a segement collection.", pLineFeat.OID));

                        //todo: but for now, only deals with single segment short segments
                        Marshal.ReleaseComObject(pLineFeat);
                        continue;
                    }

                    //if the geometry is a circular arc and the attributes reflect that, move on to the next feature
                    //obsolete, filter is pushed to database
                    //if (pSeg is ICircularArc)
                    //{
                    //    object dVal1 = pLineFeat.get_Value(idxRADIUS);
                    //    object dVal2 = pLineFeat.get_Value(idxCENTERPTID);
                    //    if (!(dVal1 is DBNull) && !(dVal2 is DBNull))
                    //    {
                    //        Marshal.ReleaseComObject(pLineFeat);
                    //        continue;
                    //    }
                    //}

                    //query near lines
                    List<RelatedLine> tangentLines;
                    List<RelatedCurve> sCurveInfoFromNeighbours = GetTangentCurveMatchFeatures(pFabricLinesFC, pLineFeat, (IPolycurve)pGeom, "", positions.RadiusFieldIdx, positions.CenterpointIDFieldIdx, pSeg.Length, out tangentLines);
                                
                    if(sCurveInfoFromNeighbours.Count > 0)
                    //if (HasTangentCurveMatchFeatures(pFabricLinesFC, (IPolycurve)pGeom, "", pSeg.Length, out iFoundTangent, ref sCurveInfoFromNeighbours))
                    {
                        InferredCurve curve = new InferredCurve(pLineFeat.OID, Name, sCurveInfoFromNeighbours);
                        IPolyline polyLine = (IPolyline)pGeom;
                        curve.FromPoint = polyLine.FromPoint;
                        curve.ToPoint = polyLine.ToPoint;
                     
                        //evaluated the position of any tangent lines, and determines if there is a junction situation.  If there is, it will:
                        //  Retrun true with curve.Accepted set
                        //  Return true without curve.Accepted set
                        //  Return false (this indicates that the junction has been used to verify that this segemnt should not have a curve)
                        if (evaluateJunctions(curve, tangentLines))
                        {
                            //junction couldn't eliminate the curve, so return it
                            Curves.Add(curve);
                            curve.PropertyChanged += new PropertyChangedEventHandler(curve_PropertyChanged);
                            curve.Parcel = (int)pLineFeat.get_Value(positions.ParcelIDFieldIdx);

                            if (!curve.HasValue) //if the junction logic didn't set the curve
                            {
                                //check to see if one of the tange curves overlap
                                if (curve.TangentCurves[0].Orientation == RelativeOrientation.Same || curve.TangentCurves[0].Orientation == RelativeOrientation.Reverse)
                                {
                                    curve.InferredRadius = curve.TangentCurves[0].Radius;
                                    curve.InferredCenterpointID = curve.TangentCurves[0].CenterpointID;
                                }
                                else
                                {
                                    //check radial and tangent lines (both need a single centerpoint and radius tangent curve (check done in function)
                                    RefineToBestRadiusAndCenterPoint(curve, pFabricLinesFC, pLineFeat, (IPolycurve)pGeom, tangentLines);
                                }
                            }

                            //if the curve has an accepted curve (ie, it's a candidate to be changed), record the parcel id
                            //if (curve.Accepted != null)
                            //    affectedParcels.Add();

                            //cache the parcel so it can be looked up later
                        }
                    }
                }
                Marshal.ReleaseComObject(pLineFeat);
            }
            Marshal.ReleaseComObject(cursor);

            Total = Curves.Count;
            Inferred = Curves.Count(w => w.Action == UpdateAction.Update);
        }
示例#2
0
        /// <summary>
        /// ��㡢�յ����Ҫ�ӱ߶���
        /// </summary>
        /// <param name="bIsFromOver"></param>
        /// <param name="bIsToOver"></param>
        /// <param name="ipToSpatialFilter"></param>
        /// <param name="ipFromSpatialFilter"></param>
        /// <param name="ipSourceRow"></param>
        /// <param name="ipSourceCursor"></param>
        /// <param name="ipTargetSelectionSet"></param>
        /// <param name="sMatchEdgeWhereClause"></param>
        /// <param name="lSourceRowOID"></param>
        /// <param name="sSourceRowOID"></param>
        /// <param name="sOIDs"></param>
        /// <param name="sCheckInfos"></param>
        /// <returns></returns>
        private bool JointFromToPoints(bool bIsFromOver, bool bIsToOver, ISpatialFilter ipToSpatialFilter,
                                       ISpatialFilter ipFromSpatialFilter,
                                       ref IRow ipSourceRow, ICursor ipSourceCursor, ISelectionSet ipTargetSelectionSet,
                                       string sMatchEdgeWhereClause, int lSourceRowOID, string sSourceRowOID,
                                       ref List<string> sOIDs, ref List<string> sCheckInfos)
        {
            try
            {
                int lFromSelectionCount, lToSelectionCount;
                ISelectionSet ipFromSelectionSet = null;
                ISelectionSet ipToSelectionSet = null;
                if (bIsFromOver == false)
                {
                    try
                    {
                        ipFromSelectionSet = ipTargetSelectionSet.Select(ipFromSpatialFilter,
                                                                         esriSelectionType.esriSelectionTypeHybrid,
                                                                         esriSelectionOption.esriSelectionOptionNormal,
                                                                         null);
                    }
                    catch (Exception ex)
                    {
                        SendMessage(enumMessageType.Exception, ex.ToString());
                        Marshal.ReleaseComObject(ipSourceRow);
                        ipSourceRow = ipSourceCursor.NextRow();
                        return false;
                    }

                    lFromSelectionCount = ipFromSelectionSet.Count;
                }
                else
                {
                    lFromSelectionCount = 0;
                }

                if (bIsToOver == false)
                {
                    try
                    {
                        ipToSelectionSet =
                            ipTargetSelectionSet.Select(ipToSpatialFilter,
                                                        esriSelectionType.esriSelectionTypeHybrid,
                                                        esriSelectionOption.esriSelectionOptionNormal,
                                                        null);
                    }
                    catch (Exception ex)
                    {
                        SendMessage(enumMessageType.Exception, ex.ToString());
                        Marshal.ReleaseComObject(ipSourceRow);
                        ipSourceRow = ipSourceCursor.NextRow();
                        return false;
                    }
                    lToSelectionCount = ipToSelectionSet.Count;
                }
                else
                {
                    lToSelectionCount = 0;
                }

                if (lFromSelectionCount > 0 && lToSelectionCount > 0)
                {
                    //�������յ��ͼ��ͼ�νӱ�
                    ipFromSpatialFilter.WhereClause = sMatchEdgeWhereClause;
                    ipToSpatialFilter.WhereClause = sMatchEdgeWhereClause;

                    ISelectionSet ipFromAttrSelectionSet, ipToAttrSelectionSet;
                    ipFromAttrSelectionSet =
                        ipFromSelectionSet.Select(ipFromSpatialFilter,
                                                  esriSelectionType.esriSelectionTypeHybrid,
                                                  esriSelectionOption.esriSelectionOptionNormal, null);

                    ipToAttrSelectionSet =
                        ipToSelectionSet.Select(ipToSpatialFilter,
                                                esriSelectionType.esriSelectionTypeHybrid,
                                                esriSelectionOption.esriSelectionOptionNormal, null);
                    int lFromAttrSelectionCount, lToAttrSelectionCount;
                    lFromAttrSelectionCount = ipFromAttrSelectionSet.Count;
                    lToAttrSelectionCount = ipToAttrSelectionSet.Count;

                    if (lFromAttrSelectionCount > 0 && lToAttrSelectionCount > 0)
                    {
                        //�����յ������Խӱ�
                        //�ж������յ�Ľӱ߶����Ƿ����һ��
                        ICursor ipFromAttrCursor, ipToAttrCursor;
                        ipFromAttrSelectionSet.Search(null, false, out ipFromAttrCursor);
                        ipToAttrSelectionSet.Search(null, false, out ipToAttrCursor);
                        //����

                        IRow ipFromAttrRow = ipFromAttrCursor.NextRow();
                        int nFromAttr = 0;
                        while (ipFromAttrRow != null)
                        {
                            int lFromAttrOID = ipFromAttrRow.OID;
                            if (lFromAttrOID != lSourceRowOID)
                            {
                                nFromAttr++;
                            }
                            ipFromAttrRow = ipFromAttrCursor.NextRow();
                        }

                        //�ж��յ�
                        IRow ipToAttrRow = ipToAttrCursor.NextRow();
                        int nToAttr = 0;
                        while (ipToAttrRow != null)
                        {
                            int lToAttrOID = ipToAttrRow.OID;

                            if (lToAttrOID != lSourceRowOID)
                            {
                                nToAttr++;
                            }
                            ipToAttrRow = ipToAttrCursor.NextRow();
                        }

                        Marshal.ReleaseComObject(ipFromAttrCursor);
                        Marshal.ReleaseComObject(ipToAttrCursor);

                        string sInfo = null;
                        if (nFromAttr > 1 && nToAttr > 1)
                        {
                            sOIDs.Add(sSourceRowOID);
                            sInfo = sSourceRowOID + "Ҫ����㴦��" + nFromAttr + "���ӱ߶���;�յ㴦��" + nToAttr +
                                    "���ӱ߶���";
                            sCheckInfos.Add(sInfo);
                        }
                        else if (nFromAttr > 1)
                        {
                            sOIDs.Add(sSourceRowOID);
                            sInfo = sSourceRowOID + "Ҫ����㴦��" + nFromAttr + "���ӱ߶���";
                            sCheckInfos.Add(sInfo);
                        }
                        else if (nToAttr > 1)
                        {
                            sOIDs.Add(sSourceRowOID);
                            sInfo = sSourceRowOID + "Ҫ���յ㴦��" + nToAttr + "���ӱ߶���";
                            sCheckInfos.Add(sInfo);
                        }
                    }
                    else if (lFromAttrSelectionCount > 0)
                    {
                        //��������Խӱ߶���,�յ�û�����Խӱ߶���
                        ICursor ipFromAttrCursor = null;
                        ipFromAttrSelectionSet.Search(null, false, out ipFromAttrCursor);
                        //����
                        IRow ipFromAttrRow = ipFromAttrCursor.NextRow();
                        int nFromAttr = 0;
                        while (ipFromAttrRow != null)
                        {
                            int lFromAttrOID = ipFromAttrRow.OID;

                            if (lFromAttrOID != lSourceRowOID)
                            {
                                nFromAttr++;
                            }
                            ipFromAttrRow = ipFromAttrCursor.NextRow();
                        }

                        Marshal.ReleaseComObject(ipFromAttrCursor);

                        if (nFromAttr > 1)
                        {
                            sOIDs.Add(sSourceRowOID);
                            string sInfo = sSourceRowOID + "Ҫ����㴦��" + nFromAttr + "���ӱ߶���,�����յ㴦�ӱ߶�������Բ�ͬ";
                            sCheckInfos.Add(sInfo);
                        }
                        else
                        {
                            sOIDs.Add(sSourceRowOID);
                            string sInfo = sSourceRowOID + "Ҫ���յ㴦�ӱ߶�������Բ�ͬ";
                            sCheckInfos.Add(sInfo);
                        }
                    }
                    else if (lToAttrSelectionCount > 0)
                    {
                        //�յ������Խӱ߶���,���û�����Խӱ߶���
                        //�ж��յ�
                        ICursor ipToAttrCursor = null;
                        ipToAttrSelectionSet.Search(null, false, out ipToAttrCursor);
                        IRow ipToAttrRow = ipToAttrCursor.NextRow();
                        int nToAttr = 0;
                        while (ipToAttrRow != null)
                        {
                            int lToAttrOID = ipToAttrRow.OID;

                            if (lToAttrOID != lSourceRowOID)
                            {
                                nToAttr++;
                            }
                            ipToAttrRow = ipToAttrCursor.NextRow();
                        }

                        Marshal.ReleaseComObject(ipToAttrCursor);
                        if (nToAttr > 1)
                        {
                            sOIDs.Add(sSourceRowOID);
                            string sInfo = sSourceRowOID + "Ҫ���յ㴦��" + nToAttr + "���ӱ߶���,������㴦�ӱ߶�������Բ�ͬ";
                            sCheckInfos.Add(sInfo);
                        }
                        else
                        {
                            sOIDs.Add(sSourceRowOID);
                            string sInfo = sSourceRowOID + "Ҫ����㴦�ӱ߶�������Բ�ͬ";
                            sCheckInfos.Add(sInfo);
                        }
                    }
                    else
                    {
                        sOIDs.Add(sSourceRowOID);
                        //�����յ㶼û�����Խӱ߶���
                        string sInfo = sSourceRowOID + "Ҫ�������յ㴦�нӱ߶���,�����Բ�ͬ";
                        sCheckInfos.Add(sInfo);
                    }
                }
                else if (lFromSelectionCount > 0)
                {
                    ipFromSpatialFilter.WhereClause = sMatchEdgeWhereClause;

                    ISelectionSet ipFromAttrSelectionSet =
                        ipFromSelectionSet.Select(ipFromSpatialFilter,
                                                  esriSelectionType.esriSelectionTypeHybrid,
                                                  esriSelectionOption.esriSelectionOptionNormal, null);

                    int lFromAttrSelectionCount = ipFromAttrSelectionSet.Count;

                    if (lFromAttrSelectionCount > 0)
                    {
                        //��������Խӱ߶���
                        ICursor ipFromAttrCursor = null;
                        ipFromAttrSelectionSet.Search(null, false, out ipFromAttrCursor);
                        //����
                        IRow ipFromAttrRow = ipFromAttrCursor.NextRow();
                        int nFromAttr = 0;
                        while (ipFromAttrRow != null)
                        {
                            int lFromAttrOID = ipFromAttrRow.OID;

                            if (lFromAttrOID != lSourceRowOID)
                            {
                                nFromAttr++;
                            }
                            ipFromAttrRow = ipFromAttrCursor.NextRow();
                        }

                        Marshal.ReleaseComObject(ipFromAttrCursor);

                        if (nFromAttr > 1)
                        {
                            sOIDs.Add(sSourceRowOID);
                            string sInfo = sSourceRowOID + "Ҫ����㴦��" + nFromAttr + "���ӱ߶���,�����յ㴦ȱ�ٽӱ߶���";
                            sCheckInfos.Add(sInfo);
                        }
                        else
                        {
                            if (nFromAttr < 1)
                            {
                                sOIDs.Add(sSourceRowOID);
                                string sInfo = sSourceRowOID + "Ҫ���յ㴦ȱ�ٽӱ߶���";
                                sCheckInfos.Add(sInfo);
                            }
                        }
                    }
                    else
                    {
                        sOIDs.Add(sSourceRowOID);
                        string sInfo = sSourceRowOID + "Ҫ����㴦�нӱ߶���,�����Բ�ͬ;�����յ㴦ȱ�ٽӱ߶���";
                        sCheckInfos.Add(sInfo);
                    }
                }
                else if (lToSelectionCount > 0)
                {
                    ipToSpatialFilter.WhereClause = sMatchEdgeWhereClause;

                    ISelectionSet ipToAttrSelectionSet =
                        ipToSelectionSet.Select(ipToSpatialFilter,
                                                esriSelectionType.esriSelectionTypeHybrid,
                                                esriSelectionOption.esriSelectionOptionNormal, null);

                    int lToAttrSelectionCount = ipToAttrSelectionSet.Count;

                    if (lToAttrSelectionCount > 0)
                    {
                        //�յ������Խӱ߶���
                        ICursor ipToAttrCursor = null;
                        ipToAttrSelectionSet.Search(null, false, out ipToAttrCursor);
                        //�ж��յ�
                        IRow ipToAttrRow = ipToAttrCursor.NextRow();
                        int nToAttr = 0;
                        while (ipToAttrRow != null)
                        {
                            int lToAttrOID = ipToAttrRow.OID;

                            if (lToAttrOID != lSourceRowOID)
                            {
                                nToAttr++;
                            }
                            ipToAttrRow = ipToAttrCursor.NextRow();
                        }

                        Marshal.ReleaseComObject(ipToAttrCursor);

                        if (nToAttr > 1)
                        {
                            sOIDs.Add(sSourceRowOID);
                            string sInfo = sSourceRowOID + "Ҫ���յ㴦��" + nToAttr + "���ӱ߶���,������㴦ȱ�ٽӱ߶���";
                            sCheckInfos.Add(sInfo);
                        }
                        else
                        {
                            if (nToAttr < 1)
                            {
                                sOIDs.Add(sSourceRowOID);
                                string sInfo = sSourceRowOID + "%sҪ����㴦ȱ�ٽӱ߶���";
                                sCheckInfos.Add(sInfo);
                            }
                        }
                    }
                    else
                    {
                        sOIDs.Add(sSourceRowOID);
                        string sInfo = sSourceRowOID + "%sҪ���յ㴦�нӱ߶���,�����Բ�ͬ;������㴦ȱ�ٽӱ߶���";
                        sCheckInfos.Add(sInfo);
                    }
                }
                else
                {
                    if (bIsFromOver == false && bIsToOver == false)
                    {
                        sOIDs.Add(sSourceRowOID);
                        //û��ͼ�νӱ�
                        string sInfo = sSourceRowOID + "Ҫ�������յ㴦��ȱ�ٶ�Ӧ�Ľӱ߶���";
                        sCheckInfos.Add(sInfo);
                    }
                }
                if (ipFromSelectionSet != null)
                {
                    Marshal.ReleaseComObject(ipFromSelectionSet);
                }
                if (ipToSelectionSet != null)
                {
                    Marshal.ReleaseComObject(ipToSelectionSet);
                }
                return true;
            }
            catch (Exception ex)
            {
                SendMessage(enumMessageType.Exception, ex.ToString());
                Marshal.ReleaseComObject(ipSourceRow);
                ipSourceRow = ipSourceCursor.NextRow();
                return false;
            }
        }