1

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[0].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.

  • This arcpy.env.extent = emodisfile and similar are fundamentally wrong. Get extent from the sourse, get extent and do assignment – FelixIP Mar 7 '16 at 20:08
  • Can you explain how to get the extent or cellsize or cartographicCoordinateSystem from the source file ? Thank you very much. – htjoseph Mar 8 '16 at 1:25
  • How about a) d=arcpy.Describe(emodisfile) b) ext=d.extent c) arcpy.env.extent=ext and so on. Your emodisfile is no more than a string. Period. – FelixIP Mar 8 '16 at 1:31
  • The only exception is cellsize=emodisfile.meanCellHeight – FelixIP Mar 8 '16 at 1:40
  • Thanks for your precious advice ! ! But right now a new problem showed, all the values in the output ascii file are all null... they should be "FIPS" value. – htjoseph Mar 8 '16 at 3:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.