Geotools获取功能信息

时间:2017-04-21 01:07:45

标签: java maps shapefile coordinate geotools

我正在使用geotools库。我的目标是输入一个坐标,然后获取包含它的要素信息。

Geotools快速入门教程的地图完全符合我想要的按钮,我在下面以红色圈出。但是,我找不到使用的方法。

我一直在谷歌搜索,阅读文档和调试代码无济于事。这种方法似乎是要走的路: FeatureCollection myCollection = mySimpleFeatureSource.getFeatures(查询查询);

FeatureCollection myCollection = mySimpleFeatureSource.getFeatures(Filter filter);

但我还没弄明白或者发现如何用坐标查询。如果有人在意放贷 亲自动手,我非常感激!

提前致谢!

enter image description here

我正在运行的示例如下:

package org.geotools.tutorial.quickstart; import java.io.File; import org.geotools.data.FileDataStore; import org.geotools.data.FileDataStoreFinder; import org.geotools.data.simple.SimpleFeatureSource; import org.geotools.map.FeatureLayer; import org.geotools.map.Layer; import org.geotools.map.MapContent; import org.geotools.styling.SLD; import org.geotools.styling.Style; import org.geotools.swing.JMapFrame; import org.geotools.swing.data.JFileDataStoreChooser; /** * Prompts the user for a shapefile and displays the contents on the screen in a map frame. * <p> * This is the GeoTools Quickstart application used in documentationa and tutorials. * */ public class Quickstart { /** * GeoTools Quickstart demo application. Prompts the user for a shapefile and displays its * contents on the screen in a map frame */ public static void main(String[] args) throws Exception { // display a data store file chooser dialog for shapefiles File file = JFileDataStoreChooser.showOpenFile("shp", null); if (file == null) { return; } FileDataStore store = FileDataStoreFinder.getDataStore(file); SimpleFeatureSource featureSource = store.getFeatureSource(); // Create a map content and add our shapefile to it MapContent map = new MapContent(); map.setTitle("Quickstart"); Style style = SLD.createSimpleStyle(featureSource.getSchema()); Layer layer = new FeatureLayer(featureSource, style); map.addLayer(layer); // Now display the map JMapFrame.showMap(map); } }

1 个答案:

答案 0 :(得分:1)

理想情况下,在完成QuickStart之后,您应该完成other tutorials,然后来Query Tutorial。这将向您介绍如何创建简单的import android.app.ActionBar.Tab; import android.app.FragmentTransaction; import android.app.ActionBar; public class Adapter implements ActionBar.TabListener { private android.support.v4.app.Fragment fragment; // The contructor. public Adapter(android.support.v4.app.Fragment fragment) { this.fragment = fragment; } @Override public void onTabSelected(Tab tab, FragmentTransaction ft) { ft.replace(R.id.activity_main, fragment); } @Override public void onTabUnselected(Tab tab, FragmentTransaction ft) { ft.remove(fragment); } @Override public void onTabReselected(Tab tab, FragmentTransaction ft) { } } 和更复杂的Filter(它添加到具有排序顺序的过滤器,属性的子集等)。

因此,要创建一个简单的过滤器,最简单的方法是使用通用查询语言(CQL)静态Query方法:

toFilter

您的要素具有几何属性Filter f = CQL.toFilter("contains(the_geom,Point("+p.x+" "+p.y+"))"); ,而the_geom是一个点。

BTW您正在寻找的小工具是InfoTool,实际p是在FeatureLayerHelper中构建的。