+
+ public static double calculateDistance(ReadGraph graph, Resource startVertex, Resource endVertex) throws DatabaseException {
+ Layer0 L0 = Layer0.getInstance(graph);
+ Resource startComposite = graph.getSingleObject(startVertex, L0.PartOf);
+ Resource endComposite = graph.getSingleObject(endVertex, L0.PartOf);
+ if (!startComposite.equalsResource(endComposite)) {
+ throw new DatabaseException("Can not calculate distance between vertices on different composites! " + startVertex + " -> " + endVertex);
+ }
+ Resource crs = graph.getSingleObject(startComposite, DistrictNetworkResource.getInstance(graph).HasSpatialRefSystem);
+
+ CRS crsClass = graph.adapt(crs, CRS.class);
+
+ double[] startCoords = graph.getRelatedValue2(startVertex, DiagramResource.getInstance(graph).HasLocation, Bindings.DOUBLE_ARRAY);
+ double[] endCoords = graph.getRelatedValue2(endVertex, DiagramResource.getInstance(graph).HasLocation, Bindings.DOUBLE_ARRAY);
+
+ return crsClass.calculateDistance(startCoords, endCoords);
+ }
+
+ public static final String claimFreshElementName(WriteGraph graph, Resource diagram, Resource element) throws DatabaseException {
+ Layer0 L0 = Layer0.getInstance(graph);
+ DiagramResource DIA = DiagramResource.getInstance(graph);
+ // Get name prefix from diagram
+ String namePrefix = graph.getPossibleRelatedValue2(diagram, Layer0X.getInstance(graph).HasGeneratedNamePrefix);
+ if (namePrefix == null)
+ namePrefix = "";
+ // Give running name to element and increment the counter attached to the diagram.
+ Long l = graph.getPossibleRelatedValue(diagram, DIA.HasModCount, Bindings.LONG);
+ if (l == null)
+ l = Long.valueOf(0L);
+ String name = namePrefix + l.toString();
+ graph.claimLiteral(element, L0.HasName, name, Bindings.STRING);
+ graph.claimLiteral(diagram, DIA.HasModCount, ++l, Bindings.LONG);
+ return name;
+ }