我是shapefile
加工的新手。请指导我如何实现以下查询。
我正在使用census.gov:TIGER-LINE中的shapefile tl_2018_us_aiannh.shp。我将根据用户提供的纬度和经度从shapefile获取人口普查区块组实体,如Block,Tract,County subdivision和County details。
我的要求是单独通过shapefile
而不是通过任何API实现这一点。
有人可以帮助我实现这个框架吗?
到目前为止我尝试/使用的内容:
GeoTools
来阅读shapefile
。我可以继续使用吗?我的要求是否可以通过这个工具实现?人口普查局分配代码,这些代码出现在“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作为值。
任何帮助都会有所帮助。
我找到了解决方案。希望这对有需要的人有所帮助。
SimpleFeature
是具有形状文件属性的类型,您可以在尝试在运行时调试或打印行时检查这些属性。您可以使用SimpleFeature
获取酒店。属性可以通过以下方式实现:
try {
while (iterator.hasNext()) {
SimpleFeature feature = iterator.next();
Property intptlat = feature.getProperty("TRACTCE");
}
}
确保在Tiger-Line
中选择阻止组作为要下载的图层类型,或者在下载形状文件时使用哪个站点。