Basically, the emodisfile is the raw data file, and shapefile is one of the CLU shapefiles. I need to convert the shapefile from polygon to raster and then to ASCII file based on the emodisfile. So I set the extent, cell size and coordinate system to be exactly the same as the emodisfile. After that, I convert the shapefile and the output ASCII file is shpfipstest.TXT.
And I also convert the emodisfile to ASCII file, which is called emodisCoordtest.txt. Since I convert the shapefile all based on the settings of emodisfile, then they should have the same extent and Coordinate System.
However, according to the results, they cannot match together and have different number of columns and rows.
While I also tested it with ArcMap, it had the expected result. But when it comes to Python and ArcPy, it seems something wrong.
Any ideas? Below is a part of the code:
emodisfile = workingDir+"\\US_eMTH_NDVI.2014.365-006.QKM.VI_NDVI.005.2014010002626.tif" shapefile = workingDir+"\\clu_public_a_ar039\\clu_public_a_ar039.shp" env.workspace = workingDir env.overwriteOutput = True arcpy.env.coincidentPoints="MAX" arcpy.env.extent = emodisfile arcpy.env.cellSize = emodisfile arcpy.env.cartographicCoordinateSystem = emodisfile outraster = workingDir+"\shapeFIPS" outascii = workingDir+"\shpfipstest.TXT" arcpy.PolygonToRaster_conversion(in_features=shapefile, value_field="FIPS", out_rasterdataset=outraster, cell_assignment="CELL_CENTER") arcpy.RasterToASCII_conversion(in_raster=outraster, out_ascii_file=outascii) emodisAscii = workingdir+"emodisCoordtest.txt" arcpy.RasterToASCII_conversion( in_raster=emodisfile, out_ascii_file=emodisAscii)
I have changed some settings into:
des = arcpy.Describe(emodisfile)
arcpy.env.extent = des.extent
arcpy.env.cellSize = des.children.meanCellHeight
And right now the files have the same numbers of rows and columns, and origin coordinates, but a problem came up that the outraster file did not have an attribute table, while it should contain "FIPS" value in it. Therefore, in the outascii file, all values are -9999.