use of net.geoprism.registry.etl.ShapefileFormatException in project geoprism-registry by terraframe.
the class ShapefileService method getSheetInformation.
private JSONObject getSheetInformation(File dbf) {
try {
ShapefileDataStore store = new ShapefileDataStore(dbf.toURI().toURL());
try {
String[] typeNames = store.getTypeNames();
if (typeNames.length > 0) {
String typeName = typeNames[0];
FeatureSource<SimpleFeatureType, SimpleFeature> source = store.getFeatureSource(typeName);
SimpleFeatureType schema = source.getSchema();
List<AttributeDescriptor> descriptors = schema.getAttributeDescriptors();
JSONObject attributes = new JSONObject();
attributes.put(AttributeBooleanType.TYPE, new JSONArray());
attributes.put(GeoObjectImportConfiguration.TEXT, new JSONArray());
attributes.put(GeoObjectImportConfiguration.NUMERIC, new JSONArray());
attributes.put(AttributeDateType.TYPE, new JSONArray());
for (AttributeDescriptor descriptor : descriptors) {
if (!(descriptor instanceof GeometryDescriptor)) {
String name = descriptor.getName().getLocalPart();
String baseType = GeoObjectImportConfiguration.getBaseType(descriptor.getType());
attributes.getJSONArray(baseType).put(name);
if (baseType.equals(GeoObjectImportConfiguration.NUMERIC)) {
attributes.getJSONArray(GeoObjectImportConfiguration.TEXT).put(name);
}
}
}
JSONObject sheet = new JSONObject();
sheet.put("name", typeName);
sheet.put("attributes", attributes);
return sheet;
} else {
// TODO Change exception type
throw new ProgrammingErrorException("Shapefile does not contain any types");
}
} finally {
store.dispose();
}
} catch (RuntimeException e) {
Throwable cause = e.getCause();
if (cause instanceof IOException) {
throw new ShapefileFormatException(e);
}
throw e;
} catch (Exception e) {
throw new ProgrammingErrorException(e);
}
}
Aggregations