use of com.revolsys.record.io.format.esri.gdb.xml.model.enums.GeometryType in project com.revolsys.open by revolsys.
the class EsriXmlRecordDefinitionUtil method newDETable.
public static DETable newDETable(final RecordDefinition recordDefinition, final SpatialReference spatialReference, final boolean createLengthField, final boolean createAreaField) {
final String typePath = recordDefinition.getPath();
String schemaPath = PathUtil.getPath(typePath).replaceAll("/", "\\\\");
final FieldDefinition geometryField = recordDefinition.getGeometryField();
boolean hasGeometry = false;
DataType geometryDataType = null;
GeometryType shapeType = null;
if (geometryField != null) {
if (spatialReference == null) {
throw new IllegalArgumentException("A Geometry Factory with a coordinate system must be specified.");
}
geometryDataType = geometryField.getDataType();
if (FIELD_TYPES.getFieldType(geometryDataType) != null) {
hasGeometry = true;
// TODO Z,m
if (geometryDataType.equals(DataTypes.POINT)) {
shapeType = GeometryType.esriGeometryPoint;
} else if (geometryDataType.equals(DataTypes.MULTI_POINT)) {
shapeType = GeometryType.esriGeometryMultipoint;
} else if (geometryDataType.equals(DataTypes.LINE_STRING)) {
shapeType = GeometryType.esriGeometryPolyline;
} else if (geometryDataType.equals(DataTypes.LINEAR_RING)) {
shapeType = GeometryType.esriGeometryPolyline;
} else if (geometryDataType.equals(DataTypes.MULTI_LINE_STRING)) {
shapeType = GeometryType.esriGeometryPolyline;
} else if (geometryDataType.equals(DataTypes.POLYGON)) {
shapeType = GeometryType.esriGeometryPolygon;
} else if (geometryDataType.equals(DataTypes.MULTI_POLYGON)) {
shapeType = GeometryType.esriGeometryPolygon;
} else {
throw new IllegalArgumentException("Unable to detect geometry type");
}
}
}
final List<FieldDefinition> fieldDefinitions = new ArrayList<>(recordDefinition.getFields());
final String path = recordDefinition.getPath();
final String name = PathUtil.getName(path);
DETable table;
if (hasGeometry) {
final DEFeatureClass featureClass = new DEFeatureClass();
table = featureClass;
featureClass.setShapeType(shapeType);
final String geometryFieldName = geometryField.getName();
featureClass.setShapeFieldName(geometryFieldName);
final GeometryFactory geometryFactory = spatialReference.getGeometryFactory();
featureClass.setSpatialReference(spatialReference);
featureClass.setHasM(geometryFactory.hasM());
featureClass.setHasZ(geometryFactory.hasZ());
final EnvelopeN envelope = new EnvelopeN(spatialReference);
featureClass.setExtent(envelope);
final Class<?> geometryClass = geometryDataType.getJavaClass();
if (!Punctual.class.isAssignableFrom(geometryClass)) {
final LengthFieldName lengthFieldNameProperty = LengthFieldName.getProperty(recordDefinition);
String lengthFieldName = lengthFieldNameProperty.getFieldName();
if (createLengthField) {
if (!Property.hasValue(lengthFieldName)) {
lengthFieldName = geometryFieldName + "_Length";
lengthFieldNameProperty.setFieldName(lengthFieldName);
}
if (!recordDefinition.hasField(lengthFieldName)) {
fieldDefinitions.add(new FieldDefinition(lengthFieldName, DataTypes.DOUBLE, true));
}
}
featureClass.setLengthFieldName(lengthFieldName);
if (!Lineal.class.isAssignableFrom(geometryClass)) {
final AreaFieldName areaFieldNameProperty = AreaFieldName.getProperty(recordDefinition);
String areaFieldName = areaFieldNameProperty.getFieldName();
if (createAreaField) {
if (!Property.hasValue(areaFieldName)) {
areaFieldName = geometryFieldName + "_Area";
areaFieldNameProperty.setFieldName(areaFieldName);
}
if (!recordDefinition.hasField(areaFieldName)) {
fieldDefinitions.add(new FieldDefinition(areaFieldName, DataTypes.DOUBLE, true));
}
}
featureClass.setAreaFieldName(areaFieldName);
}
}
} else {
table = new DETable();
schemaPath = "\\";
}
String oidFieldName = recordDefinition.getProperty(EsriGeodatabaseXmlConstants.ESRI_OBJECT_ID_FIELD_NAME);
if (!Property.hasValue(oidFieldName)) {
oidFieldName = "OBJECTID";
}
final String catalogPath;
if (schemaPath.equals("\\")) {
catalogPath = "\\" + name;
} else {
catalogPath = schemaPath + "\\" + name;
}
table.setCatalogPath(catalogPath);
table.setName(name);
table.setHasOID(true);
table.setOIDFieldName(oidFieldName);
addObjectIdField(table);
final FieldDefinition idField = recordDefinition.getIdField();
for (final FieldDefinition fieldDefinition : fieldDefinitions) {
if (fieldDefinition == geometryField) {
addGeometryField(shapeType, table, fieldDefinition);
} else {
final String fieldName = fieldDefinition.getName();
if (!fieldName.equals(oidFieldName)) {
final Field field = addField(table, fieldDefinition);
if (idField == fieldDefinition) {
table.addIndex(field, true, fieldName + "_PK");
}
}
}
}
table.setAliasName(name);
return table;
}
use of com.revolsys.record.io.format.esri.gdb.xml.model.enums.GeometryType in project com.revolsys.open by revolsys.
the class EsriXmlRecordDefinitionUtil method addField.
private static void addField(final RecordDefinitionImpl recordDefinition, final DETable deTable, final String tableName, final Field field, final String fieldName) {
final FieldType fieldType = field.getType();
final int precision = field.getPrecision();
final DataType dataType;
if (fieldType == FieldType.esriFieldTypeGeometry && deTable instanceof DEFeatureClass) {
final DEFeatureClass featureClass = (DEFeatureClass) deTable;
final GeometryType shapeType = featureClass.getShapeType();
switch(shapeType) {
case esriGeometryPoint:
dataType = DataTypes.POINT;
break;
case esriGeometryMultipoint:
dataType = DataTypes.MULTI_POINT;
break;
case esriGeometryPolyline:
dataType = DataTypes.MULTI_LINE_STRING;
break;
case esriGeometryPolygon:
dataType = DataTypes.POLYGON;
break;
default:
throw new RuntimeException("Unknown geometry type" + shapeType + " for " + tableName + "." + fieldName);
}
} else if (precision > 0 && (fieldType.equals(FieldType.esriFieldTypeSingle) || fieldType.equals(FieldType.esriFieldTypeDouble))) {
dataType = DataTypes.DECIMAL;
} else {
dataType = EsriGeodatabaseXmlFieldTypeRegistry.INSTANCE.getDataType(fieldType);
}
final int scale = field.getScale();
int length = field.getLength();
if (precision != 0) {
length = precision;
}
final Boolean required = !field.isIsNullable() || Booleans.getBoolean(field.getRequired());
final FieldDefinition attribute = new FieldDefinition(fieldName, dataType, length, scale, required);
recordDefinition.addField(attribute);
if (fieldName.equals(tableName + "_ID")) {
recordDefinition.setIdFieldName(fieldName);
}
}
use of com.revolsys.record.io.format.esri.gdb.xml.model.enums.GeometryType in project com.revolsys.open by revolsys.
the class FeatureLayer method getGeometryDataType.
private DataType getGeometryDataType(final String geometryType) {
DataType geometryDataType = null;
if (Property.hasValue(geometryType)) {
final GeometryType esriGeometryType = GeometryType.valueOf(geometryType);
geometryDataType = esriGeometryType.getDataType();
if (geometryDataType == null) {
throw new IllegalArgumentException("Unsupported geometryType=" + geometryType + " for " + getServiceUrl());
}
}
return geometryDataType;
}
Aggregations