[Gvsig_desarrolladores] Re: FNullGeometry
Francisco José Peñarrubia
fpenarru en gmail.com
Jue Jul 12 23:54:31 CEST 2007
Hola Angel.
Lo siento, pero a ese código le falta un pequeño detalle. Mira esta
modificación en addGeometry():
if(! (geom instanceof FNullGeometry)){
Rectangle2D boundsShp = geom.getBounds();
memShapeInfo.addShapeInfo (boundsShp, geom.getGeometryType());
arrayGeometries.add(geom);
if (fullExtent == null) {
fullExtent = boundsShp;
} else {
fullExtent.add(boundsShp);
}
}
else
{
Rectangle2D boundsShp = new Rectangle2D.Double();
memShapeInfo.addShapeInfo (boundsShp, geom.getGeometryType());
arrayGeometries.add(geom);
}
Es decir, SIEMPRE hay que añadir algo a la lista de geometrías. De otra
forma, si añades tres registros y el del medio es nulo, al seleccionar en la
tabla el 2 (el nulo), te seleccionaría la geometría 3. Con esto, la
selección también funcionará correctamente.
Saludos, y espero que se te de bien la lectura del proyecto.
PS: No pongas en edición esa capa, porque saltará un error. Si necesitas
ponerla en edición, avisanos y veremos qué se puede hacer.
Fran.
2007/7/12, Angel Rodriguez Fernandez <anxelin en hotmail.com>:
>
> Muchas gracias Álvaro, quedo arreglado.
>
> Lo de no enviar a la lista fue que le dí a reenviar sin más sin fijarme a
> quien se lo enviaba.
>
> Eso sí, la función "public void addGeometry(IGeometry geom, Object[] row)"
> que pones tiene una variable que no está definida (fieldWidth), yo lo
> arregle haciendo lo que dices al principio
>
> Un saludo
> Anxo
>
>
> ----- Original Message -----
> *From:* Alvaro Zabala <azabala en gmail.com>
> *To:* Lista de Desarrolladores de gvSIG<gvsig_desarrolladores en runas.cap.gva.es>
> *Sent:* Thursday, July 12, 2007 7:24 PM
> *Subject:* Re: [Gvsig_desarrolladores] Re: FNullGeometry
>
> Ultima corrección (cosas de las tardes de verano en visperas de vacaciones
> ;) )
>
> además de lo indicado en el correo anterior, hay que añadir los siguientes
> cambios a MemoryDriver para que todo funcione correctamente;
>
> public long getRowCount() throws DriverException {
> return m_TableModel.getRowCount();
> }
>
> Esto hace que la tabla te muestre el nº correcto de filas alfanuméricas
> (antes te incluia la geometria null, ahora no)
>
> public void addGeometry(IGeometry geom, Object[] row) {
> if (geom == null) {
> return; // No añadimos nada
> }
> if(! (geom instanceof FNullGeometry)){
> Rectangle2D boundsShp = geom.getBounds();
> memShapeInfo.addShapeInfo (boundsShp, geom.getGeometryType());
> arrayGeometries.add(geom);
> if (fullExtent == null) {
> fullExtent = boundsShp;
> } else {
> fullExtent.add(boundsShp);
> }
>
> }
> // Rectangle2D boundsShp = geom.getBounds();
> // memShapeInfo.addShapeInfo(boundsShp, geom.getGeometryType());
> // arrayGeometries.add(geom);
> if (fieldWidth==null) {
> initializeFieldWidth(row);
> }
> actualizeFieldWidth(row);
> m_TableModel.addRow(row);
>
> try {
> fullExtent = getFullExtent();
> } catch (IOException e) {
> e.printStackTrace();
> }
>
> m_Position++;
> }
>
>
> Y aquí un código de ejemplo de uso:
>
> public void execute(String actionCommand) {
> View v = (View) PluginServices.getMDIManager().getActiveWindow();
> MapControl mapCtrl = v.getMapControl();
>
>
> // DRIVER DEFINITION (SHAPE TYPE AND FIELDS)
> ConcreteMemoryDriver driver = new ConcreteMemoryDriver();
> driver.setShapeType(FShape.LINE);
>
> ArrayList arrayFields = new ArrayList();
> arrayFields.add("ID");
> Value[] auxRow = new Value[1];
>
> driver.getTableModel().setColumnIdentifiers(arrayFields.toArray());
>
>
> // GEOMETRY DEFINITION
> GeneralPathX gp = new GeneralPathX();
>
> gp.moveTo(20,80);
> gp.lineTo(80,60);
> gp.lineTo(100, 140);
>
> FShape shp = new FPolyline2D(gp);
>
>
> // ATRIBUTES
> auxRow[0] = ValueFactory.createValue(0);
> Value[] auxRow2 = new Value[1];
> auxRow2[0] = ValueFactory.createValue(1);
> FNullGeometry nula = new FNullGeometry();
>
> // ADD RECORD
> driver.addShape(shp, auxRow);
> driver.addGeometry(nula, auxRow2);
>
>
> // CREATE AND ADD LAYER
> FLayer lyr;
> String layerName = "Example";
> lyr = LayerFactory.createLayer (layerName,driver, mapCtrl.getProjection
> ());
>
> if (lyr != null) {
> lyr.setVisible(true);
> mapCtrl.getMapContext().getLayers().addLayer(lyr);
>
> }
>
>
> }
>
>
> Espero que ya sí funcione todo.
>
> Un saludo.
>
> ------------------------------
>
> _______________________________________________
> gvSIG_desarrolladores mailing list
> gvSIG_desarrolladores en runas.cap.gva.es
> http://runas.cap.gva.es/mailman/listinfo/gvsig_desarrolladores
>
>
> _______________________________________________
> gvSIG_desarrolladores mailing list
> gvSIG_desarrolladores en runas.cap.gva.es
> http://runas.cap.gva.es/mailman/listinfo/gvsig_desarrolladores
>
>
--
Francisco José Peñarrubia
Equipo gvSIG
IVER T.I. S.A.
------------ próxima parte ------------
Se ha borrado un adjunto en formato HTML...
URL: http://runas.cap.gva.es/pipermail/gvsig_desarrolladores/attachments/20070712/4ae61274/attachment.htm
Más información sobre la lista de distribución gvSIG_desarrolladores