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); } }
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); } }
/// <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); }
private void frmNetworkPropertySheet_Load(object sender, EventArgs e) { int num2; string[] strArray; ListViewItem item; this.lblNetworkName.Text = (this.inetworkDataset_0 as IDataset).Name; this.lblNetworkType.Text = this.method_0(this.inetworkDataset_0.NetworkType); INetworkQuery query = this.inetworkDataset_0 as INetworkQuery; string str = ""; str = ((query.get_ElementCount(esriNetworkElementType.esriNETJunction).ToString() + "个连接点\r\n") + query.get_ElementCount(esriNetworkElementType.esriNETEdge).ToString() + "条边\r\n") + query.get_ElementCount(esriNetworkElementType.esriNETTurn).ToString() + "个转向\r\n"; this.lblNetworkElements.Text = str; for (num2 = 0; num2 < this.inetworkDataset_0.SourceCount; num2++) { strArray = new string[3]; INetworkSource source = this.inetworkDataset_0.get_Source(num2); strArray[0] = source.Name; strArray[1] = this.method_1(source.SourceType); strArray[2] = this.method_2(source.ElementType); item = new ListViewItem(strArray); this.lsvSource.Items.Add(item); if (source.SourceType == esriNetworkSourceType.esriNSTEdgeFeature) { strArray[0] = source.Name; strArray[1] = "From End"; strArray[2] = (source as IEdgeFeatureSource).FromElevationFieldName; item = new ListViewItem(strArray); this.lsvElevation.Items.Add(item); strArray[1] = "To End"; strArray[2] = (source as IEdgeFeatureSource).ToElevationFieldName; item = new ListViewItem(strArray); this.lsvElevation.Items.Add(item); if (source.NetworkSourceDirections == null) { } } else if (source.SourceType == esriNetworkSourceType.esriNSTJunctionFeature) { strArray[0] = source.Name; strArray[1] = ""; strArray[2] = (source as IJunctionFeatureSource).ElevationFieldName; item = new ListViewItem(strArray); this.lsvElevation.Items.Add(item); } } for (num2 = 0; num2 < this.inetworkDataset_0.AttributeCount; num2++) { strArray = new string[6]; INetworkAttribute attribute = this.inetworkDataset_0.get_Attribute(num2); strArray[0] = ""; strArray[1] = ""; strArray[2] = attribute.Name; strArray[3] = CommonHelper.GetUsageTypeDescriptor(attribute.UsageType); strArray[4] = CommonHelper.GetNetworkUnitTypeDescriptor(attribute.Units); strArray[5] = CommonHelper.GetDataTypeDescriptor(attribute.DataType); item = new ListViewItem(strArray); this.lsvAttributes.Items.Add(item); } }
private static Dictionary <string, List <int> > GetEIDListsBySourceName(INetworkAnalystExtension nax, object searchObject, string baseName) { if (nax == null) { return(null); } bool naxEnabled = false; IExtensionConfig naxConfig = nax as IExtensionConfig; naxEnabled = naxConfig.State == esriExtensionState.esriESEnabled; if (!naxEnabled) { return(null); } INAWindow naWindow = nax.NAWindow; INALayer naLayer = null; INAContext naContext = null; INetworkDataset nds = null; naLayer = naWindow.ActiveAnalysis; if (naLayer != null) { naContext = naLayer.Context; } if (naContext != null) { nds = naContext.NetworkDataset; } INetworkQuery netQuery = nds as INetworkQuery; if (netQuery == null) { return(null); } bool oidSearch = false; bool geometrySearch = false; if (searchObject == null) { return(null); } else if (searchObject is Dictionary <string, ILongArray> ) { oidSearch = true; } else if (searchObject is IGeometry) { geometrySearch = true; } else { return(null); } VarType vt = GetEIDArrayParameterType(); List <string> sourceNames = FindParameterizedSourceNames(nds, baseName, vt); Dictionary <string, List <int> > eidsBySourceName = new Dictionary <string, List <int> >(); foreach (string sourceName in sourceNames) { INetworkSource netSource = nds.get_SourceByName(sourceName); int sourceID = netSource.ID; List <int> eids = new List <int>(); if (oidSearch) { Dictionary <string, ILongArray> oidArraysBySourceName = (Dictionary <string, ILongArray>)searchObject; ILongArray oids = null; IEnumNetworkElement enumNetElement; INetworkElement netElement; if (oidArraysBySourceName.TryGetValue(sourceName, out oids)) { enumNetElement = netQuery.get_ElementsByOIDs(sourceID, oids); enumNetElement.Reset(); netElement = enumNetElement.Next(); while (netElement != null) { eids.Add(netElement.EID); netElement = enumNetElement.Next(); } } } else if (geometrySearch) { IGeometry searchGeometry = (IGeometry)searchObject; if (searchGeometry != null && !searchGeometry.IsEmpty) { IGeometry elementGeometry = null; esriNetworkElementType elementType = esriNetworkElementType.esriNETEdge; int eid = -1; // Search for the network dataset layer associated with the active analysis layer or create one using the // network dataset if matching one not found. // If, for example, multiple network dataset layers are added to the map, the active analysis layer // might not reference the current network dataset layer (nax.CurrentNetworkLayer). INetworkLayer ndsLayer = new NetworkLayerClass(); ndsLayer.NetworkDataset = nds; int count = nax.NetworkLayerCount; for (int i = 0; i < count; ++i) { ndsLayer = nax.get_NetworkLayer(i); if (ndsLayer.NetworkDataset == nds) { break; } else { ndsLayer = null; } } if (ndsLayer == null) { ndsLayer = new NetworkLayerClass(); ndsLayer.NetworkDataset = nds; } IEnumLocatedNetworkElement enumLocatedNetElement = null; if (ndsLayer != null) { enumLocatedNetElement = ndsLayer.SearchLocatedNetworkElements(sourceName, searchGeometry); enumLocatedNetElement.Reset(); eid = enumLocatedNetElement.Next(ref elementGeometry, ref elementType); while (eid != -1) { eids.Add(eid); eid = enumLocatedNetElement.Next(ref elementGeometry, ref elementType); } } } } eidsBySourceName.Add(sourceName, eids); } return(eidsBySourceName); }
private byte[] QueryByExtentHandler(NameValueCollection boundVariables, JsonObject operationInput, string outputFormat, string requestProperties, out string responseProperties) { responseProperties = null; if (networkDataset == null) { throw new NullReferenceException("Could not access the network dataset."); } if (!operationInput.TryGetString("Extent", out var envelopeString)) { throw new ArgumentNullException("Extent is invalid."); } var coords = envelopeString.Split(';'); var minCoords = coords[0].Split(','); var maxCoords = coords[1].Split(','); double.TryParse(minCoords[0].Trim(), out var minX); double.TryParse(minCoords[1].Trim(), out var minY); double.TryParse(maxCoords[0].Trim(), out var maxX); double.TryParse(maxCoords[0].Trim(), out var maxY); // Find features in envelope IEnvelope env = new EnvelopeClass(); env.PutCoords(minX, minY, maxX, maxY); ISpatialFilter spatialFilter = new SpatialFilter(); spatialFilter.Geometry = env; spatialFilter.SpatialRel = esriSpatialRelEnum.esriSpatialRelIntersects; // Add selected features OID into LongArray ILongArray oIDs = new LongArray(); IFeatureCursor fCursor = streetFC.Search(spatialFilter, true); IFeature feature = fCursor.NextFeature(); while (feature != null) { oIDs.Add(feature.OID); feature = fCursor.NextFeature(); } // Get the network edges corresponding to the streets and write out information about them INetworkQuery networkQuery = networkDataset as INetworkQuery; INetworkJunction fromJunction = networkQuery.CreateNetworkElement(esriNetworkElementType.esriNETJunction) as INetworkJunction; INetworkJunction toJunction = networkQuery.CreateNetworkElement(esriNetworkElementType.esriNETJunction) as INetworkJunction; IEnumNetworkElement networkElements = networkQuery.ElementsByOIDs[streetsSourceID, oIDs]; INetworkElement networkElement = networkElements.Next(); JSONObject result = new JSONObject(); JSONArray elementArray = new JSONArray(); INetworkEdge networkEdge; while (networkElement != null) { JSONObject jo = new JSONObject(); networkEdge = networkElement as INetworkEdge; networkEdge.QueryJunctions(fromJunction, toJunction); double travelTime = (double)networkEdge.AttributeValue[travelTimeAttributeID]; jo.AddLong("EdgeID", networkEdge.EID); jo.AddLong("FromJunctionID", fromJunction.EID); jo.AddLong("ToJunctionID", toJunction.EID); jo.AddDoubleEx(costAttributeName, travelTime, 4); elementArray.AddJSONObject(jo); networkElement = networkElements.Next(); } result.AddJSONArray("NetworkElements", elementArray); return(Encoding.UTF8.GetBytes(result.ToJSONString(null))); }