Machine Learning on Geographical Data Using Python 1st Edition Joos Korstanje instant download
Machine Learning on Geographical Data Using Python 1st Edition Joos Korstanje instant download
https://ebookmeta.com/product/machine-learning-on-geographical-
data-using-python-1st-edition-joos-korstanje/
https://ebookmeta.com/product/adaptive-machine-learning-
algorithms-with-python-solve-data-analytics-and-machine-learning-
problems-on-edge-devices-1st-edition-chanchal-chatterjee/
https://ebookmeta.com/product/natural-language-processing-
recipes-unlocking-text-data-with-machine-learning-and-deep-
learning-using-python-2nd-edition-akshay-kulkarni-2/
https://ebookmeta.com/product/natural-language-processing-
recipes-unlocking-text-data-with-machine-learning-and-deep-
learning-using-python-2nd-edition-akshay-kulkarni/
https://ebookmeta.com/product/the-culture-of-judicial-
independence-in-a-globalised-world-1st-edition-shimon-shetreet-
wayne-mccormack/
Information Technology for Healthcare Managers 9th
Edition Gerald L. Glandon
https://ebookmeta.com/product/information-technology-for-
healthcare-managers-9th-edition-gerald-l-glandon/
https://ebookmeta.com/product/stress-and-your-body-1st-edition-
robert-sapolsky/
https://ebookmeta.com/product/workplace-ostracism-its-nature-
antecedents-and-consequences-1st-edition-cong-liu/
https://ebookmeta.com/product/investing-in-stocks-for-dummies-
paul-mladjenovic/
https://ebookmeta.com/product/2021-african-small-publishers-
catalogue-colleen-higgs/
Love at First Swim Tiaras and Treats Book 5 1st Edition
Rachelle Stevensen Stevensen Rachelle
https://ebookmeta.com/product/love-at-first-swim-tiaras-and-
treats-book-5-1st-edition-rachelle-stevensen-stevensen-rachelle/
Joos Korstanje
Apress Standard
The publisher, the authors and the editors are safe to assume that the
advice and information in this book are believed to be true and accurate
at the date of publication. Neither the publisher nor the authors or the
editors give a warranty, expressed or implied, with respect to the
material contained herein or for any errors or omissions that may have
been made. The publisher remains neutral with regard to jurisdictional
claims in published maps and institutional affiliations.
Source Code
All source code used in the book can be downloaded from
github.com/apress/machine-learning-geographic-
data-python.
Any source code or other supplementary material referenced by the
author in this book is available to readers on GitHub
(https://github.com/Apress). For more detailed information, please
visit http://www.apress.com/source-code.
Table of Contents
Part I: General Introduction
Chapter 1:Introduction to Geodata
Reading Guide for This Book
Geodata Definitions
Cartesian Coordinates
Polar Coordinates and Degrees
The Difference with Reality
Geographic Information Systems and Common Tools
What Are Geographic Information Systems
Standard Formats of Geodata
Shapefile
Google KML File
GeoJSON
TIFF/JPEG/PNG
CSV/TXT/Excel
Overview of Python Tools for Geodata
Key Takeaways
Chapter 2:Coordinate Systems and Projections
Coordinate Systems
Geographic Coordinate Systems
Projected Coordinate Systems
Local Coordinate Systems
Which Coordinate System to Choose
Playing Around with Some Maps
Example:Working with Own Data
Key Takeaways
Chapter 3:Geodata Data Types
Vector vs.Raster Data
Dealing with Attributes in Vector and Raster
Points
Definition of a Point
Importing an Example Point Dataset in Python
Some Basic Operations with Points
Lines
Definition of a Line
An Example Line Dataset in Python
Polygons
Definition of a Polygon
An Example Polygon Dataset in Python
Some Simple Operations with Polygons
Rasters/Grids
Definition of a Grid or Raster
Importing a Raster Dataset in Python
Key Takeaways
Chapter 4:Creating Maps
Mapping Using Geopandas and Matplotlib
Getting a Dataset into Python
Making a Basic Plot
Plot Title
Plot Legend
Mapping a Point Dataset with Geopandas and Matplotlib
Concluding on Mapping with Geopandas and Matplotlib
Making a Map with Cartopy
Concluding on Mapping with Cartopy
Making a Map with Plotly
Concluding on Mapping with Plotly
Making a Map with Folium
Concluding on Mapping with Folium
Key Takeaways
Part II: GIS Operations
Chapter 5:Clipping and Intersecting
What Is Clipping?
A Schematic Example of Clipping
What Happens in Practice When Clipping?
Clipping in Python
What Is Intersecting?
What Happens in Practice When Intersecting?
Conceptual Examples of Intersecting Geodata
Intersecting in Python
Difference Between Clipping and Intersecting
Key Takeaways
Chapter 6:Buffers
What Are Buffers?
A Schematic Example of Buffering
What Happens in Practice When Buffering?
Creating Buffers in Python
Creating Buffers Around Points in Python
Creating Buffers Around Lines in Python
Creating Buffers Around Polygons in Python
Combining Buffers and Set Operations
Key Takeaways
Chapter 7:Merge and Dissolve
The Merge Operation
What Is a Merge?
A Schematic Example of Merging
Merging in Python
Row-Wise Merging in Python
Attribute Join in Python
Spatial Join in Python
The Dissolve Operation
What Is the Dissolve Operation?
Schematic Overview of the Dissolve Operation
The Dissolve Operation in Python
Key Takeaways
Chapter 8:Erase
The Erase Operation
Schematic Overview of Spatially Erasing Points
Schematic Overview of Spatially Erasing Lines
Schematic Overview of Spatially Erasing Polygons
Erase vs.Other Operations
Erase vs.Deleting a Feature
Erase vs.Clip
Erase vs.Overlay
Erasing in Python
Erasing Portugal from Iberia to Obtain Spain
Erasing Points in Portugal from the Dataset
Cutting Lines to Be Only in Spain
Key Takeaways
Part III: Machine Learning and Mathematics
Chapter 9:Interpolation
What Is Interpolation?
Different Types of Interpolation
Linear Interpolation
Polynomial Interpolation
Nearest Neighbor Interpolation
From One-Dimensional to Spatial Interpolation
Spatial Interpolation in Python
Linear Interpolation Using Scipy Interp2d
Kriging
Linear Ordinary Kriging
Gaussian Ordinary Kriging
Exponential Ordinary Kriging
Conclusion on Interpolation Methods
Key Takeaways
Chapter 10:Classification
Quick Intro to Machine Learning
Quick Intro to Classification
Spatial Classification Use Case
Feature Engineering with Additional Data
Importing and Inspecting the Data
Spatial Operations for Feature Engineering
Reorganizing and Standardizing the Data
Modeling
Model Benchmarking
Key Takeaways
Chapter 11:Regression
Introduction to Regression
Spatial Regression Use Case
Importing and Preparing Data
Iteration 1 of Data Exploration
Iteration 1 of the Model
Iteration 2 of Data Exploration
Iteration 2 of the Model
Iteration 3 of the Model
Iteration 4 of the Model
Interpretation of Iteration 4 Model
Key Takeaways
Chapter 12:Clustering
Introduction to Unsupervised Modeling
Introduction to Clustering
Different Clustering Models
Spatial Clustering Use Case
Importing and Inspecting the Data
Cluster Model for One Person
Tuning the Clustering Model
Applying the Model to All Data
Key Takeaways
Chapter 13:Conclusion
What You Should Remember from This Book
Recap of Chapter 1 – Introduction to Geodata
Recap of Chapter 2 – Coordinate Systems and Projections
Recap of Chapter 3 – Geodata Data Types
Recap of Chapter 4 – Creating Maps
Recap of Chapter 5 – Clipping and Intersecting
Recap of Chapter 6 – Buffers
Recap of Chapter 7 – Merge and Dissolve
Recap of Chapter 8 – Erase
Recap of Chapter 9 – Interpolation
Recap of Chapter 10 – Classification
Recap of Chapter 11 – Regression
Recap of Chapter 12 – Clustering
Further Learning Path
Going into Specialized GIS
Specializing in Machine Learning
Remote Sensing and Image Treatment
Other Specialties
Key Takeaways
Index
About the Author
Joos Korstanje
is a data scientist, with over five years of
industry experience in developing
machine learning tools. He has a double
MSc in Applied Data Science and in
Environmental Science and has extensive
experience working with geodata use
cases. He has worked at a number of
large companies in the Netherlands and
France, developing machine learning for
a variety of tools. His experience in
writing and teaching has motivated him
to write this book on machine learning
for geodata with Python.
About the Technical Reviewer
Xiaochi Liu
is a PhD researcher and data scientist at
Macquarie University, specializing in
machine learning, explainable artificial
intelligence, spatial analysis, and their
novel application in environmental and
public health. He is a programming
enthusiast using Python and R to
conduct end-to-end data analysis. His
current research applies cutting-edge AI
technologies to untangle the causal
nexus between trace metal
contamination and human health to
develop evidence-based intervention
strategies for mitigating environmental exposure.
Part I
General Introduction
© The Author(s), under exclusive license to APress Media, LLC, part of Springer
Nature 2022
J. Korstanje, Machine Learning on Geographical Data Using Python
https://doi.org/10.1007/978-1-4842-8287-8_1
1. Introduction to Geodata
Joos Korstanje1
(1) VIELS MAISONS, France
Geodata Definitions
To get started, I want to cover the basics of coordinate systems in the
simplest mathematic situation: the Euclidean space. Although the world
does not respect the hypothesis made by Euclidean geometry, it is a great
entry into the deeper understanding of coordinate systems.
A two-dimensional Euclidean space is often depicted as shown in
Figure 1-1.
Cartesian Coordinates
To locate points in the Euclidean space, we can use the Cartesian
coordinate system. This coordinate system specifies each point uniquely
by a pair of numerical coordinates. For example, look at the coordinate
system in Figure 1-2, in which two points are located: a square and a
triangle.
The square is located at x = 2 and y = 1 (horizontal axis). The triangle
is located at x = -2 and y = -1.
Figure 1-2 Two points in a coordinate system. Image by author
The point where the x and y axes meet is called the Origin, and
distances are measured from there. Cartesian coordinates are among the
most well-known coordinate system and work easily and intuitively in the
Euclidean space.
The letter r signifies the distance and the letter φ is the angle. You can go
the other way as well, using the following formulas:
ArcGIS
ArcGIS, made by ESRI, is arguably the most famous software package for
working with Geographic Information Systems. It has a very large number
of functionalities that can be accessed through a user-friendly click-
button system, but visual programming of geodata processing pipelines is
also allowed. Python integration is even possible for those who have
specific tasks for which there are no preexisting tools in ArcGIS. Among
its tools are also AI and data science options.
ArcGIS is a great software for working with geodata. Yet there is one
big disadvantage, and that is that it is a paid, proprietary software. It is
therefore accessible only to companies or individuals that have no
difficulty paying the considerably high price. Even though it may be worth
its price, you’ll need to be able to pay or convince your company to pay for
such software. Unfortunately, this is often not the case.
Python/R Programming
Finally, you can use Python or R programming for working with geodata
as well. Programming, especially in Python or R, is a very common skill
among data professionals nowadays.
As programming skills were less well spread a few years back, the
boom in data science, machine learning, and artificial intelligence has
made languages like Python become very commonly spread throughout
the workforce.
Now that many are able to code or have access to courses to learn how
to code, the need for full software becomes less. The availability of a
number of well-functioning geodata packages is enough for many to get
started.
Python or R programming is a great tool for treating geodata with
common or more modern methods. By using these programming
languages, you can easily apply tools from other libraries to your geodata,
without having to convert this to QGIS modules, for example.
The only problem that is not very well solved by programming
languages is long-term geodata storage. For this, you will need a database.
Cloud-based databases are nowadays relatively easy to arrange and
manage, and this problem is therefore relatively easily solved.
Shapefile
The shapefile is a very commonly used file format for geodata because it
is the standard format for ArcGIS. The shapefile is not very friendly for
being used outside of ArcGIS, but due to the popularity of ArcGIS, you will
likely encounter shapefiles at some point.
The shapefile is not really a single file. It is actually a collection of files
that are stored together in one and the same directory, all having the
same name. You have the following files that make up a shapefile:
– myfile.shp: The main file, also called the shapefile (confusing but true)
– myfile.shx: The shapefile index file
– myfile.dbf: The shapefile data file that stores attribute data
– myfile.prj: Optional file that stores spatial reference and projection
metadata
As an example, let’s look at an open data dataset containing the
municipalities of the Paris region that is provided by the French
government. This dataset is freely available at
https://geo.data.gouv.fr/en/datasets/8fadd7040c4b94f
2c318a0971e8faedb7b5675d6
On this website, you can download the data in SHP/L93 format, and
this will allow you to download a directory with a zip file. Figure 1-6
shows what this contains.
Figure 1-6 The inside of the shapefile. Image by author Data source: Ministry of
DINSIC. Original data downloaded from
https://geo.data.gouv.fr/en/datasets/8fadd7040c4b94f2c318a0971e8faedb7b5675d6,
updated on 1 July 2016. Open Licence 2.0 (www.etalab.gouv.fr/wp-
content/uploads/2018/11/open-licence.pdf)
As you can see, there are the .shp file (the main file), the .shx file (the
index file), the .dbf file containing the attributes, and finally the optional
.prj file.
For this exercise, if you want to follow along, you can use your local
environment or a Google Colab Notebook at
https://colab.research.google.com/.
You have to make sure that in your environment, you install
geopandas:
Then, make sure that in your environment you have a directory called
Communes_MGP.shp in which you have the four files:
– Communes_MGP.shp
– Communes_MGP.dbf
– Communes_MGP.prj
– Communes_MGP.shx
In a local environment, you need to put the “sample_data” file in the
same directory as the notebook, but when you are working on Colab, you
will need to upload the whole folder to your working environment, by
clicking the folder icon and then dragging and dropping the whole folder
onto there. You can then execute the Python code in Code Block 1-1 to
have a peek inside the data.
shapefile.plot()
Code Block 1-2 Plotting the shapefile
You will obtain the map corresponding to this dataset as in Figure 1-8.
Figure 1-8 The map resulting from Code Block 1-2. Image by author Data source:
Ministry of DINSIC. Original data downloaded from
https://geo.data.gouv.fr/en/datasets/8fadd7040c4b94f2c318a0971e8faedb7b5675d6,
updated on 1 July 2016. Open Licence 2.0 (www.etalab.gouv.fr/wp-
content/uploads/2018/11/open-licence.pdf)
import fiona
gpd.io.file.fiona.drvsupport.supported_drivers['KML']
= 'rw'
You’ll then see the exact same geodataframe as before, which is shown
in Figure 1-10.
Figure 1-10 The KML data shown in Python. Image by author Data source: Ministry of
DINSIC. Original data downloaded from
https://geo.data.gouv.fr/en/datasets/8fadd7040c4b94f2c318a0971e8faedb7b5675d6,
updated on 1 July 2016. Open Licence 2.0 (www.etalab.gouv.fr/wp-
content/uploads/2018/11/open-licence.pdf)
As before, you can plot this geodataframe to obtain a basic map
containing the municipalities of the area of Paris and around. This is done
in Code Block 1-4.
kmlfile.plot()
Code Block 1-4 Plotting the KML file data
Figure 1-11 The plot resulting from Code Block 1-4. Screenshot by author Data source:
Ministry of DINSIC. Original data downloaded from
https://geo.data.gouv.fr/en/datasets/8fadd7040c4b94f2c318a0971e8faedb7b5675d6,
updated on 1 July 2016. Open Licence 2.0 (www.etalab.gouv.fr/wp-
content/uploads/2018/11/open-licence.pdf)
GeoJSON
The json format is a data format that is well known and loved by
developers. Json is much used in communication between different
information systems, for example, in website and Internet
communication.
The json format is loved because it is very easy to parse, and this
makes it a perfect storage for open source and other developer-oriented
tools.
Json is a key-value dataset, which is much like the dictionary in
Python. The whole is surrounded by accolades. As an example, I could
write myself as a json object as in this example:
{ 'first_name': 'joos',
'last_name': 'korstanje',
'job': 'data scientist' }
As you can see, this is a very flexible format, and it is very easy to
adapt to all kinds of circumstances. You might easily add GPS coordinates
like this:
{ 'first_name': 'joos',
'last_name': 'korstanje',
'job': 'data scientist',
'latitude': '48.8566° N',
'longitude': '2.3522° E' }
As expected, the data looks exactly like before (Figure 1-13). This is
because it is transformed into a geodataframe, and therefore the original
representation as json is not maintained anymore.
Figure 1-13 The geojson content in Python. Image by author Data source: Ministry of
DINSIC. Original data downloaded from
https://geo.data.gouv.fr/en/datasets/8fadd7040c4b94f2c318a0971e8faedb7b5675d6,
updated on 1 July 2016. Open Licence 2.0 (www.etalab.gouv.fr/wp-
content/uploads/2018/11/open-licence.pdf)
You can make the plot of this geodataframe to obtain a map, using the
code in Code Block 1-6.
geojsonfile.plot()
Code Block 1-6 Plotting the geojson data
TIFF/JPEG/PNG
Image file types can also be used to store geodata. After all, many maps
are 2D images that lend themselves well to be stored as an image. Some of
the standard formats to store images are TIFF, JPEG, and PNG.
– The TIFF format is an uncompressed image. A georeferenced TIFF
image is called a GeoTIFF, and it consists of a directory with a TIFF file
and a tfw (world file).
– The better-known JPEG file type stores compressed image data. When
storing a JPEG in the same folder as a JPW (world file), it becomes a
GeoJPEG.
– The PNG format is another well-known image file format. You can make
this file into a GeoJPEG as well when using it together with a PWG
(world file).
Image file types are generally used to store raster data. For now,
consider that raster data is image-like (one value per pixel), whereas
vector data contains objects like lines, points, and polygons. We’ll get to
the differences between raster and vector data in a next chapter.
On the following website, you can download a GeoTIFF file that
contains an interpolated terrain model of Kerbernez in France:
https://geo.data.gouv.fr/en/datasets/b0a420b9e003
d45aaf0670446f0d600df14430cb
You can use the code in Code Block 1-7 to read and show the raster file
in Python.
Note Depending on your OS, you may obtain a .tiff file format rather
than a .tif when downloading the data. In this case, you can simply
change the path to become .tiff, and the result should be the same. In
both cases, you will obtain the image shown in Figure 1-15.
Figure 1-15 The plot resulting from Code Block 1-7. Image by author Data source:
Ministry of DINSIC. Original data downloaded from
https://geo.data.gouv.fr/en/datasets/b0a420b9e003d45aaf0670446f0d600df14430cb,
updated on “unknown.” Open Licence 2.0 (www.etalab.gouv.fr/wp-
content/uploads/2018/11/open-licence.pdf)
CSV/TXT/Excel
The same file as used in the first three examples is also available in CSV.
When downloading it and opening it with a text viewer, you will observe
something like Figure 1-16.
Figure 1-16 The contents of the CSV file. Image by author Data source: Ministry of
DINSIC. Original data downloaded from
https://geo.data.gouv.fr/en/datasets/b0a420b9e003d45aaf0670446f0d600df14430cb,
updated on “unknown.” Open Licence 2.0 (www.etalab.gouv.fr/wp-
content/uploads/2018/11/open-licence.pdf)
The important thing to take away from this part of the chapter is that
geodata is “just data,” but with geographic references. These can be stored
in different formats or in different coordinate systems to make things
complicated, but in the end you must simply make sure that you have
some sort of understanding of what you have in your data.
You can use many different tools for working with geodata. The goal of
those tools is generally to make your life easier. As a last step for this
introduction, let’s have a short introduction to the different Python tools
that you may encounter on your geodata journey.
Overview of Python Tools for Geodata
Here is a list of Python packages that you may want to look into on your
journey into geodata with Python:
Geopandas
General GIS tool with a pandas-like code syntax that makes it very
accessible for the data science world.
Fiona
Reading and writing geospatial data.
Rasterio
Python package for reading and writing raster data.
GDAL/OGR
A Python package that can be used for translating between different GIS
file formats.
RSGISLIB
A package containing remote sensing tools together with raster
processing and analysis.
PyProj
A package that can transform coordinates with multiple geographic
reference systems.
Geopy
Find postal addresses using coordinates or the inverse.
Shapely
Manipulation of planar geometric objects.
PySAL
Spatial analysis package in Python.
Scipy.spatial
Spatial algorithms based on the famous scipy package for data science.
Cartopy
Package for drawing maps.
GeoViews
Package for interactive maps.
A small reminder: As Python is an open source environment and those
libraries are mainly developed and maintained by unpaid open source
developers, there is always that chance that something changes or
becomes unavailable. This is the risk of working with open source. In
most cases, there are no such big problems, but they can and do
sometimes happen.
Key Takeaways
1. Cartesian coordinates and polar coordinates are two alternative
coordinate systems that can indicate points in a two-dimensional
Euclidean space.
5. The advantage of using Python is that you can have a lot of autonomy
on your geodata treatment and that you can benefit from the large
number of geodata and other data science and AI packages in the
ecosystem.
Figure 2-1 Airplane routes are not straight on a mapImage adapted from
https://en.wikipedia.org/wiki/World_map#/media/File:Blue_Marble_2002.png (Public
Domain Image. 10 February 2002)
Let’s now consider an example where you are holding a round soccer
ball. When going from one point to another on a ball, you will intuitively
be able to say which path is the fastest. If you are looking straight at the
ball, when following your finger going from one point to another, you will
see your hand making a shape like in Figure 2-2.
Figure 2-2 The shortest path on a ball is not a straight line in two-dimensional view.
Image by author
When making maps, we cannot plot in three dimensions, and we,
therefore, need to find some way or another to put a three-dimensional
path onto a two-dimensional image.
Many map makers have proposed all sorts of ways to solve this
unsolvable problem, and the goal of this chapter is to help you understand
how to deal effectively with those 3D to 2D mapping distortions that will
be continuously looking to complexify your work on geodata.
Coordinate Systems
While the former discussion was merely intuitive, it is now time to slowly
get to more official definitions of the concepts that you have seen. As we
are ignoring the height of a point (e.g., with respect to sea level) for the
moment, we can identify three types of coordinate systems:
– Geographic Coordinate Systems
– Projected Coordinate Systems
– Local Coordinate Systems
Let’s go over all three of them.
Whatever the world may say of the right or wrong of the “Lost
Cause,” it will never deny that many of those by whom it was
upheld, and who crowned its banners with glory in carrying them
so gallantly and so far, were inspired by motives as patriotic, as
pure and bright as ever burned in the bosom of mortal man.
They were brave men; they fought as brave men fight, and died
as brave men die. Upon a hundred “stormy heights and carnage-
covered fields,” they attested their devotion to their cause, and
among the truest and bravest of them all, the name of Gen.
Turner Ashby shines with a radiant glory that will brighten still as
it goes “sounding down the ages,”
“The knightliest of the knightly race,
Who since the days of old
Have kept the lamp of chivalry
Alight in hearts of gold.”
There was mourning in the camp that night, and every face
wore a look of gloom as if in the calamity which had just befallen
them, the soldiers felt that a harbinger of still greater desolation
had been given them, and when Gen. Jackson appeared in the
morning, all eyes looked eagerly to see how he felt the loss of
the great cavalier, but in that calm and steady eye was an
inscrutable look, and no man could form an idea of what were
the feelings of the commander by the expression of the face that
never changed, either in the glory of triumph or the gloom of
defeat.
The army lay quiet all day, and the next moved towards Port
Republic, encamping near the old Church at Cross Keys. Some of the
men became very impatient at the constant and rapid marching, and
one of them asked Gen. Jackson, as he passed along the column,
where he was going to fight the Yankees. The General, with a half
smile, replied, "We’ll fight them in Brown’s Gap," and the soldiers at
once became exceedingly interested in that place, continually asking
each other “how far it was to Brown’s Gap. Would the Yankees follow
them there?” &c., little imagining that the ground upon which they
then stood was to be their battle-field for the morrow.
Sunday morning, June 8th, broke bright, clear and hot, and by 8
o’clock every one knew that Ewell was going to match his division
against the advancing columns of Fremont, for the cavalry, now
commanded by Col. T. T. Munford, slowly retired before the Yankee
infantry, and Gen. Ewell’s brigades moved out quietly and formed
their battle lines. The scouts and couriers now had plenty of work
again, and Lieut. Barrett, with a part of the company, was ordered to
act as provost guard again, while Gen. Ewell ordered Lieut. Myers
and Ed. Wright to scout on the right, and let him know when the
enemy made any demonstration in that direction. The remainder of
the boys were on duty as couriers with the Generals. The battle
opened with some artillery firing, but pretty soon Taylor’s brigade
met and whipped a line of Yankees that advanced upon Ewell’s
centre, and all was quiet again for an hour, when Elzey’s men
became engaged, and at the same time Myers and Wright
discovered a heavy force moving by the flank to Ewell’s right. Gen.
Trimble was the first man they met on their return with this
important information, and communicating it to him, that officer
promptly moved his brigade forward, and attacking the flanking
party in flank, they were very soon driven off with heavy loss in men
and all their artillery. About the time Trimble’s guns opened, General
Taylor advanced, and for a while the battle raged with great fury, but
General Trimble’s movement exposed the enemy’s left flank, and
they fell back along the whole line.
This ended the battle of Cross Keys, with the exception of some
cannonading on the left about sundown, and although some horses
of the couriers had been struck, only one of White’s men was
touched, and he very slightly, by a bouncing grape shot.
That night they slept upon the battle-field, but with the dawn
everything moved rapidly towards Port Republic, for Shields, with his
army, was moving up the river, and Gen. Jackson was going to "fight
in Brown’s Gap" again.
On Monday morning “Stonewall” crossed the bridge almost alone,
and rode into the town, but on his return found a Yankee Major with
two pieces posted at the mouth of the bridge, and, without a
moment’s hesitation, rode up to the officer, saying, “Turn your guns,
sir, turn your guns; the enemy is coming from that direction,”
pointing at the same time down the river, and without a question,
the unsuspecting Major had his pieces wheeled about, in order to
command the approach of the enemy, which to him was no enemy
at all, and without waiting to explain any further, Gen. Jackson
dashed rapidly across the bridge to his own people, but he had not a
moment to spare, for the baffled Yankee had his guns going on him
before he cleared the bridge.
Jackson instantly ordered his artillery up, and very soon the
enterprising “boys in blue” were compelled to change their position,
thus leaving the bridge open to the Confederates, and General
Jackson’s old Division crossed the river, followed slowly by that of
Gen. Ewell, with whom White’s cavalry moved.
Immediately on reaching the east bank, the line of battle was
formed, and the fight commenced, and as soon as everything had
crossed the bridge it was fired, cutting off Fremont’s army from that
of Shields, and with it a company of the 6th Va. Cavalry, which acted
as rear guard and was compelled to swim the river.
Here was begun and carried through to complete success one of
the most brilliant displays of generalship witnessed during the war,
or, in fact, in any war of modern times.
“Stonewall” had not only eluded the superior force of Fremont, but
had actually whipped him, almost in cannon shot of his colleague, on
the 8th, and now, on the 9th of June, was massing all his troops and
crushing the army of that colleague—(Gen. Shields)—while Fremont,
with his troops formed in battle-ranks on the hill-sides bordering the
Shenandoah, was unable to do more than look at the battle and see
the army of Shields annihilated; while, without a guard, and just in
his front, moved the long train composed of all of Jackson’s wagons,
all of Ewell’s and nearly every one of Banks’, besides some of his
own; and standing still in all the circumstance and panoply of war,
the blazing bridge cutting off his last and only means of doing harm
to his wily foe, the savage Gen. Fremont, in pitiful helplessness and
vindictive vandalism, could only fire his guns upon the empty town
of Port Republic.
By 10 o’clock the battle was over and Shields flying down the river
with the scattered remnant of his army, which Gen. Jackson only
followed for nine miles when he returned to look after his trains and
captures.
The enemy had lost all of his artillery, consisting of about fifteen
guns, all of his wagons and a great number of prisoners, besides
many killed and wounded, for Shields fought with more obstinacy
than Fremont, although the latter had considerably more force than
his adversary—Gen. Ewell—while Shields had an inferior one to the
combined troops of Jackson and Ewell.
The couriers had very warm and exciting work to-day, as is usual
on the battle-field, but although many narrow escapes were made
not one was wounded, and they captured a full company of Ohio
infantry.
Lieut. Myers was sent by Gen. Jackson, during the heat of the
battle, with a dispatch to Col. Munford to charge, with his cavalry, a
battery which was doing heavy execution, and remained with the
Colonel until the enemy’s lines broke up in full retreat, when he
rejoined Gen. Jackson and kept with him in the nine mile pursuit,
which caused him to be the recipient of another scolding from Gen.
Ewell, who informed him that he was no courier for Gen. Jackson,
and that his business was to keep his (Ewell’s) Division supplied with
couriers, and to obey his orders and nobody else’s. It is needless to
say that the lesson was laid to heart and closely followed thereafter.
The army bivouacked in Brown’s Gap that night, and the next day
the usual rain storm which follows a battle poured down upon them,
as they still waited to see and do whatever “Old Stonewall” might
decide upon as best for them; and two days after, the great
commander put his people in camp at Mount Meridian, where, for
several very beautiful June days, the troops passed away the time,
fishing and bathing in the blue Shenandoah, and visiting the
wonderful Weyer’s Cave, while each day a regular detail was made
to go to Port Republic and “make believe” build a bridge as if
Jackson intended to try another campaign down the Valley, when, in
reality, he was preparing to march his army to the relief of the
Confederate Capital, which was now closely environed by the
magnificent army of McClellan, and was anxiously waiting the critical
moment when the last spadeful of dirt should be thrown, and the
“Young Napoleon” would replace his sappers and miners with the
splendid battalions who were to immortalize the name of McClellan
by taking, under his plans and direction, the now world-renowned
City of Richmond.
White’s company was in splendid condition, the ranks full, the
horses thriving and the men all armed equal to any cavalry in the
army, and all they wanted was for their Captain to come up and take
command again. While at Mount Meridian Gen. Jackson had divine
service regularly, and appointed times for praise and thanksgiving to
the God of battles who had crowned his arms with victory; while
from all around our borders came news of Confederate successes,
and rumors that foreign nations had recognized the independence of
the Southern Confederacy. So that the future was brilliant with hope
and no man in the army would have willingly exchanged his
Confederate dollars for an equal amount of greenbacks.
CHAPTER V.
About the 20th of June the army crossed the Blue Ridge, and
moved quietly towards the beleaguered capital; but the men did
not know any more about their destination than the enemy, who
never knew, until his artillery boomed upon McClellan’s flank at
Richmond, that Jackson had left the Valley. On arriving at
Charlottesville, Capt. White, now entirely recovered from the
effects of his wound, rejoined his company, and it now appeared
that the little band of scouts and couriers was to be the
foundation upon which a larger command was to be built up, for
here the news was received that Capt. George W. Chiswell, of
Maryland, was on the march from that State with a full company
to join White’s Cavalry, and all the boys began to look forward to
the time when the irksome duty of waiting upon the Generals
and playing telegraph for an army, was to be exchanged for the
more congenial and pleasant one of once more scouting on the
frontier. Encamped at Charlottesville they had seen a battalion of
men commanded by Major John Scott, of Fauquier Co., Va., and
organized by that officer to act as Partisan rangers. It seemed
that mainly through the influence of Major Scott, a bill had been
introduced into the Confederate Congress, and which afterwards
became a law, authorizing the formation of such bands, and
offering premiums in captured property for an independent
border warfare upon the outposts and communications of the
enemy’s army, and this idea struck the minds of White’s men
very forcibly as containing the very principle upon which their
company had been formed, and the one they most desired to
have applied to their own particular case, and they believed that
in strict justice, Capt. White could get the authority under the
law to become a Partisan, as soon as his command was large
enough to justify it, and all hailed with joyful acclamation the
report that Maryland men were coming to join them; in fact the
advance guard of the company met them at Charlottesville in the
persons of Ed. J. Chiswell, Sam. White, Frank. Williams and
Elijah Viers.
Some anecdotes of Gen. Jackson, and the manner in which he
was regarded by his men, and the enemy too, were current in the
army during this campaign, and were true in idea if not in detail.
Before leaving camp at Mount Meridian, an order was issued
instructing the men not to tell what or whose troops they were, and
to answer all questions on the subject with Gen. Ewell’s
abomination, "don’t know," as a precaution against the enemy
getting a knowledge of Jackson’s movement from the Valley. One
day the General saw a soldier crossing a field towards some cherry
trees, and as the great abundance of cherries along the route had
caused any amount of straggling, he resolved to make an example
of this man. So riding up to him he inquired, “What division do you
belong to?” "Don’t know," said the soldier. “What brigade?” asked
the General; and again the soldier replied, "don’t know." “Well,”
asked Jackson, “what regiment do you belong to?” thinking he had
now found an answerable question; but again the man replied,
"don’t know," and with some asperity of tone the General exclaimed,
“What do you know, sir?” when the cute “gray jacket” answered—"I
know that old Stonewall ordered me not to know anything, and
damned if I ain’t going to stick to it."
The General turned and rode away without a word, smiling at the
extremely literal construction of orders which had saved the soldier
from the punishment he had meditated for him.
Gen. Jackson got aboard the cars at Louisa C. H., to go to
Richmond, and took a seat in the same car in which a Yankee Major,
who had been captured among some of the raiding parties on the
Rail Road, was being carried also to Richmond.
The Major entered into conversation with the quiet officer, not
knowing, of course, who he was talking to, and began explaining to
him the absolute certainty of McClellan’s capture of the Confederate
capital. After listening for some time to the manner in which each
division of Lee’s army was tied up by a stronger force from the other
side, “Stonewall” ventured the remark, "But suppose Jackson’s army
should move from the Valley and strike McClellan in flank and rear
while he is engaging Lee in front." “Oh,” said the Major, "there’s no
danger of that, Jackson has been badly crippled in his engagements
in the Valley, and is now hemmed in closely by Fremont’s army, so
that he can’t move." “But,” persisted the Confederate, “suppose he
should getaway and come to Richmond.” "No, I say it’s no use to talk
about that," said the Major, "for he can’t get away, it is impossible."
“Yes,” said the other, “and I say it is possible, for he has already
whipped Fremont, and his army will be in front of Richmond in less
than twenty-four hours.” The Yankee looked at him a moment, and
with an anxious expression asked, “Who are you, sir?” “I am Gen.
Jackson,” replied the hero; upon which the Major smacked his hands
together exclaiming, “Whipped again, by God!” and at once subsided
into silence.
When the army of Jackson reached its position and it was plain to
everybody that the time had come for the great battle, the men who
had followed “Stonewall” all over the Valley, and had seen his banner
wave in triumph on every field, were rendered still more proud of
their great leader by seeing, about noon on the day of “Cold
Harbour,” the men whose names were already encircled with a halo
of glorious deeds performed during the war, ride up and report to
Gen. Jackson for instruction.
Longstreet, A. P. Hill, Magruder, and Stuart, all acknowledged the
solemn soldier as their superior, and took his orders for the day’s
work.
That day’s work too was a sad and bloody one, and when night
ended the conflict, many were the corpses strewn over the carnage-
stained ground, and terrible arose the groans and shrieks of
mangled men; but the enemy still held the front and all thought the
morning sun must look down on a repetition of the same unchristian
work.
Gen. Ewell was found about midnight by the men who were sent
to him to relieve the couriers who had passed with him through
"Cold Harbour’s" baleful death-fires, lying along his lines, which were
drawn close up to the enemy, waiting for some sign to commence
anew the work of slaughter; but when daylight broke over the battle
lines the men in blue had disappeared, and soon after, Gen. Lee
found one of White’s boys and sent him to find Gen. Stuart and take
him to the Commander-in-chief.
This conference ended in Stuart posting off to see what had
become of the enemy, and it wasn’t long until that enterprising
cavalier had found out all about him.
In the operations which followed, Gen. Ewell moved with his
division to Despatch Station, on the York River Rail Road; and as a
matter of course White’s cavalry went with him. On their way to that
place they passed Yankee camps where the fires were still burning,
the camp-kettles of old ham and vegetables, and the coffee, still
boiling; while at many of them there were wagon loads, in some
instances houses full, of supplies of all kinds on fire; but what
created the greatest excitement of all, was a report that the Yankees
had poisoned the wells all around their camps by throwing into them
the supplies of medicines which their surgeons could not carry away
in their hasty retreat.
These rumors grew out of the fact that large quantities of powder
and cartridges had been tumbled into some of the wells, and those
who drank the water readily imagined it to be poisoned, not only
from the taste, but also that several of them were made sick by it;
and all threatened summary vengeance on the prisoners, but the
true state of the case was soon discovered and the excitement
quelled.
On arriving at the Station Gen. Ewell caused the railroad bridge
over the Chickahominy to be destroyed and a part of the track torn
up, and being now between McClellan and the White House, waited
for whatever force might come down the road.
About 4 o’clock in the afternoon a sound as of an enormous train
of cars was heard on the railroad, and every man was on the lookout
for something interesting to occur, supposing that the Yankees did
not know the road was cut and were attempting to run some trains
through, and knowing that if this should be the case they would
certainly meet a bloody overthrow at the bridge. The 13th Virginia
infantry was lying on the railroad, and White’s boys gathered on the
bank of the river, when soon, in the distance, appeared the most
singular looking affair any of them had ever seen on a railroad track.
It was a train of cars certainly, but high up over the locomotive was
built an affair that looked very much like a barn, being made of
plank and very long.
The general impression of the men at first sight was that it was a
contrivance from which the Yankees could fire at any rebels they
might discover, and thus keep the track clear; but there was very
little time to think much about it, for the iron-horse, under a full
head of steam, was carrying it at a rapid rate towards them, and
pretty soon the infernal machine leaped from the track into the
Chickahominy, and at the same moment a blaze of fire went up from
it that seemed to meet and melt into the blue of the sky, while an
explosion, so terrible that men lying on the ground a hundred yards
distant were lifted bodily, and in some cases had the blood forced
from ears and nostrils, broke out on the evening air. Just as soon as
they got their senses together White’s boys walked quietly off to
their horses, which had been feeding in an oat field a quarter of a
mile distant, and concluded they didn’t want to be around when
McClellan run his trains to the White House. This curiously contrived
affair must have contained three or four tons of powder and artillery
ammunition, for shells were exploding constantly from the time the
machine blew up until dark, but fortunately did no damage.
The next day Col. Bradley T. Johnson, of the 1st Maryland,
(afterward Brigadier General of the Maryland Line,) and Capt. White
were prospecting along the river for the enemy, the Colonel having
with him a rifle cannon with which he occasionally “felt the woods”
on the opposite side, and in the evening elicited a reply from several
batteries, whose smoke rolled lazily up through the trees in white,
foggy-looking masses, and showed that the “Young Napoleon” still
had a line of battle there. During the firing Gen. Ewell, accompanied
by White’s company, rode out to Col. Johnson, who showed him the
Yankee positions, remarking, at the same time, “and by the way,
General, I think I heard the long roll.” By this time the Colonel’s one
iron gun was attracting considerable attention from the Yankee
artillery, and their shells were flying very plentifully around him,
when Gen. Ewell turned his horse, and remarking to his escort "we’ll
go back now, boys," rode over the hill towards Despatch Station,
and in so doing passed in full view of the enemy’s line, who now
opened warmly upon him, and just before reaching the woods a
heavy shot passed between the General’s head and his horse’s neck,
causing the old fellow to make a very sudden backward motion, but
he instantly righted up, and noticing that the shot had struck a large
pine tree about twenty feet from the ground, and cut it off so clear
and sudden that the upper part of it came down perpendicularly and
stuck in the ground beside the stump, he exclaimed "wasn’t that
beautiful; wasn’t that well done!" but some of the boys remarked
afterwards that they didn’t know exactly whether he had reference
to his dodge or to the cutting of the tree, and they were afraid to
ask him.
On the 30th of June Gen. Jackson’s corps crossed the
Chickahominy at Grapevine bridge, and pushing on after the
retreating Yankees came up with them at White Oak Swamp, where
he had to fight them several hours with his artillery before his army
could get over. During the arrangement for this fight Capt. White
marched his company along the battle-line with “Old Stonewall,” and
after the latter had gotten his seventy guns in position, we halted to
watch the result. The enemy was firing constantly, but Gen. Jackson
made no reply until he had everything arranged to his notion, when
he gave the signal to commence firing, and it was soon evident that
he was more than a match for the Yankees. While the roar of the
guns was waking the echoes of swamp and forest, Gen. Jackson
rode along the line, where the shells from the enemy’s batteries
were flying the thickest, and, greatly to our wonder, held one hand
up as high as his shoulder nearly all the time, but wonder turned to
reverence when found that our hero was praying to the God of
battles to spare the lives of his men and crown their arms with
victory. Before long the bridge over the swamp was uncovered, and
Jackson’s infantry went across, capturing several of the enemy’s
guns and many prisoners. Here White’s men got into a snap with
some of the Pennsylvania Bucktail riflemen, but the Captain led them
in a charge, in which they captured a whole set of German-silver
wind instruments for a band, and several prisoners, killing and
wounding some of the “Bucktails.” They also got a splendid suit of
armor belonging to a Colonel, over which they had a great deal of
amusement, but in their experiments with the breastplate they
learned that it was bullet-proof against Colt’s army revolvers and all
the guns they could find, with one exception, and that was the
Maynard rifle, which tore a hole in it large enough for a hen’s egg to
pass through.
On the 1st of July we went to Malvern Hill, and the company was
busy enough during all of that long and bloody afternoon, carrying
dispatches for the several Generals operating in connection with
Ewell, and acting as provost guard to stop the soldiers from
straggling.
At the close of the battle, which continued until dark, Capt. White
took a detail of his men to Gen. Ewell, who had sent for him, and
found that officer, in company with Gen. Whiting, lying on the
ground to the left of the road, and with the advanced vedettes of
the army, conversing in whispers, the enemy being so close that
they could not talk in an ordinary tone without being heard by them;
and when White and his boys had crawled up to the General, finding
him with great difficulty, he sent them back, saying he was going to
advance his infantry line pretty soon, and had no scouting to do, as
he had found the enemy and they were in his front—so close that he
could throw a stone over their line.
White and his men crept back in the same noiseless manner to
their horses, where they waited anxiously for the opening fire of the
intended advance; but it was not made, or, if made, the Yankees had
gone, and the ever-memorable campaign of seven days’ battle
around Richmond was at an end; while with it ended the Northern
policy of conducting the war according to the established rules of
humanity recognized by civilized nations, for now McClellan, who
had treated the citizens inside of his military lines humanely, and had
respected their rights and protected their property, as far as
possible, from the usual pillaging that attends the movements of
every large army, was to give place to another who had nothing but
his brutality to recommend him to the favor of the “greatest and
best government the world ever saw,” which was now represented in
Washington City by a crew of foul birds of the devil’s own hatching,
whose names will make the cheeks of Americans crimson with
shame as long as American history is read; and Gen. Pope, from his
“headquarters in the saddle,” announced that henceforth the
business of his army should be to investigate the color of the coat
tails of the rebels, and that the time had arrived when a new era in
military tactics should dawn upon the astonished world through the
transcendent genius of “John the Pope,” and that under him the
battles of Abolitiondom should be fought with fire and sword,
according to the most approved rules laid down by the aborigines of
North America, with all the improvements which the Spanish
greasers of Mexico had been enabled to add from the familiarity of
their fathers with the horrible scenes of the infernal inquisition; all of
which had been revised and corrected within the sound of Mr.
Seward’s little tinkling bell for special use in the Grand Army of “John
the Pope,” and the world was assured that the war had commenced
in earnest; while those whose attention had heretofore been called,
by accident, to the career of Mr. Pope, and had formed their opinion
therefrom, predicted that women and children would suffer now, for
the chosen Sachem of the little-souled Yankee Nation was on the
war-path, and the influence of the Northern people in whose hearts
the God-given principle of chivalric forbearance towards the weak
and helpless had an abiding place, was literally smothered to death
in the smoky vengeance which the nigger crusaders had
manufactured for crushing the rebellion—“vide” Brownlow, Stevens
& Co.
CHAPTER VI.
For several days after the close of the seven days’ campaign
the army lay quiet, and White’s people had a delightful camp at
Meadow Bridge, about 7 miles from Richmond, on the Rail Road,
from which they could send to the city daily for such luxuries as
the markets afforded; and during this time there was not much
to do in the way of carrying dispatches, so that there was little to
do except rest. Here the company held an election for Orderly
Sergeant, which resulted in the choice of C. M. C. Whaley, for
that important position, and the list of non-commissioned
officers was now full, viz: Edward S. Wright, 2d Sergt.; Benjamin
F. Conrad, 3d Sergt.; John Dove, 4th Sergt.; and J. Mortimore
Kilgour, 5th Sergeant and Quartermaster; John T. Tribbey, 1st
Corporal; Daniel C. Pettingall, 2d Corporal; William Snoots, 3d
Corporal; and Peter J. Kabrich, 4th Corporal.
About the 10th of July, Gen. Ewell marched his division to his old
camp near Liberty Mills, on the Rapidan, where for some weeks he
remained watching “Mr. Head-quarters-in-the-saddle,” who was
prospecting towards Gordonsville, in the new “On to Richmond”
movement of his own and father Abraham’s invention, and ravaging
all the country inside of his lines in the barbarous manner which had
been predicted of him from the beginning of his reign, which was as
literally a “reign of terror,” to the defenseless people under his
dominion, as ever was the bloody revolution to the citizens of Paris
during the days when flame and murder held high carnival at
command of the devils incarnate who ruled in France.
White’s company had now increased to nearly one hundred men,
and the Captain spent much time in scouting in Madison County,
which was just on the border of the “grand army,” and very much
infested with its cavalry raiding parties.
On one occasion, with about thirty men, he drove a strong force of
infantry and cavalry from Madison C. H., making the citizens imagine
that they were once more free from the terrible dominion of Pope.
And again, from the mountain top near Wolfton, he discovered a
company of cavalry engaged in plundering a farm-house, and as
rapidly as possible came down on them; but owing to the fact that
some of his men had been seen by the enemy as they descended
the mountain, he was only able to catch about half a dozen, chasing,
however, the remainder out of their hats, and into their camp. About
the last of July, Capt. White left camp at dark, and marching all
night, with twenty men, reached a farm-house five miles from
Stanardsville about daylight, and halting his command, he sent
Lieut. Myers, with the citizen pilot who had volunteered to guide
him, to look up the Yankees. On reaching the Conway river, about
sunrise, they discovered seven Yankees on foot, going from a camp
over the river to a citizen’s house for breakfast, and sending the
guide with all haste to inform the Captain, the Lieutenant took a
position at the gate, about one hundred yards from the house, to
watch the “boys in blue” until the command could come up and get
them.
After about an hour’s watching and waiting, which, to the lonely
picket appeared like four hours, the Captain came up with a part of
his squad, and before the Yankees knew it, the rebels were in the
yard; when, hastily leaving the table, they each “took a tree,” and
with their carbines attempted to fight it out; but it was too late, and
with what grace they could command, the foragers had to “on to
Richmond.”
The next expedition White made was for the purpose of
bushwhacking a patrol of cavalry, which daily passed over the road
from Robertson river to Madison C. H., and reaching the road in the
evening, he dismounted his men and placed them in the woods
alongside of it, sending Lieut. Myers, with Ferro and Spicer, up the
road as a decoy, expecting the Yankees to chase these men past the
ambuscade, when the others would open on them with their double-
barrels and buckshot; but the