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); } }
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))); }
static void Main(string[] args) { try { // Initialize ArcObjects ESRI.ArcGIS.RuntimeManager.Bind(ESRI.ArcGIS.ProductCode.Desktop); LicenseInitializer aoLicenseInitializer = new LicenseInitializer(); if (!aoLicenseInitializer.InitializeApplication(new esriLicenseProductCode[] { esriLicenseProductCode.esriLicenseProductCodeBasic, esriLicenseProductCode.esriLicenseProductCodeStandard, esriLicenseProductCode.esriLicenseProductCodeAdvanced }, new esriLicenseExtensionCode[] { esriLicenseExtensionCode.esriLicenseExtensionCodeNetwork })) { System.Windows.Forms.MessageBox.Show("This application could not initialize with the correct ArcGIS license and will shutdown. LicenseMessage: " + aoLicenseInitializer.LicenseMessage()); aoLicenseInitializer.ShutdownApplication(); return; } // Get the network dataset string networkDatasetPath = args[0]; INetworkDataset nd = GetNetworkDatasetFromPath(networkDatasetPath); var networkQuery = nd as INetworkQuery3; // Name of source containing transit lines. Probably hard-wired to "TransitLines" string sourceName = args[1]; // Get the source object from the network INetworkSource networkSource = nd.get_SourceByName(sourceName); int networkSourceID = networkSource.ID; // The SQLDbase containing the transit schedules string SQLDbase_path = args[2]; // Connect to the SQL database, loop through the network's features, and add EID values to the table for each SourceOID. string workspaceConnectionString = @"Data Source=" + SQLDbase_path + "; Version=3;"; using (SQLiteConnection conn = new SQLiteConnection(workspaceConnectionString)) { conn.Open(); using (SQLiteCommand cmd = new SQLiteCommand(conn)) { using (var transaction = conn.BeginTransaction()) { List <int> BadSourceOIDs = new List <int>(); // Get all the transit lines from the network IEnumNetworkElement transit_lines = networkQuery.get_ElementsForSource(networkSourceID); // Loop through all the transit lines and add their EIDs to the SQL table INetworkElement transit_line = transit_lines.Next(); while (transit_line != null) { // Note: We are assuming that there is a one-to-one mapping between SourceOID and EID. This should always be // the case for transit lines feature classes correctly created using the Add GTFS to a Network Dataset toolbox. int EID = transit_line.EID; int SourceOID = transit_line.OID; try { string updateStmt = string.Format("UPDATE linefeatures SET eid={0} WHERE SourceOID={1}", EID.ToString(), SourceOID.ToString()); cmd.CommandText = updateStmt; cmd.ExecuteNonQuery(); } catch { // For some reason, the item couldn't be inserted into the table, likely because SourceOID couldn't be found. BadSourceOIDs.Add(SourceOID); continue; } transit_line = transit_lines.Next(); } // Add the eids to the table in batch. transaction.Commit(); if (BadSourceOIDs.Count != 0) { // Write out an error if something went wrong while filling the table. Console.Error.WriteLine("The network EID value could not be determined for the following transit line source OIDs:"); foreach (int BadSourceOID in BadSourceOIDs) { Console.Error.WriteLine(BadSourceOID); } Console.Error.WriteLine("You probably need to recreate your transit lines feature class."); } } } } } catch (Exception e) { Console.Error.WriteLine(e.Message); } }