如何与Java Geotools Lib查询多边形的范围?
我有很多坐标点。现在,我在地图上画了一个多边形,并查询该范围内的点,例如美国的加油站。
我所有的数据都存储在arraylist中。我该如何通过Java Geotool Lib实现这一目标
List<Point> points = new ArrayList();
I have a lot of coordinate points. Now I draw a polygon on the map and query the points within this range, such as gas stations in the United States.
All my data is stored in ArrayList. How can I achieve this through java geotool lib
List<Point> points = new ArrayList();
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
this a>(在更相关的 https://gis.stackexchange.com 上)显示了几种可能以不同速度解决此问题的方法。它们都基本上是使用过滤器(从您的
polygon
构建的)来从数据存储中返回功能(您的点)的子集合。因此,首先,我们需要一个点功能(加油站)的
数据存储
理想情况下,这将是一个启用空间的数据库(因此查询是在数据库中使用索引等),但是ShapeFile或CSV可以。如果您只有几百个记录或仅进行几次查询。拥有数据存储后,您可以获得
simpleFeatUrecollection
,然后使用过滤器调用subcolection
方法。创建
过滤器
的简便方法是使用cql.tofilter
方法,该方法采用类似的字符串:This answer (on the more relevant https://gis.stackexchange.com) shows several possible ways of solving this problem with different speeds. They all come down to basically using a filter (constructed from your
Polygon
) to return the subcollection of features (your points) from a datastore.So first we need a
DataStore
of point features (Gas Stations) ideally this would be a spatially enabled database (so the query is done in the database with indexes etc), but a shapefile or CSV would be OK if you only have a few hundred records or are only doing the query a few times.Once you have a datastore, you can get a
SimpleFeatureCollection
and then you call thesubCollection
method with your filter.The easy way to create a
Filter
is to use theCQL.toFilter
method which takes a string like: