예제 #1
0
        private IFeature WalkLine(IFeatureLayer pDepthSoundings, IFeatureLayer pLineLayer, IFeature pLineFeature)
        {
            try
            {
                IEnvelope pCombinedEnvelope = CombineExtents(pDepthSoundings.FeatureClass, pLineLayer.FeatureClass);

                IPointCollection4 pPointColl = pLineFeature.Shape as IPointCollection4;
                IPoint            ppoint     = new PointClass();



                IFeatureCursor pDepthCursor = pDepthSoundings.Search(null, false);
                IFeatureIndex2 pFtrInd      = new FeatureIndexClass();
                pFtrInd.FeatureClass  = pDepthSoundings.FeatureClass;
                pFtrInd.FeatureCursor = pDepthCursor;
                pFtrInd.Index(null, pCombinedEnvelope);
                IIndexQuery2 pIndQry = pFtrInd as IIndexQuery2;

                int    FtdID     = 0;
                double dDist2Ftr = 0;
                pIndQry.NearestFeature(ppoint, out FtdID, out dDist2Ftr);

                IFeature pCloseFeature = pDepthSoundings.FeatureClass.GetFeature(FtdID);
                return(pCloseFeature);
            }

            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
                MessageBox.Show(ex.StackTrace);
                return(null);
            }
        }
예제 #2
0
        private double GetEndElevation(IFeatureLayer pDepthSoundings, IFeatureLayer pLineLayer, IFeature pLineFeature, string strDepthField)
        {
            try
            {
                IEnvelope pCombinedEnvelope = CombineExtents(pDepthSoundings.FeatureClass, pLineLayer.FeatureClass);

                IPointCollection4 pPointColl = pLineFeature.Shape as IPointCollection4;
                IPoint            ppoint     = new PointClass();


                //Get the last point on the line
                ppoint = pPointColl.get_Point(-1);

                IFeatureCursor pDepthCursor = pDepthSoundings.Search(null, false);
                IFeatureIndex2 pFtrInd      = new FeatureIndexClass();
                pFtrInd.FeatureClass  = pDepthSoundings.FeatureClass;
                pFtrInd.FeatureCursor = pDepthCursor;
                pFtrInd.Index(null, pCombinedEnvelope);
                IIndexQuery2 pIndQry = pFtrInd as IIndexQuery2;

                int    FtdID     = 0;
                double dDist2Ftr = 0;
                pIndQry.NearestFeature(ppoint, out FtdID, out dDist2Ftr);

                IFeature pCloseFeature = pDepthSoundings.FeatureClass.GetFeature(FtdID);
                return(Convert.ToDouble(pCloseFeature.get_Value(pCloseFeature.Fields.FindField(strDepthField))));
            }

            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
                MessageBox.Show(ex.StackTrace);
                return(0);
            }
        }
        private double GetPointElevation(IFeatureLayer pDepthSoundings, IFeatureLayer pLineLayer, IPoint ppoint, string strDepthField)
        {
            IEnvelope pCombinedEnvelope = CombineExtents(pDepthSoundings.FeatureClass, pLineLayer.FeatureClass);

            //if (IsPointCoincident(ppoint ,pDepthSoundings))
            //{


            IFeatureCursor pDepthCursor = pDepthSoundings.Search(null, false);
            IFeatureIndex2 pFtrInd      = new FeatureIndexClass();

            pFtrInd.FeatureClass  = pDepthSoundings.FeatureClass;
            pFtrInd.FeatureCursor = pDepthCursor;
            pFtrInd.Index(null, pCombinedEnvelope);
            IIndexQuery2 pIndQry = pFtrInd as IIndexQuery2;

            int    FtdID     = 0;
            double dDist2Ftr = 0;

            pIndQry.NearestFeature(ppoint, out FtdID, out dDist2Ftr);

            IFeature pCloseFeature = pDepthSoundings.FeatureClass.GetFeature(FtdID);

            return(Convert.ToDouble(pCloseFeature.get_Value(pCloseFeature.Fields.FindField(strDepthField))));
            //}
            //else{

            //    return 0;
            //}
        }
        private double GetStartElevation(IFeatureLayer pDepthSoundings, IFeatureLayer pLineLayer, IFeature pLineFeature, string DepthPointDepthField)
        {
            IEnvelope pCombinedEnvelope = CombineExtents(pDepthSoundings.FeatureClass, pLineLayer.FeatureClass);


            IFeatureCursor pDepthCursor = pDepthSoundings.Search(null, false);
            IFeatureIndex2 pFtrInd      = new FeatureIndexClass();

            pFtrInd.FeatureClass  = pDepthSoundings.FeatureClass;
            pFtrInd.FeatureCursor = pDepthCursor;
            pFtrInd.Index(null, pCombinedEnvelope);
            IIndexQuery2 pIndQry = pFtrInd as IIndexQuery2;

            int    FtdID     = 0;
            double dDist2Ftr = 0;

            pIndQry.NearestFeature(pLineFeature.Shape, out FtdID, out dDist2Ftr);

            IFeature pCloseFeature = pDepthSoundings.FeatureClass.GetFeature(FtdID);

            return(Convert.ToDouble(pCloseFeature.get_Value(pCloseFeature.Fields.FindField(DepthPointDepthField))));
        }
예제 #5
0
        public void Calculate(string sShorelineLayer, string sDepthPointsLayer, double dblInterval, string strShoreDepthField, string strDepthPointDepthField)
        {
            try
            {
                IMxDocument pmxdoc = ArcMap.Document as IMxDocument;
                IMap        pmap   = pmxdoc.FocusMap;

                IFeatureLayer pDepthSoundings = FindLayer(pmap, sDepthPointsLayer) as IFeatureLayer;
                IFeatureLayer pShorelineLayer = FindLayer(pmap, sShorelineLayer) as IFeatureLayer;

                //IFeatureLayer pOutpoints = FindLayer(pmap, sOutpoints) as IFeatureLayer;
                IFeatureLayer pOutpoints = new FeatureLayerClass();
                pOutpoints.FeatureClass = MakePointFC();
                pOutpoints.Name         = "Output Points";
                ArcMap.Document.ActiveView.FocusMap.AddLayer(pOutpoints);

                IFeatureLayer pConnectingLines = FindLayer(pmap, "ConnectingLines") as IFeatureLayer;
                IFeatureLayer pShorePoints     = FindLayer(pmap, "ShorePoints") as IFeatureLayer;



                ////Add fields if necessary
                //AddField(pOutpoints, "Distance");
                //AddField(pOutpoints, "Elevation");


                //Set up the Outpoints cursor
                IFeatureCursor pFCurOutPoints = pOutpoints.Search(null, false);
                pFCurOutPoints = pOutpoints.FeatureClass.Insert(true);
                IFeatureBuffer pFOutPointsBuffer = pOutpoints.FeatureClass.CreateFeatureBuffer();


                //Set up the LineLayer Cursor (now using selected lines)
                IFeatureSelection pShoreLineSelection = pShorelineLayer as IFeatureSelection;

                if (pShoreLineSelection.SelectionSet.Count == 0)
                {
                    MessageBox.Show("You must have at least one shoreline feature selected");
                    return;
                }
                ICursor        pShorelineCursor;
                IFeatureCursor pSelShoreFeatCur;
                pShoreLineSelection.SelectionSet.Search(null, false, out pShorelineCursor);
                pSelShoreFeatCur = pShorelineCursor as IFeatureCursor;
                IFeature pShoreLineFeature = pSelShoreFeatCur.NextFeature();
                //IFeatureCursor pFCur = pShorelineLayer.Search(null, false);
                //IFeature pShoreLineFeature = pFCur.NextFeature();

                //Set up the pConnectingLines cursor
                IFeatureCursor pFCurOutLines = pConnectingLines.Search(null, false);
                pFCurOutLines = pConnectingLines.FeatureClass.Insert(true);
                IFeatureBuffer pFBuffer = pConnectingLines.FeatureClass.CreateFeatureBuffer();

                //Set up the pShorePoints cursor
                IFeatureCursor pShorePointsCursor = pShorePoints.Search(null, false);
                IFeature       pShorePointFeature = pShorePointsCursor.NextFeature();



                IFeature         pNewLineFeature   = null;
                IPointCollection pNewLinePointColl = null;


                double dblDistance = 0;
                double dblTotalDistanceCalculated = 0;
                int    iNumIntervals        = 0;
                double dblElevationDiff     = 0;
                double dblElevationInterval = 0;
                double dblElevation         = 0;
                double dlbStartElevation    = 0;
                double dblEndElevation      = 0;

                int iLineProgressCount           = 0;
                IProgressDialog2 pProgressDialog = ShowProgressIndicator("Calculating points for shoreline vertex: ", 0, 1);
                pProgressDialog.ShowDialog();



                IEnvelope pCombinedEnvelope = CombineExtents(pDepthSoundings.FeatureClass, pShorelineLayer.FeatureClass);
                while (pShoreLineFeature != null)
                {
                    //IPointCollection4 pPointColl = pShoreLineFeature.Shape as IPointCollection4;

                    IPoint ppoint = new PointClass();



                    //for (int i = 0; i <= pPointColl.PointCount - 1; i++)
                    while (pShorePointFeature != null)
                    {
                        ppoint = pShorePointFeature.ShapeCopy as IPoint;
                        System.Diagnostics.Debug.WriteLine("ppoint: " + ppoint.X.ToString());
                        System.Diagnostics.Debug.WriteLine("shorepoint: " + pShorePointFeature.OID.ToString());

                        ////try walking line at set intervals instead of just at vertices
                        //IPoint pLineVertex = new PointClass();
                        //pLineVertex = pPointColl.get_Point(i);

                        IFeatureCursor pDepthCursor = pDepthSoundings.Search(null, false);
                        IFeatureIndex2 pFtrInd      = new FeatureIndexClass();
                        pFtrInd.FeatureClass  = pDepthSoundings.FeatureClass;
                        pFtrInd.FeatureCursor = pDepthCursor;
                        pFtrInd.Index(null, pCombinedEnvelope);
                        IIndexQuery2 pIndQry = pFtrInd as IIndexQuery2;

                        int    FtdID     = 0;
                        double dDist2Ftr = 0;
                        pIndQry.NearestFeature(ppoint, out FtdID, out dDist2Ftr);

                        IFeature pCloseFeature = pDepthSoundings.FeatureClass.GetFeature(FtdID);

                        IPoint pEndPoint = new PointClass();
                        pEndPoint = pCloseFeature.Shape as IPoint;


                        //Make the line here
                        pNewLineFeature   = pConnectingLines.FeatureClass.CreateFeature();
                        pNewLinePointColl = new PolylineClass();

                        object missing = Type.Missing;
                        pNewLinePointColl.AddPoint(pEndPoint, ref missing, ref missing);
                        pNewLinePointColl.AddPoint(ppoint, ref missing, ref missing);
                        pNewLineFeature.Shape = pNewLinePointColl as PolylineClass;

                        //Check to see if new line crosses land, if not, process it.
                        //bool bLineIntersectsShore = FeatureIntersects(pShorelineLayer, pConnectingLines, pNewLineFeature);
                        bool bLineIntersectsShore = false;
                        if (bLineIntersectsShore == false)
                        {
                            pNewLineFeature.Store();



                            ICurve pCurve = pNewLineFeature.Shape as ICurve;
                            pCurve.Project(pmap.SpatialReference);

                            //Get the Starting Elevation from the closest depth point
                            dlbStartElevation = GetStartElevation(pDepthSoundings, pConnectingLines, pNewLineFeature, strDepthPointDepthField);
                            //The Elevation for the first run IS the start elevation
                            dblElevation = dlbStartElevation;
                            //////Get the ending elevation from the shoreline
                            dblEndElevation = GetEndElevation(pShorelineLayer, pConnectingLines, pNewLineFeature, strShoreDepthField);

                            //number of line segments based on the user's interval
                            iNumIntervals    = Convert.ToInt32(pCurve.Length / dblInterval);
                            dblElevationDiff = Math.Abs(dblEndElevation - dlbStartElevation);
                            //The calculated elevation interval to step up each time
                            dblElevationInterval = dblElevationDiff / iNumIntervals;


                            ppoint = new PointClass();

                            while (dblTotalDistanceCalculated <= pCurve.Length)
                            {
                                pFOutPointsBuffer.set_Value(pFOutPointsBuffer.Fields.FindField("LineOID"), pNewLineFeature.OID);
                                pFOutPointsBuffer.set_Value(pFOutPointsBuffer.Fields.FindField("Distance"), dblDistance);
                                pFOutPointsBuffer.set_Value(pFOutPointsBuffer.Fields.FindField("Elevation"), dblElevation);


                                //this code set the point on the line at a distance
                                pCurve.QueryPoint(0, dblDistance, false, ppoint);

                                pFOutPointsBuffer.set_Value(pFOutPointsBuffer.Fields.FindField("X"), ppoint.X);
                                pFOutPointsBuffer.set_Value(pFOutPointsBuffer.Fields.FindField("Y"), ppoint.Y);


                                //reCalc the new distance and elevation values for the next iteration
                                dblDistance = dblDistance + dblInterval;

                                //add or subtract elevation depending on whether dblElevationDiff is positve or negative
                                if (dblElevationDiff > 0)
                                {
                                    dblElevation = dblElevation - dblElevationInterval;
                                }
                                else
                                {
                                    dblElevation = dblElevation + dblElevationInterval;
                                }
                                dblTotalDistanceCalculated = dblTotalDistanceCalculated + dblInterval;



                                //Insert the feature into the featureclass
                                pFOutPointsBuffer.Shape = ppoint;
                                pFCurOutPoints.InsertFeature(pFOutPointsBuffer);
                            }



                            //Reset the distance values back to 0 for the next feature
                            dblDistance = 0;
                            dblTotalDistanceCalculated = 0;
                            pFCurOutPoints.Flush();


                            pStepProgressor.Step();
                            pProgressDialog.Description = "Calculating points for shoreline vertex: " + pShorePointFeature.OID.ToString();
                            iLineProgressCount++;
                        }

                        pShorePointFeature = pShorePointsCursor.NextFeature();
                    }

                    pShoreLineFeature = pSelShoreFeatCur.NextFeature();
                }
                //cleanup
                pFCurOutLines.Flush();
                pSelShoreFeatCur.Flush();
                pProgressDialog.HideDialog();
                pmxdoc.ActiveView.Refresh();
            }

            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
                MessageBox.Show(ex.StackTrace);
            }
        }