[Gvsig_desarrolladores] Doble bucle para recorrer dos rásters
Joaquin del Cerro
jjdelcerro.gvsig en gmail.com
Mar Abr 3 15:21:16 CEST 2012
El 02/04/12 18:09, spginternet escribió:
> Hola,
>
> estoy intentando preparar un algoritmo que, desde cada punto de un DEM,
> seleccione los ángulos verticales máximo y mínimo que se generan desde el
> mismo a un área determinada del territorio. Pretendo aplicarlo a paisaje,
> por ejemplo para valorar desde una cima qué amplitud vertical de campo
> visual hay respecto a un lago.
>
> El problema es que necesito encadenar dos bucles, uno que haga recorrer
> todos los puntos del DEM, y lanzar desde cada uno de ellos otro que recorra
> todos los puntos del área seleccionada, eligiendo los ángulos máximo y
> mínimo que se forman con ella, pero parece que no logro coordinar bien las
> variables. He estado estudiando el algoritmo VisualExposure de SEXTANTE como
> ejemplo, pero no encuentro qué puede fallar. ¿Podrían echarme una mano? Pego
> el código a continuación. Muchas gracias y saludos.
>
No he seguido mucho el algoritmo y lo que esta haciendo, pero te comento un par
de detalles que me han llamado la atencion.
Inserto los comentarios en medio del codigo.
> public class EJEMPLOAlgorithm
> extends
> GeoAlgorithm {
>
> public static final String DEM = "DEM";
> public static final String FEATURES = "FEATURES";
> public static final String RADIUS = "RADIUS";
> public static final String RESULTAMAX = "RESULTAMAX";
> public static final String RESULTAMIN = "RESULTAMIN";
>
> private int m_iNX, m_iNY;
> private int m_iRadius;
> private int m_iRadius2;
>
> private IRasterLayer m_Amax;
> private IRasterLayer m_Amin;
> private IRasterLayer m_DEM = null;
> private IRasterLayer m_Features = null;
>
>
> @Override
> public boolean processAlgorithm() {
>
> int x, y, x2, y2, m_iNX2, m_iNY2;
> double z, z2, di, r, dx, dy, dz, bc, br, b, bmax, bmin;
>
> try {
> m_DEM = m_Parameters.getParameterValueAsRasterLayer(DEM);
> m_Features = m_Parameters.getParameterValueAsRasterLayer(FEATURES);
> m_Amax = getNewRasterLayer(RESULTAMAX, Sextante.getText("AVmax"),
> IRasterLayer.RASTER_DATA_TYPE_DOUBLE);
> m_Amin = getNewRasterLayer(RESULTAMIN, Sextante.getText("AVmin"),
> IRasterLayer.RASTER_DATA_TYPE_DOUBLE);
>
> m_DEM.setWindowExtent(getAnalysisExtent());
> m_Features.setWindowExtent(getAnalysisExtent());
>
> m_Features.setInterpolationMethod(IRasterLayer.INTERPOLATION_NearestNeighbour);
>
> m_Amax.assign(0.0);
> m_Amin.assign(0.0);
>
> m_iNX = m_DEM.getNX();
> m_iNY = m_DEM.getNY();
>
> //Bucle para recorrer las celdas del DEM
>
> for (y = 0; (y < m_iNY) && setProgress(y, m_iNY); y++) {
> for (x = 0; x < m_iNX; x++) {
>
> z = m_DEM.getCellValueAsDouble(x, y);
>
> final int posx = x;
> final int posy = y;
>
> m_iNX2 = m_Features.getNX();
> m_iNY2 = m_Features.getNY();
>
> //Bucle para recorrer, desde cada celda del DEM, las celdas del área de
> interés (Features)
>
> for (y2 = 0; (y2 < m_iNY2); y2++) {
El punto y como del final de la linea siguiente construye un bucle vacio, que
apatentemente no hace nada.
¿ No habras querido porner una apertura de llaves en vez del punto y coma ?
> for (x2=0; (x2 < m_iNX2); x2++);
>
> dx = posx - x2;
> dy = posy - y2;
>
> z2 = m_DEM.getCellValueAsDouble(x2, y2);
>
> di = dx*dx + dy*dy;
>
> r = Math.sqrt(di);
>
> dz = z - z2;
>
> bc = dz / r;
> br = Math.atan(bc);
> b = Math.toDegrees(br);
>
A cada vuelta del bucle inicializas bmax y bmin a cero, asi que
las comparaciones de despues es facil que esten dando resultados
inesperados.
Probablemente lo que quieres es inicializarlos a cero antes de entrar
en el bucle "for (y2 = 0; (y2 < m_..."
A ver si te sirven de algo los comentarios.
Un saludo
Joaquin
> bmax = 0;
> bmin = 0;
>
> //Selección de los ángulos máximo y mínimo, y salida.
>
> if( b > bmax) {
> bmax = b;
> m_Amax.setCellValue(x, y, bmax);}
>
> if( b < bmin) {
> bmin = b;
> m_Amin.setCellValue(x, y, bmin);}
> }
>
> }
> }
> }
> catch (final Exception e) {
> Sextante.addErrorToLog(e);
> return false;
> }
>
> return !m_Task.isCanceled();
> }
>
> @Override
> public void defineCharacteristics() {
>
> setUserCanDefineAnalysisExtent(true);
> setGroup(Sextante.getText("Visibility_and_lighting"));
> setName(Sextante.getText("Santiago"));
>
> try {
> m_Parameters.addInputRasterLayer(DEM, Sextante.getText("Elevation"),
> true);
> m_Parameters.addInputRasterLayer(FEATURES, Sextante.getText("Elements"),
> true);
> addOutputRasterLayer(RESULTAMAX, Sextante.getText("AVmax"));
> addOutputRasterLayer(RESULTAMIN, Sextante.getText("AVmin"));
> }
> catch (final RepeatedParameterNameException e) {
> Sextante.addErrorToLog(e);
> }
> }
> }
>
>
> --
> View this message in context: http://osgeo-org.1560.n6.nabble.com/Doble-bucle-para-recorrer-dos-rasters-tp4679380p4679380.html
> Sent from the gvSIG desarrolladores mailing list archive at Nabble.com.
> _______________________________________________
> gvSIG_desarrolladores mailing list
> gvSIG_desarrolladores en listserv.gva.es
> Para ver histórico de mensajes, editar sus preferencias de usuario o darse de baja en esta lista, acuda a la siguiente dirección: http://listserv.gva.es/cgi-bin/mailman/listinfo/gvsig_desarrolladores
>
--
--------------------------------------
Joaquin Jose del Cerro
Development and software arquitecture manager.
jjdelcerro en gvsig.com
gvSIG Association
www.gvsig.com
www.gvsig.org
Más información sobre la lista de distribución gvSIG_desarrolladores