arcgis-knowledge-graphs
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseArcGIS Knowledge Graphs
ArcGIS Knowledge 图谱
Use this skill for working with knowledge graphs, graph queries, and relationship visualization.
本技能可用于处理知识图谱、图查询以及关系可视化操作。
Knowledge Graph Service
Knowledge 图谱服务
Fetch Knowledge Graph
获取Knowledge 图谱
javascript
import KGModule from "@arcgis/core/rest/knowledgeGraphService.js";
const url = "https://your-server/server/rest/services/Hosted/YourKG/KnowledgeGraphServer";
const knowledgeGraph = await KGModule.fetchKnowledgeGraph(url);
console.log("Graph name:", knowledgeGraph.name);
console.log("Entity types:", knowledgeGraph.dataModel.entityTypes);
console.log("Relationship types:", knowledgeGraph.dataModel.relationshipTypes);javascript
import KGModule from "@arcgis/core/rest/knowledgeGraphService.js";
const url = "https://your-server/server/rest/services/Hosted/YourKG/KnowledgeGraphServer";
const knowledgeGraph = await KGModule.fetchKnowledgeGraph(url);
console.log("Graph name:", knowledgeGraph.name);
console.log("Entity types:", knowledgeGraph.dataModel.entityTypes);
console.log("Relationship types:", knowledgeGraph.dataModel.relationshipTypes);KnowledgeGraphLayer
KnowledgeGraphLayer
Add to Map
添加到地图
javascript
import KnowledgeGraphLayer from "@arcgis/core/layers/KnowledgeGraphLayer.js";
const kgLayer = new KnowledgeGraphLayer({
url: "https://your-server/server/rest/services/Hosted/YourKG/KnowledgeGraphServer"
});
await kgLayer.load();
map.add(kgLayer);javascript
import KnowledgeGraphLayer from "@arcgis/core/layers/KnowledgeGraphLayer.js";
const kgLayer = new KnowledgeGraphLayer({
url: "https://your-server/server/rest/services/Hosted/YourKG/KnowledgeGraphServer"
});
await kgLayer.load();
map.add(kgLayer);Configure Sublayers
配置子图层
javascript
const kgLayer = new KnowledgeGraphLayer({
url: "...",
// Only include specific entity types
inclusionModeDefinition: {
generateAllSublayers: false,
namedTypeDefinitions: new Map([
["Person", { useAllData: true }],
["Location", { useAllData: true }]
])
}
});javascript
const kgLayer = new KnowledgeGraphLayer({
url: "...",
// 仅包含特定实体类型
inclusionModeDefinition: {
generateAllSublayers: false,
namedTypeDefinitions: new Map([
["Person", { useAllData: true }],
["Location", { useAllData: true }]
])
}
});Querying with openCypher
使用openCypher进行查询
Basic Query
基础查询
javascript
import KGModule from "@arcgis/core/rest/knowledgeGraphService.js";
const result = await KGModule.executeQuery(knowledgeGraph, {
openCypherQuery: "MATCH (n:Person) RETURN n LIMIT 10"
});
console.log("Results:", result.resultRows);javascript
import KGModule from "@arcgis/core/rest/knowledgeGraphService.js";
const result = await KGModule.executeQuery(knowledgeGraph, {
openCypherQuery: "MATCH (n:Person) RETURN n LIMIT 10"
});
console.log("Results:", result.resultRows);Streaming Query (Large Results)
流式查询(处理大量结果)
javascript
const queryResults = await KGModule.executeQueryStreaming(knowledgeGraph, {
openCypherQuery: "MATCH (n:Person)-[r]->(m) RETURN n, r, m"
});
// Read stream
const reader = queryResults.resultRowsStream.getReader();
while (true) {
const { done, value } = await reader.read();
if (done) break;
// Process chunk
value.forEach(row => {
console.log("Row:", row);
});
}javascript
const queryResults = await KGModule.executeQueryStreaming(knowledgeGraph, {
openCypherQuery: "MATCH (n:Person)-[r]->(m) RETURN n, r, m"
});
// 读取流
const reader = queryResults.resultRowsStream.getReader();
while (true) {
const { done, value } = await reader.read();
if (done) break;
// 处理数据块
value.forEach(row => {
console.log("Row:", row);
});
}Spatial Query with Bind Parameters
带绑定参数的空间查询
javascript
import KGModule from "@arcgis/core/rest/knowledgeGraphService.js";
import Polygon from "@arcgis/core/geometry/Polygon.js";
// Create geometry for spatial filter
const searchArea = new Polygon({
rings: [[
[-76, 45],
[-70, 45],
[-70, 40],
[-76, 40],
[-76, 45]
]]
});
const queryResults = await KGModule.executeQueryStreaming(knowledgeGraph, {
openCypherQuery: `
MATCH path=(a:User)-[]->(b:Observation)
WHERE esri.graph.ST_Intersects($geometry, b.shape)
RETURN path
`,
bindParameters: {
geometry: searchArea
}
});javascript
import KGModule from "@arcgis/core/rest/knowledgeGraphService.js";
import Polygon from "@arcgis/core/geometry/Polygon.js";
// 创建空间过滤的几何图形
const searchArea = new Polygon({
rings: [[
[-76, 45],
[-70, 45],
[-70, 40],
[-76, 40],
[-76, 45]
]]
});
const queryResults = await KGModule.executeQueryStreaming(knowledgeGraph, {
openCypherQuery: `
MATCH path=(a:User)-[]->(b:Observation)
WHERE esri.graph.ST_Intersects($geometry, b.shape)
RETURN path
`,
bindParameters: {
geometry: searchArea
}
});Query with Filters
带过滤条件的查询
javascript
// Filter by property
const result = await KGModule.executeQuery(knowledgeGraph, {
openCypherQuery: `
MATCH (p:Person)
WHERE p.age > 30 AND p.name CONTAINS 'John'
RETURN p
`
});
// Query relationships
const result = await KGModule.executeQuery(knowledgeGraph, {
openCypherQuery: `
MATCH (p:Person)-[r:WORKS_AT]->(c:Company)
WHERE c.name = 'Esri'
RETURN p.name, r.startDate, c.name
`
});javascript
// 按属性过滤
const result = await KGModule.executeQuery(knowledgeGraph, {
openCypherQuery: `
MATCH (p:Person)
WHERE p.age > 30 AND p.name CONTAINS 'John'
RETURN p
`
});
// 查询关系
const result = await KGModule.executeQuery(knowledgeGraph, {
openCypherQuery: `
MATCH (p:Person)-[r:WORKS_AT]->(c:Company)
WHERE c.name = 'Esri'
RETURN p.name, r.startDate, c.name
`
});Link Chart Visualization
关联图表可视化
Create Link Chart
创建关联图表
javascript
import WebLinkChart from "@arcgis/core/WebLinkChart.js";
import LinkChartView from "@arcgis/core/views/LinkChartView.js";
import LinkChartLayer from "@arcgis/core/layers/LinkChartLayer.js";
const linkChartLayer = new LinkChartLayer({
url: "https://your-server/.../KnowledgeGraphServer"
});
const linkChart = new WebLinkChart({
layers: [linkChartLayer]
});
const linkChartView = new LinkChartView({
container: "linkChartDiv",
map: linkChart
});javascript
import WebLinkChart from "@arcgis/core/WebLinkChart.js";
import LinkChartView from "@arcgis/core/views/LinkChartView.js";
import LinkChartLayer from "@arcgis/core/layers/LinkChartLayer.js";
const linkChartLayer = new LinkChartLayer({
url: "https://your-server/.../KnowledgeGraphServer"
});
const linkChart = new WebLinkChart({
layers: [linkChartLayer]
});
const linkChartView = new LinkChartView({
container: "linkChartDiv",
map: linkChart
});LinkChartView Configuration
LinkChartView 配置
javascript
const linkChartView = new LinkChartView({
container: "linkChartDiv",
map: linkChart,
// Enable interaction
highlightOptions: {
color: [0, 255, 255, 1],
haloColor: [0, 255, 255, 0.5],
haloOpacity: 0.8
},
// Navigation
navigation: {
mouseWheelZoomEnabled: true,
browserTouchPanEnabled: true
}
});
// View events
linkChartView.on("click", async (event) => {
const response = await linkChartView.hitTest(event);
if (response.results.length > 0) {
const graphic = response.results[0].graphic;
console.log("Clicked:", graphic.attributes);
}
});
// Watch for selection changes
linkChartView.on("selection-change", (event) => {
console.log("Selected entities:", event.added);
console.log("Deselected entities:", event.removed);
});javascript
const linkChartView = new LinkChartView({
container: "linkChartDiv",
map: linkChart,
// 启用交互
highlightOptions: {
color: [0, 255, 255, 1],
haloColor: [0, 255, 255, 0.5],
haloOpacity: 0.8
},
// 导航设置
navigation: {
mouseWheelZoomEnabled: true,
browserTouchPanEnabled: true
}
});
// 视图事件
linkChartView.on("click", async (event) => {
const response = await linkChartView.hitTest(event);
if (response.results.length > 0) {
const graphic = response.results[0].graphic;
console.log("Clicked:", graphic.attributes);
}
});
// 监听选择变化
linkChartView.on("selection-change", (event) => {
console.log("Selected entities:", event.added);
console.log("Deselected entities:", event.removed);
});Link Chart Component
关联图表组件
html
<arcgis-link-chart>
<arcgis-legend slot="top-right"></arcgis-legend>
<arcgis-zoom slot="bottom-right"></arcgis-zoom>
</arcgis-link-chart>
<script type="module">
const linkChartComponent = document.querySelector("arcgis-link-chart");
await linkChartComponent.componentOnReady();
const lcView = linkChartComponent.view;
const linkChart = lcView.map;
// Add records to link chart
linkChart.addRecords([
{ id: "entity1", typeName: "Person" },
{ id: "entity2", typeName: "Company" }
]);
</script>html
<arcgis-link-chart>
<arcgis-legend slot="top-right"></arcgis-legend>
<arcgis-zoom slot="bottom-right"></arcgis-zoom>
</arcgis-link-chart>
<script type="module">
const linkChartComponent = document.querySelector("arcgis-link-chart");
await linkChartComponent.componentOnReady();
const lcView = linkChartComponent.view;
const linkChart = lcView.map;
// 向关联图表添加记录
linkChart.addRecords([
{ id: "entity1", typeName: "Person" },
{ id: "entity2", typeName: "Company" }
]);
</script>Link Chart Layout Settings
关联图表布局设置
javascript
// Access layout settings
const layoutSettings = linkChart.layoutSettings;
// Organic Layout (default)
linkChart.layoutSettings = {
type: "organic",
avoidLabelOverlap: true,
compactness: 0.5, // 0-1, how tightly packed
orientation: "top-to-bottom" // top-to-bottom, bottom-to-top, left-to-right, right-to-left
};
// Chronological Layout
linkChart.layoutSettings = {
type: "chronological",
dateField: "timestamp",
groupByField: "category",
orientation: "horizontal", // horizontal, vertical
showTimeline: true
};javascript
// 访问布局设置
const layoutSettings = linkChart.layoutSettings;
// 有机布局(默认)
linkChart.layoutSettings = {
type: "organic",
avoidLabelOverlap: true,
compactness: 0.5, // 0-1,控制紧凑程度
orientation: "top-to-bottom" // top-to-bottom, bottom-to-top, left-to-right, right-to-left
};
// 时间线布局
linkChart.layoutSettings = {
type: "chronological",
dateField: "timestamp",
groupByField: "category",
orientation: "horizontal", // horizontal, vertical
showTimeline: true
};OrganicLayoutSettings
OrganicLayoutSettings
javascript
import OrganicLayoutSettings from "@arcgis/core/webdoc/applicationProperties/OrganicLayoutSettings.js";
const organicLayout = new OrganicLayoutSettings({
avoidLabelOverlap: true,
compactness: 0.6,
componentLayoutEnabled: true,
deterministic: true,
minimumNodeDistance: 50,
orientation: "top-to-bottom",
preferredEdgeLength: 100,
starSubstructureEnabled: true,
treeSubstructureEnabled: true
});
linkChart.layoutSettings = organicLayout;javascript
import OrganicLayoutSettings from "@arcgis/core/webdoc/applicationProperties/OrganicLayoutSettings.js";
const organicLayout = new OrganicLayoutSettings({
avoidLabelOverlap: true,
compactness: 0.6,
componentLayoutEnabled: true,
deterministic: true,
minimumNodeDistance: 50,
orientation: "top-to-bottom",
preferredEdgeLength: 100,
starSubstructureEnabled: true,
treeSubstructureEnabled: true
});
linkChart.layoutSettings = organicLayout;ChronologicalLayoutSettings
ChronologicalLayoutSettings
javascript
import ChronologicalLayoutSettings from "@arcgis/core/webdoc/applicationProperties/ChronologicalLayoutSettings.js";
const chronoLayout = new ChronologicalLayoutSettings({
dateField: "event_date",
groupByField: "event_type",
orientation: "horizontal",
showTimeline: true,
timelinePosition: "bottom",
sortOrder: "ascending" // ascending, descending
});
linkChart.layoutSettings = chronoLayout;javascript
import ChronologicalLayoutSettings from "@arcgis/core/webdoc/applicationProperties/ChronologicalLayoutSettings.js";
const chronoLayout = new ChronologicalLayoutSettings({
dateField: "event_date",
groupByField: "event_type",
orientation: "horizontal",
showTimeline: true,
timelinePosition: "bottom",
sortOrder: "ascending" // ascending, descending
});
linkChart.layoutSettings = chronoLayout;LinkChartLayoutSwitcher Widget
LinkChartLayoutSwitcher 部件
javascript
import LinkChartLayoutSwitcher from "@arcgis/core/widgets/LinkChartLayoutSwitcher.js";
const layoutSwitcher = new LinkChartLayoutSwitcher({
view: linkChartView,
layouts: [
{
name: "Organic",
settings: new OrganicLayoutSettings({ compactness: 0.5 })
},
{
name: "Timeline",
settings: new ChronologicalLayoutSettings({ dateField: "date" })
}
]
});
linkChartView.ui.add(layoutSwitcher, "top-right");javascript
import LinkChartLayoutSwitcher from "@arcgis/core/widgets/LinkChartLayoutSwitcher.js";
const layoutSwitcher = new LinkChartLayoutSwitcher({
view: linkChartView,
layouts: [
{
name: "Organic",
settings: new OrganicLayoutSettings({ compactness: 0.5 })
},
{
name: "Timeline",
settings: new ChronologicalLayoutSettings({ dateField: "date" })
}
]
});
linkChartView.ui.add(layoutSwitcher, "top-right");Non-Spatial Data Display
非空间数据展示
javascript
// Configure non-spatial display for entities
const linkChartLayer = new LinkChartLayer({
url: "...",
nonspatialDataDisplay: {
entityTypes: {
Person: {
displayField: "name",
symbol: {
type: "simple-marker",
color: "blue",
size: 20
}
},
Company: {
displayField: "company_name",
symbol: {
type: "simple-marker",
color: "green",
size: 25
}
}
},
relationshipTypes: {
WORKS_AT: {
symbol: {
type: "simple-line",
color: "gray",
width: 2
}
}
}
}
});javascript
// 配置实体的非空间展示
const linkChartLayer = new LinkChartLayer({
url: "...",
nonspatialDataDisplay: {
entityTypes: {
Person: {
displayField: "name",
symbol: {
type: "simple-marker",
color: "blue",
size: 20
}
},
Company: {
displayField: "company_name",
symbol: {
type: "simple-marker",
color: "green",
size: 25
}
}
},
relationshipTypes: {
WORKS_AT: {
symbol: {
type: "simple-line",
color: "gray",
width: 2
}
}
}
}
});Adding and Removing Records
添加和删除记录
javascript
// Add records
await linkChart.addRecords([
{ id: "person-1", typeName: "Person" },
{ id: "company-1", typeName: "Company" },
{ id: "rel-1", typeName: "WORKS_AT" }
]);
// Remove records
await linkChart.removeRecords([
{ id: "person-1", typeName: "Person" }
]);
// Clear all records
await linkChart.removeAllRecords();
// Get current records
const records = linkChart.records;
console.log("Current entities:", records.entities);
console.log("Current relationships:", records.relationships);javascript
// 添加记录
await linkChart.addRecords([
{ id: "person-1", typeName: "Person" },
{ id: "company-1", typeName: "Company" },
{ id: "rel-1", typeName: "WORKS_AT" }
]);
// 删除记录
await linkChart.removeRecords([
{ id: "person-1", typeName: "Person" }
]);
// 清空所有记录
await linkChart.removeAllRecords();
// 获取当前记录
const records = linkChart.records;
console.log("Current entities:", records.entities);
console.log("Current relationships:", records.relationships);Update Link Chart from Query Results
从查询结果更新关联图表
javascript
async function updateLinkChart(queryResults, linkChart) {
const reader = queryResults.resultRowsStream.getReader();
while (true) {
const { done, value } = await reader.read();
if (done) break;
const records = [];
for (const row of value) {
for (const record of row[0].path) {
records.push({
id: record.id,
typeName: record.typeName
});
}
}
linkChart.addRecords(records);
}
}javascript
async function updateLinkChart(queryResults, linkChart) {
const reader = queryResults.resultRowsStream.getReader();
while (true) {
const { done, value } = await reader.read();
if (done) break;
const records = [];
for (const row of value) {
for (const record of row[0].path) {
records.push({
id: record.id,
typeName: record.typeName
});
}
}
linkChart.addRecords(records);
}
}Expand/Collapse Entities
展开/折叠实体
javascript
// Expand entity to show connections
await linkChart.expand({
ids: ["entity-id"],
typeName: "Person",
relationshipTypes: ["KNOWS", "WORKS_AT"],
direction: "both" // outgoing, incoming, both
});
// Collapse entity
await linkChart.collapse({
ids: ["entity-id"],
typeName: "Person"
});javascript
// 展开实体以显示关联
await linkChart.expand({
ids: ["entity-id"],
typeName: "Person",
relationshipTypes: ["KNOWS", "WORKS_AT"],
direction: "both" // outgoing, incoming, both
});
// 折叠实体
await linkChart.collapse({
ids: ["entity-id"],
typeName: "Person"
});Selection and Highlighting
选择与高亮
javascript
// Select entities programmatically
linkChartView.select([
{ id: "person-1", typeName: "Person" },
{ id: "person-2", typeName: "Person" }
]);
// Clear selection
linkChartView.clearSelection();
// Highlight (temporary visual emphasis)
const highlightHandle = linkChartView.highlight([
{ id: "person-1", typeName: "Person" }
]);
// Remove highlight
highlightHandle.remove();
// Go to specific entities
linkChartView.goTo([
{ id: "person-1", typeName: "Person" }
]);javascript
// 以编程方式选择实体
linkChartView.select([
{ id: "person-1", typeName: "Person" },
{ id: "person-2", typeName: "Person" }
]);
// 清除选择
linkChartView.clearSelection();
// 高亮(临时视觉强调)
const highlightHandle = linkChartView.highlight([
{ id: "person-1", typeName: "Person" }
]);
// 移除高亮
highlightHandle.remove();
// 定位到特定实体
linkChartView.goTo([
{ id: "person-1", typeName: "Person" }
]);WebLinkChart Properties
WebLinkChart 属性
javascript
import WebLinkChart from "@arcgis/core/WebLinkChart.js";
const webLinkChart = new WebLinkChart({
// Portal item (load existing)
portalItem: { id: "LINKCHART_ID" },
// Or create from scratch
layers: [linkChartLayer],
// Layout settings
layoutSettings: organicLayout,
// Initial records
initialRecords: {
entities: [
{ id: "entity-1", typeName: "Person" }
],
relationships: []
}
});
// Save to portal
await webLinkChart.saveAs({
title: "My Link Chart",
snippet: "Visualization of entity relationships"
});javascript
import WebLinkChart from "@arcgis/core/WebLinkChart.js";
const webLinkChart = new WebLinkChart({
// 门户项(加载已有的图表)
portalItem: { id: "LINKCHART_ID" },
// 或从头创建
layers: [linkChartLayer],
// 布局设置
layoutSettings: organicLayout,
// 初始记录
initialRecords: {
entities: [
{ id: "entity-1", typeName: "Person" }
],
relationships: []
}
});
// 保存到门户
await webLinkChart.saveAs({
title: "My Link Chart",
snippet: "Visualization of entity relationships"
});Search Knowledge Graph
搜索Knowledge 图谱
javascript
import KGModule from "@arcgis/core/rest/knowledgeGraphService.js";
const searchResults = await KGModule.executeSearch(knowledgeGraph, {
searchQuery: "John Smith",
typeCategoryFilter: "entity", // or "relationship", "both"
typeNames: ["Person", "Employee"],
returnSearchContext: true
});
searchResults.results.forEach(result => {
console.log("Found:", result.typeName, result.id);
console.log("Context:", result.searchContext);
});javascript
import KGModule from "@arcgis/core/rest/knowledgeGraphService.js";
const searchResults = await KGModule.executeSearch(knowledgeGraph, {
searchQuery: "John Smith",
typeCategoryFilter: "entity", // 可选值:"relationship", "both"
typeNames: ["Person", "Employee"],
returnSearchContext: true
});
searchResults.results.forEach(result => {
console.log("Found:", result.typeName, result.id);
console.log("Context:", result.searchContext);
});Apply Edits
应用编辑
javascript
import KGModule from "@arcgis/core/rest/knowledgeGraphService.js";
// Add entity
const addResult = await KGModule.executeApplyEdits(knowledgeGraph, {
entityAdds: [{
typeName: "Person",
properties: {
name: "Jane Doe",
age: 28
}
}]
});
// Update entity
const updateResult = await KGModule.executeApplyEdits(knowledgeGraph, {
entityUpdates: [{
typeName: "Person",
properties: {
globalId: "{existing-global-id}",
age: 29
}
}]
});
// Delete entity
const deleteResult = await KGModule.executeApplyEdits(knowledgeGraph, {
entityDeletes: [{
typeName: "Person",
ids: ["{global-id-to-delete}"]
}]
});
// Add relationship
const relResult = await KGModule.executeApplyEdits(knowledgeGraph, {
relationshipAdds: [{
typeName: "WORKS_AT",
properties: {
originGlobalId: "{person-global-id}",
destinationGlobalId: "{company-global-id}",
startDate: new Date()
}
}]
});javascript
import KGModule from "@arcgis/core/rest/knowledgeGraphService.js";
// 添加实体
const addResult = await KGModule.executeApplyEdits(knowledgeGraph, {
entityAdds: [{
typeName: "Person",
properties: {
name: "Jane Doe",
age: 28
}
}]
});
// 更新实体
const updateResult = await KGModule.executeApplyEdits(knowledgeGraph, {
entityUpdates: [{
typeName: "Person",
properties: {
globalId: "{existing-global-id}",
age: 29
}
}]
});
// 删除实体
const deleteResult = await KGModule.executeApplyEdits(knowledgeGraph, {
entityDeletes: [{
typeName: "Person",
ids: ["{global-id-to-delete}"]
}]
});
// 添加关系
const relResult = await KGModule.executeApplyEdits(knowledgeGraph, {
relationshipAdds: [{
typeName: "WORKS_AT",
properties: {
originGlobalId: "{person-global-id}",
destinationGlobalId: "{company-global-id}",
startDate: new Date()
}
}]
});Data Model
数据模型
javascript
// Access data model
const dataModel = knowledgeGraph.dataModel;
// Entity types
dataModel.entityTypes.forEach(entityType => {
console.log("Entity:", entityType.name);
console.log("Properties:", entityType.properties);
});
// Relationship types
dataModel.relationshipTypes.forEach(relType => {
console.log("Relationship:", relType.name);
console.log("Origin:", relType.originEntityTypes);
console.log("Destination:", relType.destinationEntityTypes);
});javascript
// 访问数据模型
const dataModel = knowledgeGraph.dataModel;
// 实体类型
dataModel.entityTypes.forEach(entityType => {
console.log("Entity:", entityType.name);
console.log("Properties:", entityType.properties);
});
// 关系类型
dataModel.relationshipTypes.forEach(relType => {
console.log("Relationship:", relType.name);
console.log("Origin:", relType.originEntityTypes);
console.log("Destination:", relType.destinationEntityTypes);
});Common openCypher Patterns
常见openCypher模式
cypher
-- Find all entities
MATCH (n) RETURN n
-- Find specific type
MATCH (p:Person) RETURN p
-- Find relationships
MATCH (a)-[r]->(b) RETURN a, r, b
-- Find path
MATCH path = (a:Person)-[:KNOWS*1..3]->(b:Person)
WHERE a.name = 'John'
RETURN path
-- Aggregate
MATCH (p:Person)-[:WORKS_AT]->(c:Company)
RETURN c.name, COUNT(p) as employeeCount
-- Spatial filter
MATCH (loc:Location)
WHERE esri.graph.ST_Intersects($geometry, loc.shape)
RETURN loccypher
-- 查找所有实体
MATCH (n) RETURN n
-- 查找特定类型
MATCH (p:Person) RETURN p
-- 查找关系
MATCH (a)-[r]->(b) RETURN a, r, b
-- 查找路径
MATCH path = (a:Person)-[:KNOWS*1..3]->(b:Person)
WHERE a.name = 'John'
RETURN path
-- 聚合查询
MATCH (p:Person)-[:WORKS_AT]->(c:Company)
RETURN c.name, COUNT(p) as employeeCount
-- 空间过滤
MATCH (loc:Location)
WHERE esri.graph.ST_Intersects($geometry, loc.shape)
RETURN locCommon Pitfalls
常见注意事项
-
Authentication required: Knowledge graph services typically require authentication
-
Streaming for large results: Usefor queries that may return many results
executeQueryStreaming -
Geometry conversion: Convert geometries to WGS84 before using in spatial queries
-
Case sensitivity: openCypher property names are case-sensitive
-
需要身份验证:Knowledge 图谱服务通常需要身份验证
-
大量结果使用流式查询:对于可能返回大量结果的查询,请使用
executeQueryStreaming -
几何图形转换:在空间查询中使用前,需将几何图形转换为WGS84坐标系
-
大小写敏感:openCypher的属性名称区分大小写