Using IPointToEID without SourceMap

708
4
Jump to solution
04-24-2012 11:27 PM
OrlandoCarvajal
New Contributor III
Hi there,

I'm building a SOE that makes use of IPointToEID.GetNearestEdge(). Since I know that Map services based on MXD files will not be supported in 10.1, I want to use an MSD file. Unfortunately IPointToEID requires a reference to an IMap object that is not available from MSD-based Map services. I wonder if there's an alternative to this method, or perhaps I just have to write my own method to find the Feature (and its subelement?).

Thanks in advance for any help,
Orlando
0 Kudos
1 Solution

Accepted Solutions
nicogis
MVP Frequent Contributor
I'm seen same problem. In 10.1 I don't seen new interface for IPointToEID without map. Perahps you could use in IGeometricNetwork the method EdgeElement and JunctionElement but perahps they (I don't see tolerance) require exactly point on edge (EdgeElement) or junction (JunctionElement). you could search feature with spatialfilter and then with IProximityOperator (ReturnNearestPoint) found point on feature and then use EdgeElement. If I have new I post on forum.

View solution in original post

0 Kudos
4 Replies
nicogis
MVP Frequent Contributor
I'm seen same problem. In 10.1 I don't seen new interface for IPointToEID without map. Perahps you could use in IGeometricNetwork the method EdgeElement and JunctionElement but perahps they (I don't see tolerance) require exactly point on edge (EdgeElement) or junction (JunctionElement). you could search feature with spatialfilter and then with IProximityOperator (ReturnNearestPoint) found point on feature and then use EdgeElement. If I have new I post on forum.

View solution in original post

0 Kudos
nicogis
MVP Frequent Contributor
I have written this code. Try see if it is ok for your use



        /// <summary>
        /// search the eid nearest from point
        /// </summary>
        /// <param name="searchTolerance">tolerance for search</param>
        /// <param name="point">point input</param>
        /// <param name="elementType">type of element found</param>
        /// <returns>return eid</returns>
        private int GetEIDFromPoint(double searchTolerance, IPoint point, out esriElementType elementType)
        {
            if (searchTolerance < 0 || point == null)
            {
                throw new GeometricNetworkException("Tolerance or source not valid!");
            }

            IFeatureClassContainer featureClassContainer = this.geometricNetwork as IFeatureClassContainer;
            double distance = double.PositiveInfinity;
            int featureClassID = -1;
            IGeometry featureGeometry = null;
            for (int i = 0; i < featureClassContainer.ClassCount; i++)
            {
                IFeatureClass featureClass = featureClassContainer.get_Class(i);
                string shapeFieldName = featureClass.ShapeFieldName;
                ITopologicalOperator topologicalOperator = point as ITopologicalOperator;   
                ISpatialFilter spatialFilter = new SpatialFilterClass();
                spatialFilter.Geometry = topologicalOperator.Buffer(searchTolerance);
                spatialFilter.SpatialRel = esriSpatialRelEnum.esriSpatialRelIntersects;
                spatialFilter.GeometryField = shapeFieldName;
                using (ComReleaser comReleaser = new ComReleaser())
                {
                    IFeatureCursor featureCursor = featureClass.Search(spatialFilter, true);
                    comReleaser.ManageLifetime(featureCursor);
                    IFeature feature = featureCursor.NextFeature();
                    while (feature != null)
                    {
                        IProximityOperator proximityOperator = feature.ShapeCopy as IProximityOperator;
                        double distanceCurrent = proximityOperator.ReturnDistance(point);
                        if (distance > distanceCurrent)
                        {
                            distance = distanceCurrent;
                            featureClassID = featureClass.FeatureClassID;
                            featureGeometry = feature.ShapeCopy;
                        }
                        feature = featureCursor.NextFeature();
                    }

                }
            }

            if (featureClassID == -1)
            {
                throw new GeometricNetworkException("Element in network not found!");
            }

            IProximityOperator proximityPoint = featureGeometry as IProximityOperator;
            IPoint p = proximityPoint.ReturnNearestPoint(point, esriSegmentExtension.esriNoExtension);

            int eid = this.geometricNetwork.get_EdgeElement(p);
            elementType = esriElementType.esriETEdge;
            if (eid < 1)
            {
                eid = this.geometricNetwork.get_JunctionElement(p);
                elementType = esriElementType.esriETJunction;
            }

            if (eid < 1)
            {
                throw new GeometricNetworkException("Element in network not found!");
            }

            return eid;
        }


0 Kudos
OrlandoCarvajal
New Contributor III
Thanks a lot Domenico, it looks like your code has pretty much all the necessary pieces, and I can adjust it for what I actually need. You saved me from a little bit of research... 🙂

Take care,
Orlando
0 Kudos
nicogis
MVP Frequent Contributor
I discover the called to this function:


                esriElementType elementType;
                int eid = this.GetEIDFromPoint(tolerance, point, out elementType);

                INetElements netElements = this.geometricNetwork.Network as INetElements;
                int featureClassID, featureID, subID;
                netElements.QueryIDs(eid, elementType, out featureClassID, out featureID, out subID);



FYI: I'm starting  similar soe: http://gnutilitysoerest.codeplex.com/SourceControl/list/changesets
0 Kudos