Revision 2158

View differences:

branches/gvSIG_03_SLD/applications/appgvSIG/text.properties
329 329
Recuperar_y_eliminar_otros_zoom=Recuperar y eliminar otros zooms
330 330
refrescar=Refrescar
331 331
registros=registros
332
registros_seleccionados_total=Registros (Seleccionados/Total)
332 333
rellenar_marco_vista=Rellenar marco de la vista
333 334
relleno=Relleno:
334 335
renombrar=Renombrar
branches/gvSIG_03_SLD/applications/appgvSIG/text_ca.properties
329 329
Recuperar_y_eliminar_otros_zoom=Recuperar i eliminar altres zooms
330 330
refrescar=Refrescar
331 331
registros=registres
332
registros_seleccionados_total=Registres (Seleccionats/Tots)
332 333
rellenar_marco_vista=Reomplir marc de la vista
333 334
relleno=Farciment:
334 335
renombrar=Renomenar
branches/gvSIG_03_SLD/applications/appgvSIG/src/com/iver/cit/gvsig/gui/toc/FPopupMenu.java
141 141
	}
142 142
}
143 143

  
144
/*class FLyrVectChangeStyleTocMenuEntry extends TocMenuEntry {
145
    private JMenuItem estilo;
146
	public void initialize(FPopupMenu m) {
147
		super.initialize(m);
148
		FLayer lyr = null;
149
		
150
		if (isTocItemBranch()) {
151
			lyr = getNodeLayer();
152
			if (lyr instanceof ClassifiableVectorial) {
153
		    	estilo = new JMenuItem(PluginServices.getText(this, "Cambio_Estilo"));
154
				getMenu().add(estilo);
155
				estilo.setFont(FPopupMenu.theFont);
156
				//Cambio estilo
157
				estilo.addActionListener(this);
158
			}
159
		}
160
	}
161
	
162
	public void actionPerformed(ActionEvent e) {
163
		FThemeManagerWindow m_LegendEditor = new FThemeManagerWindow();
164
		try {
165
			m_LegendEditor.setMapContext(getMapContext());
166
		} catch (com.iver.cit.gvsig.fmap.DriverException e1) {
167
			e1.printStackTrace();
168
		}
169
		if (PluginServices.getMainFrame() == null) {
170
			JDialog dlg = new JDialog();
171
			    							
172
			m_LegendEditor.setPreferredSize(m_LegendEditor.getSize());
173
			dlg.getContentPane().add(m_LegendEditor);
174
			dlg.setModal(false);			
175
			dlg.pack();
176
			dlg.show();
177
			
178
		} else
179
			PluginServices.getMDIManager().addView(m_LegendEditor);
180
	}
181
}
182
*/
183 144
/**
184 145
 * Muestra el men? de propiedades del tema.
185 146
 * 
......
435 396
					for (int i=0;i<actives.length;i++){
436 397
						actives[i].getParentLayer().removeLayer(actives[i]);
437 398
						layerGroup.addLayer(actives[i]);
438
						
439
						///removeLayer(actives[i]);
440
						
441 399
					}
442 400
					layerGroup.setName(nombre);
443
					//getNodeLayer().getParentLayer().addLayer(layerGroup);
444 401
					View theView = (View) PluginServices.getMDIManager().getActiveView();
445 402
					theView.getMapControl().getMapContext().getLayers()
446 403
					   .addLayer(layerGroup);        
......
448 405
	    		}
449 406
				
450 407
			}
451
			/*else
452
			{
453
    	        TocItemLeaf leaf = (TocItemLeaf) tocItem;
454
    	        FSymbol sym = leaf.getSymbol();
455
    	        sym.setColor(newColor);
456
    	        			    
457
			}*/
458
	        // TRUCO PARA REFRESCAR.
408
			// TRUCO PARA REFRESCAR.
459 409
	        getMapContext().invalidate();                    
460 410

  
461 411
        }
......
477 427
			if (!(lyr instanceof FLayers)){
478 428
				isFLayers=false;
479 429
			}
480
		/*	for (int i=0;i<actives.length;i++){
481
				if (!(actives[i] instanceof FLayers)){
482
					isFLayers=false;
483
				}
484
			}
485
		*/
486 430
		}
487 431
		if (isFLayers){
488 432
			desagrupar = new JMenuItem(PluginServices.getText(this, "desagrupar_capas"));
......
507 451
					}
508 452
					parent.removeLayer(agrupa);
509 453
				}
510
			
511
					/*View theView = (View) PluginServices.getMDIManager().getActiveView();
512
					theView.getMapControl().getMapContext().getLayers()
513
					   .addLayer(layerGroup);        
514
	    		*/
515
	    		
516 454
			}
517
			/*else
518
			{
519
    	        TocItemLeaf leaf = (TocItemLeaf) tocItem;
520
    	        FSymbol sym = leaf.getSymbol();
521
    	        sym.setColor(newColor);
522
    	        			    
523
			}*/
524 455
	        // TRUCO PARA REFRESCAR.
525 456
	        getMapContext().invalidate();                    
526 457

  
527 458
        }
528 459
    
529 460
}
530

  
531 461
/**
462
 * Cambia la posici?n actual del layer a la primera posici?n.
463
 * 
464
 * @author Vicente Caballero Navarro
465
 */
466
class FirstLayerTocMenuEntry extends TocMenuEntry {
467
    private JMenuItem first;    
468
	public void initialize(FPopupMenu m) {
469
		super.initialize(m);
470
	    	first = new JMenuItem(PluginServices.getText(this, "colocar_delante"));
471
        	first.setFont(FPopupMenu.theFont);
472
        	getMenu().add(first);        
473
        	getMenu().setEnabled(true);
474
	        first.addActionListener(this);
475
	}
476
	
477
	/* (non-Javadoc)
478
	 * @see com.iver.cit.gvsig.gui.toc.TocMenuEntry#execute(com.iver.cit.gvsig.gui.toc.ITocItem)
479
	 */
480
	public void actionPerformed(ActionEvent e) {
481
		ITocItem tocItem = (ITocItem) getNodeUserObject();
482
      
483
      	if (isTocItemBranch()){
484
				FLayer layer=((TocItemBranch)tocItem).getLayer();
485
				FLayers layers=layer.getParentLayer();
486
				for (int i=0;i<layers.getLayersCount();i++){
487
					if(layers.getLayer(i).equals(layer)){
488
						layers.removeLayer(i);
489
						layers.addLayer(layer);
490
					}
491
				}
492
				
493
				
494
			}
495
			// TRUCO PARA REFRESCAR.
496
	        getMapContext().invalidate();                    
497
        
498
	}
499
}
500
/**
532 501
 * Menu de bot?n derecho para el TOC.
533 502
 * Se pueden a?adir entradas facilmente desde una extensi?n,
534 503
 * creando una clase derivando de TocMenuEntry, y a?adiendola en
......
558 527
    	menuEntrys.add(new EliminarCapaTocMenuEntry());
559 528
		menuEntrys.add(new LayersGroupTocMenuEntry());
560 529
		menuEntrys.add(new LayersUngroupTocMenuEntry());
530
		menuEntrys.add(new FirstLayerTocMenuEntry());
561 531
    }
562 532

  
563 533
    public static void addEntry(TocMenuEntry entry) {
branches/gvSIG_03_SLD/applications/appgvSIG/src/com/iver/cit/gvsig/gui/Table.java
89 89
    private boolean updating = false;
90 90
    
91 91
    private TableSelectionListener selectionListener = new TableSelectionListener();
92
    
92
    private long numReg=0;
93 93
    /**
94 94
     * This is the default constructor
95 95
     */
......
132 132
	        model.getModelo().addSelectionListener(selectionListener);
133 133
	        
134 134
	        updateSelection();
135
	
136
	        jLabelStatus.setText(" " + dataSource.getRowCount() + " " +
137
	            PluginServices.getText(this, "registros") + ".");
135
			numReg=dataSource.getRowCount();
136
	        jLabelStatus.setText(" " + dataSource.getSelection().cardinality() + " / " + numReg +" "+
137
	            PluginServices.getText(this, "registros_seleccionados_total") + ".");
138 138
    	}catch (DriverException e){
139 139
    		NotificationManager.addError("No se pudo leer la informaci?n", e);
140 140
    	}
......
231 231
                        	if (fmap != null)
232 232
                        	fmap.beginAtomicEvent();
233 233
                        }
234
						jLabelStatus.setText(" " + selection.cardinality() + " / " + numReg + " " +
235
					            PluginServices.getText(this, "registros_seleccionados_total") + ".");
234 236
                    }
235 237
                });
236 238
        }
branches/gvSIG_03_SLD/applications/appgvSIG/text_en.properties
329 329
Recuperar_y_eliminar_otros_zoom=Recover and delete other zoom
330 330
refrescar=Refresh
331 331
registros=registers
332
registros_seleccionados_total=Registers (Select/All)
332 333
rellenar_marco_vista=Fill framework of the view
333 334
relleno=Fill:
334 335
renombrar=Rename
branches/gvSIG_03_SLD/applications/appgvSIG/text_fr.properties
329 329
Recuperar_y_eliminar_otros_zoom=R?cuperer et ?liminer les autres zooms
330 330
refrescar=Raffraichir
331 331
registros=registers
332
registros_seleccionados_total=Registers (S?lection/Tout)
332 333
rellenar_marco_vista=Remplir le cadre de la vue
333 334
relleno=Remplir :
334 335
renombrar=Renomer
branches/gvSIG_03_SLD/applications/appgvSIG/text_it.properties
329 329
Recuperar_y_eliminar_otros_zoom=Recupera ed elimina gli altri zoom
330 330
refrescar=Aggiorna
331 331
registros=registri
332
registros_seleccionados_total=Registri (Seleziona/Tutto)
332 333
rellenar_marco_vista=Riempi il bordo della vista
333 334
relleno=Riempi:
334 335
renombrar=Rinomina
branches/FMap_SLD/libraries/libFMap/src/com/iver/cit/gvsig/fmap/drivers/shp/SHP.java
40 40
 */
41 41
package com.iver.cit.gvsig.fmap.drivers.shp;
42 42

  
43
import java.io.File;
44
import java.util.BitSet;
45

  
46
import com.hardcode.gdbms.engine.values.Value;
47
import com.iver.cit.gvsig.fmap.DriverException;
48
import com.iver.cit.gvsig.fmap.FMap;
49 43
import com.iver.cit.gvsig.fmap.core.IGeometry;
50
import com.iver.cit.gvsig.fmap.drivers.shp.write.DBFFromSelected;
51 44
import com.iver.cit.gvsig.fmap.drivers.shp.write.SHPMultiLine;
52 45
import com.iver.cit.gvsig.fmap.drivers.shp.write.SHPMultiPoint;
53 46
import com.iver.cit.gvsig.fmap.drivers.shp.write.SHPPoint;
54 47
import com.iver.cit.gvsig.fmap.drivers.shp.write.SHPPolygon;
55
import com.iver.cit.gvsig.fmap.drivers.shp.write.SHPSHXFromSelectedVisitor;
56 48
import com.iver.cit.gvsig.fmap.drivers.shp.write.SHPShape;
57 49
import com.iver.cit.gvsig.fmap.drivers.shp.write.ShapefileException;
58 50
import com.iver.cit.gvsig.fmap.layers.SelectableDataSource;
59
import com.iver.cit.gvsig.fmap.operations.strategies.SelectedShapeVisitor;
60
import com.iver.cit.gvsig.fmap.operations.strategies.VisitException;
61 51

  
52
import java.io.File;
62 53

  
54
import java.util.BitSet;
63 55

  
56

  
64 57
/**
65 58
 * Clase con las constantes que representan los diferentes tipos de Shape y
66 59
 * m?todos est?ticos relativos a los shapes.
......
85 78
	 *
86 79
	 * @return Geometr?a m?s adecuada.
87 80
	 *
88
	 * @throws ShapefileException Se lanza cuando es causada por la creaci?n del shape.
81
	 * @throws ShapefileException Se lanza cuando es causada por la creaci?n
82
	 * 		   del shape.
89 83
	 */
90 84
	public static SHPShape create(int type) throws ShapefileException {
91 85
		SHPShape shape;
......
126 120
		return shape;
127 121
	}
128 122

  
129
	public static void SHPFileFromSelected(FMap map,File f){
130
	 	SHPSHXFromSelectedVisitor visitor = new SHPSHXFromSelectedVisitor();
131
		visitor.setFile(f);
132
		//int type=getTypeShape();
133
		//visitor.setType(5);
134
		try {
135
			map.getLayers().process(visitor);
136
			} catch (DriverException e1) {
137
				throw new RuntimeException("No se espera que SelectByPointVisitor lance esta excepci?n",
138
						e1);
139
			} catch (VisitException e) {
140
				throw new RuntimeException("No se espera que SelectByPointVisitor lance esta excepci?n",
141
						e);
142
			}
143
			
144
		try {
145
			DBFFromSelected dbf=new DBFFromSelected();
146
			dbf.setFile(f);
147
			dbf.setGeometries(visitor.getGeometries());
148
			dbf.setIsNewDBF(true);
149
			visitor.getSDS().start();
150
			dbf.start(visitor.getSDS());
151
			dbf.createdbf(visitor.getBitSet());
152
			dbf.stop();
153
			visitor.getSDS().stop();
154
		} catch (com.hardcode.gdbms.engine.data.driver.DriverException e2) {
155
			e2.printStackTrace();
156
		}
157
	
158
	 }
159
	public static void SHPFileFromGeometries(IGeometry[] fgs,BitSet bitset,SelectableDataSource sds,File f){
160
		
161
		SHPSHXFromGeometries ssfg = new SHPSHXFromGeometries(fgs,f);
123
	/**
124
	 * Crea un fichero en formato shape con las geometr?as que se pasan como
125
	 * par?metro en forma de array, un bitset para saber las seleccionadas, un
126
	 * SelectableDataSource para obtener los valores y el fichero a crear.
127
	 *
128
	 * @param fgs Array de geometr?as.
129
	 * @param bitset Bitset con la selecci?n.
130
	 * @param sds SelectableDataSource.
131
	 * @param f Fichero a crear o modificar.
132
	 */
133
	public static void SHPFileFromGeometries(IGeometry[] fgs, BitSet bitset,
134
		SelectableDataSource sds, File f) {
135
		SHPSHXFromGeometries ssfg = new SHPSHXFromGeometries(fgs, f);
162 136
		ssfg.create();
163
		DBFFromGeometries dfg=new DBFFromGeometries(fgs,f);
164
		dfg.create(sds,bitset);
137

  
138
		DBFFromGeometries dfg = new DBFFromGeometries(fgs, f);
139
		dfg.create(sds, bitset);
165 140
	}
166
	public static double[] getZMinMax(double[] zs){
167
		if (zs==null)return null;
168
		double min=Double.MAX_VALUE;
169
		double max=Double.MIN_VALUE;
170
		for (int i=0;i<zs.length;i++){
171
			if (zs[i]>max)max=zs[i];
172
			if (zs[i]<min)min=zs[i];
141

  
142
	/**
143
	 * Devuelve un array con dos doubles, el primero representa el m?nimo valor
144
	 * y el segundo el m?ximo de entre los valores que se pasan como par?metro
145
	 * en forma de array.
146
	 *
147
	 * @param zs Valores a comprobar.
148
	 *
149
	 * @return Array de doubles con el valor m?nimo y el valor m?ximo.
150
	 */
151
	public static double[] getZMinMax(double[] zs) {
152
		if (zs == null) {
153
			return null;
173 154
		}
174
		return new double[]{min,max};
155

  
156
		double min = Double.MAX_VALUE;
157
		double max = Double.MIN_VALUE;
158

  
159
		for (int i = 0; i < zs.length; i++) {
160
			if (zs[i] > max) {
161
				max = zs[i];
162
			}
163

  
164
			if (zs[i] < min) {
165
				min = zs[i];
166
			}
167
		}
168

  
169
		return new double[] { min, max };
175 170
	}
176 171
}
branches/FMap_SLD/libraries/libFMap/src/com/iver/cit/gvsig/fmap/drivers/shp/write/DBFFromSelected.java
1
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
2
 *
3
 * Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
4
 *
5
 * This program is free software; you can redistribute it and/or
6
 * modify it under the terms of the GNU General Public License
7
 * as published by the Free Software Foundation; either version 2
8
 * of the License, or (at your option) any later version.
9
 *
10
 * This program is distributed in the hope that it will be useful,
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 * GNU General Public License for more details.
14
 *
15
 * You should have received a copy of the GNU General Public License
16
 * along with this program; if not, write to the Free Software
17
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
18
 *
19
 * For more information, contact:
20
 *
21
 *  Generalitat Valenciana
22
 *   Conselleria d'Infraestructures i Transport
23
 *   Av. Blasco Ib??ez, 50
24
 *   46010 VALENCIA
25
 *   SPAIN
26
 *
27
 *      +34 963862235
28
 *   gvsig@gva.es
29
 *      www.gvsig.gva.es
30
 *
31
 *    or
32
 *
33
 *   IVER T.I. S.A
34
 *   Salamanca 50
35
 *   46005 Valencia
36
 *   Spain
37
 *
38
 *   +34 963163400
39
 *   dac@iver.es
40
 */
41
package com.iver.cit.gvsig.fmap.drivers.shp.write;
42

  
43
import java.io.File;
44
import java.io.IOException;
45
import java.io.RandomAccessFile;
46
import java.nio.channels.FileChannel;
47
import java.nio.channels.WritableByteChannel;
48

  
49
import com.hardcode.gdbms.engine.data.driver.DriverException;
50
import com.iver.cit.gvsig.fmap.core.IGeometry;
51
import com.iver.cit.gvsig.fmap.drivers.shp.DbaseFileHeaderNIO;
52
import com.iver.cit.gvsig.fmap.drivers.shp.DbaseFileWriterNIO;
53
import com.iver.cit.gvsig.fmap.layers.FBitSet;
54
import com.iver.cit.gvsig.fmap.layers.SelectableDataSource;
55

  
56

  
57
/**
58
 * Visitor de zoom a lo seleccionado.
59
 *
60
 * @author Vicente Caballero Navarro
61
 */
62
public class DBFFromSelected {
63
	private IGeometry[] fgs = null;
64
	private boolean hasdbf = false;
65
	private String dbfPath;
66
	private int temp = 0;
67
	private DbaseFileWriterNIO dbfWrite;
68
	private Integer[] enteros;
69
	private SelectableDataSource sds;
70
	private Object[] record;
71

  
72
	//private DbaseFileNIO m_FichDbf = new DbaseFileNIO();
73

  
74
	/**
75
	 * Inserta el fichero.
76
	 *
77
	 * @param f Fichero.
78
	 */
79
	public void setFile(File f) {
80
		String strFichDbf = f.getAbsolutePath().replaceAll("\\.shp", ".dbf");
81
		dbfPath = strFichDbf.replaceAll("\\.SHP", ".DBF");
82

  
83
	}
84

  
85
	/**
86
	 * Inserta true si se quiere crear el dbf vacio y no copiar el contenido de otro dbf.
87
	 *
88
	 * @param b True si se quiere crear vacio el dbf.
89
	 */
90
	public void setIsNewDBF(boolean b) {
91
		hasdbf = b;
92
	}
93

  
94
	/**
95
	 * Inserta las geometr?as.
96
	 *
97
	 * @param g Geometr?as.
98
	 */
99
	public void setGeometries(IGeometry[] g) {
100
		fgs = g;
101
	}
102

  
103
	/**
104
	 * Inicializa.
105
	 *
106
	 * @param sds Capa.
107
	 */
108
	public void start(SelectableDataSource sds) {
109
		//if (layer instanceof AlphanumericData) {
110
		try {
111
			this.sds = sds;
112

  
113
			if (!hasdbf) {
114
				DbaseFileHeaderNIO myHeader = DbaseFileHeaderNIO.createNewDbaseHeader();
115
				myHeader.setNumRecords(fgs.length);
116
				dbfWrite = new DbaseFileWriterNIO(myHeader,
117
						(FileChannel) getWriteChannel(dbfPath));
118
				enteros = new Integer[1];
119
			} else {
120
				//VectorialFileAdapter vfa=(VectorialFileAdapter)((SingleLayer)lv).getSource();
121
				DbaseFileHeaderNIO myHeader;
122

  
123
				myHeader = DbaseFileHeaderNIO.createDbaseHeader(sds);
124

  
125
				myHeader.setNumRecords(fgs.length);
126
				dbfWrite = new DbaseFileWriterNIO(myHeader,
127
						(FileChannel) getWriteChannel(dbfPath));
128
				record = new Object[sds.getFieldCount()];
129
			}
130
		} catch (IOException e) {
131
			e.printStackTrace();
132

  
133
			///} catch (DriverException e1) {
134
			//	e1.printStackTrace();
135
		} catch (DriverException e) {
136
			e.printStackTrace();
137
		}
138

  
139
		//return true;
140
		//}
141
		//return false;
142
	}
143

  
144
	/**
145
	 * Finaliza.
146
	 */
147
	public void stop() {
148
		System.out.println("Acabado el DBF con NIO escritura");
149
	}
150

  
151
	/**
152
	 * Rellena los registros del dbf.
153
	 */
154
	public void createdbf(FBitSet bitset) {
155
		int i=0;
156
		for (int j = bitset.nextSetBit(0);
157
		j >= 0;
158
		j = bitset.nextSetBit(j + 1)){
159
		//for (int i = 0; i < fgs.length; i++) {
160
			try {
161
				if (!hasdbf) {
162
					enteros[0] = Integer.valueOf(String.valueOf(i));
163
					dbfWrite.write(enteros);
164
					i++;
165
				} else {
166
					for (int r = 0; r < sds.getFieldCount(); r++) {
167
						record[r] = sds.getFieldValue(j, r);
168
					}
169

  
170
					dbfWrite.write(record);
171
				}
172
			} catch (IOException e1) {
173
				e1.printStackTrace();
174
			} catch (DriverException e) {
175
				e.printStackTrace();
176
			}
177
		}
178
	}
179

  
180
	
181

  
182
	private WritableByteChannel getWriteChannel(String path)
183
		throws IOException {
184
		WritableByteChannel channel;
185

  
186
			File f = new File(path);
187

  
188
			if (!f.exists() && !f.createNewFile()) {
189
				throw new IOException("Cannot create file " + f);
190
			}
191

  
192
			RandomAccessFile raf = new RandomAccessFile(f, "rw");
193
			channel = raf.getChannel();
194

  
195
		return channel;
196
	}
197
}
branches/FMap_SLD/libraries/libFMap/src/com/iver/cit/gvsig/fmap/drivers/shp/write/SHPSHXFromSelectedVisitor.java
1
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
2
 *
3
 * Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
4
 *
5
 * This program is free software; you can redistribute it and/or
6
 * modify it under the terms of the GNU General Public License
7
 * as published by the Free Software Foundation; either version 2
8
 * of the License, or (at your option) any later version.
9
 *
10
 * This program is distributed in the hope that it will be useful,
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 * GNU General Public License for more details.
14
 *
15
 * You should have received a copy of the GNU General Public License
16
 * along with this program; if not, write to the Free Software
17
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
18
 *
19
 * For more information, contact:
20
 *
21
 *  Generalitat Valenciana
22
 *   Conselleria d'Infraestructures i Transport
23
 *   Av. Blasco Ib??ez, 50
24
 *   46010 VALENCIA
25
 *   SPAIN
26
 *
27
 *      +34 963862235
28
 *   gvsig@gva.es
29
 *      www.gvsig.gva.es
30
 *
31
 *    or
32
 *
33
 *   IVER T.I. S.A
34
 *   Salamanca 50
35
 *   46005 Valencia
36
 *   Spain
37
 *
38
 *   +34 963163400
39
 *   dac@iver.es
40
 */
41
package com.iver.cit.gvsig.fmap.drivers.shp.write;
42

  
43
import com.iver.cit.gvsig.fmap.core.FShape;
44
import com.iver.cit.gvsig.fmap.core.IGeometry;
45
import com.iver.cit.gvsig.fmap.core.v02.FConstant;
46
import com.iver.cit.gvsig.fmap.layers.FBitSet;
47
import com.iver.cit.gvsig.fmap.layers.FLayer;
48
import com.iver.cit.gvsig.fmap.layers.SelectableDataSource;
49
import com.iver.cit.gvsig.fmap.layers.layerOperations.AlphanumericData;
50
import com.iver.cit.gvsig.fmap.layers.layerOperations.Selectable;
51
import com.iver.cit.gvsig.fmap.operations.strategies.FeatureVisitor;
52
import com.iver.cit.gvsig.fmap.operations.strategies.VisitException;
53

  
54
import java.io.File;
55
import java.io.IOException;
56
import java.io.RandomAccessFile;
57

  
58
import java.net.MalformedURLException;
59

  
60
import java.nio.channels.FileChannel;
61
import java.nio.channels.WritableByteChannel;
62

  
63

  
64
/**
65
 * Visitor de creaci?n de un shape de los elementos seleccionados.
66
 *
67
 * @author Vicente Caballero Navarro
68
 */
69
public class SHPSHXFromSelectedVisitor implements FeatureVisitor {
70
	private IGeometry[] fgs = null;
71
	private SelectableDataSource sds = null;
72
	private String shpPath;
73
	private String shxPath;
74
	private int temp = 0;
75
	private int type;
76
	private FBitSet bitset = null;
77
	private int num = 0;
78

  
79
	/**
80
	 * DOCUMENT ME!
81
	 *
82
	 * @param f DOCUMENT ME!
83
	 */
84
	public void setFile(File f) {
85
		shpPath = f.getAbsolutePath();
86

  
87
		String strFichshx = f.getAbsolutePath().replaceAll("\\.shp", ".shx");
88
		shxPath = strFichshx.replaceAll("\\.SHP", ".SHX");
89
	}
90

  
91
	/**
92
	 * DOCUMENT ME!
93
	 *
94
	 * @param layer DOCUMENT ME!
95
	 *
96
	 * @return DOCUMENT ME!
97
	 */
98

  
99
	/*public void setType(int i) {
100
	   type = i;
101
	   }
102
	 */
103

  
104
	/**
105
	 * Inicializa el visitor.
106
	 *
107
	 * @param layer Capa.
108
	 *
109
	 * @return True si se inicializa correctamente.
110
	 */
111
	public boolean start(FLayer layer) {
112
		if (layer instanceof AlphanumericData && layer instanceof Selectable) {
113
			try {
114
				sds = ((AlphanumericData) layer).getRecordset();
115
				bitset = ((Selectable) layer).getSelection();
116

  
117
				///fgs = new IGeometry[(int) sds.getRowCount()];
118
				fgs = new IGeometry[bitset.cardinality()];
119

  
120
				///} catch (DriverException e) {
121
				///	e.printStackTrace();
122
			} catch (com.iver.cit.gvsig.fmap.DriverException e) {
123
				e.printStackTrace();
124
			}
125

  
126
			return true;
127
		}
128

  
129
		return false;
130
	}
131

  
132
	/**
133
	 * Finaliza el visitor.
134
	 *
135
	 * @param layer Capa.
136
	 */
137
	public void stop(FLayer layer) {
138
		SHPFileWrite filewrite;
139

  
140
		try {
141
			filewrite = new SHPFileWrite((FileChannel) getWriteChannel(shpPath),
142
					(FileChannel) getWriteChannel(shxPath));
143

  
144
			if (fgs.length > 0) {
145
				type = getTypeShape(fgs[0].getGeometryType());
146
				filewrite.write(fgs, type);
147
			}
148
		} catch (ShapefileException e1) {
149
			e1.printStackTrace();
150
		} catch (MalformedURLException e) {
151
			e.printStackTrace();
152
		} catch (IOException e) {
153
			e.printStackTrace();
154
		}
155

  
156
		System.out.println("Acabado SHP y SHX");
157
	}
158

  
159
	/**
160
	 * @see com.iver.cit.gvsig.fmap.operations.strategies.FeatureVisitor#visit(com.iver.cit.gvsig.fmap.core.IGeometry,
161
	 * 		int)
162
	 */
163
	public void visit(IGeometry g, int index) throws VisitException {
164
		if (bitset.get(index)) {
165
			fgs[num] = g;
166
			num++;
167
		}
168
	}
169

  
170
	/**
171
	 * DOCUMENT ME!
172
	 *
173
	 * @param path DOCUMENT ME!
174
	 *
175
	 * @return DOCUMENT ME!
176
	 *
177
	 * @throws IOException DOCUMENT ME!
178
	 */
179
	private WritableByteChannel getWriteChannel(String path)
180
		throws IOException {
181
		WritableByteChannel channel;
182

  
183
		File f = new File(path);
184

  
185
		if (!f.exists()) {
186
			System.out.println("Creando fichero " + f.getAbsolutePath());
187

  
188
			if (!f.createNewFile()) {
189
				System.err.print("Error al crear el fichero " +
190
					f.getAbsolutePath());
191
				throw new IOException("Cannot create file " + f);
192
			}
193
		}
194

  
195
		RandomAccessFile raf = new RandomAccessFile(f, "rw");
196
		channel = raf.getChannel();
197

  
198
		return channel;
199
	}
200

  
201
	/**
202
	 * DOCUMENT ME!
203
	 *
204
	 * @return DOCUMENT ME!
205
	 */
206
	public IGeometry[] getGeometries() {
207
		return fgs;
208
	}
209

  
210
	/**
211
	 * DOCUMENT ME!
212
	 *
213
	 * @param geometryType DOCUMENT ME!
214
	 *
215
	 * @return DOCUMENT ME!
216
	 */
217
	private int getTypeShape(int geometryType) {
218
		switch (geometryType) {
219
			case FShape.POINT:
220
				return FConstant.SHAPE_TYPE_POINT;
221

  
222
			case FShape.LINE:
223
				return FConstant.SHAPE_TYPE_POLYLINE;
224

  
225
			case FShape.POLYGON:
226
				return FConstant.SHAPE_TYPE_POLYGON;
227

  
228
			case FShape.MULTI:
229
				return 0; //TODO falta aclarar cosas aqu?.
230
		}
231

  
232
		return FConstant.SHAPE_TYPE_NULL;
233
	}
234

  
235
	/**
236
	 * DOCUMENT ME!
237
	 *
238
	 * @return DOCUMENT ME!
239
	 */
240
	public SelectableDataSource getSDS() {
241
		return sds;
242
	}
243

  
244
	/**
245
	 * DOCUMENT ME!
246
	 *
247
	 * @return DOCUMENT ME!
248
	 */
249
	public FBitSet getBitSet() {
250
		return bitset;
251
	}
252
}
branches/FMap_SLD/libraries/libFMap/src/com/iver/cit/gvsig/fmap/drivers/shp/DemoSHPDriver.java
40 40
 */
41 41
package com.iver.cit.gvsig.fmap.drivers.shp;
42 42

  
43
import com.iver.cit.gvsig.fmap.MapControl;
44 43
import com.iver.cit.gvsig.fmap.core.FShape;
45 44
import com.iver.cit.gvsig.fmap.core.GeneralPathX;
46 45
import com.iver.cit.gvsig.fmap.core.IGeometry;
branches/FMap_SLD/libraries/libFMap/src/com/iver/cit/gvsig/fmap/core/FPolygon3D.java
65 65
	 * @return FShape clonado.
66 66
	 */
67 67
	public FShape cloneFShape() {
68
		return new FPolygon3D((GeneralPathX) gp.clone(),(double[])pZ.clone());
68
		return new FPolygon3D((GeneralPathX) gp.clone(), (double[]) pZ.clone());
69 69
	}
70 70

  
71
	/**
72
	 * Devuelve un array con los valores de todas las Z.
73
	 *
74
	 * @return Array de Zs.
75
	 */
71 76
	public double[] getZs() {
72 77
		return pZ;
73 78
	}
79

  
74 80
	/**
75 81
	 * @see com.iver.cit.gvsig.fmap.core.FShape#getShapeType()
76 82
	 */
branches/FMap_SLD/libraries/libFMap/src/com/iver/cit/gvsig/fmap/core/FPoint3D.java
45 45
 *
46 46
 * @author Vicente Caballero Navarro
47 47
 */
48
public class FPoint3D extends FPoint2D implements FShape3D{
48
public class FPoint3D extends FPoint2D implements FShape3D {
49 49
	double z;
50 50

  
51 51
	/**
......
59 59
		super(x, y);
60 60
		this.z = z;
61 61
	}
62
	public double getZ()
63
	{
64
	    return z;
65
	}
62

  
63
	/**
64
	 * Devuelve un Array con los valores de todas las Zs, en este caso con un
65
	 * ?nico vaor de z.
66
	 *
67
	 * @return Array de Zs.
68
	 */
66 69
	public double[] getZs() {
67
		return new double[]{getZ()};
70
		return new double[] { z };
68 71
	}
72

  
69 73
	/**
70 74
	 * @see com.iver.cit.gvsig.fmap.core.FShape#getShapeType()
71 75
	 */
72 76
	public int getShapeType() {
73 77
		return FShape.POINT | FShape.Z;
74 78
	}
79

  
75 80
	/* (non-Javadoc)
76 81
	 * @see com.iver.cit.gvsig.fmap.core.FShape#cloneFShape()
77 82
	 */
78 83
	public FShape cloneFShape() {
79
		return new FPoint3D(p.getX(), p.getY(),z);
84
		return new FPoint3D(p.getX(), p.getY(), z);
80 85
	}
81 86
}
branches/FMap_SLD/libraries/libFMap/src/com/iver/cit/gvsig/fmap/core/FPolyline2D.java
42 42

  
43 43
import org.cresques.cts.ICoordTrans;
44 44

  
45
import com.vividsolutions.jts.geom.Coordinate;
46
import com.vividsolutions.jts.geom.CoordinateArrays;
47
import com.vividsolutions.jts.geom.GeometryFactory;
48

  
49 45
import java.awt.Rectangle;
50 46
import java.awt.geom.AffineTransform;
51 47
import java.awt.geom.PathIterator;
branches/FMap_SLD/libraries/libFMap/src/com/iver/cit/gvsig/fmap/core/FPolyline3D.java
1 1
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
2
*
3
* Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
4
*
5
* This program is free software; you can redistribute it and/or
6
* modify it under the terms of the GNU General Public License
7
* as published by the Free Software Foundation; either version 2
8
* of the License, or (at your option) any later version.
9
*
10
* This program is distributed in the hope that it will be useful,
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
* GNU General Public License for more details.
14
*
15
* You should have received a copy of the GNU General Public License
16
* along with this program; if not, write to the Free Software
17
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
18
*
19
* For more information, contact:
20
*
21
*  Generalitat Valenciana
22
*   Conselleria d'Infraestructures i Transport
23
*   Av. Blasco Ib??ez, 50
24
*   46010 VALENCIA
25
*   SPAIN
26
*
27
*      +34 963862235
28
*   gvsig@gva.es
29
*      www.gvsig.gva.es
30
*
31
*    or
32
*
33
*   IVER T.I. S.A
34
*   Salamanca 50
35
*   46005 Valencia
36
*   Spain
37
*
38
*   +34 963163400
39
*   dac@iver.es
40
*/
41

  
2
 *
3
 * Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
4
 *
5
 * This program is free software; you can redistribute it and/or
6
 * modify it under the terms of the GNU General Public License
7
 * as published by the Free Software Foundation; either version 2
8
 * of the License, or (at your option) any later version.
9
 *
10
 * This program is distributed in the hope that it will be useful,
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 * GNU General Public License for more details.
14
 *
15
 * You should have received a copy of the GNU General Public License
16
 * along with this program; if not, write to the Free Software
17
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
18
 *
19
 * For more information, contact:
20
 *
21
 *  Generalitat Valenciana
22
 *   Conselleria d'Infraestructures i Transport
23
 *   Av. Blasco Ib??ez, 50
24
 *   46010 VALENCIA
25
 *   SPAIN
26
 *
27
 *      +34 963862235
28
 *   gvsig@gva.es
29
 *      www.gvsig.gva.es
30
 *
31
 *    or
32
 *
33
 *   IVER T.I. S.A
34
 *   Salamanca 50
35
 *   46005 Valencia
36
 *   Spain
37
 *
38
 *   +34 963163400
39
 *   dac@iver.es
40
 */
42 41
package com.iver.cit.gvsig.fmap.core;
43 42

  
44 43
/**
......
46 45
 *
47 46
 * @author Vicente Caballero Navarro
48 47
 */
49
public class FPolyline3D extends FPolyline2D implements FShape3D{
48
public class FPolyline3D extends FPolyline2D implements FShape3D {
50 49
	double[] pZ = null;
51 50

  
52 51
	/**
......
59 58
		super(gpx);
60 59
		this.pZ = pZ;
61 60
	}
61

  
62 62
	/**
63 63
	 * @see com.iver.cit.gvsig.fmap.core.FShape#getShapeType()
64 64
	 */
65 65
	public int getShapeType() {
66 66
		return FShape.LINE | FShape.Z;
67 67
	}
68

  
69
	/**
70
	 * Devuelve un Array con todos los valores de Z.
71
	 *
72
	 * @return Array de Zs.
73
	 */
68 74
	public double[] getZs() {
69 75
		return pZ;
70 76
	}
77

  
71 78
	/* (non-Javadoc)
72 79
	 * @see com.iver.cit.gvsig.fmap.core.FShape#cloneFShape()
73 80
	 */
74 81
	public FShape cloneFShape() {
75
		return new FPolyline3D((GeneralPathX) gp.clone(),(double[])pZ);
82
		return new FPolyline3D((GeneralPathX) gp.clone(), (double[]) pZ);
76 83
	}
77 84
}
branches/FMap_SLD/libraries/libFMap/src/com/iver/cit/gvsig/fmap/core/FMultipoint3D.java
45 45
 *
46 46
 * @author Vicente Caballero Navarro
47 47
 */
48
public class FMultipoint3D extends FMultiPoint2D implements IGeometry3D{
48
public class FMultipoint3D extends FMultiPoint2D implements IGeometry3D {
49 49
	double[] z = null;
50 50

  
51 51
	/**
52 52
	 * Crea un nuevo Multipoint3D.
53 53
	 *
54
	 * @param x DOCUMENT ME!
55
	 * @param y DOCUMENT ME!
56
	 * @param z DOCUMENT ME!
54
	 * @param x Array de Xs.
55
	 * @param y Array de Ys.
56
	 * @param z Array de Zs.
57 57
	 */
58 58
	public FMultipoint3D(double[] x, double[] y, double[] z) {
59 59
		super(x, y);
60 60
		this.z = z;
61 61
	}
62

  
62 63
	/* (non-Javadoc)
63 64
	 * @see com.iver.cit.gvsig.fmap.core.IGeometry#cloneGeometry()
64 65
	 */
65 66
	public IGeometry cloneGeometry() {
66
		return new FMultipoint3D((double[])x.clone(),(double[])y.clone(),(double[])z.clone());
67
		return new FMultipoint3D((double[]) x.clone(), (double[]) y.clone(),
68
			(double[]) z.clone());
67 69
	}
70

  
71
	/**
72
	 * Devuelve un array con todos los valores de Z.
73
	 *
74
	 * @return Array de Zs.
75
	 */
68 76
	public double[] getZs() {
69 77
		return z;
70 78
	}
79

  
71 80
	/**
72 81
	 * @see com.iver.cit.gvsig.fmap.core.IGeometry#getGeometryType()
73 82
	 */
branches/FMap_SLD/libraries/libFMap/src/com/iver/cit/gvsig/fmap/core/FGeometry.java
199 199
	 * @see com.iver.cit.gvsig.fmap.core.IGeometry#getGeneralPathXIterator()
200 200
	 */
201 201
	public GeneralPathXIterator getGeneralPathXIterator() {
202
		return (GeneralPathXIterator)shp.getPathIterator(null);
202
		return (GeneralPathXIterator) shp.getPathIterator(null);
203 203
	}
204 204

  
205
    /* (non-Javadoc)
206
     * @see com.iver.cit.gvsig.fmap.core.IGeometry#fastIntersects(double, double, double, double)
207
     */
208
    public boolean fastIntersects(double x, double y, double w, double h) {
209
        return shp.intersects(x,y,w,h);
210
    }
205
	/* (non-Javadoc)
206
	 * @see com.iver.cit.gvsig.fmap.core.IGeometry#fastIntersects(double, double, double, double)
207
	 */
208
	public boolean fastIntersects(double x, double y, double w, double h) {
209
		return shp.intersects(x, y, w, h);
210
	}
211 211

  
212
	/**
213
	 * Devuelve un array con todos los valores de Z.
214
	 *
215
	 * @return Array de Zs.
216
	 */
212 217
	public double[] getZs() {
213
		return ((FShape3D)shp).getZs();
218
		return ((FShape3D) shp).getZs();
214 219
	}
215 220
}

Also available in: Unified diff