Hola Sergio y gracias por la respuesta.
En los últimos dias he estado mirando el codigo fuente del driver de
postgis con el fin de realizar una versión para JASPA.
He encontrado que kosmo da error a la hora de escribir en una capa 3d en
postgis ya sea al actualizar o insertar una geometria. Os anexo algún
pequeño cambio que hace posible el soporte de escritura en capas postgis
3d (claro esta que los nuevos elementos tendran cota 0 pero al menos no
da error y conserva las cotas previas).
@Override
protected String getSQLForInsert( Feature feature ) throws
TopologyException {
String selInsert = "INSERT INTO " + getFullTableName() + " ("
//$NON-NLS-1$ //$NON-NLS-2$
+ getBasicSQLInsert(feature) + " )values("; //$NON-NLS-1$
int coordDim = 2;
if (is3d) {
coordDim = 3;
}
WKTWriter geometryWriter = new WKTWriter(coordDim);
for( int i = 0; i < schema.getAttributeCount(); i++ ) {
Attribute attr = schema.getAttribute(i);
if (attr instanceof AttributeCalculate)
continue;
if (i == schema.getGeometryIndex()) {
Geometry geom = (Geometry) feature.getAttribute(i);
if (geom == null) {
// Creamos una geometria vacia
geom = new GeometryFactory().buildGeometry(new
ArrayList());
}
String wktGeometry = "GeometryFromText('" //$NON-NLS-1$
+ geometryWriter.write(geom) + "'," + srid + ")";
//$NON-NLS-1$ //$NON-NLS-2$
//jomarlla: bug can not write in a 3d table
if (is3d()) wktGeometry = "ST_Force_3D (" + wktGeometry
+ ")";
selInsert += (wktGeometry + ","); //$NON-NLS-1$
continue;
}
selInsert += ("?" + ","); //$NON-NLS-1$ //$NON-NLS-2$
} // for
selInsert = selInsert.substring(0, selInsert.length() - 1);
selInsert += ")"; //$NON-NLS-1$
return selInsert;
}
@Override
protected String getSQLForUpdate( Feature feature ) {
String selInsert = "UPDATE " + getFullTableName() + " SET ";
//$NON-NLS-1$ //$NON-NLS-2$
int geometryIndex = schema.getGeometryIndex();
//WKTWriter geometryWriter = new WKTWriter();
//jomarlla: support to write wkt in 3 dimensions too
WKTWriter geometryWriter = null;
if (is3d()) geometryWriter = new WKTWriter(3);
else geometryWriter = new WKTWriter(2);
for( int i = 0; i < schema.getAttributeCount(); i++ ) {
Attribute attr = schema.getAttribute(i);
if (attr instanceof AttributeCalculate)
continue;
if (i == geometryIndex) {
Geometry geom = (Geometry) feature.getAttribute(i);
if (geom == null) {
// Creamos una geometria vacia
geom = new GeometryFactory().buildGeometry(new
ArrayList());
}
String wktGeometry = "GeometryFromText('" //$NON-NLS-1$
+ geometryWriter.write(geom) + "'," + srid + ")";
//$NON-NLS-1$ //$NON-NLS-2$
//jomarlla: bug can not write in a 3d table
//Anyways..the z values are changed to 0
if (is3d()) wktGeometry = "ST_Force_3D (" + wktGeometry
+ ")";
selInsert += ("\"" + attr.getName() + "\"=" +
wktGeometry + ","); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
} else {
selInsert += "\"" + attr.getName() + "\"=?,";
//$NON-NLS-1$ //$NON-NLS-2$
}
} // for
selInsert = selInsert.substring(0, selInsert.length() - 1);
selInsert += " where "; //$NON-NLS-1$
selInsert += "\"" + schema.getPrimaryKeyName() + "\" = '"
//$NON-NLS-1$ //$NON-NLS-2$
+
feature.getAttribute(schema.getPrimaryKeyIndex()).toString() + "'";
//$NON-NLS-1$
return selInsert;
}
A parte de estos cambios he cambiado el driver para que funcione con
jaspa (aunque la idea es realizar un driver nuevo), todo bien salvo una
función que bajo mi opinión es un poco rara y origina problemas en
jaspa. Mi pregunta es Por qué se utiliza (typeName.equals("geometry")
para saber si el campo es de tipo geometría? No se podría utilziar la
información de la capa cargada (donde previamente se ha mirado en
geometry_columns cual es la columna de geometria?)...el comparar el
typeName puede orignar problemas en postgis y además en jaspa no funciona.
protected AttributeType buildAttributeType( ResultSet rs ) throws
IOException {
final int DATA_TYPE = 5;
final int TYPE_NAME = 6;
try {
int dataType = rs.getInt(DATA_TYPE);
String typeName = rs.getString(TYPE_NAME);
if (typeName.equals("geometry")) { //$NON-NLS-1$
return AttributeType.toAttributeType(Geometry.class);
} else {
Class type = (Class) TYPE_MAPPINGS.get(new
Integer(dataType));
if (type == null) {
return AttributeType.OBJECT;
} else {
return AttributeType.toAttributeType(type);
}
}
} catch (SQLException e) {
throw new
IOException(I18N.getString("org.saig.core.dao.datasource.dbdatasource.PostGisDataSource.sql-exception-ocurred")
+ " " + e.getMessage()); //$NON-NLS-1$ //$NON-NLS-2$
}
}
Bueno gracias y enohorabuena por el proyecto.
José Carlos
El 04/11/2010 12:28, Sergio Baños Calvo escribió:
Buenos días José Carlos.
En realidad la versión 2.0 estable está casi terminada desde el pasado
agosto, solo que debido a la falta de un tiempo disponible para
terminar de generar la documentación necesaria y publicar la misma no
la hemos hecho disponible (de hecho, en el LiveDVD del pasado FOSS4G
2010 de Barcelona está incluida una versión de Kosmo Desktop 2.0 casi
definitiva).
Esperamos hacerla disponible lo antes posible a lo largo de este mes.
Saludos,
El 03/11/2010 10:42, Jose C. Martinez-Llario escribió:
Hola a todos,
Quiero programar un driver nuevo para la base de datos JASPA en Kosmo y
me gustaría saber el estado del desarrollo de Kosmo, va a haber una
nueva versión o una versión estable próximamente?
Muchas gracias y un saludo,
José Carlos
_______________________________________________
Kosmo mailing list
[email protected]
http://lists.saig.es/mailman/listinfo/kosmo
--
Sergio Baños Calvo
Jefe de desarrollos
Sistemas Abiertos de Información Geográfica, S.L. (SAIG S.L.)
Tlfno. móvil: 685005960
Tlfno. fijo: (+34) 954788876
E-mail: [email protected]
_______________________________________________
Kosmo mailing list
[email protected]
http://lists.saig.es/mailman/listinfo/kosmo
_______________________________________________
Kosmo mailing list
[email protected]
http://lists.saig.es/mailman/listinfo/kosmo