基于latlong输入从shapefile获取人口普查区块组 - Java

问题描述 投票:0回答:1

我是shapefile加工的新手。请指导我如何实现以下查询。

我正在使用census.gov:TIGER-LINE中的shapefile tl_2018_us_aiannh.shp。我将根据用户提供的纬度和经度从shapefile获取人口普查区块组实体,如Block,Tract,County subdivision和County details。

我的要求是单独通过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作为值。

任何帮助都会有所帮助。

java coordinates shapefile coordinate-systems census
1个回答
0
投票

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

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

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

确保在Tiger-Line中选择阻止组作为要下载的图层类型,或者在下载形状文件时使用哪个站点。

© www.soinside.com 2019 - 2024. All rights reserved.