【问题标题】:Visualize Neo4j-Spatial database in a map在地图中可视化 Neo4j-Spatial 数据库
【发布时间】:2016-03-29 00:57:41
【问题描述】:

我已经能够将一些 shapefile 导入 Neo4j 2.3.1。 现在如何在地图上查看这些数据?

我已经尝试过 GeoServer 和 uDig 上的 Wiki 说明,但它们都已过时,我无法使其正常工作。

最近有什么教程或其他工具可以解决这个问题吗?

【问题讨论】:

    标签: neo4j geoserver neo4j-spatial


    【解决方案1】:

    我已经使用 neo4j-spatial 和 Mapbox.js 来可视化地图中的几何图形。

    对于我的用例,我在 neo4j-spatial 中索引了美国国会区几何图形,然后根据用户在地图上的点击位置查询空间索引,返回最近的区,包括 WKT 字符串和 Cypher 查询的结果。为了在地图中渲染 WKT 多边形,我编写了一个简单的 javascript 函数来将其解析为点数组以添加地图注释。

    这里有一些相关的代码sn-ps:

    创建地图并为地图定义点击处理程序:

    L.mapbox.accessToken = MB_API_TOKEN;
    var map = L.mapbox.map('map', 'mapbox.streets')
      .setView([39.8282, -98.5795], 5);
    
    map.on('click', function(e) {
      clearMap(map);
      getClosestDistrict(e);
    });
    

    处理鼠标点击

    /**
      *  Find the District for a given latlng.
      *  Find the representative, commitees and subjects for that rep.
      */
    function infoDistrictWithinDistance(latlng, distance) {
    
      var districtParams = {
        "layer": "geom",
        "pointX": latlng.lng,
        "pointY": latlng.lat,
        "distanceInKm": distance
      };
    
     var districtURL = baseURI + findGeometriesPath;
     makePOSTRequest(districtURL, districtParams, function (error, data) {
    
       if (error) {
        console.log("Error");
       } else {
        console.log(data);
    
       var params = {
        "state": data[0]["data"]["state"],
        "district": data[0]["data"]["district"]
       };
    
       var points = parseWKTPolygon(data[0]["data"]["wkt"]);
    
       makeCypherRequest([{"statement": subjectsQuery, "parameters": params}], function (error, data) {
    
        if (error) {
          console.log("Error");
        } else {
          console.log(data);
    
          var districtInfo = data["results"][0]["data"][0]["row"][0];
          districtInfo["points"] = points;
          districtInfo["state"] = params["state"];
          districtInfo["district"] = params["district"];
          console.log(districtInfo);
    
          addDistrictToMap(districtInfo, latlng);
        }
       });
     }
    });
    

    将 WKT 解析为点数组

    /**
     *  Converts Polygon WKT string to an array of [x,y] points
     */
    function parseWKTPolygon(wkt) {
      var pointArr = [];
      var points = wkt.slice(10, -3).split(",");
    
      $.each(points, function(i,v) {
        var point = $.trim(v).split(" ");
        var xy = [Number(point[1]), Number(point[0])];
        pointArr.push(xy)
      });
    
      return pointArr;
    }
    

    代码在this repo。您可以看到简单的地图演示here(只需单击美国任何地方即可开始)。最近还有一篇关于此示例的博客文章here

    【讨论】:

    • 谢谢!这就是我一直在寻找的。我看到您以与我类似的方式将数据添加到 Neo4j。您的图层脚本的导入/添加节点工作速度真的很慢还是只有我?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-12-13
    • 1970-01-01
    • 2014-07-18
    相关资源
    最近更新 更多