use of com.revolsys.io.PathName in project com.revolsys.open by revolsys.
the class MapGuideWebServer method actionAddLayer.
private static void actionAddLayer(final FeatureLayer layerDescription) {
final Project project = Project.get();
if (project != null) {
LayerGroup layerGroup = project;
final PathName layerPath = layerDescription.getPathName();
for (final String groupName : layerPath.getParent().getElements()) {
layerGroup = layerGroup.addLayerGroup(groupName);
}
final MapGuideWebServerRecordLayer layer = new MapGuideWebServerRecordLayer(layerDescription);
layerGroup.addLayer(layer);
if (AbstractLayer.isShowNewLayerTableView()) {
layer.showTableView();
}
}
}
use of com.revolsys.io.PathName in project com.revolsys.open by revolsys.
the class FeatureLayer method initialize.
@Override
protected void initialize(final MapEx properties) {
super.initialize(properties);
this.boundingBox = ArcGisResponse.newBoundingBox(properties, "extent");
final PathName pathName = getPathName();
final List<MapEx> fields = properties.getValue("fields");
if (fields != null) {
final RecordDefinitionImpl newRecordDefinition = new RecordDefinitionImpl(pathName);
newRecordDefinition.setPolygonRingDirection(ClockDirection.CLOCKWISE);
final String description = properties.getString("description");
newRecordDefinition.setDescription(description);
final String geometryType = properties.getString("geometryType");
for (final MapEx field : fields) {
addField(newRecordDefinition, geometryType, field);
}
if (Property.hasValue(geometryType)) {
if (!newRecordDefinition.hasGeometryField()) {
final DataType geometryDataType = getGeometryDataType(geometryType);
if (geometryDataType == null) {
throw new IllegalArgumentException("No geometryType specified for " + getServiceUrl());
} else {
newRecordDefinition.addField("GEOMETRY", geometryDataType);
}
}
}
if (this.boundingBox != null) {
final GeometryFactory geometryFactory = this.boundingBox.getGeometryFactory();
newRecordDefinition.setGeometryFactory(geometryFactory);
}
final FieldDefinition objectIdField = newRecordDefinition.getField("OBJECTID");
if (newRecordDefinition.getIdField() == null && objectIdField != null) {
final int fieldIndex = objectIdField.getIndex();
newRecordDefinition.setIdFieldIndex(fieldIndex);
objectIdField.setRequired(true);
}
this.recordDefinition = newRecordDefinition;
}
}
use of com.revolsys.io.PathName in project com.revolsys.open by revolsys.
the class AbstractRecordReader method newRecordDefinition.
protected RecordDefinition newRecordDefinition(final String baseName, final List<String> fieldNames) throws IOException {
this.hasPointFields = Property.hasValue(this.pointXFieldName) && Property.hasValue(this.pointYFieldName);
if (this.hasPointFields) {
this.geometryType = DataTypes.POINT;
} else {
this.pointXFieldName = null;
this.pointYFieldName = null;
}
final List<FieldDefinition> fields = new ArrayList<>();
FieldDefinition geometryField = null;
for (final String fieldName : fieldNames) {
if (fieldName != null) {
DataType type;
int length = 0;
boolean isGeometryField = false;
if (fieldName.equalsIgnoreCase(this.geometryColumnName)) {
type = this.geometryType;
isGeometryField = true;
} else if ("GEOMETRY".equalsIgnoreCase(fieldName)) {
type = DataTypes.GEOMETRY;
isGeometryField = true;
} else if ("SHAPE".equalsIgnoreCase(fieldName)) {
type = DataTypes.GEOMETRY;
isGeometryField = true;
} else if ("GEOMETRYCOLLECTION".equalsIgnoreCase(fieldName) || "GEOMETRY_COLLECTION".equalsIgnoreCase(fieldName)) {
type = DataTypes.GEOMETRY_COLLECTION;
isGeometryField = true;
} else if ("POINT".equalsIgnoreCase(fieldName)) {
type = DataTypes.POINT;
isGeometryField = true;
} else if ("MULTI_POINT".equalsIgnoreCase(fieldName) || "MULTIPOINT".equalsIgnoreCase(fieldName)) {
type = DataTypes.MULTI_POINT;
isGeometryField = true;
} else if ("LINE_STRING".equalsIgnoreCase(fieldName) || "LINESTRING".equalsIgnoreCase(fieldName) || "LINE".equalsIgnoreCase(fieldName)) {
type = DataTypes.LINE_STRING;
isGeometryField = true;
} else if ("MULTI_LINESTRING".equalsIgnoreCase(fieldName) || "MULTILINESTRING".equalsIgnoreCase(fieldName) || "MULTILINE".equalsIgnoreCase(fieldName) || "MULTI_LINE".equalsIgnoreCase(fieldName)) {
type = DataTypes.MULTI_LINE_STRING;
isGeometryField = true;
} else if ("POLYGON".equalsIgnoreCase(fieldName)) {
type = DataTypes.POLYGON;
isGeometryField = true;
} else if ("MULTI_POLYGON".equalsIgnoreCase(fieldName) || "MULTIPOLYGON".equalsIgnoreCase(fieldName)) {
type = DataTypes.MULTI_POLYGON;
isGeometryField = true;
} else {
type = DataTypes.STRING;
length = 4000;
}
final FieldDefinition field;
if (isGeometryField) {
field = new GeometryFieldDefinition(this.geometryFactory, fieldName, type, false);
geometryField = field;
} else {
field = new FieldDefinition(fieldName, type, length, false);
}
fields.add(field);
}
}
if (this.hasPointFields) {
if (geometryField == null) {
geometryField = new FieldDefinition(this.geometryColumnName, this.geometryType, true);
fields.add(geometryField);
}
}
if (geometryField != null) {
geometryField.setProperty(FieldProperties.GEOMETRY_FACTORY, this.geometryFactory);
}
final RecordStoreSchema schema = getProperty("schema");
String typePath = getProperty("typePath");
if (!Property.hasValue(typePath)) {
typePath = "/" + baseName;
String schemaPath = getProperty("schemaPath");
if (Property.hasValue(schemaPath)) {
if (!schemaPath.startsWith("/")) {
schemaPath = "/" + schemaPath;
}
typePath = schemaPath + typePath;
}
}
final PathName pathName = PathName.newPathName(typePath);
this.recordDefinition = new RecordDefinitionImpl(schema, pathName, getProperties(), fields);
return this.recordDefinition;
}
use of com.revolsys.io.PathName in project com.revolsys.open by revolsys.
the class EsriXmlRecordDefinitionUtil method getRecordDefinition.
public static RecordDefinition getRecordDefinition(final String schemaName, final DETable deTable, final boolean ignoreEsriFields) {
final String tableName = deTable.getName();
final PathName typePath = PathName.newPathName(PathUtil.toPath(schemaName, tableName));
final RecordDefinitionImpl recordDefinition = new RecordDefinitionImpl(typePath);
final List<String> ignoreFieldNames = new ArrayList<>();
if (ignoreEsriFields) {
ignoreFieldNames.add(deTable.getOIDFieldName());
if (deTable instanceof DEFeatureClass) {
final DEFeatureClass featureClass = (DEFeatureClass) deTable;
ignoreFieldNames.add(featureClass.getLengthFieldName());
ignoreFieldNames.add(featureClass.getAreaFieldName());
}
}
for (final Field field : deTable.getFields()) {
final String fieldName = field.getName();
if (!ignoreFieldNames.contains(fieldName)) {
addField(recordDefinition, deTable, tableName, field, fieldName);
}
}
for (final Index index : deTable.getIndexes()) {
final String indexName = index.getName();
if (indexName.endsWith("_PK")) {
final List<Field> indexFields = index.getFields();
final Field indexField = CollectionUtil.get(indexFields, 0);
final String idName = indexField.getName();
recordDefinition.setIdFieldName(idName);
}
}
if (deTable instanceof DEFeatureClass) {
final DEFeatureClass featureClass = (DEFeatureClass) deTable;
final String shapeFieldName = featureClass.getShapeFieldName();
recordDefinition.setGeometryFieldName(shapeFieldName);
final SpatialReference spatialReference = featureClass.getSpatialReference();
GeometryFactory geometryFactory = spatialReference.getGeometryFactory();
int axisCount = 2;
if (featureClass.isHasM()) {
axisCount = 4;
} else if (featureClass.isHasZ()) {
axisCount = 3;
}
final double[] scales = geometryFactory.newScales(axisCount);
geometryFactory = GeometryFactory.fixed(geometryFactory.getCoordinateSystemId(), axisCount, scales);
final FieldDefinition geometryField = recordDefinition.getGeometryField();
geometryField.setProperty(FieldProperties.GEOMETRY_FACTORY, geometryFactory);
}
return recordDefinition;
}
use of com.revolsys.io.PathName in project com.revolsys.open by revolsys.
the class RecordStoreLayer method initializeDo.
@Override
protected boolean initializeDo() {
RecordStore recordStore = this.recordStore;
if (recordStore == null) {
final Map<String, String> connectionProperties = getProperty("connection");
if (connectionProperties == null) {
Logs.error(this, "A record store layer requires a connection entry with a name or url, username, and password: " + getPath());
return false;
} else {
final Map<String, Object> config = new HashMap<>();
config.put("connection", connectionProperties);
recordStore = RecordStoreConnectionManager.getRecordStore(config);
if (recordStore == null) {
Logs.error(this, "Unable to create record store for layer: " + getPath());
return false;
} else {
try {
recordStore.initialize();
} catch (final Throwable e) {
throw new RuntimeException("Unable to iniaitlize record store for layer " + getPath(), e);
}
setRecordStore(recordStore);
}
}
}
final PathName typePath = getPathName();
RecordDefinition recordDefinition = getRecordDefinition();
if (recordDefinition == null) {
recordDefinition = getRecordDefinition(typePath);
if (recordDefinition == null) {
Logs.error(this, "Cannot find table " + typePath + " for layer " + getPath());
return false;
} else {
final MapEx recordDefinitionProperties = getProperty("recordDefinitionProperties", MapEx.EMPTY);
recordDefinition.setProperties(recordDefinitionProperties);
setRecordDefinition(recordDefinition);
}
}
initRecordMenu();
return true;
}
Aggregations