Revision 26861
trunk/extensions/extGraph/config/config.xml | ||
---|---|---|
20 | 20 |
active="true"> |
21 | 21 |
|
22 | 22 |
<menu text="Network/Load_Network" tooltip="Load_Red" |
23 |
action-command="LOAD_RED"
|
|
23 |
action-command="LOAD_NET"
|
|
24 | 24 |
icon="network" /> |
25 |
<menu text="Network/Load_Network_From_File" tooltip="Load_Red_From_File" |
|
26 |
action-command="LOAD_NET_FROM_FILE" |
|
27 |
icon="network" /> |
|
25 | 28 |
|
26 | 29 |
<!-- <menu text="Network/Load_Network_from_tables" tooltip="Load_Red" |
27 | 30 |
action-command="LOAD_NETWORK_FROM_TABLES" |
trunk/extensions/extGraph/src/org/gvsig/graph/GenerateNetworkExtension.java | ||
---|---|---|
404 | 404 |
} |
405 | 405 |
|
406 | 406 |
private void generateRedNetwork(FLyrVect lyr, FLayers tocLyrs) { |
407 |
lyr.createSpatialIndex(); |
|
407 |
|
|
408 | 408 |
NetworkFileRedWriter netBuilder = new NetworkFileRedWriter(); |
409 | 409 |
// Por ahora, a pelo, pero hay que sacar un cuadro |
410 | 410 |
// de di?logo para hecer el mapping. |
... | ... | |
424 | 424 |
String fieldLength = wiz.getFieldLength(); |
425 | 425 |
String fieldCost = wiz.getFieldCost(); |
426 | 426 |
String fieldSense = wiz.getFieldSense(); |
427 |
|
|
427 | 428 |
netBuilder.setLayer(lyr); |
428 | 429 |
netBuilder.setFieldType(fieldType); |
429 | 430 |
netBuilder.setFieldDist(fieldLength); |
430 | 431 |
netBuilder.setFieldSense(fieldSense); |
431 | 432 |
netBuilder.setFieldCost(fieldCost); |
432 |
File redFile = NetworkUtils.getNetworkFile(lyr); |
|
433 |
netBuilder.setDigitalizationDirection(wiz.getSenseDigitalization()); |
|
434 |
netBuilder.setReverseDigitalizationDirection(wiz.getSenseReverseDigitalization()); |
|
435 |
File redFile = wiz.getNetworkFile(); |
|
433 | 436 |
|
434 | 437 |
boolean cleanOrigLyr = wiz.getCleanOriginalLayer(); |
435 | 438 |
LineCleanGeoprocess clean = null; |
trunk/extensions/extGraph/src/org/gvsig/graph/gui/wizard/NetPage4.java | ||
---|---|---|
1 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana |
|
2 |
* |
|
3 |
* Copyright (C) 2005 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 |
|
|
42 |
/* CVS MESSAGES: |
|
43 |
* |
|
44 |
* $Id$ |
|
45 |
* $Log$ |
|
46 |
* Revision 1.4 2006-12-04 17:13:39 fjp |
|
47 |
* *** empty log message *** |
|
48 |
* |
|
49 |
* Revision 1.3 2006/10/24 08:04:41 jaume |
|
50 |
* *** empty log message *** |
|
51 |
* |
|
52 |
* Revision 1.2 2006/10/19 15:15:27 jaume |
|
53 |
* *** empty log message *** |
|
54 |
* |
|
55 |
* Revision 1.1 2006/10/19 15:12:10 jaume |
|
56 |
* *** empty log message *** |
|
57 |
* |
|
58 |
* |
|
59 |
*/ |
|
60 |
package org.gvsig.graph.gui.wizard; |
|
61 |
|
|
62 |
import java.awt.event.ActionEvent; |
|
63 |
import java.awt.event.ActionListener; |
|
64 |
|
|
65 |
import jwizardcomponent.JWizardPanel; |
|
66 |
|
|
67 |
import org.gvsig.gui.beans.swing.GridBagLayoutPanel; |
|
68 |
|
|
69 |
import com.iver.andami.PluginServices; |
|
70 |
import com.iver.utiles.swing.JComboBox; |
|
71 |
|
|
72 |
/** |
|
73 |
* Configuring sense |
|
74 |
* |
|
75 |
* @author jaume dominguez faus - jaume.dominguez@iver.es |
|
76 |
* @deprecated |
|
77 |
*/ |
|
78 |
class NetPage4 extends JWizardPanel implements ActionListener { |
|
79 |
private NetWizard owner; |
|
80 |
private JComboBox cmbSenseField; |
|
81 |
private Object nullValue = "- "+PluginServices.getText(this, "none")+" -"; |
|
82 |
|
|
83 |
NetPage4(NetWizard wizard) { |
|
84 |
super(wizard.getWizardComponents()); |
|
85 |
this.owner = wizard; |
|
86 |
initialize(); |
|
87 |
} |
|
88 |
|
|
89 |
private void initialize() { |
|
90 |
GridBagLayoutPanel contentPane = new GridBagLayoutPanel(); |
|
91 |
|
|
92 |
cmbSenseField = new JComboBox(); |
|
93 |
cmbSenseField.addItem(nullValue); |
|
94 |
String[] fieldNames = owner.getLayerFieldNames(); |
|
95 |
for (int i = 0; i < fieldNames.length; i++) { |
|
96 |
cmbSenseField.addItem(fieldNames[i]); |
|
97 |
} |
|
98 |
cmbSenseField.addActionListener(this); |
|
99 |
contentPane.addComponent(PluginServices.getText(this, "select_sense_field"),cmbSenseField); |
|
100 |
add(contentPane); |
|
101 |
actionPerformed(null); |
|
102 |
} |
|
103 |
|
|
104 |
public void actionPerformed(ActionEvent e) { |
|
105 |
// refresh table |
|
106 |
owner.setSenseField(cmbSenseField.getSelectedItem().equals(nullValue)? |
|
107 |
"" : (String) cmbSenseField.getSelectedItem()); |
|
108 |
} |
|
109 |
|
|
110 |
|
|
111 |
} |
trunk/extensions/extGraph/src/org/gvsig/graph/gui/wizard/NetPage2.java | ||
---|---|---|
1 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana |
|
2 |
* |
|
3 |
* Copyright (C) 2005 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 |
|
|
42 |
/* CVS MESSAGES: |
|
43 |
* |
|
44 |
* $Id$ |
|
45 |
* $Log$ |
|
46 |
* Revision 1.4 2006-12-04 17:13:39 fjp |
|
47 |
* *** empty log message *** |
|
48 |
* |
|
49 |
* Revision 1.3 2006/11/14 11:10:27 jaume |
|
50 |
* *** empty log message *** |
|
51 |
* |
|
52 |
* Revision 1.2 2006/10/19 15:15:27 jaume |
|
53 |
* *** empty log message *** |
|
54 |
* |
|
55 |
* Revision 1.1 2006/10/19 15:12:10 jaume |
|
56 |
* *** empty log message *** |
|
57 |
* |
|
58 |
* |
|
59 |
*/ |
|
60 |
package org.gvsig.graph.gui.wizard; |
|
61 |
|
|
62 |
import javax.swing.ButtonGroup; |
|
63 |
import javax.swing.JRadioButton; |
|
64 |
|
|
65 |
import jwizardcomponent.JWizardPanel; |
|
66 |
|
|
67 |
import org.gvsig.gui.beans.swing.GridBagLayoutPanel; |
|
68 |
|
|
69 |
import com.iver.andami.PluginServices; |
|
70 |
/** |
|
71 |
* Select costs or way type. |
|
72 |
* @author jaume dominguez faus - jaume.dominguez@iver.es |
|
73 |
* @deprecated |
|
74 |
*/ |
|
75 |
public class NetPage2 extends JWizardPanel { |
|
76 |
|
|
77 |
private NetWizard owner; |
|
78 |
private JRadioButton rdBtnCosts; |
|
79 |
private JRadioButton rdBtnWayType; |
|
80 |
|
|
81 |
NetPage2(NetWizard wizard) { |
|
82 |
super(wizard.getWizardComponents()); |
|
83 |
this.owner = wizard; |
|
84 |
initialize(); |
|
85 |
} |
|
86 |
|
|
87 |
private void initialize() { |
|
88 |
GridBagLayoutPanel contentPane = new GridBagLayoutPanel(); |
|
89 |
contentPane.setBorder(javax.swing.BorderFactory.createTitledBorder(null, |
|
90 |
PluginServices.getText(this, "criterium"), |
|
91 |
javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, |
|
92 |
javax.swing.border.TitledBorder.DEFAULT_POSITION, null, null)); |
|
93 |
|
|
94 |
contentPane.addComponent( |
|
95 |
rdBtnCosts = new JRadioButton( |
|
96 |
PluginServices.getText(this, "cost_from_a_table_field"))); |
|
97 |
contentPane.addComponent( |
|
98 |
rdBtnWayType = new JRadioButton( |
|
99 |
PluginServices.getText(this, "based_upon_the_road_type"))); |
|
100 |
|
|
101 |
ButtonGroup group = new ButtonGroup(); |
|
102 |
group.add(rdBtnCosts); |
|
103 |
group.add(rdBtnWayType); |
|
104 |
this.add(contentPane); |
|
105 |
} |
|
106 |
|
|
107 |
public void next() { |
|
108 |
Boolean costs = null; |
|
109 |
if (rdBtnCosts.isSelected()) |
|
110 |
costs = new Boolean(true); |
|
111 |
if (rdBtnWayType.isSelected()) |
|
112 |
costs = new Boolean(false); |
|
113 |
|
|
114 |
if (costs!=null) { |
|
115 |
owner.setUsingCosts(costs); |
|
116 |
((NetPage3) owner.getWizardComponents().getWizardPanel(2)) |
|
117 |
.refresh(); |
|
118 |
goNext(); |
|
119 |
} |
|
120 |
|
|
121 |
} |
|
122 |
|
|
123 |
|
|
124 |
} |
trunk/extensions/extGraph/src/org/gvsig/graph/gui/wizard/NetPage3.java | ||
---|---|---|
1 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana |
|
2 |
* |
|
3 |
* Copyright (C) 2005 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 |
|
|
42 |
/* CVS MESSAGES: |
|
43 |
* |
|
44 |
* $Id$ |
|
45 |
* $Log$ |
|
46 |
* Revision 1.3 2006-10-24 08:04:41 jaume |
|
47 |
* *** empty log message *** |
|
48 |
* |
|
49 |
* Revision 1.2 2006/10/19 15:15:27 jaume |
|
50 |
* *** empty log message *** |
|
51 |
* |
|
52 |
* Revision 1.1 2006/10/19 15:12:10 jaume |
|
53 |
* *** empty log message *** |
|
54 |
* |
|
55 |
* |
|
56 |
*/ |
|
57 |
package org.gvsig.graph.gui.wizard; |
|
58 |
|
|
59 |
import java.awt.event.ActionEvent; |
|
60 |
import java.awt.event.ActionListener; |
|
61 |
|
|
62 |
import jwizardcomponent.JWizardPanel; |
|
63 |
|
|
64 |
import org.gvsig.gui.beans.swing.GridBagLayoutPanel; |
|
65 |
|
|
66 |
import com.iver.andami.PluginServices; |
|
67 |
import com.iver.utiles.swing.JComboBox; |
|
68 |
/** |
|
69 |
* Configure costs or way types |
|
70 |
* @author jaume dominguez faus - jaume.dominguez@iver.es |
|
71 |
* @deprecated |
|
72 |
*/ |
|
73 |
class NetPage3 extends JWizardPanel implements ActionListener { |
|
74 |
|
|
75 |
private NetWizard owner; |
|
76 |
private JComboBox cmbCostField; |
|
77 |
private JComboBox cmbCostUnits; |
|
78 |
private Boolean usingCosts; |
|
79 |
private Object useLineLengthItem = "< "+PluginServices.getText(this, "use_line_length")+" >"; |
|
80 |
|
|
81 |
NetPage3(NetWizard wizard) { |
|
82 |
super(wizard.getWizardComponents()); |
|
83 |
this.owner = wizard; |
|
84 |
} |
|
85 |
|
|
86 |
public void refresh() { |
|
87 |
removeAll(); |
|
88 |
GridBagLayoutPanel contentPane = new GridBagLayoutPanel(); |
|
89 |
usingCosts = owner.isUsingCosts(); |
|
90 |
if (usingCosts == null) { |
|
91 |
goBack(); |
|
92 |
} else if (usingCosts.booleanValue() == true) { |
|
93 |
contentPane.addComponent( |
|
94 |
PluginServices.getText(this, "cost_field"), |
|
95 |
cmbCostField = new JComboBox()); |
|
96 |
|
|
97 |
cmbCostField.addItem(useLineLengthItem ); |
|
98 |
cmbCostField.addActionListener(this); |
|
99 |
String[] numericFields = owner.getNumericLayerFieldNames(); |
|
100 |
|
|
101 |
for (int i = 0; i < numericFields.length; i++) |
|
102 |
cmbCostField.addItem(numericFields[i]); |
|
103 |
|
|
104 |
contentPane.addComponent( |
|
105 |
PluginServices.getText(this, "cost_units"), |
|
106 |
cmbCostUnits = new JComboBox(NetWizard.COST_UNITS)); |
|
107 |
} else { |
|
108 |
// TODO missing configure tipo de via |
|
109 |
} |
|
110 |
this.add(contentPane); |
|
111 |
actionPerformed(null); |
|
112 |
} |
|
113 |
|
|
114 |
public void next() { |
|
115 |
if (usingCosts==null) return; |
|
116 |
|
|
117 |
if (usingCosts.equals(Boolean.TRUE)) { |
|
118 |
owner.setCostField( |
|
119 |
cmbCostField.getSelectedIndex() == 0 ? |
|
120 |
"" : (String)cmbCostField.getSelectedItem()); |
|
121 |
owner.setCostsUnit( |
|
122 |
(String) NetWizard.COST_UNITS[cmbCostUnits.getSelectedIndex()]); |
|
123 |
} else { |
|
124 |
|
|
125 |
} |
|
126 |
goNext(); |
|
127 |
} |
|
128 |
|
|
129 |
public void actionPerformed(ActionEvent e) { |
|
130 |
cmbCostUnits.setEnabled( |
|
131 |
!cmbCostField.getSelectedItem().equals(useLineLengthItem)); |
|
132 |
} |
|
133 |
|
|
134 |
} |
trunk/extensions/extGraph/src/org/gvsig/graph/gui/wizard/NetPage1.java | ||
---|---|---|
62 | 62 |
*/ |
63 | 63 |
package org.gvsig.graph.gui.wizard; |
64 | 64 |
|
65 |
import java.awt.BorderLayout; |
|
65 | 66 |
import java.awt.event.ActionEvent; |
66 | 67 |
import java.awt.event.ActionListener; |
68 |
import java.io.File; |
|
67 | 69 |
import java.util.Hashtable; |
68 | 70 |
|
71 |
import javax.swing.JButton; |
|
69 | 72 |
import javax.swing.JCheckBox; |
70 | 73 |
import javax.swing.JComboBox; |
74 |
import javax.swing.JFileChooser; |
|
71 | 75 |
import javax.swing.JLabel; |
76 |
import javax.swing.JPanel; |
|
77 |
import javax.swing.JTextField; |
|
78 |
import javax.swing.filechooser.FileFilter; |
|
72 | 79 |
|
73 | 80 |
import jwizardcomponent.JWizardPanel; |
74 | 81 |
|
82 |
import org.gvsig.exceptions.BaseException; |
|
83 |
import org.gvsig.graph.core.NetworkUtils; |
|
75 | 84 |
import org.gvsig.gui.beans.swing.GridBagLayoutPanel; |
85 |
import org.gvsig.gui.beans.swing.JIncrementalNumberField; |
|
76 | 86 |
|
87 |
import com.hardcode.gdbms.driver.exceptions.ReadDriverException; |
|
88 |
import com.hardcode.gdbms.engine.instruction.IncompatibleTypesException; |
|
89 |
import com.hardcode.gdbms.engine.values.BooleanValue; |
|
90 |
import com.hardcode.gdbms.engine.values.NullValue; |
|
91 |
import com.hardcode.gdbms.engine.values.Value; |
|
92 |
import com.hardcode.gdbms.engine.values.ValueFactory; |
|
77 | 93 |
import com.iver.andami.PluginServices; |
94 |
import com.iver.cit.gvsig.fmap.layers.SelectableDataSource; |
|
78 | 95 |
/** |
79 | 96 |
* Configures the length |
80 | 97 |
* |
... | ... | |
87 | 104 |
private Hashtable exceptions; |
88 | 105 |
private JComboBox cmbTypeField; |
89 | 106 |
private JComboBox cmbSenseField; |
90 |
private JComboBox cmbCostUnits;
|
|
107 |
private JIncrementalNumberField txtUnitFactor;
|
|
91 | 108 |
private JComboBox cmbCostField; |
92 | 109 |
|
93 | 110 |
private Object useLineLengthItem = "< "+PluginServices.getText(this, "use_line_length")+" >"; |
... | ... | |
98 | 115 |
private JCheckBox chkCostUnits; |
99 | 116 |
private JCheckBox chkSenseField; |
100 | 117 |
private JCheckBox chkCostField; |
118 |
private JTextField txtDigitizedDir; |
|
119 |
private JTextField txtReverseDigitizedDir; |
|
120 |
private JTextField txtFile; |
|
101 | 121 |
|
102 | 122 |
NetPage1(NetWizard wizard) { |
103 | 123 |
super(wizard.getWizardComponents()); |
... | ... | |
150 | 170 |
cmbCostField.addItem(numericFields[i]); |
151 | 171 |
|
152 | 172 |
// Costs units |
153 |
cmbCostUnits = new JComboBox(NetWizard.COST_UNITS);
|
|
154 |
chkCostUnits = new JCheckBox(PluginServices.getText(this, "cost_units")+":");
|
|
173 |
txtUnitFactor = new JIncrementalNumberField("1");
|
|
174 |
chkCostUnits = new JCheckBox(PluginServices.getText(this, "unit_factor")+":");
|
|
155 | 175 |
chkCostUnits.addActionListener(this); |
156 |
contentPane.addComponent(chkCostUnits, cmbCostUnits);
|
|
157 |
cmbCostUnits.setToolTipText(PluginServices.getText(this, "cost_units_text"));
|
|
176 |
contentPane.addComponent(chkCostUnits, txtUnitFactor);
|
|
177 |
txtUnitFactor.setToolTipText(PluginServices.getText(this, "unit_factor_text"));
|
|
158 | 178 |
|
159 | 179 |
// Sense |
160 | 180 |
cmbSenseField = new JComboBox(); |
161 | 181 |
cmbSenseField.addItem(nullValue); |
162 |
String[] fieldNames = owner.getNumericLayerFieldNames();
|
|
182 |
String[] fieldNames = owner.getLayerFieldNames(); |
|
163 | 183 |
for (int i = 0; i < fieldNames.length; i++) { |
164 | 184 |
cmbSenseField.addItem(fieldNames[i]); |
165 | 185 |
} |
... | ... | |
167 | 187 |
cmbSenseField.setToolTipText(PluginServices.getText(this, "sense_field_text")); |
168 | 188 |
chkSenseField = new JCheckBox(PluginServices.getText(this, "select_sense_field")+":"); |
169 | 189 |
chkSenseField.addActionListener(this); |
190 |
txtDigitizedDir = new JTextField(12); |
|
191 |
txtReverseDigitizedDir = new JTextField(12); |
|
170 | 192 |
contentPane.addComponent(chkSenseField, cmbSenseField); |
171 | 193 |
contentPane.addComponent(new JLabel(PluginServices.getText(this, |
172 |
"explanation_sense_field"))); |
|
194 |
"digitizedDirection")), txtDigitizedDir); |
|
195 |
contentPane.addComponent(new JLabel(PluginServices.getText(this, |
|
196 |
"reverseDigitizedDirection")), txtReverseDigitizedDir); |
|
197 |
|
|
198 |
// separator |
|
199 |
contentPane.addComponent(new JLabel(" ")); |
|
200 |
|
|
201 |
// Choose a .net file to write network. By default, saved in a temp directory, but |
|
202 |
// the user may decide to change the place to save it. |
|
203 |
JPanel panelFile = new JPanel(); |
|
204 |
txtFile = new JTextField(); |
|
205 |
txtFile.setText(NetworkUtils.getNetworkFile(owner.getLayer()).getPath()); |
|
206 |
JButton btnJFC = new JButton("..."); |
|
207 |
btnJFC.addActionListener(new ActionListener() { |
|
208 |
|
|
209 |
public void actionPerformed(ActionEvent e) { |
|
210 |
JFileChooser fileChooser = new JFileChooser(); |
|
211 |
fileChooser.setFileFilter(new FileFilter() { |
|
212 |
|
|
213 |
@Override |
|
214 |
public boolean accept(File f) { |
|
215 |
String path = f.getPath().toLowerCase(); |
|
216 |
if (path.endsWith(".net")) |
|
217 |
return true; |
|
218 |
return false; |
|
219 |
} |
|
220 |
|
|
221 |
@Override |
|
222 |
public String getDescription() { |
|
223 |
return ".net files"; |
|
224 |
} |
|
225 |
|
|
226 |
}); |
|
227 |
int res = fileChooser.showSaveDialog(getParent()); |
|
228 |
if (res==JFileChooser.APPROVE_OPTION) { |
|
229 |
String path = fileChooser.getSelectedFile().getPath(); |
|
230 |
if (!path.toLowerCase().endsWith(".net")) |
|
231 |
path = path + ".net"; |
|
232 |
txtFile.setText(path); |
|
233 |
} |
|
234 |
} |
|
235 |
|
|
236 |
}); |
|
237 |
panelFile.setLayout(new BorderLayout()); |
|
238 |
panelFile.add(txtFile, BorderLayout.CENTER); |
|
239 |
panelFile.add(btnJFC, BorderLayout.EAST); |
|
240 |
contentPane.addComponent(new JLabel(PluginServices.getText(this, |
|
241 |
"save_net_file_in")), panelFile); |
|
242 |
|
|
173 | 243 |
actionPerformed(null); |
174 | 244 |
this.add(contentPane); |
175 | 245 |
} |
176 | 246 |
|
177 | 247 |
public void actionPerformed(ActionEvent e) { |
178 | 248 |
|
179 |
cmbCostUnits.setEnabled(
|
|
249 |
txtUnitFactor.setEnabled(
|
|
180 | 250 |
!cmbCostField.getSelectedItem().equals(useLineLengthItem)); |
181 | 251 |
if (chkTypeField.isSelected()) { |
182 | 252 |
owner.setTypeField(cmbTypeField.getSelectedItem().equals(nullValue)? |
... | ... | |
200 | 270 |
owner.setSenseField(cmbSenseField.getSelectedItem().equals(nullValue)? |
201 | 271 |
null : (String) cmbSenseField.getSelectedItem()); |
202 | 272 |
cmbSenseField.setEnabled(true); |
273 |
txtDigitizedDir.setEnabled(true); |
|
274 |
txtReverseDigitizedDir.setEnabled(true); |
|
275 |
if (e.getSource() == cmbSenseField) { |
|
276 |
updateDirectionValues(); |
|
277 |
} |
|
203 | 278 |
} else { |
204 | 279 |
owner.setSenseField(null); |
205 | 280 |
cmbSenseField.setEnabled(false); |
281 |
txtDigitizedDir.setEnabled(false); |
|
282 |
txtReverseDigitizedDir.setEnabled(false); |
|
206 | 283 |
} |
207 | 284 |
|
208 | 285 |
if (chkCostField.isSelected()) { |
... | ... | |
215 | 292 |
} |
216 | 293 |
|
217 | 294 |
if (chkCostUnits.isSelected()) { |
218 |
owner.setCostsUnit((String) cmbCostUnits.getSelectedItem());
|
|
219 |
cmbCostUnits.setEnabled(true);
|
|
295 |
owner.setUnitFactor( txtUnitFactor.getDouble());
|
|
296 |
txtUnitFactor.setEnabled(true);
|
|
220 | 297 |
} else { |
221 |
owner.setCostsUnit(null); // TODO use unknown?
|
|
222 |
cmbCostUnits.setEnabled(false);
|
|
298 |
owner.setUnitFactor(1); // TODO use unknown?
|
|
299 |
txtUnitFactor.setEnabled(false);
|
|
223 | 300 |
} |
224 | 301 |
} |
302 |
|
|
303 |
/** |
|
304 |
* We collect values from sense field for let say 1000 recs. |
|
305 |
* The idea is to show the user some of the possible values he may use. |
|
306 |
* For example, teleatlas: FT, TF |
|
307 |
* @throws BaseException |
|
308 |
*/ |
|
309 |
private void updateDirectionValues() { |
|
310 |
String senseField = (String) cmbSenseField.getSelectedItem(); |
|
311 |
SelectableDataSource sds = null; |
|
312 |
try { |
|
313 |
sds = owner.getLayer().getRecordset(); |
|
314 |
int fieldIndex = sds.getFieldIndexByName(senseField); |
|
315 |
Value first = null; |
|
316 |
Value second = null; |
|
317 |
sds.start(); |
|
318 |
long hasta = Math.min(sds.getRowCount(), 1000); |
|
319 |
for (int i=0; i < hasta; i++) { |
|
320 |
Value aux = sds.getFieldValue(i, fieldIndex); |
|
321 |
if (aux.toString().equalsIgnoreCase("")) |
|
322 |
continue; |
|
323 |
if ((first == null) && (!(aux instanceof NullValue))) |
|
324 |
first = aux; |
|
325 |
if (first != null) { |
|
326 |
if (!((BooleanValue)first.equals(aux)).getValue()) { |
|
327 |
second = aux; |
|
328 |
break; |
|
329 |
} |
|
330 |
} |
|
331 |
} |
|
332 |
sds.stop(); |
|
333 |
if (first == null) first = ValueFactory.createValue(""); |
|
334 |
if (second == null) second= ValueFactory.createValue(""); |
|
335 |
String aux1 = first.toString(); |
|
336 |
String aux2 = second.toString(); |
|
337 |
if (aux1.equalsIgnoreCase("TF")) |
|
338 |
if (aux2.equalsIgnoreCase("FT")) { |
|
339 |
String b = aux2; |
|
340 |
aux2 = aux1; |
|
341 |
aux1 = b; |
|
342 |
} |
|
343 |
txtDigitizedDir.setText(aux1); |
|
344 |
txtReverseDigitizedDir.setText(aux2); |
|
345 |
} catch (ReadDriverException e) { |
|
346 |
e.printStackTrace(); |
|
347 |
} catch (IncompatibleTypesException e) { |
|
348 |
e.printStackTrace(); |
|
349 |
} |
|
350 |
finally { |
|
351 |
try { |
|
352 |
sds.stop(); |
|
353 |
} catch (ReadDriverException e1) { |
|
354 |
// TODO Auto-generated catch block |
|
355 |
e1.printStackTrace(); |
|
356 |
} |
|
357 |
|
|
358 |
} |
|
359 |
|
|
360 |
} |
|
361 |
|
|
362 |
public String getTxtFile() { |
|
363 |
return txtFile.getText(); |
|
364 |
} |
|
365 |
|
|
366 |
public String getSenseDigitalization() { |
|
367 |
return txtDigitizedDir.getText(); |
|
368 |
} |
|
369 |
|
|
370 |
public String getSenseReverseDigitalization() { |
|
371 |
return txtReverseDigitizedDir.getText(); |
|
372 |
} |
|
225 | 373 |
} |
trunk/extensions/extGraph/src/org/gvsig/graph/gui/wizard/NetWizard.java | ||
---|---|---|
74 | 74 |
*/ |
75 | 75 |
package org.gvsig.graph.gui.wizard; |
76 | 76 |
|
77 |
import java.io.File; |
|
77 | 78 |
import java.sql.Types; |
79 |
import java.text.NumberFormat; |
|
80 |
import java.text.ParseException; |
|
78 | 81 |
import java.util.ArrayList; |
82 |
import java.util.Locale; |
|
79 | 83 |
|
80 | 84 |
import javax.swing.ImageIcon; |
85 |
import javax.swing.JOptionPane; |
|
81 | 86 |
|
82 | 87 |
import com.iver.andami.PluginServices; |
83 | 88 |
import com.iver.andami.ui.mdiManager.IWindow; |
... | ... | |
86 | 91 |
import com.iver.cit.gvsig.fmap.layers.FLyrVect; |
87 | 92 |
|
88 | 93 |
public class NetWizard extends WizardAndami implements IWindow{ |
89 |
public final static String[] COST_UNITS = { |
|
90 |
PluginServices.getText(NetWizard.class, "seconds" ), |
|
91 |
PluginServices.getText(NetWizard.class, "hours" ), |
|
92 |
PluginServices.getText(NetWizard.class, "minutes" ), |
|
93 |
"hh:mm:ss" , |
|
94 |
PluginServices.getText(NetWizard.class, "millimeters" ), |
|
95 |
PluginServices.getText(NetWizard.class, "meters" ), |
|
96 |
PluginServices.getText(NetWizard.class, "inches" ), |
|
97 |
PluginServices.getText(NetWizard.class, "feet" ), |
|
98 |
PluginServices.getText(NetWizard.class, "yards" ), |
|
99 |
PluginServices.getText(NetWizard.class, "miles" ), |
|
100 |
PluginServices.getText(NetWizard.class, "nautic_miles" ), |
|
101 |
PluginServices.getText(NetWizard.class, "monetary" ), // unidades monetarias |
|
102 |
PluginServices.getText(NetWizard.class, "unknown_longitude_units" ), |
|
103 |
PluginServices.getText(NetWizard.class, "unknown_time_units" ), |
|
104 |
PluginServices.getText(NetWizard.class, "unknown_units" ), |
|
105 |
}; // TODO push it to the corresponding geoprocess class |
|
94 |
// public final static String[] COST_UNITS = {
|
|
95 |
// PluginServices.getText(NetWizard.class, "seconds" ),
|
|
96 |
// PluginServices.getText(NetWizard.class, "hours" ),
|
|
97 |
// PluginServices.getText(NetWizard.class, "minutes" ),
|
|
98 |
// "hh:mm:ss" ,
|
|
99 |
// PluginServices.getText(NetWizard.class, "millimeters" ),
|
|
100 |
// PluginServices.getText(NetWizard.class, "meters" ),
|
|
101 |
// PluginServices.getText(NetWizard.class, "inches" ),
|
|
102 |
// PluginServices.getText(NetWizard.class, "feet" ),
|
|
103 |
// PluginServices.getText(NetWizard.class, "yards" ),
|
|
104 |
// PluginServices.getText(NetWizard.class, "miles" ),
|
|
105 |
// PluginServices.getText(NetWizard.class, "nautic_miles" ),
|
|
106 |
// PluginServices.getText(NetWizard.class, "monetary" ), // unidades monetarias
|
|
107 |
// PluginServices.getText(NetWizard.class, "unknown_longitude_units" ),
|
|
108 |
// PluginServices.getText(NetWizard.class, "unknown_time_units" ),
|
|
109 |
// PluginServices.getText(NetWizard.class, "unknown_units" ),
|
|
110 |
// }; // TODO push it to the corresponding geoprocess class
|
|
106 | 111 |
private FLyrVect lyr; |
107 | 112 |
private WindowInfo wi; |
108 | 113 |
private String[] numericLayerFieldNames; |
109 | 114 |
private String fieldLength; |
110 | 115 |
private Boolean usingCosts; |
111 |
private String costUnit;
|
|
116 |
private double unitFactor;
|
|
112 | 117 |
private String[] layerFieldNames; |
113 | 118 |
private String fieldType; |
114 | 119 |
private String fieldSense; |
... | ... | |
124 | 129 |
private boolean cleanOriginalLayer = false; |
125 | 130 |
private boolean applySnapTolerance = false; |
126 | 131 |
private double snapTolerance = 0d; |
127 |
|
|
132 |
private NetPage1 netPage1; |
|
128 | 133 |
|
129 | 134 |
public NetWizard(ImageIcon logo, FLyrVect lyr) { |
130 | 135 |
super(logo); |
131 | 136 |
this.lyr = lyr; |
137 |
netPage1 = new NetPage1(this); |
|
132 | 138 |
getWizardComponents().addWizardPanel(new NetPage0(this)); |
133 |
getWizardComponents().addWizardPanel(new NetPage1(this));
|
|
139 |
getWizardComponents().addWizardPanel(netPage1);
|
|
134 | 140 |
// getWizardComponents().addWizardPanel(new NetPage2(this)); |
135 | 141 |
// getWizardComponents().addWizardPanel(new NetPage3(this)); |
136 | 142 |
// getWizardComponents().addWizardPanel(new NetPage4(this)); |
... | ... | |
240 | 246 |
this.fieldSense = fieldSense; |
241 | 247 |
} |
242 | 248 |
|
243 |
public void setCostsUnit(String costUnit) {
|
|
244 |
this.costUnit = costUnit;
|
|
249 |
public void setUnitFactor(double d) {
|
|
250 |
this.unitFactor = d;
|
|
245 | 251 |
} |
252 |
public double getUnitFactor() { |
|
253 |
// NumberFormat nf = NumberFormat.getNumberInstance(Locale.ENGLISH); // use always . as decimal separator |
|
254 |
// Number aux; |
|
255 |
// try { |
|
256 |
// aux = nf.parse(unitFactor); |
|
257 |
// return aux.doubleValue(); |
|
258 |
// } catch (ParseException e) { |
|
259 |
// JOptionPane.showMessageDialog(this, PluginServices.getText(this, "Bad number format in unitFactor")); |
|
260 |
// e.printStackTrace(); |
|
261 |
// } |
|
262 |
return unitFactor; |
|
263 |
} |
|
246 | 264 |
|
265 |
|
|
247 | 266 |
public void setUsingCosts(Boolean costs) { |
248 | 267 |
this.usingCosts = costs; |
249 | 268 |
} |
... | ... | |
269 | 288 |
} |
270 | 289 |
|
271 | 290 |
|
291 |
public String getSenseDigitalization() { |
|
292 |
return netPage1.getSenseDigitalization(); |
|
293 |
} |
|
294 |
|
|
295 |
|
|
296 |
public String getSenseReverseDigitalization() { |
|
297 |
return netPage1.getSenseReverseDigitalization(); |
|
298 |
} |
|
299 |
|
|
300 |
|
|
301 |
public File getNetworkFile() { |
|
302 |
return new File(netPage1.getTxtFile()); |
|
303 |
} |
|
304 |
|
|
305 |
|
|
272 | 306 |
} |
trunk/extensions/extGraph/src/org/gvsig/graph/core/loaders/NetworkMemoryRedLoader.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 org.gvsig.graph.core.loaders; |
|
42 |
|
|
43 |
import java.io.File; |
|
44 |
import java.io.FileNotFoundException; |
|
45 |
import java.io.IOException; |
|
46 |
import java.io.RandomAccessFile; |
|
47 |
import java.nio.ByteOrder; |
|
48 |
import java.nio.MappedByteBuffer; |
|
49 |
import java.nio.channels.FileChannel; |
|
50 |
|
|
51 |
import org.gvsig.graph.core.EdgePair; |
|
52 |
import org.gvsig.graph.core.GvEdge; |
|
53 |
import org.gvsig.graph.core.GvGraph; |
|
54 |
import org.gvsig.graph.core.GvNode; |
|
55 |
import org.gvsig.graph.core.IGraph; |
|
56 |
import org.gvsig.graph.core.INetworkLoader; |
|
57 |
|
|
58 |
/** |
|
59 |
* @author fjp |
|
60 |
* |
|
61 |
* Useful when working with a network based on a jdbc layer (random access very slow). |
|
62 |
* The idea is to put in memory theGeom and every field that we may need later (street name, |
|
63 |
* length, cost, etc). |
|
64 |
* |
|
65 |
* Primero vienen los arcos, y luego los nodos. En la cabecera, 3 enteros |
|
66 |
* con el numero de tramos, el de arcos y el de nodos. |
|
67 |
* |
|
68 |
* TODO: TODO |
|
69 |
* |
|
70 |
*/ |
|
71 |
public class NetworkMemoryRedLoader implements INetworkLoader { |
|
72 |
|
|
73 |
private File netFile = new File("c:/ejes.red"); |
|
74 |
|
|
75 |
public IGraph loadNetwork() { |
|
76 |
|
|
77 |
long t1 = System.currentTimeMillis(); |
|
78 |
|
|
79 |
int numArcs; |
|
80 |
int numEdges; |
|
81 |
int numNodes; |
|
82 |
|
|
83 |
short sentidoDigit; // => 1 en esa direcci?n. 0=> Al contrario. SOLO |
|
84 |
// SE UTILIZA PARA LOS CALCULOS POR IDTRAMO Y |
|
85 |
// PORCENTAJE |
|
86 |
// PARA SABER SI EST? M?S CERCA DE UN NODO O DEL OTRO. |
|
87 |
|
|
88 |
|
|
89 |
RandomAccessFile file; |
|
90 |
try { |
|
91 |
file = new RandomAccessFile(netFile.getPath(), |
|
92 |
"r"); |
|
93 |
FileChannel channel = file.getChannel(); |
|
94 |
MappedByteBuffer buf = channel.map(FileChannel.MapMode.READ_ONLY, 0, channel.size()); |
|
95 |
buf.order(ByteOrder.LITTLE_ENDIAN); |
|
96 |
|
|
97 |
numArcs = buf.getInt(); |
|
98 |
numEdges = buf.getInt(); |
|
99 |
numNodes = buf.getInt(); |
|
100 |
|
|
101 |
GvGraph g = new GvGraph(numArcs, numEdges, numNodes); |
|
102 |
|
|
103 |
// Nodes |
|
104 |
|
|
105 |
// NOTE: EDGES ARE WRITEN BEFORE. LOOK TO NetworkFileRedWriter. |
|
106 |
// output.writeInt(id); 4 |
|
107 |
// output.writeInt(sense); 4 |
|
108 |
// |
|
109 |
// output.writeInt(idNodeOrig); 4 |
|
110 |
// output.writeInt(idNodeEnd); 4 |
|
111 |
// output.writeInt(tipoTramo); 4 |
|
112 |
// output.writeDouble(dist); 8 |
|
113 |
// output.writeDouble(cost); 8 |
|
114 |
// TOTAL = 5x4 + 2x8 = 20 + 16 = 36 bytes /edge |
|
115 |
|
|
116 |
buf.position(36*numEdges + 12); |
|
117 |
for (int i=0; i < numNodes; i++) |
|
118 |
{ |
|
119 |
GvNode node = readNode(buf); |
|
120 |
g.addNode(node); |
|
121 |
} |
|
122 |
// Arcos |
|
123 |
buf.position(12); |
|
124 |
for (int i=0; i < numEdges; i++) |
|
125 |
{ |
|
126 |
GvEdge edge = readEdge(buf); |
|
127 |
edge.setIdEdge(i); |
|
128 |
g.addEdge(edge); |
|
129 |
GvNode nodeOrig = g.getNodeByID(edge.getIdNodeOrig()); |
|
130 |
nodeOrig.addOutputLink(edge); |
|
131 |
GvNode nodeEnd = g.getNodeByID(edge.getIdNodeEnd()); |
|
132 |
nodeEnd.addInputLink(edge); |
|
133 |
|
|
134 |
EdgePair edgePair = g.getEdgesByIdArc(edge.getIdArc()); |
|
135 |
if (edgePair == null) |
|
136 |
{ |
|
137 |
edgePair = new EdgePair(); |
|
138 |
g.addEdgePair(edge.getIdArc(), edgePair); |
|
139 |
} |
|
140 |
if (edge.getDirec() == 1) |
|
141 |
edgePair.setIdEdge(i); |
|
142 |
else |
|
143 |
edgePair.setIdInverseEdge(i); |
|
144 |
|
|
145 |
} |
|
146 |
|
|
147 |
long t2 = System.currentTimeMillis(); |
|
148 |
System.out.println("Tiempo de carga: " + (t2-t1) + " msecs"); |
|
149 |
System.out.println("NumEdges = " + g.numEdges()); |
|
150 |
return g; |
|
151 |
} catch (FileNotFoundException e) { |
|
152 |
// TODO Auto-generated catch block |
|
153 |
e.printStackTrace(); |
|
154 |
} catch (IOException e) { |
|
155 |
// TODO Auto-generated catch block |
|
156 |
e.printStackTrace(); |
|
157 |
} |
|
158 |
|
|
159 |
return null; |
|
160 |
} |
|
161 |
|
|
162 |
/* public Graph loadJungNetwork() |
|
163 |
{ |
|
164 |
SparseGraph g = new SparseGraph(); |
|
165 |
long t1 = System.currentTimeMillis(); |
|
166 |
|
|
167 |
RandomAccessFile file; |
|
168 |
try { |
|
169 |
file = new RandomAccessFile(netFile.getPath(), |
|
170 |
"r"); |
|
171 |
FileChannel channel = file.getChannel(); |
|
172 |
MappedByteBuffer buf = channel.map(FileChannel.MapMode.READ_ONLY, 0, channel.size()); |
|
173 |
buf.order(ByteOrder.LITTLE_ENDIAN); |
|
174 |
|
|
175 |
int numArcs = buf.getInt(); |
|
176 |
int numEdges = buf.getInt(); |
|
177 |
int numNodes = buf.getInt(); |
|
178 |
|
|
179 |
// Nodes |
|
180 |
buf.position(24*numEdges + 12); |
|
181 |
for (int i=0; i < numNodes; i++) |
|
182 |
{ |
|
183 |
GvNode node = readNode(buf); |
|
184 |
|
|
185 |
Vertex v = new DirectedSparseVertex(); |
|
186 |
// v.addUserDatum("ID", node.idNode, UserData.CLONE); |
|
187 |
// v.addUserDatum("X", node.x, UserData.CLONE); |
|
188 |
// v.addUserDatum("Y", node.y, UserData.CLONE); |
|
189 |
// v_locations.setLocation(v, new Point2D.Double(x.doubleValue(),y.doubleValue())); |
|
190 |
g.addVertex(v); |
|
191 |
} |
|
192 |
Indexer indexer = Indexer.getIndexer(g); |
|
193 |
|
|
194 |
buf.position(12); |
|
195 |
for (int i=0; i < numEdges; i++) |
|
196 |
{ |
|
197 |
GvEdge edge = readEdge(buf); |
|
198 |
|
|
199 |
int nodeOrig = edge.getIdNodeOrig(); |
|
200 |
int nodeEnd = edge.getIdNodeEnd(); |
|
201 |
|
|
202 |
Vertex vFrom = (Vertex) indexer.getVertex(nodeOrig); |
|
203 |
Vertex vTo = (Vertex) indexer.getVertex(nodeEnd); |
|
204 |
|
|
205 |
DirectedSparseEdge edgeJ = new DirectedSparseEdge(vFrom, vTo); |
|
206 |
g.addEdge(edgeJ); |
|
207 |
} |
|
208 |
long t2 = System.currentTimeMillis(); |
|
209 |
System.out.println("Tiempo de carga: " + (t2-t1) + " msecs"); |
|
210 |
return g; |
|
211 |
} catch (FileNotFoundException e) { |
|
212 |
// TODO Auto-generated catch block |
|
213 |
e.printStackTrace(); |
|
214 |
} catch (IOException e) { |
|
215 |
// TODO Auto-generated catch block |
|
216 |
e.printStackTrace(); |
|
217 |
} |
|
218 |
return null; |
|
219 |
} */ |
|
220 |
|
|
221 |
private GvNode readNode(MappedByteBuffer buf) { |
|
222 |
GvNode node = new GvNode(); |
|
223 |
node.setIdNode(buf.getInt()); |
|
224 |
node.setX(buf.getDouble()); |
|
225 |
node.setY(buf.getDouble()); |
|
226 |
return node; |
|
227 |
} |
|
228 |
|
|
229 |
private GvEdge readEdge(MappedByteBuffer buf) { |
|
230 |
GvEdge edge = new GvEdge(); |
|
231 |
// memcpy(&Arcos[link_num].idTramo,puntero,sizeof(long)); |
|
232 |
edge.setIdArc(buf.getInt()); |
|
233 |
|
|
234 |
|
|
235 |
// Sentido de digitalizaci?n.Un 1 indica que va en ese sentido, un cero al contrario. |
|
236 |
// memcpy(&Arcos[link_num].sentido,puntero,sizeof(int)); |
|
237 |
edge.setDirec(buf.getInt()); |
|
238 |
|
|
239 |
// idNodeOrig |
|
240 |
edge.setIdNodeOrig(buf.getInt()); |
|
241 |
// memcpy(&node_num1,puntero,sizeof(long)); |
|
242 |
|
|
243 |
// idNodeEnd |
|
244 |
edge.setIdNodeEnd(buf.getInt()); |
|
245 |
// memcpy(&node_num2,puntero,sizeof(long)); |
|
246 |
|
|
247 |
// Read the link costs. |
|
248 |
// Type |
|
249 |
edge.setType(buf.getInt()); |
|
250 |
// memcpy(&Arcos[link_num].TipoTramo,puntero,sizeof(int)); |
|
251 |
|
|
252 |
// Distance |
|
253 |
edge.setDistance(buf.getDouble()); |
|
254 |
edge.setWeight(buf.getDouble()); |
|
255 |
|
|
256 |
// memcpy(&Arcos[link_num].Coste2,puntero,sizeof(float)); |
|
257 |
|
|
258 |
// pNodo1 = &Nodos[node_num1]; |
|
259 |
// Arcos[link_num].idNodo1 = node_num1; |
|
260 |
// |
|
261 |
// Arcos[link_num].idNodo2 = node_num2; |
|
262 |
// pNodo2->Enlaces.Add(link_num); |
|
263 |
|
|
264 |
// // NUEVO 11-JUL-2002 |
|
265 |
// if (Arcos[link_num].sentido) |
|
266 |
// IndiceArcos[Arcos[link_num].idTramo].idArco = link_num; |
|
267 |
// else |
|
268 |
// IndiceArcos[Arcos[link_num].idTramo].idContraArco = link_num; |
|
269 |
// |
|
270 |
// // NUEVO 27-JUL-2003 |
|
271 |
// Arcos[link_num].numSoluc = 0; |
|
272 |
// |
|
273 |
// // NUEVO 23_2_2005 |
|
274 |
// CreaConectores(link_num); |
|
275 |
return edge; |
|
276 |
} |
|
277 |
|
|
278 |
/** |
|
279 |
* @param args |
|
280 |
*/ |
|
281 |
public static void main(String[] args) { |
|
282 |
NetworkMemoryRedLoader redLoader = new NetworkMemoryRedLoader(); |
|
283 |
|
|
284 |
redLoader.loadNetwork(); |
|
285 |
// redLoader.loadJungNetwork(); |
|
286 |
|
|
287 |
} |
|
288 |
|
|
289 |
public File getNetFile() { |
|
290 |
return netFile; |
|
291 |
} |
|
292 |
|
|
293 |
public void setNetFile(File netFile) { |
|
294 |
this.netFile = netFile; |
|
295 |
} |
|
296 |
|
|
297 |
} |
|
298 |
|
|
299 |
|
trunk/extensions/extGraph/src/org/gvsig/graph/core/loaders/NetworkRedLoader.java | ||
---|---|---|
56 | 56 |
import org.gvsig.graph.core.INetworkLoader; |
57 | 57 |
|
58 | 58 |
|
59 |
import edu.uci.ics.jung.graph.Graph; |
|
59 |
/* import edu.uci.ics.jung.graph.Graph;
|
|
60 | 60 |
import edu.uci.ics.jung.graph.Vertex; |
61 | 61 |
import edu.uci.ics.jung.graph.decorators.Indexer; |
62 | 62 |
import edu.uci.ics.jung.graph.impl.DirectedSparseEdge; |
63 | 63 |
import edu.uci.ics.jung.graph.impl.DirectedSparseVertex; |
64 |
import edu.uci.ics.jung.graph.impl.SparseGraph; |
|
64 |
import edu.uci.ics.jung.graph.impl.SparseGraph; */
|
|
65 | 65 |
|
66 | 66 |
/** |
67 | 67 |
* @author fjp |
... | ... | |
161 | 161 |
return null; |
162 | 162 |
} |
163 | 163 |
|
164 |
public Graph loadJungNetwork() |
|
164 |
/* public Graph loadJungNetwork()
|
|
165 | 165 |
{ |
166 | 166 |
SparseGraph g = new SparseGraph(); |
167 | 167 |
long t1 = System.currentTimeMillis(); |
... | ... | |
218 | 218 |
e.printStackTrace(); |
219 | 219 |
} |
220 | 220 |
return null; |
221 |
} |
|
221 |
} */
|
|
222 | 222 |
|
223 | 223 |
private GvNode readNode(MappedByteBuffer buf) { |
224 | 224 |
GvNode node = new GvNode(); |
... | ... | |
284 | 284 |
NetworkRedLoader redLoader = new NetworkRedLoader(); |
285 | 285 |
|
286 | 286 |
redLoader.loadNetwork(); |
287 |
redLoader.loadJungNetwork(); |
|
287 |
// redLoader.loadJungNetwork();
|
|
288 | 288 |
|
289 | 289 |
} |
290 | 290 |
|
trunk/extensions/extGraph/src/org/gvsig/graph/core/writers/NetworkFileRedWriter.java | ||
---|---|---|
55 | 55 |
import org.gvsig.graph.core.GraphException; |
56 | 56 |
import org.gvsig.graph.core.NodeGv; |
57 | 57 |
|
58 |
import com.hardcode.gdbms.engine.instruction.IncompatibleTypesException; |
|
59 |
import com.hardcode.gdbms.engine.values.BooleanValue; |
|
58 | 60 |
import com.hardcode.gdbms.engine.values.NumericValue; |
61 |
import com.hardcode.gdbms.engine.values.Value; |
|
59 | 62 |
import com.hardcode.gdbms.engine.values.ValueFactory; |
60 | 63 |
import com.iver.cit.gvsig.fmap.core.FShape; |
61 | 64 |
import com.iver.cit.gvsig.fmap.core.IGeometry; |
... | ... | |
70 | 73 |
|
71 | 74 |
/** |
72 | 75 |
* @author fjp |
73 |
* |
|
74 | 76 |
* |
77 |
* |
|
75 | 78 |
*/ |
76 | 79 |
public class NetworkFileRedWriter extends AbstractNetworkWriter { |
77 | 80 |
File redFile; |
78 | 81 |
CancellableMonitorable cancel; |
79 | 82 |
private double snapTolerance = 0d; |
83 |
private double unitsFactor = 1.0; // 1.0->secs (no conversion). 60 -> |
|
84 |
// minutes, 3600 hours, etc. |
|
85 |
private String digitalizationDirection; |
|
86 |
private String reverseDigitalizationDirection; |
|
87 |
|
|
80 | 88 |
public NetworkFileRedWriter() { |
81 |
|
|
89 |
|
|
82 | 90 |
// Set up fields for table nodes |
83 | 91 |
nodeFields = new FieldDescription[3]; |
84 | 92 |
FieldDescription fieldNodeId = new FieldDescription(); |
... | ... | |
94 | 102 |
fieldY.setFieldName("Y"); |
95 | 103 |
fieldY.setFieldType(Types.DOUBLE); |
96 | 104 |
fieldY.setFieldDecimalCount(2); |
97 |
|
|
105 |
|
|
98 | 106 |
nodeFields[0] = fieldNodeId; |
99 | 107 |
nodeFields[1] = fieldX; |
100 | 108 |
nodeFields[2] = fieldY; |
101 | 109 |
|
102 |
|
|
103 | 110 |
// Set up fields for table edges |
104 | 111 |
edgeFields = new FieldDescription[7]; |
105 | 112 |
|
... | ... | |
111 | 118 |
FieldDescription fieldDirection = new FieldDescription(); |
112 | 119 |
fieldDirection.setFieldName("Direction"); |
113 | 120 |
fieldDirection.setFieldType(Types.SMALLINT); |
114 |
|
|
121 |
|
|
115 | 122 |
FieldDescription fieldNodeOrigin = new FieldDescription(); |
116 | 123 |
fieldNodeOrigin.setFieldName("NodeOrigin"); |
117 | 124 |
fieldNodeOrigin.setFieldType(Types.INTEGER); |
... | ... | |
126 | 133 |
FieldDescription fieldDistanceDist = new FieldDescription(); |
127 | 134 |
fieldDistanceDist.setFieldName("Dist"); |
128 | 135 |
fieldDistanceDist.setFieldType(Types.DOUBLE); |
129 |
|
|
136 |
|
|
130 | 137 |
FieldDescription fieldDistanceCost = new FieldDescription(); |
131 | 138 |
fieldDistanceCost.setFieldName("Cost"); |
132 | 139 |
fieldDistanceCost.setFieldType(Types.DOUBLE); |
133 |
|
|
140 |
|
|
134 | 141 |
edgeFields[0] = fieldArcID; |
135 | 142 |
edgeFields[1] = fieldDirection; |
136 | 143 |
edgeFields[2] = fieldNodeOrigin; |
... | ... | |
140 | 147 |
edgeFields[6] = fieldDistanceCost; |
141 | 148 |
} |
142 | 149 |
|
143 |
/* (non-Javadoc) |
|
150 |
/* |
|
151 |
* (non-Javadoc) |
|
152 |
* |
|
144 | 153 |
* @see org.gvsig.graph.core.INetworkWriter#writeNetwork(boolean) |
145 | 154 |
*/ |
146 | 155 |
public void writeNetwork() throws BaseException { |
... | ... | |
176 | 185 |
// PORCENTAJE |
177 | 186 |
// PARA SABER SI EST? M?S CERCA DE UN NODO O DEL OTRO. |
178 | 187 |
Hashtable nodeHash = null; |
179 |
if(snapTolerance != 0d) |
|
188 |
if (snapTolerance != 0d)
|
|
180 | 189 |
nodeHash = new SnappingCoordinateMap(snapTolerance); |
181 | 190 |
else |
182 | 191 |
nodeHash = new Hashtable(); |
183 | 192 |
ArrayList nodes = new ArrayList(); |
184 | 193 |
|
185 | 194 |
try { |
186 |
// if (lyr.getShapeType() != FShape.LINE) {
|
|
187 |
if ((lyr.getShapeType() & FShape.LINE) != FShape.LINE){ |
|
195 |
// if (lyr.getShapeType() != FShape.LINE) {
|
|
196 |
if ((lyr.getShapeType() & FShape.LINE) != FShape.LINE) {
|
|
188 | 197 |
return; |
189 | 198 |
} |
190 | 199 |
RandomAccessFile file = new RandomAccessFile(redFile.getPath(), |
191 | 200 |
"rw"); |
192 | 201 |
FileImageOutputStream output = new FileImageOutputStream(file); |
193 |
// FileChannel channel = file.getChannel();
|
|
194 |
// MappedByteBuffer buf = channel.map(MapMode.READ_WRITE, 0,
|
|
195 |
// 16 * 1024);
|
|
196 |
// buf.order(ByteOrder.LITTLE_ENDIAN);
|
|
202 |
// FileChannel channel = file.getChannel();
|
|
203 |
// MappedByteBuffer buf = channel.map(MapMode.READ_WRITE, 0,
|
|
204 |
// 16 * 1024);
|
|
205 |
// buf.order(ByteOrder.LITTLE_ENDIAN);
|
|
197 | 206 |
output.setByteOrder(ByteOrder.LITTLE_ENDIAN); |
198 | 207 |
|
199 | 208 |
nodeCount = 0; |
200 | 209 |
VectorialAdapter adapter = (VectorialAdapter) lyr.getSource(); |
201 | 210 |
adapter.start(); |
202 | 211 |
int numTramos; |
203 |
|
|
212 |
|
|
204 | 213 |
ICoordTrans ct = lyr.getCoordTrans(); |
205 | 214 |
|
206 | 215 |
numTramos = adapter.getShapeCount(); |
... | ... | |
231 | 240 |
int distFieldIndex = -1; |
232 | 241 |
int typeFieldIndex = -1; |
233 | 242 |
int costFieldIndex = -1; |
234 |
|
|
243 |
|
|
235 | 244 |
if (fieldSense != null) |
236 | 245 |
senseFieldIndex = sds.getFieldIndexByName(fieldSense); |
237 | 246 |
if (fieldDist != null) |
... | ... | |
241 | 250 |
if (fieldCost != null) |
242 | 251 |
costFieldIndex = sds.getFieldIndexByName(fieldCost); |
243 | 252 |
|
244 |
DriverAttributes attr = adapter.getDriverAttributes(); |
|
245 |
boolean bMustClone = false; |
|
246 |
if (attr != null) |
|
247 |
{ |
|
248 |
if (attr.isLoadedInMemory()) |
|
249 |
{ |
|
250 |
bMustClone = attr.isLoadedInMemory(); |
|
251 |
} |
|
252 |
} |
|
253 |
DriverAttributes attr = adapter.getDriverAttributes(); |
|
254 |
boolean bMustClone = false; |
|
255 |
if (attr != null) { |
|
256 |
if (attr.isLoadedInMemory()) { |
|
257 |
bMustClone = attr.isLoadedInMemory(); |
|
258 |
} |
|
259 |
} |
|
253 | 260 |
|
254 |
|
|
255 | 261 |
NumericValue valAux = null; |
256 | 262 |
for (i = 0; i < numTramos; i++) { |
257 | 263 |
IGeometry geom = adapter.getShape(i); |
258 |
if (ct != null) |
|
259 |
{ |
|
260 |
if (bMustClone) |
|
261 |
geom = geom.cloneGeometry(); |
|
262 |
geom.reProject(ct); |
|
264 |
if (ct != null) { |
|
265 |
if (bMustClone) |
|
266 |
geom = geom.cloneGeometry(); |
|
267 |
geom.reProject(ct); |
|
263 | 268 |
|
264 | 269 |
} |
265 | 270 |
Geometry jtsGeom = geom.toJTSGeometry(); |
266 | 271 |
Coordinate[] coords = jtsGeom.getCoordinates(); |
267 | 272 |
Coordinate c1 = coords[0]; |
268 | 273 |
Coordinate c2 = coords[coords.length - 1]; |
269 |
|
|
274 |
|
|
270 | 275 |
NodeGv nodeAux; |
271 | 276 |
if (!nodeHash.containsKey(c1)) // No est?. |
272 | 277 |
{ |
... | ... | |
292 | 297 |
idNodo2 = nodeAux.getId().intValue(); |
293 | 298 |
|
294 | 299 |
if (typeFieldIndex != -1) |
295 |
valAux = (NumericValue) sds.getFieldValue(i, typeFieldIndex); |
|
300 |
valAux = (NumericValue) sds |
|
301 |
.getFieldValue(i, typeFieldIndex); |
|
296 | 302 |
else |
297 | 303 |
valAux = ValueFactory.createValue(0); // no hay tipo |
298 | 304 |
arcType = valAux.shortValue(); |
299 | 305 |
// TipoTramo = DBFReadIntegerAttribute(hDBF, i, indiceCampo1); |
300 |
|
|
306 |
|
|
301 | 307 |
if (distFieldIndex != -1) |
302 |
valAux = (NumericValue) sds.getFieldValue(i, distFieldIndex); |
|
308 |
valAux = (NumericValue) sds |
|
309 |
.getFieldValue(i, distFieldIndex); |
|
303 | 310 |
else |
304 | 311 |
valAux = ValueFactory.createValue(jtsGeom.getLength()); |
305 | 312 |
distance = valAux.floatValue(); |
306 | 313 |
// Distancia = (float) DBFReadDoubleAttribute(hDBF, i, |
307 | 314 |
// indiceCampo2); |
308 |
if (costFieldIndex != -1) |
|
309 |
{ |
|
310 |
valAux = (NumericValue) sds.getFieldValue(i, costFieldIndex); |
|
311 |
cost = valAux.doubleValue(); |
|
312 |
} |
|
313 |
else |
|
315 |
if (costFieldIndex != -1) { |
|
316 |
valAux = (NumericValue) sds |
|
317 |
.getFieldValue(i, costFieldIndex); |
|
318 |
cost = valAux.doubleValue() * unitsFactor; |
|
319 |
} else |
|
314 | 320 |
cost = distance; |
315 |
|
|
316 |
|
|
317 | 321 |
|
318 | 322 |
direction = -1; |
319 | 323 |
|
320 | 324 |
if (senseFieldIndex == -1) |
321 | 325 |
direction = 3; // 3-> Doble sentido, 1-> seg?n viene, 2 -> |
322 |
// al rev?s, cualquier otro valor-> No hay |
|
323 |
// arco |
|
326 |
// al rev?s |
|
324 | 327 |
else { |
325 |
valAux = (NumericValue) sds.getFieldValue(i, |
|
326 |
senseFieldIndex); |
|
327 |
direction = valAux.shortValue(); |
|
328 |
Value aux = sds.getFieldValue(i, senseFieldIndex); |
|
329 |
String auxStr = aux.toString(); |
|
330 |
direction = 3; // default |
|
331 |
if (auxStr.equals(digitalizationDirection)) |
|
332 |
direction = 1; |
|
333 |
if (auxStr.equals(reverseDigitalizationDirection)) |
|
334 |
direction = 2; |
|
335 |
|
|
328 | 336 |
} |
329 | 337 |
|
330 | 338 |
if (direction == 3) { |
331 | 339 |
sentidoDigit = 1; // En esa direcci?n |
332 |
writeEdge(output, i, sentidoDigit, idNodo1, idNodo2, arcType,
|
|
333 |
distance, cost); |
|
340 |
writeEdge(output, i, sentidoDigit, idNodo1, idNodo2, |
|
341 |
arcType, distance, cost);
|
|
334 | 342 |
edgeCount++; |
335 | 343 |
|
336 | 344 |
sentidoDigit = 0; |
337 |
writeEdge(output, i, sentidoDigit, idNodo2, idNodo1, arcType,
|
|
338 |
distance, cost); |
|
345 |
writeEdge(output, i, sentidoDigit, idNodo2, idNodo1, |
|
346 |
arcType, distance, cost);
|
|
339 | 347 |
edgeCount++; |
340 | 348 |
|
341 | 349 |
} |
342 | 350 |
if (direction == 1) { |
343 | 351 |
sentidoDigit = 1; // En esa direcci?n |
344 |
writeEdge(output, i, sentidoDigit, idNodo1, idNodo2, arcType,
|
|
345 |
distance, cost); |
|
352 |
writeEdge(output, i, sentidoDigit, idNodo1, idNodo2, |
|
353 |
arcType, distance, cost);
|
|
346 | 354 |
edgeCount++; |
347 | 355 |
} |
348 | 356 |
if (direction == 2) { |
349 | 357 |
sentidoDigit = 0; |
350 |
writeEdge(output, i, sentidoDigit, idNodo2, idNodo1, arcType,
|
|
351 |
distance, cost); |
|
358 |
writeEdge(output, i, sentidoDigit, idNodo2, idNodo1, |
|
359 |
arcType, distance, cost);
|
|
352 | 360 |
edgeCount++; |
353 | 361 |
|
354 | 362 |
} |
355 |
|
|
356 |
if(cancel != null){
|
|
363 |
|
|
364 |
if (cancel != null) {
|
|
357 | 365 |
cancel.reportStep(); |
358 |
|
|
366 |
|
|
359 | 367 |
} |
360 |
}//for |
|
368 |
}// for
|
|
361 | 369 |
|
362 |
|
|
363 |
for (int j=0; j < nodes.size(); j++) { |
|
370 |
for (int j = 0; j < nodes.size(); j++) { |
|
364 | 371 |
NodeGv node = (NodeGv) nodes.get(j); |
365 | 372 |
output.writeInt(node.getId().intValue()); |
366 | 373 |
output.writeDouble(node.getCoordinate().x); |
... | ... | |
376 | 383 |
// buf.force(); |
377 | 384 |
output.close(); |
378 | 385 |
file.close(); |
379 |
|
|
386 |
|
|
380 | 387 |
adapter.stop(); |
381 |
|
|
388 |
|
|
382 | 389 |
cancel.setCurrentStep(cancel.getFinalStep()); |
383 | 390 |
|
384 |
return ;
|
|
391 |
return; |
|
385 | 392 |
} catch (IOException e) { |
386 | 393 |
e.printStackTrace(); |
387 | 394 |
throw new GraphException(e); |
388 | 395 |
} |
389 |
// } catch (ReadDriverException e) {
|
|
390 |
// e.printStackTrace();
|
|
391 |
// throw new IOException(e);
|
|
392 |
// } catch (ExpansionFileReadException e) {
|
|
393 |
// e.printStackTrace();
|
|
394 |
// throw new IOException(e);
|
|
395 |
// }
|
|
396 |
// } catch (ReadDriverException e) {
|
|
397 |
// e.printStackTrace();
|
|
398 |
// throw new IOException(e);
|
|
399 |
// } catch (ExpansionFileReadException e) {
|
|
400 |
// e.printStackTrace();
|
|
401 |
// throw new IOException(e);
|
|
402 |
// }
|
|
396 | 403 |
} |
397 | 404 |
|
398 |
|
|
399 | 405 |
public void setCancellableMonitorable(CancellableMonitorable cancel) { |
400 | 406 |
this.cancel = cancel; |
401 |
|
|
407 |
|
|
402 | 408 |
} |
403 | 409 |
|
404 | 410 |
public void setRedFile(File redFile) { |
405 | 411 |
this.redFile = redFile; |
406 |
|
|
412 |
|
|
407 | 413 |
} |
408 | 414 |
|
Also available in: Unified diff