* @return
* @throws IOException
*/
SimpleFeatureType getFeatureType(Pointer layer, String typeName, String namespaceURI)
throws IOException {
Pointer definition = null;
try {
// setup the builder
SimpleFeatureTypeBuilder tb = new SimpleFeatureTypeBuilder();
tb.setName(typeName);
tb.setNamespaceURI(namespaceURI);
if (tb.getNamespaceURI() == null) {
tb.setNamespaceURI(BasicFeatureTypes.DEFAULT_NAMESPACE);
}
// grab the layer definition
definition = OGR_L_GetLayerDefn(layer);
// figure out the geometry
Class<? extends Geometry> geometryBinding = getGeometryBinding(definition);
if (geometryBinding != null) {
CoordinateReferenceSystem crs = getCRS(layer);
tb.add("the_geom", geometryBinding, crs);
}
// get the non geometric fields
final int count = OGR_FD_GetFieldCount(definition);
for (int i = 0; i < count; i++) {
Pointer field = OGR_FD_GetFieldDefn(definition, i);
String name = OGR_Fld_GetNameRef(field).getCString();
Class binding = getBinding(field);
int width = OGR_Fld_GetWidth(field);
if (width > 0) {
tb.length(width);