POST
|
I have a original tif file which has values from 2 to 28. From that original tif file, I am extracting cells having value >=10 using the following code. The code is working. However, when I open the new extracted tif file in GIS, I found that the cell values range from 10 30 instead of 10 to 28. I would really appreciate any help/ suggestion! The code is provided below: import arcpy, os from arcpy import env from arcpy.sa import * #To overwrite output arcpy.env.overwriteOutput = True #Set environment settings env.workspace = "C:/Subhasis/Highland/Project/Python_data" outws="C:/Subhasis/Highland/Project/Python_data/HSA_10" #checkout ArcGIS spatial analyst extension license arcpy.CheckOutExtension("Spatial") inraster = arcpy.ListRasters("*", "TIF") for i in inraster: flds = ("VALUE", "COUNT") dct = {row[0]:row[1] for row in arcpy.da.SearchCursor(i, flds)} sumcnt = sum(dct.values()) dct1 = {k:v for (k,v) in dct.items() if k >= 10} sumcnt1 = sum(dct1.values()) percentage=(float(sumcnt1)/float(sumcnt)) print i,percentage newraster = ExtractByAttributes(str(i), "VALUE>=10") outname=os.path.join(outws,str(i)) newraster.save(outname)
... View more
02-25-2016
02:21 PM
|
0
|
3
|
2094
|
POST
|
Thanks a lot! I really appreciate it! Have a good one. Sean
... View more
09-29-2014
06:59 AM
|
0
|
1
|
137
|
POST
|
Hi Xander, Just a silly question. I want to extract the corresponding date of the precip along with the precip value. For that, I added one line code: growing.append(float(date)) after growing.append(prec) in your code. However, I got this error:"ValueError: invalid literal for float(): 2007-05-07". Do you mind to look at it? Thank you very much for your time and help! Sean
... View more
09-26-2014
01:04 PM
|
0
|
3
|
827
|
POST
|
How do I mark as answered. I looked at and found a link called as mark as helpful and did that. Is that what you wanted me to do?
... View more
09-24-2014
12:04 PM
|
0
|
7
|
827
|
POST
|
Hi Xander, Thanks a lot for your help! I was stuck and it really helped me.Yeah, the code is working perfect. Appreciate it. Have a good one! Sean
... View more
09-24-2014
07:25 AM
|
0
|
9
|
827
|
POST
|
Hi Guys, I have text file having two columns: 1) column 1 is in the format yyyy-mm-dd and 2) column 2 is precipitation. Objective: to extract original value of precipitation from column 2 only for month April, May, june, July, and August (4,5,6,7,8). Procedure: Used line.split to extract only mm from yyyy-mm-dd format from column-1. made dictionary to get month and precipitation value. using for k,v in dct.items() and then using a if statement to extract the corresponding month precipitation value from dictionary Problem: I can successfully print k,v (month and precipitation) from dictionary items. However, when I am using a if statement to extract the specific month's precipitation value, I am getting blank array. I was wondering can I use .append to get precipitation in (1.8,2.1,3.3) format. Code: file1 = open("test.txt","r") Growing=[] Intermediate=[] Dormant=[] for line in file1: line2 = line.split() WQ = line2[1] month = line2[0].split("-")[1] dct1={month:WQ} for k,v in dct1.items(): if (k ==4 or k==5 or k==6 or k==7 or k==8): Growing.append(dct1 ) print Growing
... View more
09-23-2014
09:51 AM
|
0
|
11
|
3260
|
POST
|
Hi Xander, Thanks a lot for all your help! I really appreciate it! Specially, the way you explain each line in the code and its corresponding role. Have a good day! Regards, Subhasis
... View more
08-04-2014
05:54 AM
|
0
|
0
|
935
|
POST
|
Thanks again Ian!. Changed the code, but don't know still I didn't get anything.
... View more
08-01-2014
05:35 AM
|
0
|
4
|
935
|
POST
|
Thank you very much Ian! I ran the code replacing &'s by or's . still didn't get any error or the result.
... View more
07-31-2014
11:34 AM
|
0
|
6
|
935
|
POST
|
Hi Guys, I want to calculate the counts of each landuse type based on the unique landuse code from each raster datasets. Raster dataset consists of six major landuse and their unique codes are below: 1) Agriculture : Landuse code(2100, 2200, 2300, 2400) 2) Barren Land: Landuse code( 7100,7200,7300,7400, 7500, 7600) 3)Forest: Landuse code(4110, 4120, 4210,4220, 4230, 4311, 4312,4321,4322, 4410) 4)Urban: Landuse code(1110,1120,1130,1140,1150,1200,1211,1214,1300,1400,1410,1411,1420,1440,1462,1463,1499,1500,1600,1700,1710,1741) 5)Water: Landuse code(1419,5100,5190) 6)Wetlands Landuse code (1461,1711,1750,1850) Also, I want to divide the Urban area further into 4 categories. I have the code only for agricultural area to simply test whether the code is working or not for one category of landuse. When I ran the code neither did I get any error message nor the result for agricultural land. I know it's a pretty big description, sorry for that. Thank you very much for your time and help! I am providing the code below: import arcpy, os from arcpy import env #To overwrite output arcpy.env.overwriteOutput = True #Set environment settings env.workspace = "C:/Subhasis/Project-06-02-14/Landuse/New folder/Merged/Landuse_raster" outws="C:/Subhasis/Project-06-02-14/Landuse/New folder/Merged/Landuse_raster/Table" inraster = arcpy.ListRasters("*", "GRID") for i in inraster: flds = ("VALUE", "COUNT") dct = {row[0]:row[1] for row in arcpy.da.SearchCursor(i, flds)} Agriculture=[] Barrenland=[] Forest=[] Urban=[] Water=[] Wetland=[] for j in dct: if (dct.keys()==2100) & (dct.keys()==2200) & (dct.keys()==2300) & (dct.keys()==2400): ag=Agriculture.append(dct.values()) print ag else: break
... View more
07-31-2014
11:20 AM
|
0
|
8
|
3077
|
POST
|
The above code worked. Except I had to replace inraster by i in "arcpy.RasterToPolygon_conversion(inraster, outPolygons, "NO_SIMPLIFY", field)"
... View more
07-28-2014
11:24 AM
|
0
|
0
|
392
|
POST
|
Thank you very much Xander again! Yes, I should have posted the error message and would read about code blocks. Regards, Subhasis
... View more
07-28-2014
11:05 AM
|
0
|
0
|
392
|
Online Status |
Offline
|
Date Last Visited |
11-11-2020
02:23 AM
|