JavaScript 中的地理空间查询

发布于 2024-10-12 11:02:47 字数 1539 浏览 4 评论 0原文

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(8

半透明的墙 2024-10-19 11:02:47

2014 年 4 月 29 日更新:查看 Turf,看起来非常有前途

JSTS 可以在浏览器中进行几何对象的并集。 JSTS 与 openlayers 库集成,并扩展了 openlayers 几何类(例如 OpenLayers.Geometry.Polygon),因此它们能够进行几何操作。示例:

>> var poly1 = OpenLayers.Geometry.Polygon.createRegularPolygon(
                                   new OpenLayers.Geometry.Point(0.0,0.0), 2, 5);
>> var poly2 = OpenLayers.Geometry.Polygon.createRegularPolygon(
                                   new OpenLayers.Geometry.Point(1.0,1.0), 2, 4);
>> var poly_u = poly1.union(poly2);
>> var poly_d = poly1.difference(poly2);
>> print(poly_u);
POLYGON((1.5667154718422638 -0.4142135623730949,1.1755705045849463 -1.618033988749895,
  -1.1755705045849465 -1.6180339887498947,-1.902113032590307 0.618033988749895,
  -0.41421356237309503 1.6990562312593451,-0.4142135623730949 2.414213562373095,
   2.414213562373095 2.414213562373095,2.414213562373095 -0.4142135623730949,
   1.5667154718422638 -0.4142135623730949))

如果您想在 JS 中进行服务器端几何操作,Geoscript JS 会很好。

Update 2014-04-29: Check out Turf, looks really promising

JSTS can do unions of geometric objects in the browser. JSTS integrates with the openlayers library and it extends openlayers geometric classes (e.g. OpenLayers.Geometry.Polygon) so they are capable of geometric operations. Example:

>> var poly1 = OpenLayers.Geometry.Polygon.createRegularPolygon(
                                   new OpenLayers.Geometry.Point(0.0,0.0), 2, 5);
>> var poly2 = OpenLayers.Geometry.Polygon.createRegularPolygon(
                                   new OpenLayers.Geometry.Point(1.0,1.0), 2, 4);
>> var poly_u = poly1.union(poly2);
>> var poly_d = poly1.difference(poly2);
>> print(poly_u);
POLYGON((1.5667154718422638 -0.4142135623730949,1.1755705045849463 -1.618033988749895,
  -1.1755705045849465 -1.6180339887498947,-1.902113032590307 0.618033988749895,
  -0.41421356237309503 1.6990562312593451,-0.4142135623730949 2.414213562373095,
   2.414213562373095 2.414213562373095,2.414213562373095 -0.4142135623730949,
   1.5667154718422638 -0.4142135623730949))

Geoscript JS is nice if you want to do serverside geometric operations in JS.

简单爱 2024-10-19 11:02:47

我编写了空间查询 https://github.com/netshade/spatial_query 来做到这一点。

或者,您可以查看 http://geoscript.org/index.html ,这可能得到更好的支持比空间查询是。如果您决定查看 SQ,我会很高兴听到它是否适合您。

I wrote Spatial Query https://github.com/netshade/spatial_query to do just this.

Alternatively, you could check out http://geoscript.org/index.html , which is likely better supported than Spatial Query is. If you decide to check out SQ though, I'd be flattered to hear if it worked for you.

北陌 2024-10-19 11:02:47

您可以扩展 OpenLayers 以支持此操作。我使用 OpenLayers 本机函数来实现此目的。尝试一下,也许您必须修复并自定义此代码。

// The first object is instanced using data given from gmaps
var objBound1 = new OpenLayers.Bounds();
objBound1.extend(new OpenLayers.LonLat(2,2));
objBound1.extend(new OpenLayers.LonLat(8,8));

// The second object is instanced using data given from gmaps
var objBound2 = new OpenLayers.Bounds();
objBound2.extend(new OpenLayers.LonLat(5,5));
objBound2.extend(new OpenLayers.LonLat(10,10));

// Extract limits from our objects
var arrBound1 = objBound1.toArray();
var arrBound2 = objBound2.toArray();

// Determine an virtual bound. It must contain our two bounds
var intMinLeft = arrBound1.left < arrBound2.left ? arrBound1.left : arrBound2.left;
var intMinTop = arrBound1.top < arrBound2.top ? arrBound1.top : arrBound2.top;
var intMaxRight = arrBound1.right > arrBound2.right ? arrBound1.right : arrBound2.right;
var intMaxBottom = arrBound1.bottom > arrBound2.bottom ? arrBound1.bottom : arrBound2.bottom;

// Search all points of virtual bound, storing the points contained in bound1 or bound2
var objBoundResult = new OpenLayers.Bounds();
for(var intI = intMinLeft; intI < intMaxRight; intI++) {
    for(var intJ = intMinTop; intJ < intMaxBottom; intJ++) {
        if(objBound1.containsLonLat(new OpenLayers.LonLat(intI, intJ)) || objBound2.containsLonLat(new OpenLayers.LonLat(intI, intJ))) {
            objBoundResult.add(intI, intJ);
        }
    }
}

// objBoundResult is what you want

You can extend OpenLayers to support this operation. I make this using OpenLayers native functions. Try this, maybe you must fix and customize this code.

// The first object is instanced using data given from gmaps
var objBound1 = new OpenLayers.Bounds();
objBound1.extend(new OpenLayers.LonLat(2,2));
objBound1.extend(new OpenLayers.LonLat(8,8));

// The second object is instanced using data given from gmaps
var objBound2 = new OpenLayers.Bounds();
objBound2.extend(new OpenLayers.LonLat(5,5));
objBound2.extend(new OpenLayers.LonLat(10,10));

// Extract limits from our objects
var arrBound1 = objBound1.toArray();
var arrBound2 = objBound2.toArray();

// Determine an virtual bound. It must contain our two bounds
var intMinLeft = arrBound1.left < arrBound2.left ? arrBound1.left : arrBound2.left;
var intMinTop = arrBound1.top < arrBound2.top ? arrBound1.top : arrBound2.top;
var intMaxRight = arrBound1.right > arrBound2.right ? arrBound1.right : arrBound2.right;
var intMaxBottom = arrBound1.bottom > arrBound2.bottom ? arrBound1.bottom : arrBound2.bottom;

// Search all points of virtual bound, storing the points contained in bound1 or bound2
var objBoundResult = new OpenLayers.Bounds();
for(var intI = intMinLeft; intI < intMaxRight; intI++) {
    for(var intJ = intMinTop; intJ < intMaxBottom; intJ++) {
        if(objBound1.containsLonLat(new OpenLayers.LonLat(intI, intJ)) || objBound2.containsLonLat(new OpenLayers.LonLat(intI, intJ))) {
            objBoundResult.add(intI, intJ);
        }
    }
}

// objBoundResult is what you want
倒带 2024-10-19 11:02:47

您可以获取包含多边形的半径或矩形的查询结果,然后使用此处描述的技术筛选结果:http://msdn.microsoft.com/en-us/library/cc451895.aspx。该示例使用 bing 地图,但您可以使用您喜欢的任何地图服务轻松地使用相同的原理。

You can get query results for a radius or rectangle that includes your polygon, then filter the results using the technique described here: http://msdn.microsoft.com/en-us/library/cc451895.aspx. The example uses bing maps, but you could easily use the same principles using whatever mapping service you prefer.

爱给你人给你 2024-10-19 11:02:47

你看过geoUtils吗?

我不确定它是否支持工会操作,但可能值得一试。

Did you look at geoUtils?

I am not sure whether it supports the union op, but might be worth giving a try.

記柔刀 2024-10-19 11:02:47

如果您有可用的服务器,则可以运行 ESRI ArcGIS Server 10 并启动几何服务。通过 API(包括 REST)接口可以使用此功能。查看他们的帮助文档:SOAP SDK

If you have a server available, you can run the ESRI ArcGIS Server 10 and start a Geometry service. This has this functionality available through an API (including REST) interface. Look at their help documentation: SOAP SDK

情深已缘浅 2024-10-19 11:02:47

您可以使用支持 JDBC 的 PostGIS DB。
请查看此处的示例:
http://postgis.refractions.net/docs/ch05.html#id2644717

:)

DSP

You cound use the PostGIS DB wich has support for JDBC.
Check here for an example:
http://postgis.refractions.net/docs/ch05.html#id2644717

:)

DsP

殊姿 2024-10-19 11:02:47

您真的需要在客户端执行此操作吗?联合是一项相当繁重的操作,最好在服务器端完成。

另一个可能有用的 API 是 ArcGIS Javascript API,尽管从我所看到的情况来看,我认为如果没有 ArcGIS Server,它不会进行联合: http://help.arcgis.com/en/webapi/javascript/arcgis/

Do you really need to do this on the client side? Union is a fairly heavy operation and might be better done on the server side.

Another API that may be useful is the ArcGIS Javascript API, although from what I can see I don't think it will do union without ArcGIS Server: http://help.arcgis.com/en/webapi/javascript/arcgis/

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文