Mapping

Script for Downloading NYS DHES LiDAR and Creating Contours and Hillshades

Here is a brief PHP script I use to download LiDAR data from NYGIS website. You simply supply it a list of quads on the command line like php getlidar.php u_3592573775_1m_DEM.img u_3600073175_1m_DEM.img then execute the below script. This script requires PHP and the dbase extension. If you use PHP7, you can download a version of dbase for PHP7 .

#!/usr/bin/php -q
 array_shift($argv); // remove program name

$lidarDir = "/home/andy/Documents/GIS.Data/lidar";

$tomerge = "";
$merged = "";
$conDir = "/tmp";

foreach ($argv as $quad) {
$wgetCommand = "wget -c -P $lidarDir \"ftp://ftporthos.dhses.ny.gov/lidar/nysdop/dem/$quad\"";
#echo "$wgetCommand\n";
system($wgetCommand);

$tomerge .= "$lidarDir/$quad ";

$merged = "merge".substr($quad,1,-4);
}

$mergeLidarCommand = "gdalwarp -co \"COMPRESS=LZW\" $tomerge $conDir/$merged.tif -r average -overwrite";
#echo "$mergeLidarCommand\n";
system($mergeLidarCommand);

// produce hillshade
system("gdaldem hillshade {$conDir}/{$merged}.tif {$conDir}/{$merged}hillshade.tif -z 2.0 -s 1.0 -az 315.0 -alt 45.0 -compute_edges");

// produce deeper hillshade
system("gdaldem hillshade {$conDir}/{$merged}.tif {$conDir}/{$merged}hillshade.6x.tif -z 6.0 -s 1.0 -az 315.0 -alt 45.0 -compute_edges &");

$minor = 5;
$major = 25;
$minorMeters = $minor * 0.3048;
$majorMeters = $major * 0.3048;

// produce contours
if (file_exists("{$conDir}/{$merged}{$major}ft-contour.shp")) {
unlink("{$conDir}/{$merged}{$major}ft-contour.shp");
}

if (file_exists("{$conDir}/{$merged}{$minor}ft-contour.shp")) {
unlink("{$conDir}/{$merged}{$minor}ft-contour.shp");
}

system("gdal_contour -a elev -i {$majorMeters} {$conDir}/{$merged}.tif {$conDir}/{$merged}{$major}ft-contour.shp");
system("gdal_contour -a elev -i {$minorMeters} {$conDir}/{$merged}.tif {$conDir}/{$merged}{$minor}ft-contour.shp");

// convert contour elevation to feet from meters

foreach (array("{$conDir}/{$merged}{$minor}ft-contour.dbf", "{$conDir}/{$merged}{$major}ft-contour.dbf") as $file) {
$db = dbase_open("$file", 2);

if ($db) {
$record_numbers = dbase_numrecords($db);
for ($i = 1; $i <= $record_numbers; $i++) {

// gets the old row
$row = dbase_get_record($db, $i);

// Update the date field with feet instead of meters
$row[1] = ceil($row[1] * 3.280839);

// remove the 'deleted' entry
unset($row['deleted']);

// replace record and save
dbase_replace_record($db, $row, $i);
}
}

dbase_close($db);
}

I use this script for my various map making efforts when I use LiDAR data in making hillshades and contours. I have automated the calling of this script from QGIS by using PyQGIS plugin that I developed.

Balmville Tree Springs Back To Life.

Balmville Tree Springs Back To Life.

"Local folklore has it that the tree grew when George Washington planted his walking stick while he and the Continental Army were encamped in nearby Newburgh during the final years of the Revolutionary War but core samples of the tree have dated its growth to 1699, well before American independence. Franklin Roosevelt often came to visit the tree."

The tree was cut down in 2015 when it was in terminal decline and ready to collapse on the road and surrounding houses. This summer though, the energy in the roots have allowed it to spring new branches and come back alive. While not uncommon for a large cut tree to do this, it's still a wonderful story of rebirth.

Zero Centered Color Ramp in QGIS

I often need zero-centered color ramps in QGIS. Here is how to quickly make them:

  1. Open up the Layer Styling Dialog.
  2. Select the column you want to use and number of classes.
  3. Select the color ramp you want to use — typically a two or three color ramp — such as green-white-red or blue-white-red.
  4. Click classify.
  5. Note the highest or lowest value in the classes (such as -152 or 80).
  6. You will want to use the largest absolute value — in this case -152.
  7. Put in the column box, rand(-152, 152) and click classify. If you a using a simple shapefile without many objects, you may have to expand the range slightly, e.g. rand(-200,200),Β to ensure a full ramp is generated.
  8. Select the column you want to use. Do not click classify.
  9. You will now have a nice, zero centered, balanced color ramp for displaying your data.

The GPS Forefather.

Transit: The GPS Forefather.

One of the great questions faced by man kind -- but only recently answered conveniently and accurately -- is where am I? From precision agriculture to ship navigation to bus systems to navigation systems in cars, the answer to this question has solved many problems for mankind.

It wasn't all that long ago -- maybe 5 or 10 years ago -- when the average person couldn't just pull a cellphone out of their pocket, and find out their exact location down to 10 feet from their cellphone. Now such technology is common place.

The Transit Satellites, the first successfully launched today in 1960, started to answer that question. The transit satellites were primitive technology compared to the modern GPS satellites, but a necessary first step in man answering the question -- where am I?