<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: HideBa</title>
    <description>The latest articles on DEV Community by HideBa (@hideba).</description>
    <link>https://dev.to/hideba</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F518681%2F6fbf7cac-e597-4f4a-8f4f-abe829f9363d.jpeg</url>
      <title>DEV Community: HideBa</title>
      <link>https://dev.to/hideba</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/hideba"/>
    <language>en</language>
    <item>
      <title>Developed Python CLI to easily download Dutch point cloud data</title>
      <dc:creator>HideBa</dc:creator>
      <pubDate>Sat, 04 May 2024 09:41:53 +0000</pubDate>
      <link>https://dev.to/hideba/developed-python-cli-to-easily-download-dutch-point-cloud-data-2k1e</link>
      <guid>https://dev.to/hideba/developed-python-cli-to-easily-download-dutch-point-cloud-data-2k1e</guid>
      <description>&lt;h1&gt;
  
  
  Building a CLI Tool for Downloading AHN Point Cloud Data
&lt;/h1&gt;

&lt;p&gt;Hey there, fellow developers! I recently had the opportunity to work on a really cool project—developing a Command-Line Interface (CLI) tool that makes it a breeze to download Actueel Hoogtebestand Nederland (AHN) point cloud data for specific cities. Here is the GitHub link. &lt;a href="https://github.com/HideBa/ahn_cli"&gt;https://github.com/HideBa/ahn_cli&lt;/a&gt; I thought I'd share my experience with you all, so buckle up and let's dive in!&lt;/p&gt;

&lt;h2&gt;
  
  
  The Objective
&lt;/h2&gt;

&lt;p&gt;The main goal was to create a tool that would streamline the process of getting geospatial data, making it easier for various GIS applications like urban planning and environmental analysis. I mean, who doesn't love a good time-saver, right?&lt;/p&gt;

&lt;h2&gt;
  
  
  The Journey
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Step 1: Simplifying City Polygons
&lt;/h3&gt;

&lt;p&gt;First things first, I had to create simplified polygons of Dutch cities to make processing smoother. I found a comprehensive list of cities from the Nationaal Georegister &lt;a href="https://www.nationaalgeoregister.nl/geonetwork/srv/dut/catalog.search#/metadata/208bc283-7c66-4ce7-8ad3-1cf3e8933fb5"&gt;GeoNetwork&lt;/a&gt;. But here's the catch—the original polygons were so detailed that the software couldn't handle them efficiently. So, I put on my problem-solving hat and used the Douglas-Peucker Algorithm in QGIS to simplify those polygons. Voila! Optimized polygons that didn't compromise much on geographic accuracy.&lt;/p&gt;

&lt;h3&gt;
  
  
  Step 2: GeoJSON Conversion
&lt;/h3&gt;

&lt;p&gt;Next up, I converted the original dataset from a Web Feature Service (WFS) to GeoJSON format. This made it way easier to work with the data as standalone files and boosted the CLI tool's data handling capabilities.&lt;/p&gt;

&lt;h3&gt;
  
  
  Step 3: GeoTiles Grid Data Prep
&lt;/h3&gt;

&lt;p&gt;I downloaded the GeoTiles grid data from &lt;a href="https://weblog.fwrite.org/kaartbladen/"&gt;fwrite.org&lt;/a&gt;, which is crucial for identifying relevant point cloud data segments. Then, I converted the shapefile to GeoJSON to keep everything consistent and user-friendly.&lt;/p&gt;

&lt;h2&gt;
  
  
  The CLI Magic
&lt;/h2&gt;

&lt;p&gt;Now, let's talk about how this CLI tool actually works its magic:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;User Input:&lt;/strong&gt; The CLI tool starts by receiving parameters from the user, like the city name or geographic coordinates.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Tile Detection:&lt;/strong&gt; It uses the simplified city polygons and GeoTiles grid data to find overlapping tiles by checking for intersections. This step figures out which point cloud data segments the user needs.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Data Download:&lt;/strong&gt; Once the relevant tiles are identified, the CLI tool downloads the corresponding LAZ formatted point cloud data from the GeoTiles source.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Data Manipulation:&lt;/strong&gt; This is where the real fun begins! I created a data manipulation process with numpy and geopandas. It can filter by AHN classification classes, clip to the city polygon, apply user-defined polygonal clips, decimate, and even do radius-based clipping. Talk about flexibility!&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Output Generation:&lt;/strong&gt; Finally, the processed data is saved in the user's preferred format (LAS or LAZ), ready to be used in further GIS analyses or applications.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Challenges and Solutions
&lt;/h2&gt;

&lt;p&gt;Of course, no project is complete without a few hurdles. Here are some of the issues I faced and how I tackled them:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Slow AHN download:&lt;/strong&gt; Even for the smallest city in the Netherlands, the download took forever! I implemented multi-threading to download data simultaneously, reducing the total download time by around 8x.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Slow point cloud data manipulation:&lt;/strong&gt; Initially, I simply used laspy and numpy, but it was taking way too long. To speed up polygon intersection test, I employed rasterisation to make time complexity log(O). That results in way faster than before.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Runtime errors galore:&lt;/strong&gt; Dynamic typing in Python led to many runtime errors. Introducing a type system helped validate the program and improved productivity.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Invalid user parameters:&lt;/strong&gt; Validating parameters on the fly wasn't user-friendly, so I implemented validation that runs immediately after the CLI is invoked.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Large LAS/LAZ file sizes:&lt;/strong&gt; To help users deal with large file sizes, I added options for decimation and radius clipping, allowing them to reduce the number of points and focus on specific areas.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Wrapping Up
&lt;/h2&gt;

&lt;p&gt;There you have it, folks! Developing this CLI tool was an incredible learning experience, and I hope sharing my journey has given you some insights and inspiration for your own projects. Remember, every challenge is an opportunity to grow and find creative solutions. Happy coding!&lt;/p&gt;

</description>
      <category>python</category>
      <category>pointcloud</category>
      <category>gis</category>
      <category>las</category>
    </item>
  </channel>
</rss>
