OrientDB GraphDB 空间模块支持
OrientDB GraphDB Spatial Module Support
OrientDB 有一个新的空间模块 (http://orientdb.com/docs/2.1/Spatial-Module.html),可用于 2.2 版。请问是否适用于图数据库?
当我阅读他们的文档时,上面写着 "OrientDB stores those objects like embedded documents with special classes." 和给定的示例 Java 代码仅适用于文档数据库。
ODocument location = new ODocument("OPoint");
location.field("coordinates", Arrays.asList(12.4684635, 41.8914114));
ODocument doc = new ODocument("Restaurant");
doc.field("name","Dar Poeta");
doc.field("location",location);
doc.save();
我尝试将 OPoint 实例作为 属性 添加到 OrientVertex,但没有成功。下面的异常是 throw;
com.orientechnologies.orient.core.exception.OSchemaException: Document belongs to abstract class OPoint and cannot be saved
Storage URL="remote:127.0.0.1/phd2"
at com.orientechnologies.orient.core.tx.OTransactionAbstract.getClusterName(OTransactionAbstract.java:236)
at com.orientechnologies.orient.core.tx.OTransactionOptimistic.saveRecord(OTransactionOptimistic.java:374)
at com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx.save(ODatabaseDocumentTx.java:2480)
at com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx.save(ODatabaseDocumentTx.java:118)
at com.orientechnologies.orient.core.record.impl.ODocument.save(ODocument.java:1812)
at com.orientechnologies.orient.core.record.impl.ODocument.save(ODocument.java:1808)
at com.tinkerpop.blueprints.impls.orient.OrientElement.save(OrientElement.java:325)
at com.tinkerpop.blueprints.impls.orient.OrientBaseGraph.addVertex(OrientBaseGraph.java:588)
我的示例代码是这样的;
String id = "HERE+IS+ID";
ODocument location = new ODocument("OPoint");
location.field("coordinates", Arrays.asList(12.2323, 34.3233));
Vertex sink = graph.addVertex(id, Constants.NAME, "Sink-Root", Constants.LOCATION, location);
能否请您帮助我对我的 OrientDB 图形数据库(而非文档数据库)使用空间查询?示例 Java 代码将非常有帮助。
非常感谢。
您应该在顶点 class 中创建嵌入的 属性,就像在文档示例中一样
CREATE PROPERTY Restaurant.location EMBEDDED OPoint
感谢 wolf4ood 提供了准确答案的途径。这是在 OrientDB 中创建 Spatial 属性 的 Java 代码。
manager.createVertexClass(SensorNodeType.Sink, SensorNodeType.Sink);
OrientVertexType vertex = graph.getVertexType(SensorNodeType.Sink);
if (vertex.getProperty(Constants.NAME) == null) {
vertex.createProperty(Constants.NAME, OType.STRING);
}
if (vertex.getProperty(Constants.POSITION) == null) {
ODocument location = new ODocument("OPoint");
vertex.createProperty(Constants.POSITION, OType.EMBEDDED, location.getSchemaClass());
}
OrientDB 有一个新的空间模块 (http://orientdb.com/docs/2.1/Spatial-Module.html),可用于 2.2 版。请问是否适用于图数据库?
当我阅读他们的文档时,上面写着 "OrientDB stores those objects like embedded documents with special classes." 和给定的示例 Java 代码仅适用于文档数据库。
ODocument location = new ODocument("OPoint");
location.field("coordinates", Arrays.asList(12.4684635, 41.8914114));
ODocument doc = new ODocument("Restaurant");
doc.field("name","Dar Poeta");
doc.field("location",location);
doc.save();
我尝试将 OPoint 实例作为 属性 添加到 OrientVertex,但没有成功。下面的异常是 throw;
com.orientechnologies.orient.core.exception.OSchemaException: Document belongs to abstract class OPoint and cannot be saved
Storage URL="remote:127.0.0.1/phd2"
at com.orientechnologies.orient.core.tx.OTransactionAbstract.getClusterName(OTransactionAbstract.java:236)
at com.orientechnologies.orient.core.tx.OTransactionOptimistic.saveRecord(OTransactionOptimistic.java:374)
at com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx.save(ODatabaseDocumentTx.java:2480)
at com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx.save(ODatabaseDocumentTx.java:118)
at com.orientechnologies.orient.core.record.impl.ODocument.save(ODocument.java:1812)
at com.orientechnologies.orient.core.record.impl.ODocument.save(ODocument.java:1808)
at com.tinkerpop.blueprints.impls.orient.OrientElement.save(OrientElement.java:325)
at com.tinkerpop.blueprints.impls.orient.OrientBaseGraph.addVertex(OrientBaseGraph.java:588)
我的示例代码是这样的;
String id = "HERE+IS+ID";
ODocument location = new ODocument("OPoint");
location.field("coordinates", Arrays.asList(12.2323, 34.3233));
Vertex sink = graph.addVertex(id, Constants.NAME, "Sink-Root", Constants.LOCATION, location);
能否请您帮助我对我的 OrientDB 图形数据库(而非文档数据库)使用空间查询?示例 Java 代码将非常有帮助。
非常感谢。
您应该在顶点 class 中创建嵌入的 属性,就像在文档示例中一样
CREATE PROPERTY Restaurant.location EMBEDDED OPoint
感谢 wolf4ood 提供了准确答案的途径。这是在 OrientDB 中创建 Spatial 属性 的 Java 代码。
manager.createVertexClass(SensorNodeType.Sink, SensorNodeType.Sink);
OrientVertexType vertex = graph.getVertexType(SensorNodeType.Sink);
if (vertex.getProperty(Constants.NAME) == null) {
vertex.createProperty(Constants.NAME, OType.STRING);
}
if (vertex.getProperty(Constants.POSITION) == null) {
ODocument location = new ODocument("OPoint");
vertex.createProperty(Constants.POSITION, OType.EMBEDDED, location.getSchemaClass());
}