我是shapefile
处理新手。请指导我如何实现以下查询。
我正在使用来自census.gov 的这个 shapefile tl_2018_us_aiannh.shp :TIGER-LINE。我要根据用户提供的经纬度从 shapefile中获取人口普查区块组实体,如Block、Tract、County subdivision和County详细信息。
我的要求是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 作为值。
任何帮助都会很有帮助。