确定地理点是否在州边界 X 米范围内(使用 shapefile 获取边界数据)
所以我正在编写一个 Java 应用程序,并且我有一个 ESRI Shapefile,其中包含美国所有州的边界。 我需要的是能够确定任何给定的纬度/经度点是否在距任何州边界线指定的距离内 - 即,我不会指定特定的边界线,只需查看该点是否接近其中的任何。
解决方案不必非常精确; 例如,我不需要处理垂直于边界的测量,或者其他什么。 只需检查向北、向南、向东或向西移动 X 米是否会导致跨越边界就足够了。 该解决方案必须具有计算效率,因为我将执行大量此类计算。
我计划将 GeoTools 库(尽管如果有更简单的选项,我完全赞成)与 Shapefile 插件一起使用。 我真正不明白的是:一旦我将形状文件加载到内存中,如何检查我是否靠近边界?
谢谢! -担
So I'm writing a Java app, and I've got an ESRI Shapefile which contains the borders of all the U.S. states. What I need is to be able to determine whether any given lat/lon point is within a specified distance from ANY state border line - i.e., I will not be specifying a particular border line, just need to see whether the point is close to any of them.
The solution does NOT have to be very precise at all; e.g. I don't need to be dealing with measuring perpendicular to the border, or whatever. Just checking to see if going X meters north, south, east or west would result in crossing a border would be more than sufficient. The solution DOES have to be computationally efficient, as I'll be performing a huge number of these calculations.
I'm planning to use the GeoTools library (though if there's a simpler option, I'm all for it) with the Shapefile plugin. What I don't really understand is: Once I've got the shapefile loaded into memory, how do I check to see whether I'm near a border?
Thanks!
-Dan
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
假设 GeoTools 中包含几何图形的 JTS:
必须出现双数来自 CRS ,它将定义计算的单位被执行。
这些是 geotools 导入:
Assuming JTS for Geometry which is what is included in GeoTools:
The double number will have to come from the CRS which will define the units in which the calculation will be performed.
These are the geotools imports:
如果您只想知道 A 点是否在州边界的 X 米范围内,并且 X 是常数,并且您不关心它是哪个边界,则可以将负空间预先计算为一系列框。 然后您所要做的就是针对该点对每个框进行包含检查。 如果它们都不匹配,则您不在负空间中。
If you just want to know if point A is within X meters of a state border and X is constant and you don't care which border it is, you can precompute the negative space as a series of boxes. Then all you have to do is a contains check for each of those boxes against the point. If none of them match, you're not in the negative space.
如果您可以以某种方式从 shapefile 中提取每个状态的形状,创建一个边长 x 米的信封(您的点位于正中心)并查看这两个形状是否相交,您将能够回答这个问题。
如果我使用 ESRI 的 ArcGIS Engine,我将使用 ISpatialFilter 和几何中定义的点(可能带有缓冲区),并针对 States shapefile 进行查询。 返回的任何结果都表明该点接近某个状态。 我不熟悉 GeoTools,在浏览他们的文档时,我没有遇到任何看起来像此类功能的东西,但他们一定有它。 您可能想要查找有关如何使用 GeoTools 对 shapefile 执行空间查询的示例。
If you can somehow extract the shape for each state from the shapefile, create an envelope that is x meters on a side (with your point in the exact center) and see if those two shapes intersect, you'll be able to answer the question.
If I was using ESRI's ArcGIS Engine, I'd use an ISpatialFilter with the point defined in the geometry (possibly with a buffer) and query that against the States shapefile. Any result(s) returned would indicate that the point was near a state. I'm unfamiliar with GeoTools and, while browsing through their documentation, I didn't come across anything that looked like that type of functionality, but they must have it. You may want to look for examples of how to use GeoTools to perform spatial queries on shapefiles.