Shortest path in one direction "IN" or "OUT" in Neo4j - search

I am interested to find the shortest path but only in one direction. For example, I have the following graph: the graph
When I consider the "INCOMING" direction then the shortest path between "A and D"should be "A-C-D". If I consider the "OUTGOING" direction the shortestpath should be "A-F-E-D"
based on the implementation I have, only "BOTH" direction can be considered:
PathExpander<Object> expander = Traversal.pathExpanderForAllTypes(Reldir);
PathFinder<Path> finder=GraphAlgoFactory.shortestPath(expander,maxDepth, 1);
Path path = finder.findSinglePath("A","D");
When I use for the Reldir="IN" I got this exception:
Java.lang.NullPointerException at org.neo4j.kernel.Traversal.pathToString(Traversal.java)
Is there any way to use either "IN" or "OUT" direction in Neo4j as it is the case in OrientDB?

Try INCOMING instead of IN.
Source

I have implemented the solution. However, I am not sure if this the best way to do:
Direction Reldir = Direction.valueOf(relation_direction);
PathExpander<Object> expander = Traversal.pathExpanderForAllTypes(Reldir);
PathFinder<Path> finder = GraphAlgoFactory.shortestPath(expander, maxDepth,1);
Path path = finder.findSinglePath(first_node, second_node);
PathPrinter pathPrinter = new PathPrinter("name");
Traversal.pathToString(path, pathPrinter);
static class PathPrinter implements Traversal.PathDescriptor<Path> {
private final String nodePropertyKey;
public PathPrinter(String nodePropertyKey) {
this.nodePropertyKey = nodePropertyKey;
}
public String nodeRepresentation(Path path, Node node)
{
System.out.println(node.getProperty(nodePropertyKey, "").toString()+" ");
}
Any much efficient solution?

Related

Revit API. ReferenceIntersector with TopografySurfaces

Does anyone know if ReferenceIntersector works with TopografySurfaces? Cannot make it work. I need to find a point on the surface based on a intersection with a line.
Did you solve it? If not, i gave it a try and for me this Code here works fine:
public XYZ ProjectPointOnTopographySurface(XYZ point, int direction)
{
// For getting the 3D view
View3D view3D = new FilteredElementCollector(Document)
.OfClass(typeof(View3D))
.Cast<View3D>()
.Where(v => v.Name == "{3D}")
.FirstOrDefault();
XYZ vectorDirection = new XYZ(0, 0, direction);
ElementClassFilter intersectionFilter = new ElementClassFilter(typeof(TopographySurface));
ReferenceIntersector referenceIntersector = new ReferenceIntersector(intersectionFilter, FindReferenceTarget.All, view3D);
ReferenceWithContext referenceWithContext = referenceIntersector.FindNearest(point, vectorDirection);
return referenceWithContext.GetReference().GlobalPoint;
}
Regardless of whether the ReferenceIntersector does or does not work with topography surfaces, you can pretty easily solve the problem you describe yourself using other means. Simply ask the surface for its tessellated representation. That will return a bunch of triangles. Then, implement your own algorithm to intersect a triangle with the line. That should give you all you need, really.

EndPointReference method

I am strugglying with a problem that is to access the reference of the end point of a pipe curve to then create a dimension in the model, by the method doc.Create.Dimension().I already tried to use the Curve.EndPointReference(int index) method but it returns only null value. Can anyone help how to access this information ?
Also discussed and answered here by Fair59:
https://forums.autodesk.com/t5/revit-api-forum/endpointreference/td-p/7131328
The answer is also pointed to from The Building Coder:
http://thebuildingcoder.typepad.com/blog/2011/10/retrieving-duct-and-pipe-endpoints.html#comment-3344122037
Fair59's answer:
You probably are using the LocationCurve to find the reference. You need to use the "reference" Curve/Line that is part of the Element.Geometry.
Selection sel = this.ActiveUIDocument.Selection;
Element elem = doc.GetElement(sel.GetElementIds().FirstOrDefault());
Options opt = new Options();
opt.ComputeReferences = true;
opt.IncludeNonVisibleObjects = true;
opt.View = doc.ActiveView;
Reference ptRef =null;
foreach( var geoObj in elem.get_Geometry(opt) )
{
Curve cv = geoObj as Curve;
if (cv==null) continue;
ptRef = cv.GetEndPointReference(0);
}
if (ptRef!=null)
{
TaskDialog.Show("debug",ptRef.ConvertToStableRepresentation(doc));
}
I think you should try something like
yourPipe.Location.Curve.GetEndPoint(1)
This will give you the XYZ object of the end point of your curve.
Regards,
Arnaud.

Markers on UML Graphical Elements

I have the .uml file which contains the UML state machine, transitions and states. I managed to put a marker on the objects in this .uml file, but cannot put a marker on their graphical representation located in a .aird file.
This is the code I use to put markers :
public static void addMarker(EObject eObj, String message, String location, int severity) throws CoreException{
Resource resource = eObj.eResource();
String uri = EcoreUtil.getURI(eObj).toString();
String platformString = resource.getURI().toPlatformString(true);
IResource iresource = ResourcesPlugin.getWorkspace().getRoot().findMember(platformString);
IMarker imarker = iresource.createMarker(EValidator.MARKER);
imarker.setAttribute(IMarker.SEVERITY, severity);
imarker.setAttribute(IMarker.LOCATION, location);
imarker.setAttribute(EValidator.URI_ATTRIBUTE, uri);
imarker.setAttribute(IMarker.MESSAGE, message);
}
This is the code I use to find the graphical representation :
for(DView dview : SessionManager.INSTANCE.getSession(eObj).getOwnedViews()){
if(dview.getViewpoint().getName().equals("Design")){
for(DRepresentation drep : dview.getOwnedRepresentations()){
for(DRepresentationElement drepElem : drep.getOwnedRepresentationElements()){
if(drepElem.getTarget() == st.getSrcTransition().getTransition()){
MarkerUtil.addMarker(drepElem, message, location, severity);
}
}
}
}
}
When I try to go to the marker of the graphical representation of a transition, it highlights the state machine.
Below are the URIs of a transition :
platform:/resource/TestSuite/default.uml#_igwUwDFJEealS5qn_7gKFw
platform:/resource/TestSuite/representations.aird#_igwUwTFJEealS5qn_7gKFw
I am not used to work with markers but I think that the marker should appear at the left corner of the box containing your edge. Consequently your marker might be out of your diagram.
If you want o explicitly add it on the transition you should check at least the type is a DEdge.
If you need more details you can ask questions about Sirius on the Eclipse forum.

How can I retrieve the geometry coordinates of a NpgsqlTypes.PostgisGeometry type field from the NpgsqlDataReader?

.NET 4.5, C#, Npgsql 3.1.0
I have a query which retrieves a Postgis geometry field - the only way I could see of doing this was:
public class pgRasterChart
{
...
public NpgsqlTypes.PostgisGeometry GEOMETRY;
...
}
...
NpgsqlDataReader reader = command.ExecuteReader();
try
{
while (reader.Read())
{
pgRasterChart chart = new pgRasterChart();
chart.GEOMETRY = (PostgisGeometry) reader.GetValue(21);
...
This functions but I need to get at the coordinates of the GEOMETRY field and I can't find a way of doing that? I want to use the coordinates to display the results on an OpenLayers map.
Any answers most gratefully received. This is my first post so my apologies if the etiquette is clumsy or question unclear.
Providing another answer because the the link above to the documentation for PostGisTypes is now broken.
PostGisGeometry is an abstract base class that does not contain anything more exiting than the SRID. Instead, you want to cast the object obtained by your datareader to the appropriate type (any of the following):
PostGisLineString
PostGisMultiLineString
PostGisMultiPoint
PostGisMultiPolygon
PostGisPoint
PostGisPolygon
These classes have ways of getting to the coordinates.
eg:
...
NpgsqlDataReader reader = command.ExecuteReader();
try
{
while (reader.Read())
{
var geom = (PostgisLineString) reader.GetValue(0);
var firstCoordinate = geom[0]; // Coordinate in linestring at index 0
var X = firstCoordinate.X;
var Y = firstCoordinate.Y;
...
As you can see here
https://github.com/npgsql/npgsql/blob/dev/src/Npgsql.LegacyPostgis/PostgisTypes.cs
PostgisGeometry types are a set of xy pairs.
For example, a linestring is an array of points, a polygon is an array of rings and so on..
You could traverse those structures and get the coordinates.
However, if you just want to display geometries using openlayers, I suggest you to use the wkt format.
You should change your query, selecting st_astext(geometry) instead of geometry, than treat the result as a string and give it back to OpenLayers.
Then use OpenLayers.Geometry.fromWKT to parse the WKT into an OpenLayers.Geometry

CLLocation does not have a Coordinates property

I am just working my way through the location services for the first time and everything appears to be working in that it correctly finds my location but I am having trouble extracting the coordinates.
The docs states that CLLocation has a "Coordinates" property and the compiler is happy with this piece of code. However at runtime the CLLocation only appears to return a string description.
I start the location manager
_locationManager = new CLLocationManager ();
_locationManager.DesiredAccuracy = 1000;
// handle the updated location method and update the UI
_locationManager.LocationsUpdated += (object sender, CLLocationsUpdatedEventArgs e) => {
UpdateLocation (e.Locations [e.Locations.Length - 1], _destinationLatitude, _destinationLongitude);
};
if (CLLocationManager.LocationServicesEnabled)
_locationManager.StartUpdatingLocation ();
The event fires correctly
static public void UpdateLocation (CLLocation current, Double destinationLat, Double destinationLng)
{
//Make the start pairing
string start = current.Coordinate.Latitude.ToString() + "," + current.Coordinate.Longitude.ToString();
//Make the destination pairing
string destination = destinationLat.ToString() + "," + destinationLng.ToString();
}
However the app just crashes out. Catching it on a breakpoint I see the following which only appears to have a description property that contains.
Description "<+50.58198902,-3.67661728> +/- 65.00m (speed -1.00 mps / course -1.00) # 25/07/2013 13:11:28 British…" string
I can obviously extract the lat/lng from this text field but I get the feeling I shouldn't need to do this. Any help appreciated.
I moved the exact same code into a different controller and it worked fine. The only difference between the two controllers was that the failing controller was using the monotouch dialog reflection api to bind the screen elements. I can't see why this would make any difference but it is the only difference between the two controllers. Everything is working now, I will try to reproduce in a smaller sample if I get the time.

Resources