Skip to content

Instantly share code, notes, and snippets.

@gadomski
Created October 31, 2013 19:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gadomski/7256062 to your computer and use it in GitHub Desktop.
Save gadomski/7256062 to your computer and use it in GitHub Desktop.
Cropping a set of lasfiles to rectangular bounds
#!/usr/bin/env python
import os
import subprocess
PROJECT_DIR = os.path.abspath(os.path.dirname(__file__))
def path(*a):
return os.path.join(PROJECT_DIR, *a)
LASFILE_DIR = path("UNC20130419LASv1-0")
CROP_DIR = path("cropped")
WKT_FILE = path("output.wkt", "ASO_April19_2013_0.8_octree_boundary.csv")
PIPELINE_XML = """
<?xml version="1.0" encoding="utf-8"?>
<Pipeline version="1.0">
<Writer type="drivers.las.writer">
<Option name="filename">
%(outfile)s
</Option>
<Filter type="filters.crop">
<Option name="bounds">
([259171.9260, 266197.1302], [4193597.2623, 4201173.8345], [0, 100000])
</Option>
<Reader type="drivers.las.reader">
<Option name="filename">
%(infile)s
</Option>
</Reader>
</Filter>
</Writer>
</Pipeline>
"""
def main():
try:
os.mkdir(CROP_DIR)
except OSError:
pass
with open(WKT_FILE) as f:
wkt = f.read()
for infile in os.listdir(LASFILE_DIR):
xml = PIPELINE_XML % {
"infile": os.path.join(LASFILE_DIR, infile),
"outfile": os.path.join(CROP_DIR, infile),
"wkt": wkt,
}
print "Cropping ", os.path.join(LASFILE_DIR, infile)
p = subprocess.Popen(["pcpipeline", "--stdin", "-v", "5"], stdin=subprocess.PIPE,
stdout=subprocess.PIPE, stderr=subprocess.PIPE)
(stdout, stderr) = p.communicate(xml)
print stdout
print stderr
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment