0

我是shapefile处理新手。请指导我如何实现以下查询。

我正在使用来自census.gov 的这个 shapefile tl_2018_us_aiannh.shp :TIGER-LINE。我要根据用户提供的经纬度从 shapefile中获取人口普查区块组实体,如BlockTractCounty subdivisionCounty详细信息。

我的要求是shapefile单独而不是通过任何 API 来实现这一点。

有人可以帮助我实现这个框架吗?

到目前为止我尝试/使用的内容

  • 我曾经GeoTools读过shapefile. 我可以继续使用相同的吗?这个工具能满足我的要求吗?
  • 我浏览了census.gov的文件,其中指出:

人口普查局分配一个代码,这些代码出现在“TRACTCE”等字段中,其中“CE”代表人口普查。最后,州提交的代码以“ST”结尾,例如“SLDLST”,地方教育机构代码以“LEA”结尾,例如“ELSDLEA”。

我在我的代码中尝试过

File file = new File("D:\\tl_2018_us_aiannh.shp");

        try {
            Map<String, String> connect = new HashMap();
            connect.put("url", file.toURI().toString());

            DataStore dataStore = DataStoreFinder.getDataStore(connect);
            String[] typeNames = dataStore.getTypeNames();
            String typeName = typeNames[0];

            System.out.println("Reading content " + typeName);

            SimpleFeatureSource featureSource = dataStore
                    .getFeatureSource(typeName);
            SimpleFeatureCollection collection = featureSource.getFeatures();
            SimpleFeatureIterator iterator = collection.features();

            try {
                while (iterator.hasNext()) {
                    SimpleFeature feature = iterator.next();
                    GeometryAttribute sourceGeometry = feature
                            .getDefaultGeometryProperty();
                    String name = (String) (feature).getAttribute("TRACTCE");
                    Property property = feature.getProperty("TRACTCE");
                    System.out.println(property);
                }
            } finally {
                iterator.close();
            }

        } catch (Throwable e) {
            e.getMessage();
        }

但我收到 null 作为值。

任何帮助都会很有帮助。

4

1 回答 1

0

我已经找到了解决方案。希望这对有需要的人有所帮助。

SimpleFeature是具有形状文件属性的类型,当您尝试在运行时调试或打印一行时可以检查这些属性。您可以使用SimpleFeature来获取属性。属性可以通过以下方式实现:

  try {
     while (iterator.hasNext()) {
         SimpleFeature feature = iterator.next();
         Property intptlat = feature.getProperty("TRACTCE");
     }
 }

确保您选择块组作为要下载的图层类型Tiger-Line或下载形状文件的任何站点。

于 2019-02-16T18:40:40.460 回答