Revision 385

View differences:

org.gvsig.geoprocess/trunk/org.gvsig.geoprocess/org.gvsig.geoprocess.algorithm/org.gvsig.geoprocess.algorithm.groupby/src/main/java/org/gvsig/geoprocess/algorithm/groupby/GroupByAlgorithm.java
45 45
import org.gvsig.fmap.geom.Geometry.TYPES;
46 46
import org.gvsig.fmap.geom.aggregate.MultiCurve;
47 47
import org.gvsig.fmap.geom.aggregate.MultiPoint;
48
import org.gvsig.fmap.geom.aggregate.MultiPrimitive;
48 49
import org.gvsig.fmap.geom.aggregate.MultiSurface;
49 50
import org.gvsig.fmap.geom.exception.CreateGeometryException;
50 51
import org.gvsig.fmap.geom.primitive.Curve;
......
101 102
        // setGeneratesUserDefinedRasterOutput(false);
102 103
		try {
103 104
			m_Parameters.addInputVectorLayer(LAYER, getTranslation("Input_layer"), IVectorLayer.SHAPE_TYPE_WRONG, true);
104
			m_Parameters.addNumericalValue(FIELD, getTranslation("Field"), 0, AdditionalInfoNumericalValue.NUMERICAL_VALUE_INTEGER);
105
			m_Parameters.addNumericalValue(FIELD_DATE, getTranslation("Field_date"), 0, AdditionalInfoNumericalValue.NUMERICAL_VALUE_INTEGER);
105
			m_Parameters.addString(FIELD, getTranslation("Field"));
106
			m_Parameters.addString(FIELD_DATE, getTranslation("Field_date"));
106 107
			m_Parameters.addString(FIELD_LIST, getTranslation("Field_list"));
107 108
			m_Parameters.addString(FUNCTION_LIST, getTranslation("Function_list"));
108 109
			m_Parameters.addString(LAYER_NAME, getTranslation("Layer_name"));
......
122 123
    		throw new GeoAlgorithmExecutionException(getTranslation("file_exists"));
123 124
    	}
124 125
		IVectorLayer layer = m_Parameters.getParameterValueAsVectorLayer(LAYER);
125
		int groupByField = m_Parameters.getParameterValueAsInt(FIELD);
126
		int positionFieldDate = m_Parameters.getParameterValueAsInt(FIELD_DATE);
126
		String groupByField = m_Parameters.getParameterValueAsString(FIELD);
127
		String fieldDate = m_Parameters.getParameterValueAsString(FIELD_DATE);
127 128
		String fieldsString = m_Parameters.getParameterValueAsString(FIELD_LIST);
128 129
		String functionsString = m_Parameters.getParameterValueAsString(FUNCTION_LIST);
129 130
		String layerName = m_Parameters.getParameterValueAsString(LAYER_NAME);
......
131 132
		int inputShapeType = layer.getShapeType();
132 133
		
133 134
		String[] funcList = functionsString.split(";");
134
		int[] fieldList = getFieldList(fieldsString);
135
		String[] fieldList = fieldsString.split(";");
135 136
		
136 137
		if(fieldList != null && funcList != null) {
137 138
			if(fieldList.length != funcList.length) {
......
173 174
				loadFeature(featureStore, 
174 175
						outFeatStore, 
175 176
						fieldNameGrouped, 
176
						positionFieldDate, 
177
						fieldDate, 
177 178
						groupedValue, 
178 179
						fieldList, 
179 180
						funcList,
......
192 193
	private void loadFeature(FeatureStore inStore, 
193 194
			FeatureStore outStore, 
194 195
			String fieldNameGrouped,
195
			int positionFieldDate,
196
			String fieldDate,
196 197
			String groupedValue, 
197
			int[] fieldList, 
198
			String[] fieldList, 
198 199
			String[] funcList,
199 200
			int geomOption) throws DataException {
200 201
		DataManager manager = DALLocator.getDataManager();
......
242 243
						if(values[i] == null) 
243 244
							values[i] = v;
244 245
					}
245
					if(funcList[i].compareToIgnoreCase("Last") == 0 && positionFieldDate != -1) {
246
					if(funcList[i].compareToIgnoreCase("Last") == 0 && fieldDate != null) {
246 247
						if(lastDate == null || 
247 248
								values[i] == null || 
248
								lastDate.isAfter(feature.getInstant(positionFieldDate))) {
249
							lastDate = feature.getInstant(positionFieldDate);
250
							values[i] = updateAny((Double)values[i], v);
249
								lastDate.isAfter(feature.getInstant(fieldDate))) {
250
							lastDate = feature.getInstant(fieldDate);
251
							values[i] = v;
251 252
						}
252 253
					}
253 254
				}
......
257 258
				switch (geomOption) {
258 259
				case 0: //Adds only the first geometry
259 260
					if(nFeaturesByGroup == 0) { //If is the first feature
260
						feat.set(outStore.getDefaultFeatureType().getDefaultGeometryAttributeName(), 
261
								feature.getDefaultGeometry());
261
						Geometry g = feature.getDefaultGeometry();
262
						if(!(g instanceof MultiPrimitive)) {
263
							List<Geometry> gList = new ArrayList<Geometry>();
264
							gList.add(g);
265
							g = buildMultiGeometry(gList);
266
						}
267
						feat.set(outStore.getDefaultFeatureType().getDefaultGeometryAttributeName(), g);
262 268
					}
263 269
					break;
264 270
				case 1: //Multigeometry with all geometries
......
411 417
	 * @return
412 418
	 * @throws DataException
413 419
	 */
414
	private Set<String> getGroupedValues(FeatureStore featureStore, int groupByField) throws DataException {
420
	private Set<String> getGroupedValues(FeatureStore featureStore, String groupByField) throws DataException {
415 421
		HashMap<String, String> valueGrouped = new HashMap<String, String>();
416 422
		FeatureSet featureSet = featureStore.getFeatureSet();
417 423
		DisposableIterator it = featureSet.iterator();
......
452 458
     */
453 459
    private FeatureStore buildOutPutStore(FeatureType featureType,
454 460
    		String sextanteLayerName,
455
    		int groupByField,
456
    		int[] fieldList,
461
    		String groupByField,
462
    		String[] fieldList,
457 463
    		String[] funcList,
458 464
    		int geomOption,
459 465
    		int inputShapeType) {
org.gvsig.geoprocess/trunk/org.gvsig.geoprocess/org.gvsig.geoprocess.algorithm/org.gvsig.geoprocess.algorithm.groupby/src/main/java/org/gvsig/geoprocess/algorithm/groupby/GroupByParametersPanel.java
88 88
	private JComboBox                        layersCombo        = null;
89 89
	private JList                            fieldList          = null;
90 90
	private JList                            operationJList     = null;
91
	private JScrollPane                      jlistScroll        = null;
91
	private JScrollPane                      jlistScroll1       = null;
92
	private JScrollPane                      jlistScroll2       = null;
92 93
	private AlgorithmOutputPanel             output             = null;
93 94
	private String[]                         opList             = null;
94 95
	private String[]                         opListLast         = null;
......
331 332
		if (fieldList == null) {
332 333
			fieldList = new JList();
333 334
			fieldList.setModel(new DefaultListModel());
334
			jlistScroll = new JScrollPane(fieldList);
335
			jlistScroll1 = new JScrollPane(fieldList);
335 336
			fieldList.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
336 337
			fieldList.addMouseListener(this);
337 338
			List<String> list = getFieldList();
......
339 340
				((DefaultListModel)this.fieldList.getModel()).addElement(list.get(i));
340 341
			}	
341 342
		}
342
		return jlistScroll;
343
		return jlistScroll1;
343 344
	}
344 345
	
345
	public JScrollPane getOperationJList() {
346
	private JPanel panelOpList = null;
347
	public JPanel getOperationJList() {
346 348
		if (operationJList == null) {
347 349
			operationJList = new JList();
348 350
			operationJList.setModel(new DefaultListModel());
349
			jlistScroll = new JScrollPane(operationJList);
351
			operationJList.setPreferredSize(new Dimension(70, 0));
352
			jlistScroll2 = new JScrollPane(operationJList);
350 353
			operationJList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
351 354
			operationJList.addMouseListener(this);
352
			List<String> list = getFieldList();
353
			for (int i = 0; i < list.size(); i++) {
354
				((DefaultListModel)this.fieldList.getModel()).addElement(list.get(i));
355
			}	
355
			panelOpList = new JPanel(new GridBagLayout());
356
			GridBagConstraints gbc = new GridBagConstraints();
357
			gbc.fill = GridBagConstraints.VERTICAL;
358
			gbc.weighty = 1;
359
			panelOpList.add(operationJList, gbc);
360
			panelOpList.setBorder(BorderFactory.createLineBorder(Color.black));
356 361
		}
357
		return jlistScroll;
362
		return panelOpList;
358 363
	}
359 364
	
360 365
	/**
......
482 487
			ParametersSet params = m_Algorithm.getParameters();
483 488
			params.getParameter(GroupByAlgorithm.LAYER_NAME).setParameterValue("GroupBy_Layer");
484 489
			params.getParameter(GroupByAlgorithm.LAYER).setParameterValue(getSelectedVectorLayer());
485
			params.getParameter(GroupByAlgorithm.FIELD).setParameterValue(getFields1Combo().getSelectedIndex());
486
			List<String> fList = getFieldList();
490
			params.getParameter(GroupByAlgorithm.FIELD).setParameterValue((String)getFields1Combo().getSelectedItem());
491
			//List<String> fList = getFieldList();
487 492
			String dateField = (String)getFields2Combo().getSelectedItem();
488
			int dateFieldPosition = -1;
493
			/*int dateFieldPosition = -1;
489 494
			if(getFields2Combo().getItemCount() > 0) {
490 495
				for (int i = 0; i < fList.size(); i++) {
491 496
					if(fList.get(i).equals(dateField))
492 497
						dateFieldPosition = i;
493 498
				}
494
			}
495
			params.getParameter(GroupByAlgorithm.FIELD_DATE).setParameterValue(dateFieldPosition);
499
			}*/
500
			params.getParameter(GroupByAlgorithm.FIELD_DATE).setParameterValue(dateField);
496 501
			params.getParameter(GroupByAlgorithm.FIELD_LIST).setParameterValue(getFieldStringList());
497 502
			params.getParameter(GroupByAlgorithm.FUNCTION_LIST).setParameterValue(getFunctionStringList());
498 503
			int geom = getButtonFirstGeom().isSelected() ? 0 : getButtonMultiGeom().isSelected() ? 1 : getButtonSpatialFusion().isSelected() ? 2 : -1;
......
535 540
					for (int j = 0; j < fList.size(); j++) {
536 541
						if(fList.get(j).compareTo((String)obj) == 0) {
537 542
							if(value.compareTo("") == 0)
538
								value = j + "";
543
								value = obj + "";
539 544
							else
540
								value += ";" + j;
545
								value += ";" + obj;
541 546
						}
542 547
					}
543 548
				}
......
611 616
	private void addRowToTable() {
612 617
		Object[] values = fieldList.getSelectedValues();
613 618
		for (int i = 0; i < values.length; i++) {
614
			((DefaultTableModel)table.getModel()).addRow(new Object[]{values[i], opList[0]});
619
			Object[] obj = new Object[]{values[i], opList[0]};
620
			((DefaultTableModel)table.getModel()).addRow(obj);
615 621
		}	
616
		
617 622
		//Carga la lista de operaciones
618 623
		loadOperationInJList(getFieldSelectedInTable());
619 624
	}
......
701 706
		try {
702 707
			ftype = fs.getDefaultFeatureType();
703 708
			FeatureAttributeDescriptor desc = ftype.getAttributeDescriptor(field);
704
			if(desc.getDataType().isNumeric())
709
			if(desc != null && desc.getDataType().isNumeric())
705 710
				return true;
706 711
		} catch (DataException e) {
707 712
			return false;

Also available in: Unified diff