Select to view content in your preferred language

Could you please consider improving the performance of the arcpy.conversion.RasterToPoint Tool?

755
5
07-24-2023 05:54 PM
Status: Open
Labels (1)
WentaoChe
Occasional Contributor II

Dear arcpy.conversion.RasterToPoint Tool Development Team,

I frequently need to convert numerous DEM tifs or Grids into point shape files, and I'm finding the performance of the RasterToPoint tool to be an issue. Here's an example for context: with columns and rows of 1000 and 750 respectively,

1. The arcpy.conversion.RasterToPoint Tool takes 41 seconds.
2. Using Arc Commands: gridpoint + arcshape only takes 12 seconds.
    Grid to Coverage: 6 seconds, and Coverage to shape file: 6 seconds.


I've compared the performance of ArcGIS Pro 3.1.2 and Arc/Info 10.0 on the same PC, while processing thousands of Grid or tif files. This performance issue is the primary reason why I have not yet transitioned from this particular AML to Python.

I would greatly appreciate if improvements to this could be considered for inclusion in your next release.

Thank you in advance for your attention to this matter.

Best regards,
Wentao Che
Tokyo, Japan

 

 

5 Comments
DuncanHornby

Amazing to hear AML still being used! Out of interest have you tried writing the output of the raster to point tool to a file geodatabase on the c:\ drive of the machine, is the performance any better?

WentaoChe

@DuncanHornby Thank you for your enthusiasm about Old AML! 

Yes, there are some AMLs are still proving to be useful in our production processes.

I appreciate your suggestion, and I did try writing the output of the raster to a point feature class in a file geodatabase as you recommended. The elapsed times were indeed much better, averaging around 18 seconds, which is a significant improvement compared to writing to a shape file that took 41-44 seconds.

However, our goal is to convert this point shape file to a las file. Unfortunately, we currently don't have a tool that directly converts a point feature class in a file geodatabase to a las file, now we only have a tool that converts shape files to las files.

It would be very convenient if ESRI could provide a tool to directly convert DEM tif or Grid files to las format, saving us some time and effort. I will keep an eye out for any updates or new tools that might become available in the future.

Once again, thank you for your suggestion and your interest in our work. If you have any other ideas or insights, feel free to share them. Your input is highly appreciated!

Wentao Che

DrewFlater

Hi @WentaoChe , hope you are back from UC safely, nice to see you there. 

Since you show you are willing to string together multiple commands like in your AML to achieve the best performance, I was curious and tried several workarounds including using the memory workspace as an intermediate location for writing points before converting to shapefile. Unfortunately the bottleneck seems to be the shapefile writing, and I couldn't get performance faster than just going directly to shapefile from RasterToPoint. 

For my test of 2 million tif cells, I found RasterToPoint with direct output to shapefile to take 55 seconds. Compare this to writing to memory (4 seconds) then CopyFeatures to shapefile (~70 seconds) was slower. I even tried using arcpy.da Search and Insert cursors to read the memory data and write to shapefile, and that took about 50 seconds so still not faster. 

I am relabeling this to the Spatial Analyst extension, since that team owns the RasterToPoint tool. They might be able to offer some suggestions, though I think the limitation is in shapefile writing across the board. 

WentaoChe

Hi @DrewFlater

Thank you so much for your message and for your kind words regarding my attendance at UC. It was indeed a productive and insightful event as always.

I greatly appreciate all the efforts you've invested in exploring various workarounds to enhance the performance of the RasterToPoint tool. Your testing approach, including the utilization of the memory workspace, is a good idea, and I intend to give it a try. I wholeheartedly agree with your observation that "the bottleneck seems to be the shapefile writing, and I couldn't achieve better performance than when directly outputting to a shapefile from RasterToPoint".

Your attempt to further optimize the process by utilizing arcpy.da Search and Insert cursors for reading memory data and writing to a shapefile is commendable. 

I hope that, after your relabeling, there might be potential for enhancing the shapefile writing process.

Please keep me updated on any progress or insights you gather from the Spatial Analyst extension team. Your dedication to optimizing the workflow is truly commendable, and I'm here to support your efforts in any way I can.

Best regards,

WentaoChe

WentaoChe

Hi, @DrewFlater,

Just FYI, I also tried arcpy.conversion.RasterToASCII tool + arcpy.da.InsertCursor and write to shapefile, and that took about 90+ seconds so still not faster.

 

t1 = time.time()

asc = 'md15421_ascii.asc'

lines = open(asc,'r')

ncols = int(lines.readline().split()[1])
nrows = int(lines.readline().split()[1])
xllcorner = float(lines.readline().split()[1])
yllcorner = float(lines.readline().split()[1])
cellsize = float(lines.readline().split()[1])
NODATA_value = float(lines.readline().split()[1])

out_shp = asc[:-4] + '.shp'

if Exists(out_shp):
  Delete(out_shp)

CreateFeatureclass(in_path, out_shp, 'POINT', '', 'DISABLED', 'DISABLED')

AddField(out_shp,'z','Float',7,3)

rows = da.InsertCursor(out_shp, ['Shape@','z'])
row_count = 0
for line in lines:
  row_count += 1
  cols = line.strip().split(' ')
  y = cellsize / 2.0 + yllcorner + cellsize * (nrows - row_count)
  column_count = 0
  for col in cols:
    x = xllcorner + cellsize * (column_count + cellsize / 2.0)
    z = float(col)
    rows.insertRow([Point(x,y),z])
    column_count += 1
  if row_count % 10 == 0:
    print('  %d: %.1f seconds ' % (row_count,time.time() - t1))
del rows