OSMSharp - get informations about actual road - c#

I am trying to code an app for Android (C# - Xamarin), and I loaded a PBF file, I can find route between two places (coordinates). But I dont know how can I get informations about place where I am actualy (by coordinates). I want to know something about road (street) where I am, for example street name, speed limit...
I did not found anything about this. I hope somebody knows how to do that.

DISCLAIMER: I'm the original author of OsmSharp/Itinero.
You can use this code to get info about an edge at a given location:
var routerDb = RouterDb.Deserialize(...); // load routerdb here.
var router = new Router(routerDb);
var routerPoint = router.Resolve(Vehicle.Car.Fastest(), new Coordinate(51.269692005119616f, 4.783473014831543f));
var edge = routerDb.Network.GetEdge(routerPoint.EdgeId);
var attributes = routerDb.GetProfileAndMeta(edge.Data.Profile, edge.Data.MetaId);
var speed = Vehicle.Car.Fastest().Speed(attributes);
The attributes are a collection of the orginal OSM tags, speed is a speed estimate for the Car profile.

Related

Load .3ds model with high number of polygons - Helix Toolkit Sharp DX

I used HelixToolkit a couple of f times before, and I managed to load my model (all were small-sized models), and they all worked properly. Now, I have many models with lots of polygons for a project (some have about 10000 polygons). So, when I ran my program, I got an error: "System.ArgumentOutOfRangeException: 'Non-negative number required.'
So, I googled the problem, and somebody mentioned that he uses Helix Sharp DX for his large models. I tried Helix Sharp DX. My XAML code is something like this:
<helix:Viewport3DX x:Name="Viewport3D" ZoomExtentsWhenLoaded="True">
<helix:GroupModel3D x:Name ="LoadedModels" />
</helix:Viewport3DX>
And my C# code is something like this:
Viewport3D.Items.Add(new DirectionalLight3D() { Direction = new System.Windows.Media.Media3D.Vector3D(-1, -1, -1) });
var reader = new HelixToolkit.Wpf.SharpDX.StudioReader();
var model = reader.Read(path);
foreach (var modelPart in model)
{
var sharpModel = new MeshGeometryModel3D()
{
Geometry = modelPart.Geometry,
//Material = modelPart.Material,
Name = modelPart.Name,
//Transform = new MatrixTransform3D(modelPart.Transform.ToMatrix3D())
};
LoadedModels.Children.Add(sharpModel);
}
But, I again got the same error. I wonder if there is any problem with my code; or if we should try to reduce the number of polygons.
Any help/suggestion regarding this issue is appreciated. I prefer to solve it via coding since the polygon count reduction will take most of the time of the project timeline.
Thanks

Example VU Meter using Windows Media Graph API?

The question says it all.
I would like to create the simplest possible VU-meter example, using the new UWP Media Graph API, but so far, I haven't found any good examples.
There are a couple of questions in this:
I am using the "normal" code to enumerate my microphones:
var deviceInformation = await DeviceInformation.FindAllAsync(MediaDevice.GetAudioCaptureSelector());
However, when I create an AudioGraphSettings object, I cannot find a property to pass the device found. There is a property named DesiredRenderDeviceAudioProcessing however, I'm not sure I understand it's purpose.
Following the best examples I've found, I proceed to create a graph, and use that to get an InputNode as such:
var creationResult = await AudioGraph.CreateAsync(settings);
if (creationResult.Status != AudioGraphCreationStatus.Success)
return;
_graph = creationResult.Graph;
var inputNodeCreationResult = await _graph.CreateDeviceInputNodeAsync(Windows.Media.Capture.MediaCategory.Media);
if (inputNodeCreationResult.Status != AudioDeviceNodeCreationStatus.Success)
{
DestroyGraph();
return;
}
_inputNode = inputNodeCreationResult.DeviceInputNode;
From here on, I'm running blind. Not finding any good tutorials, examples or documentation to help me.
I am only interested in sound level (dB), not the waveform. Is there anyone that can help me complete this, or point me to some decent documentation?
"Scenario 2: Device Capture" from the Windows Universal Samples - Audio Creation project should provide some guidance. From your code it looks like you're on track. Might just be a case of adding the following:
_frameOutputNode = _graph.CreateFrameOutputNode();
_frameOutputNode.Start();
_graph.QuantumProcessed += Graph_QuantumProcessed;
_graph.Start();
And using the Graph_QuantumProcessed callback to analyse the AudioFrame provided by a call to _frameOutputNode.GetFrame().
Hope it helps.

GoogleMap: Polyline doesn't draw all Options

On a GoogleMap I am drawing a polyline to show a route. The lat/long-data is requested via Google Directions API and I receive correct data, usually for two different cities, from which I extract the lat/long-values and add it to an Polyoptions-object, which is added to the Polyline of the Map. Whatever the route is long, how much positions/latLng are available, the route never has more than around 8 straight lines. I have read a lot of stuff, and I can be sure, that the route is created correctly, I can even delete one to create another one. I have also tried "geodesic()" with true an false. No change.
Can anybody tell how I can get out of this?
Some code snippet
polylineOptions = new PolylineOptions();
foreach (var position in routeCoordinates)
{
polylineOptions.Add(new LatLng(position.Latitude, position.Longitude));
}
gMap.AddPolyline(polylineOptions);
Added on Sept 09, 2016
I started by using the points for the legs-steps, lots of points but wrong route, so I finally used only the final overview for the route this way
if (createRouteStep == true && prop.Equals("overview_polyline"))
{
i++;
line = getPropAndValue(lines[i]);
prop = getProp(line);
propValue = getPropValue(line);
string point = propValue.Replace(com, space).Trim();//= "yhoyHg~ol#nvgBgbjAbcbByxlDr_iArqG";
startRS = new RouteStep();
startRS.RouteID = routeCounter;
startRS.StepPoints = point;
sql.insertRouteStep(startRS);
i++;
}
The code is stored in an sqlite database, from which is later retrieved and decoded. Decoding works correct, I have tried a sample (points-result in the comment above) from the mentioned Google-test-site for this purpose and the route was the same as on the site. The points from my own request for the route have the correct direction, but don't follow any road or reach the destination at all.

How to get truly free rooms from Exchange EWS

and sorry for a poor title of the question
I´m trying to get all free rooms (not booked ones) from my exchange server. The thing is that I also get the rooms I have booked but nobody has accepted.
I would like to exclude them from the list after I book the room.
This is the code I use to book a room
ExchangeService service;
//...code to new-up and config service
var request = new Appointment(service)
{
Subject = booking.Subject,
Start = booking.Start,
End = booking.End,
Location = booking.Room
};
request.RequiredAttendees.Add(booking.Person);
request.RequiredAttendees.Add(booking.Room);
request.Save(SendInvitationsMode.SendOnlyToAll);
To note I have tried to call request.Accept() straight after Save() but without that "realy booking" the room. Pressing accept in Outlook is the only "fix". Needlessly to say I have tried everything I could find about this issue (I do not work with Exchange regularly).
And then the code to get free rooms
var rooms = service.GetRooms(locationAddress);
// all the meeting rooms at location
var rooms= rooms.Select(i => new AttendeeInfo { SmtpAddress = i.Address, AttendeeType = MeetingAttendeeType.Room });
// Get all availabilites from all rooms at given locations
var availability = service.GetUserAvailability(rooms, timeframe, AvailabilityData.FreeBusy);
foreach (var a in availability.AttendeesAvailability)
{
// Here we always get all the free rooms
// including the ones we booked earlier
// UNTIL somebody clicks accept in Outlook and then it does not appear here!?
}
I can´t see that the rooms are marked differently before they are accepted in Outlook so I can´t differentiate between them and pull out them ones I don´t want.
I also really think that those rooms should not be available so there must bee some enum/tick/mark I can put on the room before booking it but I totally missing it.
Edit
I realy don't understand why there is no option for AvailabilityData.Free in the enum in the GetUserAvailability method (only FreeBusy, FreeBusyAndSuggestions and Suggestions but no Free only!?)
Ok this is rather silly... the code (I inherited) did not include code to actually remove rooms that where taken (busy). I only just noticed this...
The code to fix this is simply this one
var busyRoomToRemove = a.CalendarEvents.ToList().Find(x => x.FreeBusyStatus == LegacyFreeBusyStatus.Busy);
a.CalendarEvents.Remove(busyRoomToRemove);
Sorry for the inconvenience :-)

C# code completion with NRefactory 5

I just found out about NRefactory 5 and I would guess, that it is the most suitable solution for my current problem. At the moment I'm developing a little C# scripting application for which I would like to provide code completion. Until recently I've done this using the "Roslyn" project from Microsoft. But as the latest update of this project requires .Net Framework 4.5 I can't use this any more as I would like the app to run under Win XP as well. So I have to switch to another technology here.
My problem is not the compilation stuff. This can be done, with some more effort, by .Net CodeDomProvider as well. The problem ist the code completion stuff. As far as I know, NRefactory 5 provides everything that is required to provide code completion (parser, type system etc.) but I just can't figure out how to use it. I took a look at SharpDevelop source code but they don't use NRefactory 5 for code completion there, they only use it as decompiler. As I couldn't find an example on how to use it for code completion in the net as well I thought that I might find some help here.
The situation is as follows. I have one single file containing the script code. Actually it is not even a file but a string which I get from the editor control (by the way: I'm using AvalonEdit for this. Great editor!) and some assemblies that needs to get referenced. So, no solution files, no project files etc. just one string of source code and the assemblies.
I've taken a look at the Demo that comes with NRefactory 5 and the article on code project and got up with something like this:
var unresolvedTypeSystem = syntaxTree.ToTypeSystem();
IProjectContent pc = new CSharpProjectContent();
// Add parsed files to the type system
pc = pc.AddOrUpdateFiles(unresolvedTypeSystem);
// Add referenced assemblies:
pc = pc.AddAssemblyReferences(new CecilLoader().LoadAssemblyFile(
System.Reflection.Assembly.GetAssembly(typeof(Object)).Location));
My problem is that I have no clue on how to go on. I'm not even sure if it is the right approach to accomplish my goal. How to use the CSharpCompletionEngine? What else is required? etc. You see there are many things that are very unclear at the moment and I hope you can bring some light into this.
Thank you all very much in advance!
I've just compiled and example project that does C# code completion with AvalonEdit and NRefactory.
It can be found on Github here.
Take a look at method ICSharpCode.NRefactory.CSharp.CodeCompletion.CreateEngine. You need to create an instance of CSharpCompletionEngine and pass in the correct document and the resolvers. I managed to get it working for CTRL+Space compltition scenario. However I am having troubles with references to types that are in other namespaces. It looks like CSharpTypeResolveContext does not take into account the using namespace statements - If I resolve the references with CSharpAstResolver, they are resolved OK, but I am unable to correctly use this resolver in code completition scenario...
UPDATE #1:
I've just managed to get the working by obtaining resolver from unresolved fail.
Here is the snippet:
var mb = new DefaultCompletionContextProvider(doc, unresolvedFile);
var resolver3 = unresolvedFile.GetResolver(cmp, loc); // get the resolver from unresolvedFile
var engine = new CSharpCompletionEngine(doc, mb, new CodeCompletionBugTests.TestFactory(resolver3), pctx, resolver3.CurrentTypeResolveContext );
Update #2:
Here is the complete method. It references classes from unit test projects, sou you would need to reference/copy them into your project:
public static IEnumerable<ICompletionData> DoCodeComplete(string editorText, int offset) // not the best way to put in the whole string every time
{
var doc = new ReadOnlyDocument(editorText);
var location = doc.GetLocation(offset);
string parsedText = editorText; // TODO: Why there are different values in test cases?
var syntaxTree = new CSharpParser().Parse(parsedText, "program.cs");
syntaxTree.Freeze();
var unresolvedFile = syntaxTree.ToTypeSystem();
var mb = new DefaultCompletionContextProvider(doc, unresolvedFile);
IProjectContent pctx = new CSharpProjectContent();
var refs = new List<IUnresolvedAssembly> { mscorlib.Value, systemCore.Value, systemAssembly.Value};
pctx = pctx.AddAssemblyReferences(refs);
pctx = pctx.AddOrUpdateFiles(unresolvedFile);
var cmp = pctx.CreateCompilation();
var resolver3 = unresolvedFile.GetResolver(cmp, location);
var engine = new CSharpCompletionEngine(doc, mb, new CodeCompletionBugTests.TestFactory(resolver3), pctx, resolver3.CurrentTypeResolveContext );
engine.EolMarker = Environment.NewLine;
engine.FormattingPolicy = FormattingOptionsFactory.CreateMono();
var data = engine.GetCompletionData(offset, controlSpace: false);
return data;
}
}
Hope it helps,
Matra
NRefactory 5 is being used in SharpDevelop 5. The source code for SharpDevelop 5 is currently available in the newNR branch on github. I would take a look at the CSharpCompletionBinding class which has code to display a completion list window using information from NRefactory's CSharpCompletionEngine.

Categories

Resources