Select to view content in your preferred language

wrong results using a python script

1825
3
09-21-2011 11:49 AM
by Anonymous User
Not applicable
Original User: Nancititla

Hello everybody!!

I'm working with a model that I´ve exported to python scripts, I had some problems with my model (I don't know why) because when I execute it, sometimes fail in some process and throws a fatal error and arcmap is closed, the rare thing is when I run the process individually, it works very well. So, I decided work with python, but in the reclassbytable process it throws a wrong result. Why? I don't have any ideas, because the result of the simple tool, it's ok.

Here, is my script

# Se importan los módulos del sistema para poder ejecutar las herramientas
import sys, string, os, arcgisscripting, win32com.client
import arcpy
from arcpy import env
from arcpy.sa import *

arcpy.CheckOutExtension("Spatial")

# Se valida el área de trabajo establecida por el usuario
env.workspace = arcpy.GetParameterAsText(0)

# Se establecen las variables y nombres de salida de los productos del proceso
smoothsalida = "smooth"
slopesalida = "slope"
slope_recSalida = "pend_fin"
#curvatura_Salida = "curva_smo"
#perfilSalida = "profile"
#planSalida = "Plan"
geol_recSalida = "geol_rec"
isoy_recSalida = "isoy_rec"
suelo_recSalida = "suelo_rec"

# Se valida los datos de entrada seleccionados por el usuario
dem = arcpy.GetParameterAsText(1)  # Modelo Digital de Elevación
usosuelo = arcpy.GetParameterAsText(2) # Uso de suelo y vegetación
precipitacion = arcpy.GetParameterAsText(3) # Precipitación
geologia = arcpy.GetParameterAsText(2) # Geología

#---------------------------------------------------------
# Se inicializa el proceso del modelo
#---------------------------------------------------------
# Procedimientos para el Modelo Digital de Elevación (MDE)
#---------------------------------------------------------
# Proceso para determinar las estadísticas focalizadas, se establecen los parámetros
TipoVecindad = NbrCircle(5, "CELL")
smooth = FocalStatistics(dem, TipoVecindad, "MEAN", "DATA")
smooth.save(smoothsalida)

# Proceso para determinar la pendiente
slope = Slope(smooth, "DEGREE", "1")
slope.save(slopesalida)

# Proceso para reclasificar la Pendiente
slope_rec = Reclassify(slope, "VALUE", "0 5 1;5 9 2;9 14 3;14 18 4;18 23 5;23 28 6;28 32 7;32 37 8;37 42 9;42 86 10", "DATA")
slope_rec.save(slope_recSalida)

# Proceso para Determinar la curvatura del MDE
#arcpy.Curvature_3d("C:/data/smooth", "C:/data/curvatu", 1)


#---------------------------------------------------------
# Procedimientos para la Geología
#---------------------------------------------------------
# Proceso para reclasificar la cobertura de Geología
TablaRecGeol = "geologia_rec"
geol_rec = ReclassByTable(geologia, TablaRecGeol, "FROM", "TO", "OUT1", "DATA")
#geol_rec = Reclassify(geologia, "PESO", "1 2;2 1;3 2;4 1;5 4;6 5;7 5;8 3;9 1;10 2;11 4;12 3;13 2;14 2;15 4;16 4;17 4;18 4;19 4;20 3;21 2;22 1;23 5;24 5;25 2;26 2;27 1;28 1;29 1;30 1;31 2;32 5;33 3;34 2;35 4;36 1;37 1;38 1;39 1;40 1;41 1;42 2;43 2;44 2;45 1;46 1;47 1;48 2;49 5;50 5;51 5;52 2;53 1;54 2;55 2;56 2;57 2;58 2;59 0;60 0;61 3;62 2;63 2;64 1;65 1;66 3;67 1;68 2;69 2;70 3;71 3;72 3;73 2;74 2;75 4", "DATA")
geol_rec.save(geol_recSalida)

#---------------------------------------------------------
# Procedimientos para la Precipitación
#---------------------------------------------------------
# Proceso para reclasificar la cobertura de Precipitación
TablaRecIsoy = "isoyetas_rec"
isoy_rec = ReclassByTable(precipitacion, TablaRecIsoy, "FROM", "TO", "OUT", "DATA")
isoy_rec1 = ReclassByTable(precipitacion, TablaRecIsoy, "FROM", "TO", "OUT", "DATA")
isoy_suma = Plus(isoy_rec, isoy_rec1)
salida_isoy = Divide(isoy_suma, 2)
#isoy_rec = Reclassify(precipitacion, "PESO", RemapValue([[1,1],[2,1],[3,1],[4,2],[5,2],[6,2],[7,2],[8,3],[9,3],[10,3],[11,4],[12,4],[13,4],[14,5],[15,6],[16,7],[17,8],[18,9],[19,10]]), "DATA")
salida_isoy.save(isoy_recSalida)

#---------------------------------------------------------
# Procedimientos para el Uso de Suelo y Vegetación
#---------------------------------------------------------
# Proceso para reclasificar la cobertura de Uso de Suelo y Vegetación 2010
TablaRec = "usv_rec"
suelo_rec = ReclassByTable(usosuelo, TablaRec, "FROM", "TO", "OUT", "DATA")
#suelo_rec = Reclassify(usosuelo, "PESO", RemapValue([[1,1],[2,8],[3,9],[4,1],[5,0],[6,6],[7,1],[8,0],[9,5],[10,10],[11,2]]), "DATA")
suelo_rec.save(suelo_recSalida)




I load the images to ilustrate that I said, I hope someone can help me. Thanks a lot!!

The first image is my model.
The second image is the result of the python script, it have some white spaces (nodata) and thats wrong.
The third image is the result of the individually tool (reclassify), and It's ok
0 Kudos
3 Replies
curtvprice
MVP Alum
Nancititla;135527 wrote:
# Se valida los datos de entrada seleccionados por el usuario
dem = arcpy.GetParameterAsText(1)  # Modelo Digital de Elevación
usosuelo = arcpy.GetParameterAsText(2) # Uso de suelo y vegetación
precipitacion = arcpy.GetParameterAsText(3) # Precipitación
geologia = arcpy.GetParameterAsText(2) # Geología

Have you noticed that you are assigning precip and geology to the same input argument??
0 Kudos
by Anonymous User
Not applicable
Original User: Nancititla

Thanks for the reply!! 😄


Have you noticed that you are assigning precip and geology to the same input argument??


No, I don't had notice of this detail, thanks for the observation.

Well, I did the necesary changes but my problem still happend, I don't know why 😞
0 Kudos
NancyHernandez
Emerging Contributor
Thanks!! I found the mistake. I hadn't done my table in a correct way, I did it manualy (that's wrong). In reclassify tool there is an option to save the table with parameters to use later (this is the correct way to do the table). And the format is *.rmp

Atte.
Nans
0 Kudos