コード例 #1
0
        private IEnumerable <INetworkEdge> EnumerateAdjacentTurnEdges(OSMTurnInfo osmTurn, bool useToJunction)
        {
            INetworkQuery query = (INetworkQuery)_networkDataset;

            // get turn FROM-edge
            INetworkSource      source          = _networkDataset.get_SourceByName(((IDataset)osmTurn.FromFeature.Class).Name);
            IEnumNetworkElement enumNetElements = query.get_EdgesByPosition(source.ID, osmTurn.FromFeature.OID, 0.0, false);
            INetworkEdge        edgeFrom        = enumNetElements.Next() as INetworkEdge;

            // get the FROM-edge Junctions
            INetworkJunction fromJunction = query.CreateNetworkElement(esriNetworkElementType.esriNETJunction) as INetworkJunction;
            INetworkJunction toJunction   = query.CreateNetworkElement(esriNetworkElementType.esriNETJunction) as INetworkJunction;

            edgeFrom.QueryJunctions(fromJunction, toJunction);

            // Get adjacent edges from the turn center junction
            INetworkJunction junction = ((useToJunction) ? toJunction : fromJunction);

            for (int n = 0; n < junction.EdgeCount; ++n)
            {
                INetworkEdge edge = query.CreateNetworkElement(esriNetworkElementType.esriNETEdge) as INetworkEdge;
                junction.QueryEdge(n, true, edge);

                if ((edge.OID == osmTurn.FromFeature.OID) || (edge.OID == osmTurn.ToFeature.OID))
                {
                    continue;
                }

                yield return(edge);
            }
        }
コード例 #2
0
        /// <summary>
        /// Occurs when a dataGrid row header is clicked.
        ///   It is used here to flash the geometry of the newly selected row
        /// <param name="sender">The control raising this event</param>
        /// <param name="e">Arguments associated with the event</param>
        /// </summary>
        private void dataGridView_RowHeaderMouseClick(object sender, DataGridViewCellMouseEventArgs e)
        {
            // make sure none of the cells are in edit mode.  When in edit mode, the values obtained
            //  programmatically will not yet match the value the user has changed the cell to
            DataGridView dgv = (DataGridView)sender;

            dgv.EndEdit();

            // Only flash when there is one selected row
            if (dgv.SelectedRows.Count > 1)
            {
                return;
            }
            DataGridViewRow selectedRow = dgv.SelectedRows[0];

            // If it is the extra dataGrid row or has errors, then don't try to flash it
            ValidateRow(selectedRow);
            if (selectedRow.IsNewRow || selectedRow.ErrorText != "")
            {
                return;
            }

            // also, if any of the row's cell have no value, then don't want to flash it
            foreach (DataGridViewCell cell in selectedRow.Cells)
            {
                if (cell.Value == null)
                {
                    return;
                }
            }

            // use the EID to obtain the barrier's corresponding network element and source feature
            INetworkElement element = GetElementByEID(selectedRow.Cells[0].Value.ToString(), dgv.Name);

            if (element == null)
            {
                return;
            }
            IFeature sourceFeature = GetSourceFeature(element);

            // For an edge, get the part geometry of the barrier covered portion of the source feature
            //  that should be displayed
            INetworkEdge             netEdge          = element as INetworkEdge;
            esriNetworkEdgeDirection displayDirection = esriNetworkEdgeDirection.esriNEDNone;

            if (netEdge != null)
            {
                sourceFeature.Shape = GetBarrierSubcurve(netEdge, sourceFeature, selectedRow);
                displayDirection    = GetDirectionValue(selectedRow);
            }

            // Draw
            FlashFeature(sourceFeature, displayDirection);
        }
コード例 #3
0
        private IEnumerable <INetworkEdge> EnumerateAdjacentTurnEdges(OSMTurnInfo osmTurn, bool useToJunction)
        {
            INetworkQuery query = (INetworkQuery)_networkDataset;

            // get turn FROM-edge
            INetworkSource      source          = _networkDataset.get_SourceByName(((IDataset)osmTurn.FromFeature.Class).Name);
            IEnumNetworkElement enumNetElements = null;

            IRelationalOperator relationalOperator = ((IPolyline)osmTurn.ToFeature.Shape).FromPoint as IRelationalOperator;

            bool useFromPointOfToFeature = relationalOperator.Contains(osmTurn.ViaFeature.Shape);

            if (useFromPointOfToFeature)
            {
                enumNetElements = query.get_EdgesByPosition(source.ID, osmTurn.ToFeature.OID, 0, false);
            }
            else
            {
                enumNetElements = query.get_EdgesByPosition(source.ID, osmTurn.ToFeature.OID, 1, false);
            }

            INetworkEdge edgeFrom = enumNetElements.Next() as INetworkEdge;

            // get the FROM-edge Junctions
            INetworkJunction fromJunction = query.CreateNetworkElement(esriNetworkElementType.esriNETJunction) as INetworkJunction;
            INetworkJunction toJunction   = query.CreateNetworkElement(esriNetworkElementType.esriNETJunction) as INetworkJunction;

            edgeFrom.QueryJunctions(fromJunction, toJunction);

            // Get adjacent edges from the turn center junction
            INetworkJunction junction = ((useFromPointOfToFeature) ? fromJunction : toJunction);

            for (int n = 0; n < junction.EdgeCount; ++n)
            {
                INetworkEdge edge = query.CreateNetworkElement(esriNetworkElementType.esriNETEdge) as INetworkEdge;
                if (useFromPointOfToFeature)
                {
                    junction.QueryEdge(n, true, edge);
                }
                else
                {
                    junction.QueryEdge(n, false, edge);
                }

                //if ((edge.SourceID == osmTurn.FromFeature.OID) || (edge.SourceID == osmTurn.ToFeature.OID))
                if ((edge.OID == osmTurn.ToFeature.OID))
                {
                    continue;
                }

                yield return(edge);
            }
        }
コード例 #4
0
        /// <summary>
        /// Take an EID value as a string from one of the dataGridView controls and find
        ///  the network element that corresponds to the EID
        /// <param name="eidString">The EID value as a string</param>
        /// <param name="datagridviewName">The name of the dataGrid that held the EID</param>
        /// </summary>
        private INetworkElement GetElementByEID(string eidString, string datagridviewName)
        {
            int eid = -1;

            if (!Int32.TryParse(eidString, out eid))
            {
                return(null);
            }

            INetworkQuery    netQuery = m_context.NetworkDataset as INetworkQuery;
            INetworkEdge     edge     = netQuery.CreateNetworkElement(esriNetworkElementType.esriNETEdge) as INetworkEdge;
            INetworkJunction junction = netQuery.CreateNetworkElement(esriNetworkElementType.esriNETJunction) as INetworkJunction;

            INetworkElement element = null;

            try
            {
                // Populate the network element from the EID
                if (datagridviewName == "dataGridViewEdges")
                {
                    netQuery.QueryEdge(eid, esriNetworkEdgeDirection.esriNEDAlongDigitized, edge);
                    element = edge as INetworkElement;
                }
                else if (datagridviewName == "dataGridViewJunctions")
                {
                    netQuery.QueryJunction(eid, junction);
                    element = junction as INetworkElement;
                }
            }
            catch
            {
                // if the query fails, the element will not be displayed
            }

            return(element);
        }
コード例 #5
0
        /// <summary>
        /// Take a network edge, a source feature, and a row from the edges dataGrid, and determine
        ///  the geometry to be flashed on the map
        /// <param name="netEdge">The edge upon which the barrier resides</param>
        /// <param name="sourceFeature">The source feature corresponding to the network edge</param>
        /// <param name="selectedRow">The row containing the barrier's location range information</param>
        /// </summary>
        private ICurve GetBarrierSubcurve(INetworkEdge netEdge, IFeature sourceFeature, DataGridViewRow selectedRow)
        {
            // value for displaying the entire source feature
            double fromPosition = 0;
            double toPosition   = 1;

            // Find the values for displaying only the element portion of the source feature
            double fromElementPosition, toElementPosition;

            netEdge.QueryPositions(out fromElementPosition, out toElementPosition);

            // due to the element possibly being in the against digitized direction,
            //   fromPosition could be greater than toPosition.  If that is the case, swap the values
            if (fromElementPosition > toElementPosition)
            {
                double tmp = fromElementPosition;
                fromElementPosition = toElementPosition;
                toElementPosition   = tmp;
            }

            esriNetworkEdgeDirection direction = GetDirectionValue(selectedRow);

            if (direction == esriNetworkEdgeDirection.esriNEDNone)
            {
                return(null);
            }

            // Flash the edge
            if (rbFlashElementPortion.Checked)
            {
                fromPosition = fromElementPosition;
                toPosition   = toElementPosition;
            }
            // Flash the barrier portion of the edge
            else if (rbFlashBarrierPortion.Checked)
            {
                double fromBarrierPosition = -1;
                double toBarrierPosition   = -1;

                // gather the from and to position values for the barrier
                fromBarrierPosition = Double.Parse(selectedRow.Cells[2].Value.ToString());
                toBarrierPosition   = Double.Parse(selectedRow.Cells[3].Value.ToString());

                // for barriers in the against direction, we need to adjust that the element position is
                if (direction == esriNetworkEdgeDirection.esriNEDAgainstDigitized)
                {
                    fromBarrierPosition = 1 - fromBarrierPosition;
                    toBarrierPosition   = 1 - toBarrierPosition;
                }

                // use the positioning along the element of the barrier
                //  to get the position along the original source feature
                fromPosition = fromElementPosition + (fromBarrierPosition * (toElementPosition - fromElementPosition));
                toPosition   = fromElementPosition + (toBarrierPosition * (toElementPosition - fromElementPosition));
            }

            if (fromPosition > toPosition)
            {
                double tmp = fromPosition;
                fromPosition = toPosition;
                toPosition   = tmp;
            }

            // get the subspan on the polyline that represents the from and to positions we specified
            ICurve displayCurve;
            ICurve sourceCurve = sourceFeature.Shape as ICurve;

            sourceCurve.GetSubcurve(fromPosition, toPosition, true, out displayCurve);
            return(displayCurve);
        }
コード例 #6
0
		/// <summary>
		/// Take a network edge, a source feature, and a row from the edges dataGrid, and determine
		///  the geometry to be flashed on the map
		/// <param name="netEdge">The edge upon which the barrier resides</param>
		/// <param name="sourceFeature">The source feature corresponding to the network edge</param>
		/// <param name="selectedRow">The row containing the barrier's location range information</param>
		/// </summary>
		private ICurve GetBarrierSubcurve(INetworkEdge netEdge, IFeature sourceFeature, DataGridViewRow selectedRow)
		{
			// value for displaying the entire source feature
			double fromPosition = 0;
			double toPosition = 1;

			// Find the values for displaying only the element portion of the source feature
			double fromElementPosition, toElementPosition;
			netEdge.QueryPositions(out fromElementPosition, out toElementPosition);

			// due to the element possibly being in the against digitized direction,
			//   fromPosition could be greater than toPosition.  If that is the case, swap the values
			if (fromElementPosition > toElementPosition)
			{
				double tmp = fromElementPosition;
				fromElementPosition = toElementPosition;
				toElementPosition = tmp;
			}

			esriNetworkEdgeDirection direction = GetDirectionValue(selectedRow);
			if (direction == esriNetworkEdgeDirection.esriNEDNone) return null;

			// Flash the edge
			if (rbFlashElementPortion.Checked)
			{
				fromPosition = fromElementPosition;
				toPosition = toElementPosition;
			}
			// Flash the barrier portion of the edge
			else if (rbFlashBarrierPortion.Checked)
			{
				double fromBarrierPosition = -1;
				double toBarrierPosition = -1;

				// gather the from and to position values for the barrier
				fromBarrierPosition = Double.Parse(selectedRow.Cells[2].Value.ToString());
				toBarrierPosition = Double.Parse(selectedRow.Cells[3].Value.ToString());

				// for barriers in the against direction, we need to adjust that the element position is
				if (direction == esriNetworkEdgeDirection.esriNEDAgainstDigitized)
				{
					fromBarrierPosition = 1 - fromBarrierPosition;
					toBarrierPosition = 1 - toBarrierPosition;
				}

				// use the positioning along the element of the barrier
				//  to get the position along the original source feature
				fromPosition = fromElementPosition + (fromBarrierPosition * (toElementPosition - fromElementPosition));
				toPosition = fromElementPosition + (toBarrierPosition * (toElementPosition - fromElementPosition));
			}

			if (fromPosition > toPosition)
			{
				double tmp = fromPosition;
				fromPosition = toPosition;
				toPosition = tmp;
			}

			// get the subspan on the polyline that represents the from and to positions we specified
			ICurve displayCurve;
			ICurve sourceCurve = sourceFeature.Shape as ICurve;
			sourceCurve.GetSubcurve(fromPosition, toPosition, true, out displayCurve);
			return displayCurve;
		}
コード例 #7
0
ファイル: MainForm.cs プロジェクト: batuZ/Samples
        private void btnFindWC_Click(object sender, EventArgs e)
        {
            clear();
            clearDeep();

            IFdeCursor cursor = null;

            try
            {
                if (closestFacilitySolver == null)
                {
                    closestFacilitySolver = network.CreateClosestFacilitySolver();
                    closestFacilitySolver.ImpedanceAttributeName = "Length";
                }
                closestFacilitySolver.LocationSearchTolerance = double.Parse(txtSearchTolerance.Text);
                closestFacilitySolver.ClearFacilityLocations();
                closestFacilitySolver.ClearEventLocations();

                // 添加WC设施点
                foreach (IFeatureClass fc in fcMap_POI.Keys)
                {
                    if (fc.Name.Contains("WC"))
                    {
                        cursor = fc.Search(null, true);
                        IRowBuffer row = null;
                        while ((row = cursor.NextRow()) != null)
                        {
                            try
                            {
                                INetworkLocation facility = new NetworkLocation();
                                int    pos   = row.FieldIndex("Geometry");
                                IPoint point = row.GetValue(pos) as IPoint;
                                facility.Position = point;
                                facility.Name     = fc.Guid.ToString() + "_" + row.GetValue(0).ToString(); //设定名字"fcGUID_oid"
                                closestFacilitySolver.AddFacilityLocation(facility);
                            }
                            catch (COMException ex)
                            {
                            }
                        }
                        break;
                    }
                }
                if (closestFacilitySolver.FacilityLocationCount == 0)
                {
                    MessageBox.Show("添加的厕所数为0,请调整LocationSearchTolerance大小");
                    return;
                }

                // 添加人所在的位置
                INetworkEventLocation location = new NetworkEventLocation();
                this.axRenderControl1.Camera.GetCamera2(out fdepoint, out ang);
                location.Position            = fdepoint;
                location.Name                = "I'mHere";
                location.TargetFacilityCount = int.Parse(txtMaxNum.Text);
                location.SetCutoff("Length", double.Parse(txtCutoff.Text));
                closestFacilitySolver.AddEventLocation(location);
                // 可视化人的位置
                IImagePointSymbol ips = new ImagePointSymbol();
                ips.ImageName = "#(i)";
                ips.Size      = 50;
                renderPoint   = this.axRenderControl1.ObjectManager.CreateRenderPoint(fdepoint, ips, rootId);

                if (closestFacilitySolver.Solve())
                {
                    int routeCount = closestFacilitySolver.RouteCount;
                    if (routeCount == 0)
                    {
                        MessageBox.Show("没有厕所在指定范围内");
                        return;
                    }
                    for (int i = 0; i < routeCount; i++)
                    {
                        INetworkRoute route = closestFacilitySolver.GetRoute(i);
                        if (route != null)
                        {
                            // 可视化线路
                            ICurveSymbol lineSym = new CurveSymbol();
                            lineSym.Color = System.Drawing.Color.Yellow;
                            lineSym.Width = -2;
                            IGeometry geo = route.GetRouteGeometry();
                            if (geo.GeometryType == gviGeometryType.gviGeometryPolyline)
                            {
                                IPolyline line = geo as IPolyline;
                                renderLine = this.axRenderControl1.ObjectManager.CreateRenderPolyline(line, lineSym, rootId);
                                renderLine.MaxVisibleDistance = 10000;
                                renderLineArray.Add(renderLine);
                            }
                            else if (geo.GeometryType == gviGeometryType.gviGeometryMultiPolyline)
                            {
                                IMultiPolyline line = geo as IMultiPolyline;
                                multiRenderLine = this.axRenderControl1.ObjectManager.CreateRenderMultiPolyline(line, lineSym, rootId);
                                multiRenderLine.MaxVisibleDistance = 10000;
                                multiRenderLineArray.Add(multiRenderLine);
                            }

                            drawTempLine(route);

                            // 高亮厕所
                            int segmentCount = route.SegmentCount;
                            for (int j = 0; j < segmentCount; j++)
                            {
                                INetworkLocation endLocation = route.GetSegment(j).EndLocation;
                                string[]         strs        = endLocation.Name.Split('_');
                                foreach (IFeatureClass fc in fcMap_POI.Keys)
                                {
                                    if (fc.Guid.ToString() == strs[0])
                                    {
                                        this.axRenderControl1.FeatureManager.HighlightFeature(fc, int.Parse(strs[1]), System.Drawing.Color.Yellow);
                                        break;
                                    }
                                }

                                //////////////////////测试NetworkElement相关//////////////////////////////////
                                INetworkElementCollection elementCols = route.GetSegment(j).GetNetworkElements();
                                for (int c = 0; c < elementCols.Count; c++)
                                {
                                    INetworkElement element = elementCols.Get(c);
                                    if (element.Type == gviNetworkElementType.gviEdge)
                                    {
                                        INetworkEdge edge  = element as INetworkEdge;
                                        int          subId = edge.SubID;
                                    }
                                    else
                                    {
                                        INetworkJunction       junction = element as INetworkJunction;
                                        INetworkEdgeCollection edgeCol  = junction.IncomingEdges;
                                        for (int ee = 0; ee < edgeCol.Count; ee++)
                                        {
                                            INetworkEdge edge  = edgeCol.Get(ee);
                                            int          subId = edge.SubID;
                                        }
                                    }
                                }
                                //////////////////////////////////////////////////////////////////////////
                            }
                        }
                    }
                }
                else
                {
                    MessageBox.Show("查找失败");
                }
            }
            catch (COMException ex)
            {
                MessageBox.Show(ex.Message);
            }
            finally
            {
                if (cursor != null)
                {
                    //Marshal.ReleaseComObject(cursor);
                    cursor = null;
                }
            }
        }