POST
|
But the boundary not matched, what shall i do? # -*- coding: utf-8 -*- #!/usr/bin/env python print("Started\n") import gdal,osr import numpy as np #******************************************************************************* inRaster=r"E:\SEBAL_METRIC_Approaches\ASD\gcsDEM.tif" PrjRaster="E:\SEBAL_METRIC_Approaches\ASD\pcsDEM.tif" outRaster=r"E:\SEBAL_METRIC_Approaches\Outputs1\Longfh.tif" Driver="GTIFF" # HFA Erdas Imagine (.img), GTIFF (TIFF) #******************************************************************************* inRaster=gdal.Open(inRaster) rows=inRaster.RasterYSize # Z.shape[0] cols=inRaster.RasterXSize # Z.shape[1] Z=inRaster.ReadAsArray() gt=inRaster.GetGeoTransform() inBand=inRaster.GetRasterBand(1) (xBlockSize,yBlockSize)=inBand.GetBlockSize() (xOrigin,pixelWidth,rotation,yOrigin,rotation,pixelHeight)=inRaster.GetGeoTransform() X=np.array(np.arange(xOrigin,(xOrigin+(cols-0.5)*pixelWidth),pixelWidth)) Y=np.arange(yOrigin,(yOrigin+rows*pixelHeight),pixelHeight) driver=gdal.GetDriverByName(Driver) outRaster=driver.Create(outRaster,cols,rows,1,gdal.GDT_Float32) outBand=outRaster.GetRasterBand(1) for i in range(0,rows,yBlockSize): if i+yBlockSize<rows:numRows=yBlockSize else:numRows=rows-i for j in range(0,cols,xBlockSize): if j+xBlockSize<cols:numCols=xBlockSize else:numCols=cols-j BandArray=inBand.ReadAsArray(j,i,numCols,numRows).astype(np.float) OnesArr=np.ones((rows,cols)) outBand.WriteArray(X,j,i) outBand.FlushCache() stats=outBand.GetStatistics(0,1) PrjRaster=gdal.Open(PrjRaster) (xOrigin,pixelWidth,rotation,yOrigin,rotation,pixelHeight)=PrjRaster.GetGeoTransform() outRaster.SetGeoTransform((xOrigin,pixelWidth,rotation,yOrigin,rotation,pixelHeight)) outRaster.SetProjection(PrjRaster.GetProjection()) ##gdal.SetConfigOption("HFA_USE_RRD","YES") gdal.SetConfigOption("COMPRESS_OVERVIEW","LZW") outRaster.BuildOverviews(overviewlist=[2,4,8,16,32,64,128]) print("\nFinished")
... View more
06-29-2015
01:43 PM
|
0
|
2
|
3166
|
POST
|
when run this script as a tool:- # -*- coding: utf-8 -*- import arcpy import os arcpy.env.overwriteOutput = True arcpy.CheckOutExtension("spatial") InputPath = arcpy.GetParameterAsText(0) OutputPath = arcpy.GetParameterAsText(1) OutputFolderName = arcpy.GetParameterAsText(2) FeatureZone = arcpy.GetParameterAsText(3) ZoneField = arcpy.GetParameterAsText(4) arcpy.CreateFolder_management(OutputPath, OutputFolderName) arcpy.env.workspace = InputPath listDatasets = arcpy.ListDatasets() for Datasets in listDatasets: Set_Null = Datasets Zonal_Statistices = OutputPath + "\\" + OutputFolderName + "\\" + Set_Null + ".dbf" arcpy.gp.ZonalStatisticsAsTable_sa(FeatureZone, ZoneField, Set_Null, Zonal_Statistices, "True", "ALL") This message appears:- Traceback (most recent call last): File "E:\ArcPy_Toolbox\MODIS\Scripts\ZonalStatisticsAsTable.py", line 24, in <module> arcpy.gp.ZonalStatisticsAsTable_sa(FeatureZone, ZoneField, Set_Null, Zonal_Statistices, "True", "ALL") File "c:\program files (x86)\arcgis\desktop10.2\arcpy\arcpy\geoprocessing\_base.py", line 498, in <lambda> return lambda *args: val(*gp_fixargs(args, True)) ExecuteError: ERROR 999999: Error executing function. Create output table failed Failed to execute (ZonalStatisticsAsTable) Actually�?? I want the name of the table (.dbf) is the same name of input raster in the loop
... View more
05-14-2014
12:21 AM
|
0
|
0
|
468
|
POST
|
when run this script as a tool:- # -*- coding: utf-8 -*- import arcpy import os arcpy.env.overwriteOutput = True arcpy.CheckOutExtension("spatial") InputPath = arcpy.GetParameterAsText(0) OutputPath = arcpy.GetParameterAsText(1) OutputFolderName = arcpy.GetParameterAsText(2) FeatureZone = arcpy.GetParameterAsText(3) ZoneField = arcpy.GetParameterAsText(4) arcpy.CreateFolder_management(OutputPath, OutputFolderName) arcpy.env.workspace = InputPath listDatasets = arcpy.ListDatasets() for Datasets in listDatasets: Set_Null = Datasets Zonal_Statistices = OutputPath + "\\" + OutputFolderName + "\\" + Set_Null + ".dbf" arcpy.gp.ZonalStatisticsAsTable_sa(FeatureZone, ZoneField, Set_Null, Zonal_Statistices, "True", "ALL") This message appears:- Traceback (most recent call last): File "E:\ArcPy_Toolbox\MODIS\Scripts\ZonalStatisticsAsTable.py", line 24, in <module> arcpy.gp.ZonalStatisticsAsTable_sa(FeatureZone, ZoneField, Set_Null, Zonal_Statistices, "True", "ALL") File "c:\program files (x86)\arcgis\desktop10.2\arcpy\arcpy\geoprocessing\_base.py", line 498, in <lambda> return lambda *args: val(*gp_fixargs(args, True)) ExecuteError: ERROR 999999: Error executing function. Create output table failed Failed to execute (ZonalStatisticsAsTable) Actually�?? I want the name of the table (.dbf) is the same name of input raster in the loop
... View more
05-13-2014
10:54 PM
|
0
|
0
|
468
|
POST
|
You need to convert the strings you get in GetParameterAsText into Raster objects. # -*- coding: utf-8 -*-
import arcpy
from arcpy.sa import *
arcpy.CheckOutExtension("spatial")
QC = arcpy.Raster(arcpy.GetParameterAsText(0))
NDVI = arcpy.Raster(arcpy.GetParameterAsText(1))
GoodNDVI = arcpy.GetParameterAsText(2)
GoodNDVI_raster = (QC==0)*(NDVI>2000)*NDVI
GoodNDVI_raster.save(GoodNDVI + ".tif") Thank �??you, Excellent
... View more
05-13-2014
10:42 PM
|
0
|
0
|
468
|
POST
|
Please help me, when trying to run this code as a tool # -*- coding: utf-8 -*- import arcpy from arcpy.sa import * arcpy.CheckOutExtension("spatial") QC = arcpy.GetParameterAsText(0) NDVI = arcpy.GetParameterAsText(1) GoodNDVI = arcpy.GetParameterAsText(2) GoodNDVI = (QC==0)*(NDVI>2000)*NDVI GoodNDVI.save(GoodNDVI + ".tif") This�??mmessage�??aappears Traceback (most recent call last): File "E:\ArcPy_Toolbox\MODIS\Scripts\GoodNDVI.py", line 12, in <module> GoodNDVI.save(GoodNDVI + ".tif") AttributeError: 'unicode' object has no attribute 'save' Failed to execute (GoodNDVI).
... View more
05-13-2014
01:22 AM
|
0
|
4
|
801
|
Title | Kudos | Posted |
---|---|---|
1 | 07-29-2014 11:30 PM |
Online Status |
Offline
|
Date Last Visited |
11-11-2020
02:23 AM
|