Exemplo n.º 1
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);
            }
        }
Exemplo n.º 2
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);
            }
        }
        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;
            //}
        }
        public bool IsPointCoincident(IPoint ppoint, IFeatureLayer pDepthPointsLayer)
        {
            IFeatureIndex2 pFI2 = new FeatureIndexClass();

            pFI2.FeatureClass = pDepthPointsLayer.FeatureClass;
            IGeoDataset pGDS = pDepthPointsLayer.FeatureClass as IGeoDataset;

            pFI2.Index(null, pGDS.Extent);

            IIndexQuery2 pIQ2 = pFI2 as IIndexQuery2;
            object       pSAIds;

            pIQ2.IntersectedFeatures(ppoint, out pSAIds);

            if (pSAIds != null)
            {
                return(true);
            }
            return(false);
        }
        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))));
        }
Exemplo n.º 6
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);
            }
        }
Exemplo n.º 7
0
        /// <summary>
        /// Zoekt het dichtstbijzijnde punt op de spoorhartlijnen die binnen de zoekafstand liggen en waarvoor geldt dat de gevonden waarde binnen
        /// het kilometerinterval km_begin en km_eind ligt. De resultaten worden via de parameters outPoint, outPointGevonden en pDistance
        /// </summary>
        /// <param name="Point"></param>
        /// <param name="IndexQueryLRS"></param>
        /// <param name="km_begin"></param>
        /// <param name="km_eind"></param>
        /// <param name="outPoint"></param>
        /// <param name="outPointGevonden"></param>
        /// <param name="pDistance"></param>
        private void ZoekPuntOpSpoorhartlijn(IPoint Point, IIndexQuery2 IndexQueryLRS, double km_begin, double km_eind, out IPoint outPoint, out bool outPointGevonden, out double outPointDistance)
        {
            try
            {
                IPolygon buffer = (Point as ITopologicalOperator).Buffer(this.mshape_maxafstand) as IPolygon;

                distanceAlongCurve = 0;
                bRightSide = false;

                object pSAIds = null;
                double pDistanceToNearestFeature = 0;
                IndexQueryLRS.NearestFeatures(buffer as IGeometry, out pSAIds, out pDistanceToNearestFeature);

                if ((pSAIds == null) || (pDistanceToNearestFeature > 0.001)) // 1 mm
                {
                    outPoint = null;
                    outPointGevonden = false;
                    outPointDistance = double.PositiveInfinity;
                }
                else // er zijn features gevonden binnen de zoekafstand
                {
                    IFeatureCursor FeatureCursorIntersectsLRS = fcLRS.GetFeatures(pSAIds, false);

                    try
                    {
                        outPoint = null;
                        outPointGevonden = false;
                        outPointDistance = double.PositiveInfinity;

                        IFeature featureLRS = FeatureCursorIntersectsLRS.NextFeature();

                        // Zoek het punt dat binnen de kilometertolerantie valt
                        double km_begin_mshape_tolerantie = km_begin - (this.mshape_tolerantie / 1000);
                        double km_eind_mshape_tolerantie = km_eind + (this.mshape_tolerantie / 1000);
                        while (featureLRS != null)
                        {

                            ICurve curveLRS = featureLRS.Shape as ICurve;
                            outPoint = new ESRI.ArcGIS.Geometry.Point();
                            curveLRS.QueryPointAndDistance(esriSegmentExtension.esriNoExtension, Point as IPoint, false, outPoint, distanceAlongCurve, ref outPointDistance, bRightSide);
                            if (outPoint.M >= km_begin_mshape_tolerantie && outPoint.M < km_eind_mshape_tolerantie)
                            {
                                // punt gevonden, verlaat de loop.
                                outPointGevonden = true;
                                break;
                            }

                            featureLRS = FeatureCursorIntersectsLRS.NextFeature();
                        }
                    }
                    catch
                    {
                        throw;
                    }
                    finally
                    {
                        ESRI.ArcGIS.ADF.ComReleaser.ReleaseCOMObject(FeatureCursorIntersectsLRS);
                    }
                }

            }
            catch (Exception ex)
            {
                logger.LogException(LogLevel.Trace, "FOUT", ex);
                System.Windows.Forms.MessageBox.Show("Er is een onverwachte fout opgetreden; raadpleeg de logfile: " + ex.Message + ": " + ex.StackTrace, "Foutmelding");
                throw;
            }
        }
Exemplo n.º 8
0
        static void Main(string[] args)
        {
            //ESRI License Initializer generated code.
            m_AOLicenseInitializer.InitializeApplication(new esriLicenseProductCode[] { esriLicenseProductCode.esriLicenseProductCodeAdvanced },
                                                         new esriLicenseExtensionCode[] { });

            Dictionary <string, Vertex> nodeDict = new Dictionary <string, Vertex>();
            Type factoryType = Type.GetTypeFromProgID("esriDataSourcesGDB.FileGDBWorkspaceFactory");
            IWorkspaceFactory workspaceFactory = (IWorkspaceFactory)Activator.CreateInstance(factoryType);
            IWorkspace        workspace        = workspaceFactory.OpenFromFile(@"C:\Users\hellocomrade\NHDPlusV21_GL_04.gdb", 0);
            IFeatureWorkspace iFtrWs           = workspace as IFeatureWorkspace;

            if (null != iFtrWs)
            {
                IFeatureClass fcLine  = iFtrWs.OpenFeatureClass("NHD_Flowline");
                IFeatureClass fcPoint = iFtrWs.OpenFeatureClass("Hydro_Net_Junctions");
                System.Diagnostics.Debug.Assert(null != fcLine && null != fcPoint);

                var fldLst = new List <string> {
                    "OBJECTID", "FlowDir", "FTYPE", "V0001E_MA", "V0001E_MM", "V0001E_01", "V0001E_02", "V0001E_03", "V0001E_04", "V0001E_05", "V0001E_06", "V0001E_07", "V0001E_08", "V0001E_09", "V0001E_10", "V0001E_11", "V0001E_12"
                };
                Dictionary <string, int> fldDict = new Dictionary <string, int>();
                fldLst.ForEach(fldName => fldDict.Add(fldName, fcLine.FindField(fldName)));

                int lineFtrId = -1;
                //Find field index for oid in Hydro_Net_Junctions feature class
                int    pntFtrIdIdx = fcPoint.FindField("OBJECTID");
                string pntFtrId    = null;

                /*
                 * It has been observed that the most time consuming part of this script is on spatial query.
                 * We could take the same approach we had on Arcpy through fcLine.Search() with a spatial filter.
                 * However, it will make us have the same granularity as using arcpy.
                 * Instead, we took a different route here by using IFeatureIndex and IIndexQuery2
                 */
                IGeoDataset       geoLineDS = (IGeoDataset)fcLine;
                ISpatialReference srLine    = geoLineDS.SpatialReference;
                IFeatureIndex     lineIdx   = new FeatureIndexClass();
                lineIdx.FeatureClass = fcLine;
                lineIdx.Index(null, geoLineDS.Extent);
                IIndexQuery2 queryLineByIdx = lineIdx as IIndexQuery2;

                IFeatureIndex pointIdx = new FeatureIndexClass();
                pointIdx.FeatureClass = fcPoint;
                pointIdx.Index(null, ((IGeoDataset)fcPoint).Extent);
                IIndexQuery2 queryPointByIdx = pointIdx as IIndexQuery2;

                //Get a cursor on Hydro_Net_Junctions as the iterator
                IFeatureCursor pntCur        = fcPoint.Search(null, false);
                IFeature       pnt           = pntCur.NextFeature();
                IFeature       line          = null;
                IFeature       otherPnt      = null;
                List <string>  requiredTypes = new List <string> {
                    "StreamRiver", "ArtificialPath"
                };

                /*
                 * ITopologicalOpeartor is good for two geometries comparing with each other. It doesn't fit
                 * very well for our situation, which check the geometric relationships between a geometry
                 * against a feature class that may have more than 100K geometries.
                 */
                //ITopologicalOperator optor = null;

                /*
                 * It's a shame that we have to reference to a Server API in order to calcuate Geodesic
                 * distances for a polyline with lon/lat as coordinates.
                 *
                 * We could do Haversine ourselves, but we have to believe ESRI could definitely does a
                 * better job there, well, hard to figure out how to get this simple task done in an intutive
                 * way though...
                 */
                IGeometryServer2 geoOperator = new GeometryServerClass();

                IPolyline             polyLine = null;
                List <DownstreamNode> dsLst    = null;
                int[]         lineIds          = null;
                int[]         pntIds           = null;
                object        idobjs;
                object        idobjs1;
                PolylineArray tmpArr   = null;
                IDoubleArray  lengths  = null;
                double        lineLen  = 0.0;
                double        v        = 0.0;
                ILinearUnit   unit     = new LinearUnitClass();
                var           range    = Enumerable.Range(3, 14);
                int           count    = 0;
                int           incoming = 0;
                while (null != pnt)
                {
                    //get ftr id of the current vertex
                    pntFtrId = pnt.get_Value(pntFtrIdIdx).ToString();
                    //optor = pnt.Shape as ITopologicalOperator;

                    /*
                     * This should return feature ids that interects with the given geometry in the feature
                     * class having the index built.
                     */
                    queryLineByIdx.IntersectedFeatures(pnt.Shape, out idobjs);
                    lineIds = idobjs as int[];
                    if (null != lineIds && lineIds.Length > 0)
                    {
                        foreach (int id in lineIds)
                        {
                            line      = fcLine.GetFeature(id);
                            lineFtrId = int.Parse(line.get_Value(fldDict["OBJECTID"]).ToString());
                            if ("1" == line.get_Value(fldDict["FlowDir"]).ToString() && true == requiredTypes.Contains(line.get_Value(fldDict["FTYPE"]).ToString()))
                            {
                                polyLine = line.Shape as IPolyline;
                                if (isSamePoint(polyLine.FromPoint, pnt.Shape as IPoint))
                                {
                                    queryPointByIdx.IntersectedFeatures(line.Shape, out idobjs1);
                                    pntIds = idobjs1 as int[];
                                    if (null != pntIds && 2 == pntIds.Length)
                                    {
                                        foreach (int pid in pntIds)
                                        {
                                            otherPnt = fcPoint.GetFeature(pid);
                                            if (false == isSamePoint(otherPnt.Shape as IPoint, pnt.Shape as IPoint))
                                            {
                                                tmpArr = new PolylineArrayClass();
                                                tmpArr.Add(polyLine);
                                                lengths = geoOperator.GetLengthsGeodesic(srLine, tmpArr as IPolylineArray, unit);
                                                if (0 == lengths.Count)
                                                {
                                                    continue;
                                                }
                                                lineLen = lengths.get_Element(0) * 3.28084;
                                                //var velos = from idx in range select double.Parse(line.get_Value(fldDict[fldLst[idx]]).ToString());
                                                List <double> velos = new List <double>();
                                                foreach (int idx in range)
                                                {
                                                    v = double.Parse(line.get_Value(fldDict[fldLst[idx]]).ToString());
                                                    velos.Add(v == 0 ? 0 : lineLen / v);
                                                }
                                                if (null == dsLst)
                                                {
                                                    dsLst = new List <DownstreamNode>();
                                                }
                                                dsLst.Add(new DownstreamNode(pid, id, velos));
                                            }
                                        }
                                    }
                                }
                                else // pnt at the end of the polyline
                                {
                                    ++incoming;
                                }
                            }
                        }
                    }
                    if (null != dsLst || incoming > 0)
                    {
                        nodeDict.Add(pntFtrId, new Vertex(int.Parse(pntFtrId), incoming, dsLst));
                    }
                    pnt = pntCur.NextFeature();
                    if (++count % 1000 == 0)
                    {
                        Console.WriteLine("Processing Count: " + count);
                    }
                    incoming = 0;
                    dsLst    = null;
                }//end of while(null != pnt)
                ReleaseCOMObj(pntCur);
            }
            ReleaseCOMObj(workspaceFactory);
            //ESRI License Initializer generated code.
            //Do not make any call to ArcObjects after ShutDownApplication()
            m_AOLicenseInitializer.ShutdownApplication();
        }
Exemplo n.º 9
0
        /// <summary>
        /// Zoekt het dichtstbijzijnde punt op de spoorhartlijnen die binnen de zoekafstand liggen en waarvoor geldt dat de gevonden waarde binnen
        /// het kilometerinterval km_begin en km_eind ligt. De resultaten worden via de parameters outPoint, outPointGevonden en pDistance
        /// </summary>
        /// <param name="Point"></param>
        /// <param name="IndexQueryLRS"></param>
        /// <param name="km_begin"></param>
        /// <param name="km_eind"></param>
        /// <param name="outPoint"></param>
        /// <param name="outPointGevonden"></param>
        /// <param name="pDistance"></param>
        private void ZoekPuntOpSpoorhartlijn(IPoint Point, IIndexQuery2 IndexQueryLRS, double km_begin, double km_eind, out IPoint outPoint, out bool outPointGevonden, out double outPointDistance)
        {
            try
            {
                IPolygon buffer = (Point as ITopologicalOperator).Buffer(this.mshape_maxafstand) as IPolygon;

                distanceAlongCurve = 0;
                bRightSide         = false;

                object pSAIds = null;
                double pDistanceToNearestFeature = 0;
                IndexQueryLRS.NearestFeatures(buffer as IGeometry, out pSAIds, out pDistanceToNearestFeature);

                if ((pSAIds == null) || (pDistanceToNearestFeature > 0.001)) // 1 mm
                {
                    outPoint         = null;
                    outPointGevonden = false;
                    outPointDistance = double.PositiveInfinity;
                }
                else // er zijn features gevonden binnen de zoekafstand
                {
                    IFeatureCursor FeatureCursorIntersectsLRS = fcLRS.GetFeatures(pSAIds, false);

                    try
                    {
                        outPoint         = null;
                        outPointGevonden = false;
                        outPointDistance = double.PositiveInfinity;

                        IFeature featureLRS = FeatureCursorIntersectsLRS.NextFeature();

                        // Zoek het punt dat binnen de kilometertolerantie valt
                        double km_begin_mshape_tolerantie = km_begin - (this.mshape_tolerantie / 1000);
                        double km_eind_mshape_tolerantie  = km_eind + (this.mshape_tolerantie / 1000);
                        while (featureLRS != null)
                        {
                            ICurve curveLRS = featureLRS.Shape as ICurve;
                            outPoint = new ESRI.ArcGIS.Geometry.Point();
                            curveLRS.QueryPointAndDistance(esriSegmentExtension.esriNoExtension, Point as IPoint, false, outPoint, distanceAlongCurve, ref outPointDistance, bRightSide);
                            if (outPoint.M >= km_begin_mshape_tolerantie && outPoint.M < km_eind_mshape_tolerantie)
                            {
                                // punt gevonden, verlaat de loop.
                                outPointGevonden = true;
                                break;
                            }

                            featureLRS = FeatureCursorIntersectsLRS.NextFeature();
                        }
                    }
                    catch
                    {
                        throw;
                    }
                    finally
                    {
                        ESRI.ArcGIS.ADF.ComReleaser.ReleaseCOMObject(FeatureCursorIntersectsLRS);
                    }
                }
            }
            catch (Exception ex)
            {
                logger.LogException(LogLevel.Trace, "FOUT", ex);
                System.Windows.Forms.MessageBox.Show("Er is een onverwachte fout opgetreden; raadpleeg de logfile: " + ex.Message + ": " + ex.StackTrace, "Foutmelding");
                throw;
            }
        }