-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAccumulationIRIAlgorithm.java
More file actions
1452 lines (1181 loc) · 54.5 KB
/
AccumulationIRIAlgorithm.java
File metadata and controls
1452 lines (1181 loc) · 54.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*******************************************************************************
AccumulationIRIAlgorithm.java
Copyright (C) Nacho Uve
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*******************************************************************************/
package es.udc.sextante.gridAnalysis.IRI;
import com.vividsolutions.jts.geom.Coordinate;
import com.vividsolutions.jts.geom.Envelope;
import com.vividsolutions.jts.geom.Geometry;
import com.vividsolutions.jts.geom.GeometryFactory;
import es.unex.sextante.additionalInfo.AdditionalInfoNumericalValue;
import es.unex.sextante.additionalInfo.AdditionalInfoVectorLayer;
import es.unex.sextante.core.AnalysisExtent;
import es.unex.sextante.core.GeoAlgorithm;
import es.unex.sextante.core.OutputObjectsSet;
import es.unex.sextante.core.ParametersSet;
import es.unex.sextante.core.Sextante;
import es.unex.sextante.dataObjects.IFeature;
import es.unex.sextante.dataObjects.IFeatureIterator;
import es.unex.sextante.dataObjects.IRasterLayer;
import es.unex.sextante.dataObjects.IRecord;
import es.unex.sextante.dataObjects.IVectorLayer;
import es.unex.sextante.dataObjects.vectorFilters.BoundingBoxFilter;
import es.unex.sextante.exceptions.GeoAlgorithmExecutionException;
import es.unex.sextante.exceptions.IteratorException;
import es.unex.sextante.exceptions.NullParameterValueException;
import es.unex.sextante.exceptions.OptionalParentParameterException;
import es.unex.sextante.exceptions.RepeatedParameterNameException;
import es.unex.sextante.exceptions.UndefinedParentParameterNameException;
import es.unex.sextante.exceptions.UnsupportedOutputChannelException;
import es.unex.sextante.exceptions.WrongParameterIDException;
import es.unex.sextante.exceptions.WrongParameterTypeException;
import es.unex.sextante.gui.core.SextanteGUI;
import es.unex.sextante.gui.modeler.ModelAlgorithmIO;
import es.unex.sextante.gui.settings.SextanteModelerSettings;
import es.unex.sextante.outputs.FileOutputChannel;
import es.unex.sextante.outputs.Output;
import es.unex.sextante.parameters.Parameter;
import es.unex.sextante.rasterize.rasterizeVectorLayer.RasterizeVectorLayerAlgorithm;
import es.unex.sextante.vectorTools.autoincrementValue.AutoincrementValueAlgorithm;
import es.unex.sextante.vectorTools.linesToEquispacedPoints.LinesToEquispacedPointsAlgorithm;
/**
*
*
* Observaciones: - Las unidades del SIG deben ser "METROS" - ACCFLOW debe contar celdas (autom�ticamente el algoritmo obtendr� la
* cuenca en km2)
*
* @author uve, jorgelf
*
*/
public class AccumulationIRIAlgorithm
extends
GeoAlgorithm {
private static final int MAX_IRI_DIST = 5100;
//OJO: ?Deberia tener solamente 1 punto?
public static final String VERTIDO = "VERTIDO";
public static final String DEM = "MDT";
public static final String ACCFLOW = "ACCFLOW";
public static final String HE_ATTRIB = "HE_ATTRIB";
public static final String ID_ATTRIB = "ID_ATTRIB";
public static final String RESULT = "RESULT";
//Nombre de capas de FA
private static final String captacions_existentes = "captacions_existentes";
private static final String captacions_propostas = "captacions_propostas";
private static final String espacios_protegidos = "espacios_protegidos";
private static final String zonas_piscicolas_protexidas = "zonas_piscicolas_protexidas";
private static final String praias_marinas = "praias_marinas";
private static final String praias_fluviais = "praias_fluviais";
private static final String zonas_sensibles = "zonas_sensibles";
private static final String embalses = "embalses";
private static final String bateas = "bateas";
private static final String zonas_marisqueo = "zonas_marisqueo";
private static final String piscifactorias = "piscifactorias";
//// Variables
//Habitantes equivalentes
private Integer HE_VALUE = -1;
//Pesos de capas de FA
private static final String captacions_exist_weight = "captacions_exist_weight";
private static final String captacions_propos_weight = "captacions_propos_weight";
private static final String espacios_proteg_weight = "espaciosproteg_weight";
private static final String zonas_piscico_weight = "zonas_piscin_weight";
private static final String praias_marinas_weight = "prais_marinas_weight";
private static final String praias_fluviais_weight = "praias_fluviais_weight";
private static final String zonas_sensibles_weight = "zonas_sensibles_weight";
private static final String embalses_weight = "embalses_weight";
private static final String bateas_weight = "bateas_weight";
private static final String zonas_marisqueo_weight = "zonas_marisqueo_weight";
private static final String piscifactorias_weight = "piscifactorias_weight";
//Capa de masas de agua
private static final String WATER_BODIES = "water_bodies";
private static final String ECO_STATUS = "ecological_estatus";
///// Pesos de otras veriables
private static final String WATERSHED_AREA_RADIO = "watershed_area_radio";
private static final String DBO_before = "DBO_before";
private static final String MAX_DBO_after = "MAX_DBO_after";
private static final String HE_WEIGHT = "HE_WEIGHT";
private static final String DIL_WEIGHT = "DIL_WEIGHT";
//ID o nombre del Vertido
private String ID_VERTIDO = "";
//Habitantes equivalentes
private int he_weight = 0;
//Diluci�n
private int dil_weight = 0;
// OTHER PARAMETERS
private static final String SAMPLE_DIST = "sample_dist";
private static final String SEARCH_FACTOR_RADIO = "search_factor_radio";
private static final String perc_FACT = "perc_FACT";
private static final String perc_DMA = "perc_DMA";
// VARIABLES
private int num_points;
private int sample_dist;
private int num_coastal_rings;
IRasterLayer demLyr;
// Capa de puntos equiespaciados del rio (red de drenaje)
IVectorLayer network_lyr;
// Capa de anillos (poligonos) del ultimo punto network_lyr cuando llega a la costa y no ha llegado a su longitud de estudio
// Cada anillo es de la misma equidistancia
IVectorLayer networkRing_lyr;
IVectorLayer capt_existLyr;
int capt_existWei;
IVectorLayer capt_propostLyr;
int capt_propostWei;
IVectorLayer espacios_ProtLyr;
int espacios_ProtWei;
IVectorLayer zpiscic_protLyr;
int zpiscic_protWei;
IVectorLayer zsensiblesLyr;
int zsensiblesWei;
IVectorLayer praias_marLyr;
int praias_marWei;
IVectorLayer praias_fluLyr;
int praias_fluWei;
IVectorLayer embalsesLyr;
int embalsesWei;
IVectorLayer bateasLyr;
int bateasWei;
IVectorLayer zmarisqueoLyr;
int zmarisqueoWei;
IVectorLayer piscifactoriasLyr;
int piscifactoriasWei;
IVectorLayer vertidoLyr;
IVectorLayer waterBodiesLyr;
int ecoStatusAttribIdx;
int fa_radio = 0;
int perc_fact = 0;
int perc_dma = 0;
double WATERSHED_KM2 = 0;
// VARIABLES DBO
double cmez = 0.0;
double crio = 0.0;
//VARIABLES ECO WEIGHTS
int ecoA_w = 0;
int ecoB_w = 0;
int ecoC_w = 0;
int ecoD_w = 0;
int ecoE_w = 0;
//ARRAY IRI
double[] iri_f1_array;
double[] iri_f2_array;
double[] iri_f3_array;
double[] iri_f4_array;
double[] iri_f5_array;
double[] iri_f6_array;
double[] iri_f7_array;
double[] iri_f8_array;
double[] iri_f9_array;
double[] iri_f10_array;
double[] iri_f11_array;
//ARRAY PARA ALMACENAR IRI_HE, IRI_DIL, IRI_FA, IRI_DMA, IRI_FACT E IRI_TOTAL
double[][] iri_values;
double[] watershed_km2;
@Override
public void defineCharacteristics() {
setName("Accumulation IRI");
setGroup("AA_IRI Algorithms");
setUserCanDefineAnalysisExtent(true);
try {
m_Parameters.addInputVectorLayer(VERTIDO, Sextante.getText("Vertidos"), AdditionalInfoVectorLayer.SHAPE_TYPE_POINT, true);
try {
m_Parameters.addTableField(ID_ATTRIB, "ID Vertido", VERTIDO);
m_Parameters.addTableField(HE_ATTRIB, "Atributo Hab. Equiv.", VERTIDO);
}
catch (final UndefinedParentParameterNameException e) {
e.printStackTrace();
}
catch (final OptionalParentParameterException e) {
e.printStackTrace();
}
// Pesos
m_Parameters.addNumericalValue(HE_WEIGHT, "Peso HE", 25, AdditionalInfoNumericalValue.NUMERICAL_VALUE_INTEGER);
m_Parameters.addNumericalValue(DIL_WEIGHT, "Peso DIL", 10, AdditionalInfoNumericalValue.NUMERICAL_VALUE_INTEGER);
// Factores Ambientales
m_Parameters.addInputVectorLayer(captacions_existentes, Sextante.getText("captacions_existentes"),
AdditionalInfoVectorLayer.SHAPE_TYPE_ANY, true);
m_Parameters.addNumericalValue(captacions_exist_weight, captacions_existentes, 10,
AdditionalInfoNumericalValue.NUMERICAL_VALUE_INTEGER);
m_Parameters.addInputVectorLayer(captacions_propostas, Sextante.getText("captacions_propostas"),
AdditionalInfoVectorLayer.SHAPE_TYPE_ANY, true);
m_Parameters.addNumericalValue(captacions_propos_weight, captacions_propostas, 4,
AdditionalInfoNumericalValue.NUMERICAL_VALUE_INTEGER);
m_Parameters.addInputVectorLayer(espacios_protegidos, Sextante.getText("Espacios_Protegidos"),
AdditionalInfoVectorLayer.SHAPE_TYPE_ANY, true);
m_Parameters.addNumericalValue(espacios_proteg_weight, espacios_protegidos, 15,
AdditionalInfoNumericalValue.NUMERICAL_VALUE_INTEGER);
m_Parameters.addInputVectorLayer(zonas_piscicolas_protexidas, Sextante.getText("zonas_piscicolas_protexidas"),
AdditionalInfoVectorLayer.SHAPE_TYPE_ANY, true);
m_Parameters.addNumericalValue(zonas_piscico_weight, zonas_piscicolas_protexidas, 9,
AdditionalInfoNumericalValue.NUMERICAL_VALUE_INTEGER);
m_Parameters.addInputVectorLayer(praias_marinas, Sextante.getText("Praias_marinas"),
AdditionalInfoVectorLayer.SHAPE_TYPE_ANY, true);
m_Parameters.addNumericalValue(praias_marinas_weight, praias_marinas, 4,
AdditionalInfoNumericalValue.NUMERICAL_VALUE_INTEGER);
m_Parameters.addInputVectorLayer(praias_fluviais, Sextante.getText("Praias_fluviais"),
AdditionalInfoVectorLayer.SHAPE_TYPE_ANY, true);
m_Parameters.addNumericalValue(praias_fluviais_weight, praias_fluviais, 4,
AdditionalInfoNumericalValue.NUMERICAL_VALUE_INTEGER);
m_Parameters.addInputVectorLayer(zonas_sensibles, Sextante.getText("Zonas_sensibles"),
AdditionalInfoVectorLayer.SHAPE_TYPE_ANY, true);
m_Parameters.addNumericalValue(zonas_sensibles_weight, zonas_sensibles, 7,
AdditionalInfoNumericalValue.NUMERICAL_VALUE_INTEGER);
m_Parameters.addInputVectorLayer(embalses, Sextante.getText("Embalses_y_lagos"),
AdditionalInfoVectorLayer.SHAPE_TYPE_ANY, true);
m_Parameters.addNumericalValue(embalses_weight, embalses, 2, AdditionalInfoNumericalValue.NUMERICAL_VALUE_INTEGER);
m_Parameters.addInputVectorLayer(bateas, Sextante.getText("Bateas"), AdditionalInfoVectorLayer.SHAPE_TYPE_ANY, true);
m_Parameters.addNumericalValue(bateas_weight, bateas, 4, AdditionalInfoNumericalValue.NUMERICAL_VALUE_INTEGER);
m_Parameters.addInputVectorLayer(zonas_marisqueo, Sextante.getText("Zonas_marisqueo"),
AdditionalInfoVectorLayer.SHAPE_TYPE_ANY, true);
m_Parameters.addNumericalValue(zonas_marisqueo_weight, zonas_marisqueo, 4,
AdditionalInfoNumericalValue.NUMERICAL_VALUE_INTEGER);
m_Parameters.addInputVectorLayer(piscifactorias, Sextante.getText("Piscifactorias"),
AdditionalInfoVectorLayer.SHAPE_TYPE_ANY, true);
m_Parameters.addNumericalValue(piscifactorias_weight, piscifactorias, 2,
AdditionalInfoNumericalValue.NUMERICAL_VALUE_INTEGER);
// MASAS DE AGUA Y SU ESTADO ECOLOGICO
m_Parameters.addInputVectorLayer(WATER_BODIES, Sextante.getText("Masas_de_agua"),
AdditionalInfoVectorLayer.SHAPE_TYPE_ANY, true);
try {
m_Parameters.addTableField(ECO_STATUS, "Estado ecologico", WATER_BODIES);
}
catch (final UndefinedParentParameterNameException e) {
e.printStackTrace();
}
catch (final OptionalParentParameterException e) {
e.printStackTrace();
}
// MDT y ACCFLOW
m_Parameters.addInputRasterLayer(DEM, Sextante.getText("MDT"), true);
m_Parameters.addInputRasterLayer(ACCFLOW, Sextante.getText("ACCFLOW"), true);
// Parametros de la red de drenaje
m_Parameters.addNumericalValue(SAMPLE_DIST, "Distancia entre puntos del rio", 100,
AdditionalInfoNumericalValue.NUMERICAL_VALUE_INTEGER);
m_Parameters.addNumericalValue(WATERSHED_AREA_RADIO, "Radio para buscar el max area de cuenca", 100,
AdditionalInfoNumericalValue.NUMERICAL_VALUE_INTEGER);
m_Parameters.addNumericalValue(SEARCH_FACTOR_RADIO, "Radio para buscar factores amb.", 100,
AdditionalInfoNumericalValue.NUMERICAL_VALUE_INTEGER);
//Parametros para el calculo de la dilucion
//Tambien llamado "C_mez"
m_Parameters.addNumericalValue(MAX_DBO_after,
"Concentracion de DBO maxima permitida del rio despues del vertido, en ppm", 6.0,
AdditionalInfoNumericalValue.NUMERICAL_VALUE_DOUBLE);
//Tambien llamado "C_rio"
m_Parameters.addNumericalValue(DBO_before, "Concentracion de DBO del rio antes del vertido, en ppm", 3.0,
AdditionalInfoNumericalValue.NUMERICAL_VALUE_DOUBLE);
//Importancia de los dos tipos de IRI
m_Parameters.addNumericalValue(perc_DMA, "Importancia relativa de IRI_dma", 40,
AdditionalInfoNumericalValue.NUMERICAL_VALUE_INTEGER);
m_Parameters.addNumericalValue(perc_FACT, "Importancia relativa de IRI_fact", 60,
AdditionalInfoNumericalValue.NUMERICAL_VALUE_INTEGER);
//Pesos segun el estado ecologico
m_Parameters.addNumericalValue("ecoW_E", "ecoW_E", 100, AdditionalInfoNumericalValue.NUMERICAL_VALUE_INTEGER);
m_Parameters.addNumericalValue("ecoW_D", "ecoW_D", 64, AdditionalInfoNumericalValue.NUMERICAL_VALUE_INTEGER);
m_Parameters.addNumericalValue("ecoW_C", "ecoW_C", 20, AdditionalInfoNumericalValue.NUMERICAL_VALUE_INTEGER);
m_Parameters.addNumericalValue("ecoW_B", "ecoW_B", 1, AdditionalInfoNumericalValue.NUMERICAL_VALUE_INTEGER);
m_Parameters.addNumericalValue("ecoW_A", "ecoW_A", 0, AdditionalInfoNumericalValue.NUMERICAL_VALUE_INTEGER);
// Registro los Outputs
addOutputRasterLayer("RESULT_rasterize_vert", "RESULT_rasterize_vert", 1);
addOutputVectorLayer("RESULT_network", "RESULT_network", AdditionalInfoVectorLayer.SHAPE_TYPE_LINE);
addOutputVectorLayer("RESULT_netPoints", "RESULT_netPoints", AdditionalInfoVectorLayer.SHAPE_TYPE_POINT);
addOutputVectorLayer("RESULT_netPoints50", "RESULT_netPoints50", AdditionalInfoVectorLayer.SHAPE_TYPE_POINT);
addOutputVectorLayer("RESULT_networkRing", "RESULT_networkRing", AdditionalInfoVectorLayer.SHAPE_TYPE_POLYGON);
addOutputVectorLayer("IRI_network", "IRI_network", AdditionalInfoVectorLayer.SHAPE_TYPE_POINT);
addOutputVectorLayer("IRI_sumarize", "IRI_sumarize", AdditionalInfoVectorLayer.SHAPE_TYPE_POINT);
}
catch (final RepeatedParameterNameException e) {
Sextante.addErrorToLog(e);
}
}
private void initVariables() {
try {
demLyr = m_Parameters.getParameterValueAsRasterLayer(this.DEM);
vertidoLyr = m_Parameters.getParameterValueAsVectorLayer(VERTIDO);
final int he_idx = m_Parameters.getParameterValueAsInt(HE_ATTRIB);
final IFeatureIterator iter = vertidoLyr.iterator();
// Only 1 iteration per vertido layer
for (int i = 0; (i < 1) && iter.hasNext(); i++) {
IFeature n;
try {
n = iter.next();
final IRecord r = n.getRecord();
System.out.println("****************" + he_idx);
HE_VALUE = Integer.valueOf(r.getValue(he_idx).toString());
System.out.println("**************** HE_VALUE: " + HE_VALUE);
}
catch (final IteratorException e) {
e.printStackTrace();
}
}
iter.close();
vertidoLyr.open();
ID_VERTIDO = (String)getFirstFeature(vertidoLyr).getRecord().getValue(m_Parameters.getParameterValueAsInt(ID_ATTRIB));
ID_VERTIDO = ID_VERTIDO.replaceAll(" ", "-");
vertidoLyr.close();
capt_existLyr = m_Parameters.getParameterValueAsVectorLayer(captacions_existentes);
//podemos usar fa1_w
capt_existWei = m_Parameters.getParameterValueAsInt(captacions_exist_weight);
capt_propostLyr = m_Parameters.getParameterValueAsVectorLayer(captacions_propostas);
//podemos usar fa2_w
capt_propostWei = m_Parameters.getParameterValueAsInt(captacions_propos_weight);
espacios_ProtLyr = m_Parameters.getParameterValueAsVectorLayer(espacios_protegidos);
//podemos usar fa3_w
espacios_ProtWei = m_Parameters.getParameterValueAsInt(espacios_proteg_weight);
zpiscic_protLyr = m_Parameters.getParameterValueAsVectorLayer(zonas_piscicolas_protexidas);
//podemos usar fa4_w
zpiscic_protWei = m_Parameters.getParameterValueAsInt(zonas_piscico_weight);
praias_marLyr = m_Parameters.getParameterValueAsVectorLayer(praias_marinas);
//podemos usar fa5_w
praias_marWei = m_Parameters.getParameterValueAsInt(praias_marinas_weight);
praias_fluLyr = m_Parameters.getParameterValueAsVectorLayer(praias_fluviais);
//podemos usar fa6_w
praias_fluWei = m_Parameters.getParameterValueAsInt(praias_fluviais_weight);
zsensiblesLyr = m_Parameters.getParameterValueAsVectorLayer(zonas_sensibles);
//podemos usar fa7_w
zsensiblesWei = m_Parameters.getParameterValueAsInt(zonas_sensibles_weight);
embalsesLyr = m_Parameters.getParameterValueAsVectorLayer(embalses);
//podemos usar fa8_w
embalsesWei = m_Parameters.getParameterValueAsInt(embalses_weight);
bateasLyr = m_Parameters.getParameterValueAsVectorLayer(bateas);
//podemos usar fa9_w
bateasWei = m_Parameters.getParameterValueAsInt(bateas_weight);
zmarisqueoLyr = m_Parameters.getParameterValueAsVectorLayer(zonas_marisqueo);
//podemos usar fa10_w
zmarisqueoWei = m_Parameters.getParameterValueAsInt(zonas_marisqueo_weight);
piscifactoriasLyr = m_Parameters.getParameterValueAsVectorLayer(piscifactorias);
//podemos usar fa11_w
piscifactoriasWei = m_Parameters.getParameterValueAsInt(piscifactorias_weight);
//DMA Layer
waterBodiesLyr = m_Parameters.getParameterValueAsVectorLayer(WATER_BODIES);
ecoStatusAttribIdx = m_Parameters.getParameterValueAsInt(ECO_STATUS);
fa_radio = m_Parameters.getParameterValueAsInt(SEARCH_FACTOR_RADIO);
perc_fact = m_Parameters.getParameterValueAsInt(perc_FACT);
perc_dma = m_Parameters.getParameterValueAsInt(perc_DMA);
he_weight = m_Parameters.getParameterValueAsInt(HE_WEIGHT);
dil_weight = m_Parameters.getParameterValueAsInt(DIL_WEIGHT);
sample_dist = m_Parameters.getParameterValueAsInt(SAMPLE_DIST);
num_points = (MAX_IRI_DIST / sample_dist);
iri_values = new double[num_points][6];
watershed_km2 = new double[num_points];
ecoA_w = m_Parameters.getParameterValueAsInt("ecoW_A");
ecoB_w = m_Parameters.getParameterValueAsInt("ecoW_B");
ecoC_w = m_Parameters.getParameterValueAsInt("ecoW_C");
ecoD_w = m_Parameters.getParameterValueAsInt("ecoW_D");
ecoE_w = m_Parameters.getParameterValueAsInt("ecoW_E");
cmez = m_Parameters.getParameterValueAsDouble(MAX_DBO_after);
crio = m_Parameters.getParameterValueAsDouble(DBO_before);
}
catch (final WrongParameterTypeException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
catch (final WrongParameterIDException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
catch (final NullParameterValueException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
@Override
public boolean processAlgorithm() throws GeoAlgorithmExecutionException {
initVariables();
final int heAttr = m_Parameters.getParameterValueAsInt(HE_ATTRIB);
//////////////////////
// RASTERIZE
final RasterizeVectorLayerAlgorithm alg = new RasterizeVectorLayerAlgorithm();
ParametersSet params = alg.getParameters();
params.getParameter(RasterizeVectorLayerAlgorithm.LAYER).setParameterValue(vertidoLyr);
params.getParameter(RasterizeVectorLayerAlgorithm.FIELD).setParameterValue(heAttr);
OutputObjectsSet oo = alg.getOutputObjects();
AnalysisExtent extent = new AnalysisExtent(demLyr);
//extent.setCellSize(25);
extent.enlargeOneCell();
alg.setAnalysisExtent(extent);
System.out.println("-------------------------- RASTERIZE");
boolean bSucess = alg.execute(m_Task, m_OutputFactory);
IRasterLayer resultRasterize = null;
if (bSucess) {
resultRasterize = (IRasterLayer) oo.getOutput(RasterizeVectorLayerAlgorithm.RESULT).getOutputObject();
m_OutputObjects.getOutput("RESULT_rasterize_vert").setOutputObject(resultRasterize);
}
else {
return false;
}
System.out.println(resultRasterize.getMaxValue());
//////////////////////
// CHANNEL NETWORK
System.out.println("-------------------------- CHANNEL NETWORK");
//Load model
String modelsFolder = SextanteGUI.getSettingParameterValue(SextanteModelerSettings.MODELS_FOLDER);
GeoAlgorithm geomodel = ModelAlgorithmIO.loadModelAsAlgorithm(modelsFolder + "/" +"iri_channel_step2.model");
geomodel.setAnalysisExtent(extent);
params = geomodel.getParameters();
for (int j=0; j < params.getNumberOfParameters(); j++) {
Parameter p = params.getParameter(j);
if (p.getParameterDescription().equalsIgnoreCase("Punto")){
params.getParameter(j).setParameterValue(vertidoLyr);
} else if (p.getParameterDescription().equalsIgnoreCase("MDT")){
params.getParameter(j).setParameterValue(demLyr);
} else if (p.getParameterDescription().equalsIgnoreCase("pto_rasterized")){
params.getParameter(j).setParameterValue(resultRasterize);
} else if (p.getParameterDescription().equalsIgnoreCase("rios")){
params.getParameter(j).setParameterValue(waterBodiesLyr);
}
}
oo = geomodel.getOutputObjects();
extent = new AnalysisExtent(demLyr);
extent.enlargeOneCell();
geomodel.setAnalysisExtent(extent);
bSucess = geomodel.execute(m_Task, m_OutputFactory);
IVectorLayer resultNetwork = null;
if (bSucess) {
OutputObjectsSet outputs = geomodel.getOutputObjects();
for (int j = 0; j < outputs.getOutputLayersCount(); j++) {
Output o = outputs.getOutput(j);
System.out.println(j + " output name: " + o.getDescription() + " " + o.getName() + " " + o.getTypeDescription()) ;
if (o.getDescription().equalsIgnoreCase("IRI_river")){
resultNetwork = (IVectorLayer) o.getOutputObject();
resultNetwork.open();
System.out.println(">>>>>>>>> resultNetwork.feats: " + resultNetwork.getShapesCount());
m_OutputObjects.getOutput("RESULT_network").setOutputObject(resultNetwork);
resultNetwork.close();
}
}
} else {
System.out.println("NOT SUCCESS THE GEOMODEL.EXECUTE!!!!!!!!!!!");
}
//To avoid more than one network
resultNetwork.addFilter(new FirstFeaturesVectorFilter(1));
resultNetwork.open();
System.out.println("");
System.out.println("Network lines: " + resultNetwork.getShapesCount());
System.out.println("Network line LENGHT: " + getFirstFeature(resultNetwork).getGeometry().getLength());
System.out.println("");
resultNetwork.close();
//////////////////////
// NETWORK TO POINTS
final LinesToEquispacedPointsAlgorithm algLines = new LinesToEquispacedPointsAlgorithm();
params = algLines.getParameters();
params.getParameter(algLines.LINES).setParameterValue(resultNetwork);
params.getParameter(algLines.DISTANCE).setParameterValue(sample_dist);
oo = algLines.getOutputObjects();
extent = new AnalysisExtent(resultNetwork);
extent.setCellSize(25.);
extent.enlargeOneCell();
algLines.setAnalysisExtent(extent);
System.out.println("-------------------------- NETWORK TO POINTS");
System.out.println("Feat count (filter): " + resultNetwork.getShapesCount());
bSucess = algLines.execute(m_Task, m_OutputFactory);
System.out.println("-----------------------");
IVectorLayer resultNet_Points = null;
if (bSucess) {
resultNet_Points = (IVectorLayer) oo.getOutput(algLines.RESULT).getOutputObject();
// NOT OUT... before autoincrement!!
m_OutputObjects.getOutput("RESULT_netPoints").setOutputObject(resultNet_Points);
}
else {
return false;
}
//////////////////////
// AUTOINCREMENT and GET ONLY ???50??? points
final AutoincrementValueAlgorithm algAuto = new AutoincrementValueAlgorithm();
params = algAuto.getParameters();
params.getParameter(algAuto.LAYER).setParameterValue(resultNet_Points);
params.getParameter(algAuto.FIELD).setParameterValue(0); // I know it is "ID" attrib.
//params.getParameter(algLines.RESULT).setParameterValue(resultRasterize);
oo = algAuto.getOutputObjects();
extent = new AnalysisExtent(resultNetwork);
extent.setCellSize(25.);
extent.enlargeOneCell();
algAuto.setAnalysisExtent(extent);
System.out.println("-------------------------- ONLY 50 NETWORK POINTS");
bSucess = algAuto.execute(m_Task, m_OutputFactory);
IVectorLayer resultNet_Points2 = null;
IVectorLayer vectLyr = null;
if (bSucess) {
resultNet_Points2 = (IVectorLayer) oo.getOutput(algAuto.RESULT).getOutputObject();
//TODO Here we would like to create a new layer calling...
//resultNet_Points3 = getFirstFeatures(resultNet_Points2, num_points);
resultNet_Points2.open();
System.out.println("-------------------------resultNet_Points2.count(): " + resultNet_Points2.getShapesCount());
resultNet_Points2.close();
//resultNet_Points2.addFilter(new FirstFeaturesVectorFilter(num_points));
// Set the layer used after
network_lyr = getFirstFeatures(resultNet_Points2, num_points);
network_lyr.open();
System.out.println("-------------------------network_lyr.count(): " + network_lyr.getShapesCount());
network_lyr.close();
}
else {
return false;
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////
// COASTAL
//////////////////////
// COASTAL RINGS
// See if the waste_water_spill affects a coastal sector
// Primero se calcula con anillos (cortados solo en la zonas de mar)
// Luego se crean puntos (siguiendo la direccion y sentido del rio en tierra) para la representacion final
networkRing_lyr = null;
network_lyr.open();
int num_points_network = network_lyr.getShapesCount();
if (num_points_network > 0 && num_points_network < num_points ) {
System.out.println("-------------------------- COASTAL RINGS ARE NECESSARY -------------------------- "
+ num_points_network);
// Create a layer with the last point of the network
final IVectorLayer lastNetwork = network_lyr;
lastNetwork.addFilter(new LastFeaturesVectorFilter( num_points_network, 1));
num_coastal_rings = num_points - num_points_network;
System.out.println("---------> num_rings: " + num_coastal_rings);
final IFeature firstfeature = getFirstFeature(lastNetwork);
Geometry geom = firstfeature.getGeometry().buffer(num_coastal_rings * sample_dist);
final Envelope env = geom.getEnvelopeInternal();
extent = new AnalysisExtent();
final boolean recalculate_cellsize = true;
extent.setXRange(env.getMinX(), env.getMaxX(), recalculate_cellsize);
extent.setYRange(env.getMinY(), env.getMaxY(), recalculate_cellsize);
extent.setCellSize(demLyr.getLayerCellSize());
//Load model
modelsFolder = SextanteGUI.getSettingParameterValue(SextanteModelerSettings.MODELS_FOLDER);
geomodel = ModelAlgorithmIO.loadModelAsAlgorithm(modelsFolder + "/" +"bufferRing_clip_ocean-land.model");
geomodel.setAnalysisExtent(extent);
params = geomodel.getParameters();
for (int j=0; j < params.getNumberOfParameters(); j++) {
Parameter p = params.getParameter(j);
if (p.getParameterDescription().equalsIgnoreCase("Point")){
params.getParameter(j).setParameterValue(lastNetwork);
}
if (p.getParameterDescription().equalsIgnoreCase("Raster")){
params.getParameter(j).setParameterValue(demLyr);
}
if (p.getParameterDescription().equalsIgnoreCase("Buffer_dist")){
params.getParameter(j).setParameterValue(new Double(sample_dist));
}
if (p.getParameterDescription().equalsIgnoreCase("Rings_number")){
params.getParameter(j).setParameterValue(new Double(num_coastal_rings));
}
}
bSucess = geomodel.execute(m_Task, m_OutputFactory);
if (bSucess) {
OutputObjectsSet outputs = geomodel.getOutputObjects();
for (int j = 0; j < outputs.getOutputLayersCount(); j++) {
Output o = outputs.getOutput(j);
System.out.println(j + " output name: " + o.getDescription() + " " + o.getName() + " " + o.getTypeDescription()) ;
if (o.getDescription().equalsIgnoreCase("Intersection")){
networkRing_lyr = (IVectorLayer) o.getOutputObject();
networkRing_lyr.open();
System.out.println("networkRing_lyr.feats: " + networkRing_lyr.getShapesCount());
networkRing_lyr.close();
}
}
} else {
System.out.println("NOT SUCCESS THE GEOMODEL.EXECUTE!!!!!!!!!!!");
}
//Se que el valor que me interesa para identificar el mar es el ultimo attribute del resultado
if (networkRing_lyr != null) {
int last_attribute_idx = networkRing_lyr.getFieldCount()-1;
networkRing_lyr.addFilter(new SimpleAttributeVectorFilter(last_attribute_idx, "=", 1));
networkRing_lyr.open();
System.out.println("networkRing_lyr.feats: " + networkRing_lyr.getShapesCount());
networkRing_lyr.close();
m_OutputObjects.getOutput("RESULT_networkRing").setOutputObject(networkRing_lyr);
final IVectorLayer r_ring = getNewVectorLayer("RESULT_networkRing", Sextante.getText("RESULT_networkRing"),
networkRing_lyr.getShapeType(), networkRing_lyr.getFieldTypes(), networkRing_lyr.getFieldNames());
IFeatureIterator it = networkRing_lyr.iterator();
for (;it.hasNext();){
r_ring.addFeature(it.next());
}
it.close();
}
}
network_lyr.close();
network_lyr.removeFilters();
// END COASTAL
//////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////
// CALCULAR MAX WATERSHED
final int watershed_dist = m_Parameters.getParameterValueAsInt(WATERSHED_AREA_RADIO);
final IRasterLayer accflow = m_Parameters.getParameterValueAsRasterLayer(ACCFLOW);
network_lyr.open();
IFeatureIterator iter = network_lyr.iterator();
for (int h = 0; h < num_points && iter.hasNext(); h++) {
final IFeature feature = iter.next();
Geometry geom = feature.getGeometry().buffer(watershed_dist);
final Envelope env = geom.getEnvelopeInternal();
extent = new AnalysisExtent();
final boolean recalculate_cellsize = true;
extent.setXRange(env.getMinX(), env.getMaxX(), recalculate_cellsize);
extent.setYRange(env.getMinY(), env.getMaxY(), recalculate_cellsize);
extent.setCellSize(accflow.getLayerCellSize());
//extent.enlargeOneCell();
accflow.open();
accflow.setWindowExtent(extent);
final double max_value = accflow.getMaxValue();
final double cell_size_km = (accflow.getLayerCellSize() / 1000);
WATERSHED_KM2 = max_value * cell_size_km * cell_size_km;
System.out.println("-----------> Max value accflow: " + max_value);
System.out.println("-----------> WATERSHED_km2: " + WATERSHED_KM2);
System.out.println(extent.toString());
watershed_km2[h] = WATERSHED_KM2;
accflow.close();
}
network_lyr.close();
iter.close();
//////////////////////
// CALCULAR HE PARA TODOS LOS PUNTOS
System.out.println("-------------------------- CALCULE HE FOR ALL POINTS");
for (int h = 0; h < num_points; h++) {
double dist = h * sample_dist;
double hep_xp = HE_VALUE * Math.exp(-0.0009 * dist );
iri_values[h][0] = (he_weight * perc_fact * hep_xp) / 100000;
}
//////////////////////
// CALCULAR DILUCION
System.out.println("-------------------------- CALCULE DILUTION");
// Se calcula para todos los puntos
for (int h = 0; h < num_points; h++) {
// En el mar la concentracion es maxima
double concentracion_max = Double.MAX_VALUE;
if (watershed_km2[h] > 0) {
concentracion_max = getMaxConcentration(h * sample_dist, cmez, crio, watershed_km2[h], HE_VALUE);
}
System.out.println("-------------------------- DILUTION IN POINT " + h);
System.out.println(" concentracion_max: " + concentracion_max);
if (concentracion_max >= 300) {
iri_values[h][1] = 0.0;
}
else {
iri_values[h][1] = (dil_weight * perc_fact / 100) * (1 - (concentracion_max / 300));
}
System.out.println(" dil_weight: " + dil_weight);
System.out.println(" perc_fact: " + perc_fact);
System.out.println(" IRI_DILUCION: " + iri_values[h][1]);
}
//////////////////////
// CALCULAR FA
System.out.println("-------------------------- CALCULE FA Distance");
calculateArrayIRI();
//////////////////////
// CALCULAR ECOLOGICAL STATUS
System.out.println("-------------------------- CALCULE ECOLOGICAL STATUS");
final Object[][] dma_status_iri_array = calculateIRI_DMA_array(waterBodiesLyr);
//////////////////////
// PREPARE OUTPUTS
System.out.println("-------------------------- PREPARE OUTPUTS: IRI Network Points");
// CALCULATE ALL THE IRIs
for (int i1 = 0; i1 < iri_f1_array.length; i1++) {
iri_values[i1][2] = iri_f1_array[i1];
iri_values[i1][2] += iri_f2_array[i1];
iri_values[i1][2] += iri_f3_array[i1];
iri_values[i1][2] += iri_f4_array[i1];
iri_values[i1][2] += iri_f5_array[i1];
iri_values[i1][2] += iri_f6_array[i1];
iri_values[i1][2] += iri_f7_array[i1];
iri_values[i1][2] += iri_f8_array[i1];
iri_values[i1][2] += iri_f9_array[i1];
iri_values[i1][2] += iri_f10_array[i1];
iri_values[i1][2] += iri_f11_array[i1];
iri_values[i1][3] = (Double) dma_status_iri_array[1][i1];
//IRI_FACT
iri_values[i1][4] = iri_values[i1][0] + iri_values[i1][1] + iri_values[i1][2];
//IRI TOTAL
iri_values[i1][5] = iri_values[i1][4] + iri_values[i1][3];
}
final IVectorLayer result = getNewVectorLayer("IRI_network", "IRInet_"+ID_VERTIDO,
IRIAccumulatedLayer.shapetype, IRIAccumulatedLayer.fieldTypes, IRIAccumulatedLayer.fieldNames);
network_lyr.open();
iter = network_lyr.iterator();
int ii1 = 0;
/////////////////////////////////
// 1.- Puntos en tierra
for (; iter.hasNext(); ii1++) {
Geometry geom = iter.next().getGeometry();
final Object[] attributes = new Object[IRIAccumulatedLayer.fieldNames.length];
attributes[0] = ii1 * sample_dist;
attributes[1] = iri_values[ii1][5];
attributes[2] = String.valueOf(dma_status_iri_array[0][ii1]);
attributes[3] = iri_values[ii1][3];
attributes[4] = iri_values[ii1][4];
attributes[5] = iri_values[ii1][0];
attributes[6] = iri_values[ii1][1];
attributes[7] = iri_f1_array[ii1];
attributes[8] = iri_f2_array[ii1];
attributes[9] = iri_f3_array[ii1];
attributes[10] = iri_f4_array[ii1];
attributes[11] = iri_f5_array[ii1];
attributes[12] = iri_f6_array[ii1];
attributes[13] = iri_f7_array[ii1];
attributes[14] = iri_f8_array[ii1];
attributes[15] = iri_f9_array[ii1];
attributes[16] = iri_f10_array[ii1];
attributes[17] = iri_f11_array[ii1];
//Cuenca km2
attributes[18] = watershed_km2[ii1];
//ID_VERTIDO
attributes[19] = ID_VERTIDO;
result.addFeature(geom, attributes);
}
iter.close();
System.out.println("******************* Puntos en tierra: " + ii1);
/////////////////////////////////
// 2.- Puntos en el mar
Geometry[] geoms = null;
try {
geoms = getGeometriesOnSameDirection(network_lyr, num_coastal_rings, sample_dist);
System.out.println("******************* Puntos Teoricos en el mar: " + geoms.length);
} catch (NullPointerException e) {
System.out.println("POSIBLE ERROR: There is no points on the Channel Network??");
e.printStackTrace();
}
for (int k = 0; k < geoms.length; ii1++, k++) {
Geometry geom = geoms[k];
final Object[] attributes = new Object[IRIAccumulatedLayer.fieldNames.length];
attributes[0] = ii1 * sample_dist;
attributes[1] = iri_values[ii1][5];
attributes[2] = String.valueOf(dma_status_iri_array[0][ii1]);
attributes[3] = iri_values[ii1][3];
attributes[4] = iri_values[ii1][4];
attributes[5] = iri_values[ii1][0];
attributes[6] = iri_values[ii1][1];
attributes[7] = iri_f1_array[ii1];
attributes[8] = iri_f2_array[ii1];
attributes[9] = iri_f3_array[ii1];
attributes[10] = iri_f4_array[ii1];
attributes[11] = iri_f5_array[ii1];
attributes[12] = iri_f6_array[ii1];
attributes[13] = iri_f7_array[ii1];
attributes[14] = iri_f8_array[ii1];
attributes[15] = iri_f9_array[ii1];
attributes[16] = iri_f10_array[ii1];
attributes[17] = iri_f11_array[ii1];
//Cuenca km2
attributes[18] = watershed_km2[ii1];
//ID_VERTIDO
attributes[19] = ID_VERTIDO;
result.addFeature(geom, attributes);
}
network_lyr.close();
return !m_Task.isCanceled();
}
private void calculateArrayIRI() {
System.out.println("calculateIRI_FA_array(capt_existLyr, capt_existWei)");
iri_f1_array = calculateIRI_FA_array(capt_existLyr, capt_existWei);
System.out.println("calculateIRI_FA_array(capt_propostLyr, capt_propostWei);");
iri_f2_array = calculateIRI_FA_array(capt_propostLyr, capt_propostWei);
System.out.println("calculateIRI_FA_array(espacios_ProtLyr, espacios_ProtWei);");
iri_f3_array = calculateIRI_FA_array(espacios_ProtLyr, espacios_ProtWei);
System.out.println("calculateIRI_FA_array(zpiscic_protLyr, zpiscic_protWei);");
iri_f4_array = calculateIRI_FA_array(zpiscic_protLyr, zpiscic_protWei);
System.out.println("calculateIRI_FA_array(praias_marLyr, praias_marWei);");
iri_f5_array = calculateIRI_FA_array(praias_marLyr, praias_marWei);
System.out.println("calculateIRI_FA_array(praias_fluLyr, praias_fluWei);");
iri_f6_array = calculateIRI_FA_array(praias_fluLyr, praias_fluWei);
System.out.println("calculateIRI_FA_array(zsensiblesLyr, zsensiblesWei);");
iri_f7_array = calculateIRI_FA_array(zsensiblesLyr, zsensiblesWei);
System.out.println("calculateIRI_FA_array(embalsesLyr, embalsesWei);");
iri_f8_array = calculateIRI_FA_array(embalsesLyr, embalsesWei);
System.out.println("calculateIRI_FA_array(bateasLyr, bateasWei);");
iri_f9_array = calculateIRI_FA_array(bateasLyr, bateasWei);
System.out.println("calculateIRI_FA_array(zmarisqueoLyr, zmarisqueoWei);");
iri_f10_array = calculateIRI_FA_array(zmarisqueoLyr, zmarisqueoWei);
System.out.println("calculateIRI_FA_array(piscifactoriasLyr, piscifactoriasWei);");
iri_f11_array = calculateIRI_FA_array(piscifactoriasLyr, piscifactoriasWei);
}
private double getMaxConcentration(final int dist,
final double conc_mez,
final double conc_rio,
final double watershed_km2,