use of ch.interlis.iom_j.Iom_jObject in project ili2db by claeis.
the class Fgdb2iox method readGeometry.
private IomObject readGeometry() throws IOException, ParseException, IoxException {
dis.setOrder(ByteOrderValues.LITTLE_ENDIAN);
int typeInt = dis.readInt();
int geometryType = typeInt & EsriShpConstants.shapeBasicTypeMask;
if (geometryType == EsriShpConstants.ShapeNull) {
return null;
}
// determine if Z values are present
hasZ = geometryType == EsriShpConstants.ShapePointZM || geometryType == EsriShpConstants.ShapePointZ || geometryType == EsriShpConstants.ShapeMultiPointZM || geometryType == EsriShpConstants.ShapeMultiPointZ || geometryType == EsriShpConstants.ShapePolylineZM || geometryType == EsriShpConstants.ShapePolylineZ || geometryType == EsriShpConstants.ShapePolygonZM || geometryType == EsriShpConstants.ShapePolygonZ || (geometryType == EsriShpConstants.ShapeGeneralPoint || geometryType == EsriShpConstants.ShapeGeneralPolyline || geometryType == EsriShpConstants.ShapeGeneralPolygon || geometryType == EsriShpConstants.ShapeGeneralMultiPoint || geometryType == EsriShpConstants.ShapeGeneralMultiPatch) && ((typeInt & EsriShpConstants.shapeHasZs) != 0);
boolean hasM = geometryType == EsriShpConstants.ShapePointZM || geometryType == EsriShpConstants.ShapePointM || geometryType == EsriShpConstants.ShapeMultiPointZM || geometryType == EsriShpConstants.ShapeMultiPointM || geometryType == EsriShpConstants.ShapePolylineZM || geometryType == EsriShpConstants.ShapePolylineM || geometryType == EsriShpConstants.ShapePolygonZM || geometryType == EsriShpConstants.ShapePolygonM || (geometryType == EsriShpConstants.ShapeGeneralPoint || geometryType == EsriShpConstants.ShapeGeneralPolyline || geometryType == EsriShpConstants.ShapeGeneralPolygon || geometryType == EsriShpConstants.ShapeGeneralMultiPoint || geometryType == EsriShpConstants.ShapeGeneralMultiPatch) && ((typeInt & EsriShpConstants.shapeHasMs) != 0);
boolean hasCurves = (geometryType == EsriShpConstants.ShapeGeneralPolyline || geometryType == EsriShpConstants.ShapeGeneralPolygon) && (typeInt & EsriShpConstants.shapeNonBasicModifierMask) != 0 || (typeInt & EsriShpConstants.shapeHasCurves) != 0;
inputDimension = hasZ ? 3 : 2;
// only allocate ordValues buffer if necessary
if (ordValues == null || ordValues.length < inputDimension)
ordValues = new double[inputDimension];
if (geometryType == EsriShpConstants.ShapePoint || geometryType == EsriShpConstants.ShapePointZM || geometryType == EsriShpConstants.ShapePointZ || geometryType == EsriShpConstants.ShapeGeneralPoint) {
double x = dis.readDouble();
double y = dis.readDouble();
IomObject ret = new ch.interlis.iom_j.Iom_jObject("COORD", null);
ret.setattrvalue("C1", Double.toString(x));
ret.setattrvalue("C2", Double.toString(y));
if (hasZ) {
double z = dis.readDouble();
ret.setattrvalue("C3", Double.toString(z));
}
return ret;
}
if (geometryType == EsriShpConstants.ShapeGeneralMultiPatch) {
throw new IoxException("unexpected geometryType " + geometryType);
}
// boundingBox
double min_x = dis.readDouble();
double min_y = dis.readDouble();
double max_x = dis.readDouble();
double max_y = dis.readDouble();
// cParts
int cParts = 0;
int[] partStart = null;
if (geometryType == EsriShpConstants.ShapeMultiPoint || geometryType == EsriShpConstants.ShapeMultiPointZM || geometryType == EsriShpConstants.ShapeMultiPointZ || geometryType == EsriShpConstants.ShapeGeneralMultiPoint) {
} else {
cParts = dis.readInt();
partStart = new int[cParts];
}
// cPoints
int cPoints = dis.readInt();
// parts[cParts]
if (cParts > 0) {
for (int i = 0; i < cParts; i++) {
partStart[i] = dis.readInt();
}
}
// points[cPoints]
Coordinate[] points = new Coordinate[cPoints];
for (int i = 0; i < cPoints; i++) {
points[i] = new Coordinate();
points[i].x = dis.readDouble();
points[i].y = dis.readDouble();
}
if (geometryType == EsriShpConstants.ShapeMultiPoint || geometryType == EsriShpConstants.ShapeMultiPointZM || geometryType == EsriShpConstants.ShapeMultiPointZ || geometryType == EsriShpConstants.ShapeGeneralMultiPoint) {
throw new IoxException("unexpected geometryType " + geometryType);
} else if (geometryType == EsriShpConstants.ShapePolyline || geometryType == EsriShpConstants.ShapePolylineZM || geometryType == EsriShpConstants.ShapePolylineZ || geometryType == EsriShpConstants.ShapeGeneralPolyline) {
} else if (geometryType == EsriShpConstants.ShapePolygon || geometryType == EsriShpConstants.ShapePolygonZM || geometryType == EsriShpConstants.ShapePolygonZ || geometryType == EsriShpConstants.ShapeGeneralPolygon) {
} else {
throw new IoxException("unexpected geometryType " + geometryType);
}
if (hasZ) {
double min_z = dis.readDouble();
double max_z = dis.readDouble();
// Zs[cPoints]
for (int i = 0; i < cPoints; i++) {
points[i].z = dis.readDouble();
}
}
if (hasM) {
double min_m = dis.readDouble();
double max_m = dis.readDouble();
// Ms[cPoints]
for (int i = 0; i < cPoints; i++) {
// ignore
dis.readDouble();
}
}
java.util.Map<Integer, Arc> arcs = null;
if (hasCurves) {
int cSegmentModifiers = dis.readInt();
arcs = new java.util.HashMap<Integer, Arc>();
for (int i = 0; i < cSegmentModifiers; i++) {
int startPointIndex = dis.readInt();
int segmentType = dis.readInt();
if (segmentType == EsriShpConstants.segmentArc) {
double v1 = dis.readDouble();
double v2 = dis.readDouble();
int bits = dis.readInt();
// int skip1=dis.readInt();
if ((bits & EsriShpConstants.arcIsEmpty) != 0) {
// skip it
} else if ((bits & EsriShpConstants.arcIsLine) != 0) {
// straight line, skip it
} else if ((bits & EsriShpConstants.arcIsPoint) != 0) {
throw new IoxException("not supported SegmentArc.Bits " + bits);
} else if ((bits & EsriShpConstants.arcDefinedIP) != 0) {
// throw new IoxException("not supported SegmentArc.Bits "+bits);
} else {
if ((bits & EsriShpConstants.arcIsCCW) != 0) {
// counterclockwise
} else {
// clockwise
}
}
// double skip1=dis.readDouble();
// double skip2=dis.readDouble();
// double skip3=dis.readDouble();
arcs.put(startPointIndex, new Arc(startPointIndex, v1, v2, bits));
} else if (segmentType == EsriShpConstants.segmentLine) {
// will never appear; should be ignored
} else if (segmentType == EsriShpConstants.segmentSpiral) {
} else if (segmentType == EsriShpConstants.segmentBezier3Curve) {
// two middle control points
double skip1 = dis.readDouble();
double skip2 = dis.readDouble();
double skip3 = dis.readDouble();
double skip4 = dis.readDouble();
} else if (segmentType == EsriShpConstants.segmentEllipticArc) {
// center
double skip1 = dis.readDouble();
double skip2 = dis.readDouble();
// rotation or fromV
double skip3 = dis.readDouble();
// semiMajor
double skip4 = dis.readDouble();
// minorMajorRatio or deltaV
double skip5 = dis.readDouble();
// bits
int skip6 = dis.readInt();
} else if (segmentType == 0) {
break;
} else {
throw new IoxException("unexpected segmentType " + segmentType);
// EhiLogger.traceState(("unexpected segmentType "+segmentType));
// continue;
}
}
}
JtsextGeometryFactory fact = new JtsextGeometryFactory();
if (geometryType == EsriShpConstants.ShapePolyline || geometryType == EsriShpConstants.ShapePolylineZM || geometryType == EsriShpConstants.ShapePolylineZ || geometryType == EsriShpConstants.ShapeGeneralPolyline) {
if (cParts == 1) {
LineString line = getPolyline(fact, 0, points, partStart, arcs, false);
IomObject ret;
try {
ret = Jtsext2iox.JTS2polyline(line);
} catch (Iox2jtsException e) {
throw new IoxException(e);
}
return ret;
}
IomObject ret = new Iom_jObject(Wkb2iox.OBJ_MULTIPOLYLINE, null);
for (int i = 0; i < cParts; i++) {
LineString line = getPolyline(fact, i, points, partStart, arcs, false);
try {
IomObject lineObj = Jtsext2iox.JTS2polyline(line);
ret.addattrobj(Wkb2iox.ATTR_POLYLINE, lineObj);
} catch (Iox2jtsException e) {
throw new IoxException(e);
}
}
return ret;
} else if (geometryType == EsriShpConstants.ShapePolygon || geometryType == EsriShpConstants.ShapePolygonZM || geometryType == EsriShpConstants.ShapePolygonZ || geometryType == EsriShpConstants.ShapeGeneralPolygon) {
if (cParts == 1) {
LineString line = getPolyline(fact, 0, points, partStart, arcs, true);
if (line.getCoordinateSequence().size() <= 3) {
throw new IoxException("Not a Ring");
}
Polygon polygon = fact.createCurvePolygon(fact.createRing(line));
IomObject ret;
try {
ret = Jtsext2iox.JTS2surface(polygon);
} catch (Iox2jtsException e) {
throw new IoxException(e);
}
return ret;
}
ArrayList<LineString> shells = new ArrayList<LineString>();
ArrayList<LineString> holes = new ArrayList<LineString>();
for (int i = 0; i < cParts; i++) {
LineString line = getPolyline(fact, i, points, partStart, arcs, true);
if (line.getCoordinateSequence().size() <= 3) {
throw new IoxException("Not a Ring");
}
if (CGAlgorithms.isCCW(line.getCoordinates())) {
holes.add(line);
} else {
shells.add(line);
}
}
if (shells.size() == 0) {
throw new IoxException("polygon without shell");
} else if (shells.size() == 1) {
LinearRing shell = fact.createRing(shells.get(0));
Polygon polygon = null;
if (holes.size() == 0) {
polygon = fact.createPolygon(shell);
} else {
LinearRing[] hole = new LinearRing[holes.size()];
int i = 0;
for (LineString line : holes) {
hole[i] = fact.createRing(line);
i++;
}
polygon = fact.createPolygon(shell, hole);
}
IomObject ret = null;
try {
ret = Jtsext2iox.JTS2surface(polygon);
} catch (Iox2jtsException e) {
throw new IoxException(e);
}
return ret;
} else {
// TODO MultiSurface
}
return null;
} else {
throw new IoxException("unexpected geometryType " + geometryType);
}
}
use of ch.interlis.iom_j.Iom_jObject in project ili2db by claeis.
the class ToXtfRecordConverter method addAttrValue.
public int addAttrValue(java.sql.ResultSet rs, int valuei, long sqlid, Iom_jObject iomObj, AttributeDef attr, ArrayList<StructWrapper> structQueue, ViewableWrapper table, FixIomObjectRefs fixref) throws SQLException {
if (attr.getExtending() == null) {
String attrName = attr.getName();
String sqlAttrName = ili2sqlName.mapIliAttributeDef(attr, table.getSqlTablename(), null);
if (attr.isDomainBoolean()) {
boolean value = rs.getBoolean(valuei);
valuei++;
if (!rs.wasNull()) {
if (value) {
iomObj.setattrvalue(attrName, "true");
} else {
iomObj.setattrvalue(attrName, "false");
}
}
} else if (attr.isDomainIli1Date()) {
java.sql.Date value = rs.getDate(valuei);
valuei++;
if (!rs.wasNull()) {
java.text.SimpleDateFormat fmt = new java.text.SimpleDateFormat("yyyyMMdd");
GregorianCalendar date = new GregorianCalendar();
date.setGregorianChange(PURE_GREGORIAN_CALENDAR);
fmt.setCalendar(date);
iomObj.setattrvalue(attrName, fmt.format(value));
}
} else if (attr.isDomainIli2Date()) {
java.sql.Date value = rs.getDate(valuei);
valuei++;
if (!rs.wasNull()) {
java.text.SimpleDateFormat fmt = new java.text.SimpleDateFormat("yyyy-MM-dd");
GregorianCalendar date = new GregorianCalendar();
date.setGregorianChange(PURE_GREGORIAN_CALENDAR);
fmt.setCalendar(date);
iomObj.setattrvalue(attrName, fmt.format(value));
}
} else if (attr.isDomainIli2Time()) {
java.sql.Time value = rs.getTime(valuei);
valuei++;
if (!rs.wasNull()) {
java.text.SimpleDateFormat fmt = new java.text.SimpleDateFormat("HH:mm:ss.SSS");
iomObj.setattrvalue(attrName, fmt.format(value));
}
} else if (attr.isDomainIli2DateTime()) {
java.sql.Timestamp value = rs.getTimestamp(valuei);
valuei++;
if (!rs.wasNull()) {
// with timezone: yyyy-MM-dd'T'HH:mm:ss.SSSZ
java.text.SimpleDateFormat fmt = new java.text.SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS");
GregorianCalendar date = new GregorianCalendar();
date.setGregorianChange(PURE_GREGORIAN_CALENDAR);
fmt.setCalendar(date);
iomObj.setattrvalue(attrName, fmt.format(value));
}
} else {
Type type = attr.getDomainResolvingAliases();
if (type instanceof CompositionType) {
if (TrafoConfigNames.CATALOGUE_REF_TRAFO_COALESCE.equals(trafoConfig.getAttrConfig(attr, TrafoConfigNames.CATALOGUE_REF_TRAFO))) {
Table catalogueReferenceTyp = ((CompositionType) type).getComponentType();
long value = rs.getLong(valuei);
valuei++;
if (!rs.wasNull()) {
IomObject catref = iomObj.addattrobj(attrName, catalogueReferenceTyp.getScopedName(null));
IomObject ref = catref.addattrobj(IliNames.CHBASE1_CATALOGUEREFERENCE_REFERENCE, "REF");
mapSqlid2Xtfid(fixref, value, ref, ((ReferenceType) ((AttributeDef) catalogueReferenceTyp.getAttributes().next()).getDomain()).getReferred());
}
} else if (TrafoConfigNames.MULTISURFACE_TRAFO_COALESCE.equals(trafoConfig.getAttrConfig(attr, TrafoConfigNames.MULTISURFACE_TRAFO))) {
MultiSurfaceMapping attrMapping = multiSurfaceAttrs.getMapping(attr);
Table multiSurfaceType = ((CompositionType) type).getComponentType();
Table surfaceStructureType = ((CompositionType) ((AttributeDef) multiSurfaceType.getElement(AttributeDef.class, attrMapping.getBagOfSurfacesAttrName())).getDomain()).getComponentType();
String multiSurfaceQname = multiSurfaceType.getScopedName(null);
String surfaceStructureQname = surfaceStructureType.getScopedName(null);
SurfaceType surface = ((SurfaceType) ((AttributeDef) surfaceStructureType.getElement(AttributeDef.class, attrMapping.getSurfaceAttrName())).getDomainResolvingAliases());
CoordType coord = (CoordType) surface.getControlPointDomain().getType();
boolean is3D = coord.getDimensions().length == 3;
Object geomobj = rs.getObject(valuei);
valuei++;
if (!rs.wasNull()) {
try {
IomObject iomMultiSurface = geomConv.toIomMultiSurface(geomobj, sqlAttrName, is3D);
IomObject iomChbaseMultiSurface = new Iom_jObject(multiSurfaceQname, null);
int surfacec = iomMultiSurface.getattrvaluecount("surface");
for (int surfacei = 0; surfacei < surfacec; surfacei++) {
IomObject iomSurface = iomMultiSurface.getattrobj("surface", surfacei);
IomObject iomChbaseSurfaceStructure = iomChbaseMultiSurface.addattrobj(attrMapping.getBagOfSurfacesAttrName(), surfaceStructureQname);
IomObject iomSurfaceClone = new ch.interlis.iom_j.Iom_jObject("MULTISURFACE", null);
iomSurfaceClone.addattrobj("surface", iomSurface);
iomChbaseSurfaceStructure.addattrobj(attrMapping.getSurfaceAttrName(), iomSurfaceClone);
}
iomObj.addattrobj(attrName, iomChbaseMultiSurface);
} catch (ConverterException ex) {
EhiLogger.logError("Object " + sqlid + ": failed to convert surface/area", ex);
}
}
} else if (TrafoConfigNames.MULTILINE_TRAFO_COALESCE.equals(trafoConfig.getAttrConfig(attr, TrafoConfigNames.MULTILINE_TRAFO))) {
MultiLineMapping attrMapping = multiLineAttrs.getMapping(attr);
Table multiLineType = ((CompositionType) type).getComponentType();
Table lineStructureType = ((CompositionType) ((AttributeDef) multiLineType.getElement(AttributeDef.class, attrMapping.getBagOfLinesAttrName())).getDomain()).getComponentType();
String multiLineQname = multiLineType.getScopedName(null);
String lineStructureQname = lineStructureType.getScopedName(null);
PolylineType surface = ((PolylineType) ((AttributeDef) lineStructureType.getElement(AttributeDef.class, attrMapping.getLineAttrName())).getDomainResolvingAliases());
CoordType coord = (CoordType) surface.getControlPointDomain().getType();
boolean is3D = coord.getDimensions().length == 3;
Object geomobj = rs.getObject(valuei);
valuei++;
if (!rs.wasNull()) {
try {
IomObject iomMultiPolygon = geomConv.toIomMultiPolyline(geomobj, sqlAttrName, is3D);
IomObject iomChbaseMultiLine = new Iom_jObject(multiLineQname, null);
int linec = iomMultiPolygon.getattrvaluecount(Wkb2iox.ATTR_POLYLINE);
for (int linei = 0; linei < linec; linei++) {
IomObject iomPolygon = iomMultiPolygon.getattrobj(Wkb2iox.ATTR_POLYLINE, linei);
IomObject iomChbaseSurfaceStructure = iomChbaseMultiLine.addattrobj(attrMapping.getBagOfLinesAttrName(), lineStructureQname);
iomChbaseSurfaceStructure.addattrobj(attrMapping.getLineAttrName(), iomPolygon);
}
iomObj.addattrobj(attrName, iomChbaseMultiLine);
} catch (ConverterException ex) {
EhiLogger.logError("Object " + sqlid + ": failed to convert polyline", ex);
}
}
} else if (TrafoConfigNames.MULTIPOINT_TRAFO_COALESCE.equals(trafoConfig.getAttrConfig(attr, TrafoConfigNames.MULTIPOINT_TRAFO))) {
MultiPointMapping attrMapping = multiPointAttrs.getMapping(attr);
Table multiPointType = ((CompositionType) type).getComponentType();
Table pointStructureType = ((CompositionType) ((AttributeDef) multiPointType.getElement(AttributeDef.class, attrMapping.getBagOfPointsAttrName())).getDomain()).getComponentType();
String multiPointQname = multiPointType.getScopedName(null);
String pointStructureQname = pointStructureType.getScopedName(null);
CoordType coord = ((CoordType) ((AttributeDef) pointStructureType.getElement(AttributeDef.class, attrMapping.getPointAttrName())).getDomainResolvingAliases());
boolean is3D = coord.getDimensions().length == 3;
Object geomobj = rs.getObject(valuei);
valuei++;
if (!rs.wasNull()) {
try {
IomObject iomMultiPoint = geomConv.toIomMultiCoord(geomobj, sqlAttrName, is3D);
IomObject iomChbaseMultiPoint = new Iom_jObject(multiPointQname, null);
int pointc = iomMultiPoint.getattrvaluecount(Wkb2iox.ATTR_COORD);
for (int pointi = 0; pointi < pointc; pointi++) {
IomObject iomPoint = iomMultiPoint.getattrobj(Wkb2iox.ATTR_COORD, pointi);
IomObject iomChbasePointStructure = iomChbaseMultiPoint.addattrobj(attrMapping.getBagOfPointsAttrName(), pointStructureQname);
iomChbasePointStructure.addattrobj(attrMapping.getPointAttrName(), iomPoint);
}
iomObj.addattrobj(attrName, iomChbaseMultiPoint);
} catch (ConverterException ex) {
EhiLogger.logError("Object " + sqlid + ": failed to convert coord", ex);
}
}
} else if (TrafoConfigNames.ARRAY_TRAFO_COALESCE.equals(trafoConfig.getAttrConfig(attr, TrafoConfigNames.ARRAY_TRAFO))) {
ArrayMapping attrMapping = arrayAttrs.getMapping(attr);
Object dbValue = rs.getObject(valuei);
valuei++;
if (!rs.wasNull()) {
try {
Table valueStructType = ((CompositionType) type).getComponentType();
String valueStructQname = valueStructType.getScopedName(null);
String[] iomArray = geomConv.toIomArray(attrMapping.getValueAttr(), dbValue, enumTypes);
for (int elei = 0; elei < iomArray.length; elei++) {
IomObject iomValueStruct = new Iom_jObject(valueStructQname, null);
iomValueStruct.setattrvalue(attrMapping.getValueAttr().getName(), iomArray[elei]);
iomObj.addattrobj(attrName, iomValueStruct);
}
} catch (ConverterException ex) {
EhiLogger.logError("Object " + sqlid + ": failed to convert array", ex);
}
}
} else if (TrafoConfigNames.MULTILINGUAL_TRAFO_EXPAND.equals(trafoConfig.getAttrConfig(attr, TrafoConfigNames.MULTILINGUAL_TRAFO))) {
IomObject iomMulti = null;
Table multilingualTextType = ((CompositionType) type).getComponentType();
String multilingualTextQname = multilingualTextType.getScopedName(null);
String localizedTextQname = ((CompositionType) ((AttributeDef) multilingualTextType.getAttributes().next()).getDomain()).getComponentType().getScopedName(null);
for (String sfx : DbNames.MULTILINGUAL_TXT_COL_SUFFIXS) {
String value = rs.getString(valuei);
valuei++;
if (!rs.wasNull()) {
if (iomMulti == null) {
iomMulti = new Iom_jObject(multilingualTextQname, null);
}
IomObject iomTxt = iomMulti.addattrobj(IliNames.CHBASE1_LOCALISEDTEXT, localizedTextQname);
iomTxt.setattrvalue(IliNames.CHBASE1_LOCALISEDTEXT_LANGUAGE, sfx.length() == 0 ? null : sfx.substring(LEN_LANG_PREFIX));
iomTxt.setattrvalue(IliNames.CHBASE1_LOCALISEDTEXT_TEXT, value);
}
}
if (iomMulti != null) {
iomObj.addattrobj(attrName, iomMulti);
}
} else {
// enque iomObj as parent
structQueue.add(new StructWrapper(sqlid, attr, iomObj, table));
}
} else if (type instanceof PolylineType) {
Object geomobj = rs.getObject(valuei);
valuei++;
if (!rs.wasNull()) {
try {
boolean is3D = ((CoordType) ((PolylineType) type).getControlPointDomain().getType()).getDimensions().length == 3;
IomObject polyline = geomConv.toIomPolyline(geomobj, sqlAttrName, is3D);
iomObj.addattrobj(attrName, polyline);
} catch (ConverterException ex) {
EhiLogger.logError("Object " + sqlid + ": failed to convert polyline", ex);
}
}
} else if (type instanceof SurfaceOrAreaType) {
if (createItfLineTables) {
} else {
Object geomobj = rs.getObject(valuei);
valuei++;
if (!rs.wasNull()) {
try {
boolean is3D = ((CoordType) ((SurfaceOrAreaType) type).getControlPointDomain().getType()).getDimensions().length == 3;
IomObject surface = geomConv.toIomSurface(geomobj, sqlAttrName, is3D);
iomObj.addattrobj(attrName, surface);
} catch (ConverterException ex) {
EhiLogger.logError("Object " + sqlid + ": failed to convert surface/area", ex);
}
}
}
if (createItfAreaRef) {
if (type instanceof AreaType) {
Object geomobj = rs.getObject(valuei);
valuei++;
if (!rs.wasNull()) {
try {
boolean is3D = false;
IomObject coord = geomConv.toIomCoord(geomobj, sqlAttrName, is3D);
iomObj.addattrobj(attrName, coord);
} catch (ConverterException ex) {
EhiLogger.logError("Object " + sqlid + ": failed to convert coord", ex);
}
}
}
}
} else if (type instanceof CoordType) {
Object geomobj = rs.getObject(valuei);
valuei++;
if (!rs.wasNull()) {
try {
boolean is3D = ((CoordType) type).getDimensions().length == 3;
IomObject coord = geomConv.toIomCoord(geomobj, sqlAttrName, is3D);
iomObj.addattrobj(attrName, coord);
} catch (ConverterException ex) {
EhiLogger.logError("Object " + sqlid + ": failed to convert coord", ex);
}
}
} else if (type instanceof EnumerationType) {
if (createEnumColAsItfCode) {
int value = rs.getInt(valuei);
valuei++;
if (!rs.wasNull()) {
iomObj.setattrvalue(attrName, mapItfCode2XtfCode((EnumerationType) type, value));
}
} else {
String value = rs.getString(valuei);
valuei++;
if (!rs.wasNull()) {
iomObj.setattrvalue(attrName, value);
}
}
} else if (type instanceof ReferenceType) {
ArrayList<ViewableWrapper> targetTables = getTargetTables(((ReferenceType) type).getReferred());
boolean refAlreadyDefined = false;
for (ViewableWrapper targetTable : targetTables) {
long value = rs.getLong(valuei);
valuei++;
if (!rs.wasNull()) {
if (refAlreadyDefined) {
sqlAttrName = ili2sqlName.mapIliAttributeDef(attr, table.getSqlTablename(), targetTable.getSqlTablename(), targetTables.size() > 1);
EhiLogger.logAdaption("Table " + table.getSqlTablename() + "(id " + sqlid + ") more than one value for refattr " + attrName + "; value of " + sqlAttrName + " ignored");
} else {
IomObject ref = iomObj.addattrobj(attrName, "REF");
mapSqlid2Xtfid(fixref, value, ref, ((ReferenceType) type).getReferred());
refAlreadyDefined = true;
}
}
}
} else if (type instanceof BlackboxType) {
if (((BlackboxType) type).getKind() == BlackboxType.eXML) {
Object obj = rs.getObject(valuei);
valuei++;
if (!rs.wasNull()) {
try {
iomObj.setattrvalue(attrName, geomConv.toIomXml(obj));
} catch (ConverterException ex) {
EhiLogger.logError("Object " + sqlid + ": failed to convert blackbox xml", ex);
}
}
} else {
Object obj = rs.getObject(valuei);
valuei++;
if (!rs.wasNull()) {
try {
iomObj.setattrvalue(attrName, geomConv.toIomBlob(obj));
} catch (ConverterException ex) {
EhiLogger.logError("Object " + sqlid + ": failed to convert blackbox binary", ex);
}
}
}
} else {
String value = rs.getString(valuei);
valuei++;
if (!rs.wasNull()) {
iomObj.setattrvalue(attrName, value);
}
}
}
}
return valuei;
}
use of ch.interlis.iom_j.Iom_jObject in project ili2db by claeis.
the class OracleColumnConverter method toIomPolyline.
@Override
public IomObject toIomPolyline(Object geomobj, String sqlAttrName, boolean is3D) throws java.sql.SQLException, ConverterException {
JGeometry geometry = JGeometry.load((oracle.sql.STRUCT) geomobj);
if (geometry.getType() != JGeometry.GTYPE_MULTICURVE) {
throw new ConverterException("unexpected GTYPE (" + OracleUtility.gtype2str(geometry.getType()) + ") in attribute " + sqlAttrName);
} else {
int dim = geometry.getDimensions();
boolean isCurrentValue3D = (dim == 3);
if (is3D != isCurrentValue3D) {
throw new ConverterException("unexpected dimension (" + Integer.toString(dim) + ") in attribute " + sqlAttrName);
} else {
int[] elev = geometry.getElemInfo();
double[] ordv = geometry.getOrdinatesArray();
final int SDO_STARTING_OFFSET = 0;
final int SDO_ETYPE = 1;
final int SDO_INTERPRETATION = 2;
final int NEXT_TRIPLET = 3;
final int COMPOUND_LINESTRING = 4;
final int LINESTRING = 2;
final int STRAIGHT = 1;
final int ARC = 2;
int elei = 0;
if (elev[elei + SDO_ETYPE] != COMPOUND_LINESTRING) {
throw new ConverterException("unexpected SDO_ETYPE (" + Integer.toString(elev[elei + SDO_ETYPE]) + ") in attribute " + sqlAttrName);
} else {
elei += NEXT_TRIPLET;
IomObject polylineValue = new Iom_jObject("POLYLINE", null);
// unclipped polyline, add one sequence
IomObject sequence = polylineValue.addattrobj("sequence", "SEGMENTS");
while (elei < elev.length) {
if (elev[elei + SDO_ETYPE] != LINESTRING) {
throw new ConverterException("unexpected SDO_ETYPE (" + Integer.toString(elev[elei + SDO_ETYPE]) + ") in attribute " + sqlAttrName);
} else {
if (elev[elei + SDO_INTERPRETATION] == STRAIGHT) {
int start = elev[elei + SDO_STARTING_OFFSET] - 1;
int end;
if (elei + NEXT_TRIPLET >= elev.length) {
end = ordv.length;
} else {
end = elev[elei + NEXT_TRIPLET + SDO_STARTING_OFFSET] - 1;
}
for (int i = start; i < end; ) {
// add control point
IomObject coordValue = sequence.addattrobj("segment", "COORD");
coordValue.setattrvalue("C1", Double.toString(ordv[i]));
coordValue.setattrvalue("C2", Double.toString(ordv[i + 1]));
if (isCurrentValue3D) {
coordValue.setattrvalue("C3", Double.toString(ordv[i + 2]));
i += 3;
} else {
i += 2;
}
}
} else if (elev[elei + SDO_INTERPRETATION] == ARC) {
int start = elev[elei + SDO_STARTING_OFFSET] - 1;
int end;
if (elei + NEXT_TRIPLET >= elev.length) {
end = ordv.length;
} else {
end = elev[elei + NEXT_TRIPLET + SDO_STARTING_OFFSET] - 1;
}
for (int i = start; i < end; ) {
// add control point
IomObject coordValue = sequence.addattrobj("segment", "ARC");
coordValue.setattrvalue("A1", Double.toString(ordv[i]));
coordValue.setattrvalue("A2", Double.toString(ordv[i + 1]));
if (isCurrentValue3D) {
// no A3 in XTF!
i += 3;
} else {
i += 2;
}
coordValue.setattrvalue("C1", Double.toString(ordv[i]));
coordValue.setattrvalue("C2", Double.toString(ordv[i + 1]));
if (isCurrentValue3D) {
coordValue.setattrvalue("C3", Double.toString(ordv[i + 2]));
i += 3;
} else {
i += 2;
}
}
} else {
throw new ConverterException("unexpected SDO_INTERPRETATION (" + Integer.toString(elev[elei + SDO_INTERPRETATION]) + ") in attribute " + sqlAttrName);
}
}
elei += NEXT_TRIPLET;
}
return polylineValue;
}
}
}
}
use of ch.interlis.iom_j.Iom_jObject in project ili2db by claeis.
the class TransferToXtf method dumpObjHelper.
/**
* helper to dump all objects/structvalues of a given class/structure.
*/
private void dumpObjHelper(IoxWriter out, Viewable aclass, Long basketSqlId, FixIomObjectRefs fixref, StructWrapper structWrapper, HashMap<String, IomObject> structelev) {
String stmt = recConv.createQueryStmt(aclass, basketSqlId, structWrapper);
EhiLogger.traceBackendCmd(stmt);
java.sql.PreparedStatement dbstmt = null;
try {
dbstmt = conn.prepareStatement(stmt);
recConv.setStmtParams(dbstmt, basketSqlId, fixref, structWrapper);
java.sql.ResultSet rs = dbstmt.executeQuery();
while (rs.next()) {
// list of not yet processed struct attrs
ArrayList<StructWrapper> structQueue = new ArrayList<StructWrapper>();
long sqlid = recConv.getT_ID(rs);
Iom_jObject iomObj = null;
if (structWrapper == null) {
fixref = new FixIomObjectRefs();
}
iomObj = recConv.convertRecord(rs, aclass, fixref, structWrapper, structelev, structQueue, sqlid);
updateObjStat(iomObj.getobjecttag(), sqlid);
// collect structvalues
while (!structQueue.isEmpty()) {
StructWrapper wrapper = (StructWrapper) structQueue.remove(0);
dumpStructs(wrapper, fixref);
}
if (structWrapper == null) {
if (!fixref.needsFixing() || out instanceof ItfWriter) {
// no forward references
// write object
ObjectEvent objEvent = new ObjectEvent(iomObj);
if (languageFilter != null) {
objEvent = (ObjectEvent) languageFilter.filter(objEvent);
}
if (exportBaseModelFilter != null) {
objEvent = (ObjectEvent) exportBaseModelFilter.filter(objEvent);
}
if (objEvent != null) {
if (validator != null)
validator.validate(objEvent);
if (out != null) {
out.write(objEvent);
}
}
} else {
delayedObjects.add(fixref);
}
}
}
// while rs
} catch (java.sql.SQLException ex) {
EhiLogger.logError("failed to query " + aclass.getScopedName(null), ex);
} catch (ch.interlis.iox.IoxException ex) {
EhiLogger.logError("failed to write " + aclass.getScopedName(null), ex);
} finally {
if (dbstmt != null) {
try {
dbstmt.close();
} catch (java.sql.SQLException ex) {
EhiLogger.logError("failed to close query of " + aclass.getScopedName(null), ex);
}
}
}
}
use of ch.interlis.iom_j.Iom_jObject in project ili2db by claeis.
the class TransferToXtf method dumpItfTableObject.
private void dumpItfTableObject(IoxWriter out, AttributeDef attr, Long basketSqlId) {
String stmt = createItfLineTableQueryStmt(attr, basketSqlId, geomConv);
String sqlTabName = ili2sqlName.mapGeometryAsTable(attr);
EhiLogger.traceBackendCmd(stmt);
SurfaceOrAreaType type = (SurfaceOrAreaType) attr.getDomainResolvingAliases();
String geomAttrName = ch.interlis.iom_j.itf.ModelUtilities.getHelperTableGeomAttrName(attr);
String refAttrName = null;
if (type instanceof SurfaceType) {
refAttrName = ch.interlis.iom_j.itf.ModelUtilities.getHelperTableMainTableRef(attr);
}
java.sql.PreparedStatement dbstmt = null;
try {
dbstmt = conn.prepareStatement(stmt);
dbstmt.clearParameters();
int paramIdx = 1;
if (basketSqlId != null) {
dbstmt.setLong(paramIdx++, basketSqlId);
}
java.sql.ResultSet rs = dbstmt.executeQuery();
while (rs.next()) {
int valuei = 1;
long sqlid = rs.getLong(valuei);
valuei++;
String sqlIliTid = null;
if (writeIliTid) {
sqlIliTid = rs.getString(valuei);
valuei++;
} else {
sqlIliTid = Long.toString(sqlid);
}
Viewable aclass = (Viewable) attr.getContainer();
Iom_jObject iomObj;
iomObj = new Iom_jObject(aclass.getScopedName(null) + "_" + attr.getName(), sqlIliTid);
// geomAttr
Object geomobj = rs.getObject(valuei);
valuei++;
if (!rs.wasNull()) {
try {
boolean is3D = false;
IomObject polyline = geomConv.toIomPolyline(geomobj, ili2sqlName.getSqlColNameItfLineTableGeomAttr(attr, sqlTabName), is3D);
iomObj.addattrobj(geomAttrName, polyline);
} catch (ConverterException ex) {
EhiLogger.logError("Object " + sqlid + ": failed to convert polyline", ex);
}
}
// is of type SURFACE?
if (type instanceof SurfaceType) {
// -> mainTable
IomObject ref = iomObj.addattrobj(refAttrName, "REF");
long refSqlId = rs.getLong(valuei);
if (sqlidPool.containsSqlid(refSqlId)) {
String refTid = sqlidPool.getXtfid(refSqlId);
ref.setobjectrefoid(refTid);
} else {
EhiLogger.logError("unknown referenced object " + attr.getContainer().getScopedName(null) + " sqlid " + refSqlId + " referenced from " + sqlTabName + " " + colT_ID + " " + sqlid);
}
valuei++;
}
Table lineAttrTable = type.getLineAttributeStructure();
if (lineAttrTable != null) {
Iterator attri = lineAttrTable.getAttributes();
while (attri.hasNext()) {
AttributeDef lineattr = (AttributeDef) attri.next();
valuei = recConv.addAttrValue(rs, valuei, sqlid, iomObj, lineattr, null, class2wrapper.get(lineAttrTable), null);
}
}
if (out != null) {
// write object
ObjectEvent objEvent = new ObjectEvent(iomObj);
if (languageFilter != null) {
objEvent = (ObjectEvent) languageFilter.filter(objEvent);
}
if (exportBaseModelFilter != null) {
objEvent = (ObjectEvent) exportBaseModelFilter.filter(objEvent);
}
if (validator != null)
validator.validate(objEvent);
out.write(objEvent);
}
}
} catch (java.sql.SQLException ex) {
EhiLogger.logError("failed to query " + attr.getScopedName(null), ex);
} catch (ch.interlis.iox.IoxException ex) {
EhiLogger.logError("failed to write " + attr.getScopedName(null), ex);
} finally {
if (dbstmt != null) {
try {
dbstmt.close();
} catch (java.sql.SQLException ex) {
EhiLogger.logError("failed to close query of " + attr.getScopedName(null), ex);
}
}
}
}
Aggregations