|
POST
|
I am testing a Python script where an ESRI shapefile is converted to a raster (based on FID). The resulting raster is converted to ASCII for further processing. Interestingly the tool worked great then started giving errors. The source of the error is that the output ASCII file is now inserting extra spaces in the header of the ASCII file where earlier in the day it was not. Here is an example of the problematic ASCII output. ncols 17 nrows 41 xllcorner 1193433.4604796 yllcorner 659603.16649559 cellsize 10 NODATA_value -9999 The column of numbers have extra spaces resulting in a left justified column of data when only one space should exist between the names (ncols, nrows...) and the data (17, 41). What would cause this behavior? Am I stuck with using regular expressions to purge the extra white spaces? try: print "Split polygon by percent area from the top down..." import sys, traceback, os import arcpy arcpy.env.overwriteOutput = True ######################################################################################## #The Input Feature Class or projected data to Divide into Percents... inFC = r"Z:\GISpublic\GerryG\PythonScripts\SplitPolygonByPercent\testData\testdata.shp" #The rasterized version of the polygon... outRas = r"Z:\GISpublic\GerryG\PythonScripts\SplitPolygonByPercent\outRas" #The cell size of the outRas-smaller is better but takes longer to process.. outCellSize = 10 #Useer defined precent by area divisions...will split a polygons into 60%, 20%, and 20% divisions = [60,25,15] #ASCII version of the raster data.... outASCII = r"Z:\GISpublic\GerryG\PythonScripts\SplitPolygonByPercent\testdata.asc" #ASCII version of the split by area data splitASCII = r"Z:\GISpublic\GerryG\PythonScripts\SplitPolygonByPercent\Split.asc" #The Output Raster.... FinalRaster = r"Z:\GISpublic\GerryG\PythonScripts\SplitPolygonByPercent\PercentArea" ########################################################################################## #Holds the total area of each percentage.... areaPercents = [] #Get the polygon area... rows = arcpy.SearchCursor(inFC) shapeName = arcpy.Describe(inFC).shapeFieldName for row in rows: feat = row.getValue(shapeName) polygonArea = feat.area #Calculate the areas for each percent division for item in divisions: areaPercents.append(polygonArea* item/100.0) print "Converting polygon to ESRI GRID..." arcpy.PolygonToRaster_conversion(inFC, "FID",outRas,"", "", outCellSize) print "Converting ESRI GRID to ASCII..." arcpy.RasterToASCII_conversion(outRas, outASCII) print "Create the new ascii file" fw = open(splitASCII, 'a') #Keep track of the line number to ensure the header gets written correctly to #the new .asc file linecounter = 1 cell_area_counter = 0 thispercentcounter = 0 with open(outASCII, 'r') as f: for line in f: #The first 6 lines are header-just copy that over to the new asc file. if linecounter <=6: fw.write(line) #The remaining lines have data...convert them to percent values.. else: #Strip those pesky blank spaces at the start and ends of the line line = line.strip() linelist = line.split(" ") newlinelist = [] for item in linelist: if item =="-9999": newlinelist.append(item) else: #thispercentcounter +=1 cell_area_counter = cell_area_counter + (outCellSize*outCellSize) if cell_area_counter <areaPercents[thispercentcounter]: newlinelist.append(str(divisions[thispercentcounter])) else: thispercentcounter +=1 cell_area_counter = 0 print thispercentcounter newlinelist.append(str(divisions[thispercentcounter])) fw.write(" ".join(newlinelist)+"\n") linecounter+=1 print "Creating output raster..." arcpy.ASCIIToRaster_conversion(splitASCII,FinalRaster, "INTEGER") #Take out the trash.... os.remove(outASCII) os.remove(splitASCII) arcpy.Delete_management(outRas) print "Done" except: print "error" tb = sys.exc_info()[2] tbinfo = traceback.format_tb(tb)[0] pymsg = "PYTHON ERRORS:\nTraceback info:\n" + tbinfo + "\nError Info:\n" + str(sys.exc_info()[1]) print pymsg + "\n"
... View more
09-06-2016
11:11 AM
|
0
|
3
|
2349
|
|
POST
|
Dan, I can get the extent of all the elements in an MXD and I can use those values and the Python Image Library to crop the exported image, but for some unknown reason the clipped output has a few pixels trimmed off of the left and bottom edges of the image. I am not sure of the cause without more investigation. See the example below.
... View more
01-04-2016
07:45 AM
|
0
|
0
|
2815
|
|
POST
|
Tarek, You could do the math using an arcpy cursor. Python would throw an error that you could catch. Still though, you would need to assign some value to the record in the shapefile that had a zero division error. Another reason to use a geodatabase, I guess. At least you end up with a null value.
... View more
12-18-2015
08:59 AM
|
0
|
1
|
7383
|
|
POST
|
You learn something new every day in GIS. If I open a shapefile attribute table, select an attribute, and use the field calculator to populate the field with an expression such as... attributeX / 0 I get an error all calculated values were invalid, no rows were updated. But attributeX / attributeY returns no error even if values in attributeY have zero values, In fact, it populates those values with zero values. This is disturbing. If I do this same test in a geodatabase I get null values for the zero division rows. I understand that there are data structure limitations. Shapefile fields are not nullable... but the shapefile example ought to give some warning!
... View more
12-17-2015
04:16 PM
|
0
|
17
|
16178
|
|
POST
|
Thanks for your help, Dan. Rest assured, I have a polygon layer that represents the bounding area of the survey that I will use to clip the Voronoi polygons with. Projected - Geographic coordinate system? I had no idea this would make such a big difference in the resulting polygons. I have projected the data and re-created the Voronoi polygons and the gap and overlap problems went away. Best to read the fine print! Problem Solved.
... View more
11-23-2015
01:40 PM
|
3
|
0
|
1372
|
|
POST
|
Ghislain, Thanks for looking into the issue. I have attached the gpk to this response.
... View more
11-23-2015
10:30 AM
|
0
|
2
|
1372
|
|
POST
|
Yes, Dan, I have. The input parameters are good, there is no other information other than what is shown below.
... View more
11-20-2015
01:46 PM
|
0
|
0
|
1031
|
|
POST
|
I have a feature class of building footprints and a surface (LiDAR highest hit - LiDAR last return). I am trying to use this surface to estimate the height of the buildings. Transferring the values from the raster to the polygons should be a straight forward operation using add surface information but that tool is useless and returns a 99999 error code. I tried the Zonal Statistics as a Table, then joined the table using the object ids. I want to populate an existing field in the feature class with the mean value from the zonal statistics output but the field calculator (both within the attribute table and the Toolbox tool) populate the attribute with the objectID value. This is odd behavior. Both data are in the same projection, UOM, datum.... I do not understand why this is happening. Is this a know bug or a problem specific to my installation? Should I accept that I should export the join to a new FC and just clean up the e-trash later?
... View more
11-20-2015
01:30 PM
|
0
|
3
|
3110
|
|
POST
|
Curtis, in this case the gaps and overlaps are a few feet over polygons that are 10 to 12 feet across. I did get confirmation from ESRI that this is a bug and will be fixed in 10.4.
... View more
11-20-2015
10:10 AM
|
0
|
1
|
3875
|
|
POST
|
I see that there are spatially duplicate points but with different attributes! That might be a problem. I have contacted the data creator to sort out the differences. Create Thiessen Polygons did not care if there were spatially duplicate points. I guess if you are going to be doing some coding, and want to produce a better tool, let the user know there are spatially duplicate points as a guard against such a thing. Thanks for throwing the error triangulation tools!
... View more
11-18-2015
03:48 PM
|
1
|
1
|
3875
|
|
POST
|
I noticed that the Create Thiessen Polygon Tool in ArcGIS 10.3 is not producing a continuous irregular tessellation across the analysis area. The resulting polygons have gaps and overlaps as confirmed by topology! I have not noticed this on other versions of ArcGIS. Can anyone confirm that this is happening on their installation of ArcGIS 10.3? Is there a fix, or does anyone have a script to replace Create Thiessen Polygons that works correctly?
... View more
11-18-2015
01:53 PM
|
0
|
12
|
8922
|
|
POST
|
I have in the past selected both the embed fonts and convert marker symbols to polygons options when exporting to PDF. I have determined that un-checking the convert marker symbols to polygons option results in a non-corrupt PDF. What would cause this change of behavior if I have not changed/upgraded my GIS software?
... View more
11-13-2015
08:15 AM
|
0
|
0
|
442
|
|
POST
|
Xander, Thanks for the reply but I do not use non-US decimal separators in ArcGIS.
... View more
11-12-2015
03:43 PM
|
0
|
0
|
3811
|
| Title | Kudos | Posted |
|---|---|---|
| 1 | 06-26-2025 08:30 AM | |
| 1 | 10-29-2024 03:51 PM | |
| 1 | 06-26-2024 08:32 AM | |
| 1 | 12-06-2023 11:53 AM | |
| 1 | 06-12-2012 07:42 AM |
| Online Status |
Offline
|
| Date Last Visited |
05-15-2026
09:46 AM
|