0

I'm looking for the highest point in each of a large number of polygons. I'm using this pipeline:

[            
    'points.las',
    {'type': 'filters.crop', 'polygon': polygons},
    {
        "type": "filters.outlier",
        "method": "statistical"
    },
    {
        "type": "filters.range",
        "limits": "Classification![7:7]"  
    },
    {'type': 'filters.locate', "dimension": "Z", "minmax": 'max'},
    {"type": "writers.text", "precision": 8, "filename": 'output.csv'},
]

Where polygons is a long list of polygons in WKT. Unfortunately if a polygon does not contains any points nothing is output to the CSV making it impossible to correlate the high points with there corresponding polygons.

I'm wondering if there is a way around this or to tell filter.locate to output something else if there are no points.

nickponline
  • 25,354
  • 32
  • 99
  • 167

1 Answers1

0

This was one way to achieve it in case anyone one else comes across this:

def locate_max(ins,outs):

    if ins['Z'].shape[0] == 0:
        for k in ins.keys():
            outs[k] = np.array([0], dtype=ins[k].dtype)
    else:
        i = np.argmax(ins['Z'])
        for k in ins.keys():
            outs[k] = np.array([ins[k][i]])
                
    return True

Then add a stage like this to your pipeline:

{
    "type":"filters.python",
    "script":"pdal_functions.py",
    "function":"locate_max", 
    "module":"anything"
}
nickponline
  • 25,354
  • 32
  • 99
  • 167