确定地理点是否在州边界 X 米范围内(使用 shapefile 获取边界数据)

发布于 2024-07-21 22:02:31 字数 384 浏览 6 评论 0原文

所以我正在编写一个 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 技术交流群。

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

发布评论

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

评论(3

七度光 2024-07-28 22:02:31

假设 GeoTools 中包含几何图形的 JTS

public boolean pointIsClose( File file, Point targetPoint,double distance) {


  boolean ret = false;
  Map connect = new HashMap();
  connect.put("url", file.toURL());
  DataStore dataStore = DataStoreFinder.getDataStore(connect);


  FeatureSource featureSource = dataStore.getFeatureSource(typeName);
  FeatureCollection collection = featureSource.getFeatures();
  FeatureIterator iterator = collection.features();



  try {
    while (iterator.hasNext()) {
      Feature feature = iterator.next();
      Geometry sourceGeometry = feature.getDefaultGeometry();
      ret= sourceGeometry.isWithinDistance(targetPoint, distance );
    }
  } finally {
    iterator.close();
  }
  return ret;
}

必须出现双数来自 CRS ,它将定义计算的单位被执行。

这些是 geotools 导入:

import org.geotools.data.DataStore;
import org.geotools.data.DataStoreFinder;
import org.geotools.data.FeatureSource;
import org.geotools.feature.Feature;
import org.geotools.feature.FeatureCollection;
import org.geotools.feature.FeatureIterator;
import org.geotools.geometry.jts.JTS;
import org.geotools.referencing.CRS;
import org.opengis.referencing.crs.CoordinateReferenceSystem;

Assuming JTS for Geometry which is what is included in GeoTools:

public boolean pointIsClose( File file, Point targetPoint,double distance) {


  boolean ret = false;
  Map connect = new HashMap();
  connect.put("url", file.toURL());
  DataStore dataStore = DataStoreFinder.getDataStore(connect);


  FeatureSource featureSource = dataStore.getFeatureSource(typeName);
  FeatureCollection collection = featureSource.getFeatures();
  FeatureIterator iterator = collection.features();



  try {
    while (iterator.hasNext()) {
      Feature feature = iterator.next();
      Geometry sourceGeometry = feature.getDefaultGeometry();
      ret= sourceGeometry.isWithinDistance(targetPoint, distance );
    }
  } finally {
    iterator.close();
  }
  return ret;
}

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:

import org.geotools.data.DataStore;
import org.geotools.data.DataStoreFinder;
import org.geotools.data.FeatureSource;
import org.geotools.feature.Feature;
import org.geotools.feature.FeatureCollection;
import org.geotools.feature.FeatureIterator;
import org.geotools.geometry.jts.JTS;
import org.geotools.referencing.CRS;
import org.opengis.referencing.crs.CoordinateReferenceSystem;
弱骨蛰伏 2024-07-28 22:02:31

如果您只想知道 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.

泪冰清 2024-07-28 22:02:31

如果您可以以某种方式从 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.

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