GraphQueryStreaming

AMD: require(["geoscene/rest/knowledgeGraph/GraphQueryStreaming"], (GraphQueryStreaming) => { /* code goes here */ });
ESM: import GraphQueryStreaming from "@geoscene/core/rest/knowledgeGraph/GraphQueryStreaming";
类: geoscene/rest/knowledgeGraph/GraphQueryStreaming
继承于:GraphQueryStreaming GraphQuery Accessor
起始版本:GeoScene Maps SDK for JavaScript 4.25
beta

定义在知识图谱服务图谱资源上执行的流查询操作。通过发送 openCypher 查询的 GeoScene 实现来查询图谱中的实体关系

流式查询返回结果的速度比查询更快,并且所返回的结果很小,可立即进行处理。流式查询还允许绑定参数

另请参阅
示例
// sample streaming query using bind parameters
// to search for entities with a the `name` property that matches a specific string
// or have their geometry within a bounding box.
// get all parts bought by each supplier.
// query returns both the supplier and the part it buys.
const query = `MATCH (s:Supplier)-[:buys_part]-(p:Part)
               WHERE s.name=$name OR geoscene.graph.ST_Intersects($geom, s.geometry)
               RETURN s,p`;

KnowledgeGraphModule.executeQueryStreaming(
  knowledgeGraph,
  {
    openCypherQuery: query,
    bindParameters: {
      name: "Supplier 1",
      geom: new Polygon({
        rings: [
          [
            [38,-78],
            [39, -78],
            [39, -76],
            [-38, -76],
            [-38, -78],
          ],
       ],
    }),
  }
}).then((streamingQueryResult)=>{
  // streaming query returns a readableStream which must be read to access the returned graph data
  readStream(streamingQueryResult);
})
// a function to read the readable stream returned from the above query
const readStream = async (streamingQueryResult) => {
  let time = Date.now();
  let reader = streamingQueryResult.resultRowsStream.getReader();
  try {
    while (true) {
      const { done, value } = await reader.read();
      if (done) {
        console.log(`All records returned, stream closed: ${(Date.now() - time) / 1000} seconds`);
        break;
      }
      console.log(`Streaming chunk returned in: ${(Date.now() - time) / 1000} seconds`, value);
      // use the results
      // list the parts bought by each supplier
      let supplierParts = {};
      // each element of the result array will contain one supplier and one part it buys
      for (var v in value){
        let supplier = value[v][0].properties.Name
        let part = value [v][1].properties.Name
        if(!(supplier in supplierParts)){
          supplierParts[supplier] = [];
        }
        // collect parts by supplier that buys them
        supplierParts[supplier].push(part);
        console.log(supplierParts);
        // result printed to the console: {Supplier 1:[Part1], Supplier 3:[Part2, Part3]}
      }
    }
  } catch (err) {
    if (err.name === "AbortError") {
      console.log("Request aborted as expected");
    } else {
      throw err;
    }
  }
};
// result stream from above query after it has been read
"Streaming chunk returned in: 0.082 seconds"
[
  [{
    "declaredClass": "geoscene.rest.knowledgeGraph.Entity",
    "properties": {
      "Name": "Supplier 1",
      "City": "Washington DC",
      "EmployeeCount": 31
    },
    "typeName": "Supplier",
    "id": "{57FDF2F3-34C8-48EF-9A3B-76ED9314C4D2}"
  },{
    "declaredClass": "geoscene.rest.knowledgeGraph.Entity",
    "properties": {
      "Part_ID": 695401,
      "Name": "Part1",
      "Minimum_quantity": 360
    },
    "typeName": "Part",
    "id": "{IWN51W4-1AW8-A2W6-1AW5F-1AW8F9F4W51AS}",
  }],
  [{
    "declaredClass": "geoscene.rest.knowledgeGraph.Entity",
    "properties": {
      "Name": "Supplier 2",
      "City": "Baltimore",
      "EmployeeCount": 53
    },
    "typeName": "Supplier",
    "id": "{1A4W8F5W-1WA8-5W6A-A1W8-A1W5F8W3S482A}"
  },{
    "declaredClass": "geoscene.rest.knowledgeGraph.Entity",
    "properties": {
      "Part_ID": 695401,
      "Name": "Part2",
      "Minimum_quantity": 2500
    },
    "typeName": "Part",
    "id": "{A1W5F8W4F-A1W8-1894-16A5-A86WF4A8SFWD}",
  }],
  [{
    "declaredClass": "geoscene.rest.knowledgeGraph.Entity",
    "properties": {
      "Name": "Supplier 2",
      "City": "Baltimore",
      "EmployeeCount": 53
    },
    "typeName": "Supplier",
    "id": "{1A4W8F5W-1WA8-5W6A-A1W8-L5H4G8RT1PK3}"
  },{
    "declaredClass": "geoscene.rest.knowledgeGraph.Entity",
    "properties": {
      "Part_ID": 695401,
      "Name": "Part3",
      "Minimum_quantity": 5000
    },
    "typeName": "Part",
    "id": "{PTJ51FT-KY4H-1GY5-G1Y8-G1Y5K49G8Y4GHJ}",
  }]
]
// aborting the query
// create instance of native browser abort controller
const controller = new AbortController();
// create query
KnowledgeGraphModule
  .executeQueryStreaming(
    knowledgeGraph,
    {
      openCypherQuery: "MATCH (n) RETURN n LIMIT 100",
    },
    {
      signal: controller.signal,
    }
  )
  .then((streamingQueryResult) => {
    readStream(streamingQueryResult);
  })
  // indicate that the stream was aborted
  .catch((err) => {
    if (err.name === "AbortError") {
      console.log("Request aborted as expected");
    }

// abort the query after half a second
setTimeout(() => {
  console.log("Sending abort signal");
  controller.abort();
}, 500);

构造函数

new GraphQueryStreaming(properties)
参数
properties Object
optional

有关可能传递给构造函数的属性的完整列表,请参见属性

属性概述

可以设置、检索或侦听任何属性。请参阅使用属性主题。
显示继承属性 隐藏继承属性
名称 类型 描述
InputQuantizationParameters

输入几何的自定义量化参数,用于压缩几何以传输到服务器。

更多详情
GraphQueryStreaming
HashMap<(HashMap<any>|Number|string|Date|{Geometry}|Array<(HashMap<any>|Number|string|Date|{Geometry})>)>

指定一组包含要包含在查询中的数据的参数。

更多详情
GraphQueryStreaming
String

类的名称。

更多详情
Accessor
String

要针对知识图谱执行 openCypher 查询的 GeoScene 实现。

更多详情
GraphQuery
OutputQuantizationParameters

用于将几何投影到虚拟格网上,可能表示屏幕上的像素。

更多详情
GraphQueryStreaming

属性详细信息

bindGeometryQuantizationParameters InputQuantizationParameters

输入几何的自定义量化参数,用于压缩几何以传输到服务器。覆盖默认的无损 WGS84 量化。

示例
// sample implementation of an input quantization parameter
// query entities within a bounding box
const query = "MATCH (n) WHERE geoscene.graph.ST_Intersects($geom, n.geometry) RETURN n"

KnowledgeGraphModule.executeQueryStreaming(
  knowledgeGraph,
  {
    openCypherQuery: query,
    bindParameters: {
      param_filter_geom: new Polygon({
        rings: [
          [
            [-89, -89],
            [89, -89],
            [89, 89],
            [-89, 89],
            [-89, -89],
          ],
        ],
      }),
    },
    inputQuantizationParameters: {
      xyResolution: 0.003,
      xFalseOrigin: 25,
      yFalseOrigin: 25,
      zResolution: 1,
      zFalseOrigin: 1,
      mResolution: 1,
      mFalseOrigin: 1,
    },
   }
  }
);
bindParameters HashMap<(HashMap<any>|Number|string|Date|{Geometry}|Array<(HashMap<any>|Number|string|Date|{Geometry})>)>

指定一组包含要包含在查询中的数据的参数。

示例
// bind a polygon to search for entities withing a bounding box.
const query = "MATCH (n) WHERE geoscene.graph.ST_Intersects($geom, n.geometry) RETURN n";

KnowledgeGraphModule.executeQueryStreaming(
  knowledgeGraph,
  {
    openCypherQuery: query,
    bindParameters: {
      geom: new Polygon({
        rings: [
          [
            [-89, -89],
            [89, -89],
            [89, 89],
            [-89, 89],
            [-89, -89],
          ],
       ],
    }),
  }
}).then((streamingQueryResult)=>{
  // streaming query returns a readableStream which must be read to access the returned graph data
  readStream(streamingQueryResult);
})
// bind a list of ids
// get all relationships between suppliers and a select list of parts.
const query = "MATCH (s:Supplier)-[rel]-(p:Part) WHERE p.globalid IN $ids RETURN rel";

KnowledgeGraphModule.executeQueryStreaming(
  knowledgeGraph,
  {
    openCypherQuery: query,
    bindParameters: {
      ids:[
         "{WIHPTR45-1RO5-9HY1-FK50-P1J5U8D1FER7}",
         "{SSOE5G4O-T7T8-4G8Y-2RD1-P8D1A7G4S7EA}",
         "{2SE8HE8D-81ES-9HY1-1SE8-OPAWON41869S}",
         "{1SE8E6G8-5DT8-S8E1-6S8E-D8R4FJ8S8S1S}",
         "{SE86I2BD-8R73-2SE8-6S8E-7R8DR86S4SD6}",
         "{N2T8K52R-2SDE-1SEG-S8ES-6SE8HUKY6AIN}",
         "{2AWAGP86-SESR-5SE8-4SE8-68RD66846SPL}",
      ],
    }),
  }
}).then((streamingQueryResult)=>{
  // streaming query returns a readableStream which must be read to access the returned graph data
  readStream(streamingQueryResult);
})
declaredClass Stringreadonly inherited

类的名称。声明的类名称格式化为 geoscene.folder.className

openCypherQuery String inherited

要针对知识图谱执行 openCypher 查询的 GeoScene 实现。

必需项

outputQuantizationParameters OutputQuantizationParameters

用于将几何投影到虚拟格网上,可能表示屏幕上的像素。几何坐标通过构建分辨率与 OutputQuantizationParameters.tolerance 相匹配的网格来转换为整数。然后将每个坐标捕捉到格网上的一个像素。

示例
// sample implementation of an output quantization parameter

// query entities within a bounding box
const query = "MATCH (n) WHERE geoscene.graph.ST_Intersects($geom, n.geometry) RETURN n"

KnowledgeGraphModule.executeQueryStreaming(
  knowledgeGraph,
  {
    openCypherQuery: query,
    bindParameters: {
      geom: new Polygon({
        rings: [
          [
            [-89, -89],
            [89, -89],
            [89, 89],
            [-89, 89],
            [-89, -89],
          ],
        ],
      }),
    },
    outputQuantizationParameters: {
      extent: {
        xmax: 30,
        xmin: 20,
        ymax: 30,
        ymin: 20,
      },
      tolerance: 0.001,
      quantizeMode: "view",
    }
   }
  }
);

方法概述

显示继承的方法 隐藏继承的方法
名称 返回值类值 描述

添加一个或多个与对象的生命周期相关联的句柄。

更多详情
Accessor
Boolean

如果存在指定的句柄组,则返回 true。

更多详情
Accessor

移除对象拥有的句柄组。

更多详情
Accessor

方法详细说明

addHandles(handleOrHandles, groupKey)inherited

添加一个或多个与对象的生命周期相关联的句柄。当对象被销毁时,将移除句柄。

// Manually manage handles
const handle = reactiveUtils.when(
  () => !view.updating,
  () => {
    wkidSelect.disabled = false;
  },
  { once: true }
);

// Handle gets removed when the object is destroyed.
this.addHandles(handle);
参数
handleOrHandles WatchHandle|WatchHandle[]

对象销毁后,标记为要移除的句柄。

groupKey *
optional

标识句柄应添加到的组的键。组中的所有句柄稍后都可使用 Accessor.removeHandles() 进行删除。如果未提供键,则句柄将被添加到默认组。

hasHandles(groupKey){Boolean}inherited

如果存在指定的句柄组,则返回 true。

参数
groupKey *
optional

组键。

返回
类型 描述
Boolean 如果存在指定的句柄组,则返回 true
示例
// Remove a named group of handles if they exist.
if (obj.hasHandles("watch-view-updates")) {
  obj.removeHandles("watch-view-updates");
}
removeHandles(groupKey)inherited

移除对象拥有的句柄组。

参数
groupKey *
optional

要移除的组键或组键的数组或集合。

示例
obj.removeHandles(); // removes handles from default group

obj.removeHandles("handle-group");
obj.removeHandles("other-handle-group");

您的浏览器不再受支持。请升级您的浏览器以获得最佳体验。请参阅浏览器弃用帖子以获取更多信息