ArcGIS by Example - Sample Chapter
ArcGIS by Example - Sample Chapter
ArcGIS by Example - Sample Chapter
C o m m u n i t y
E x p e r i e n c e
D i s t i l l e d
$ 44.99 US
28.99 UK
Hussein Nasser
"Community
Experience
Distilled"
ArcGIS By Example
ArcGIS By Example
ArcGIS By Example
Develop three engaging ArcGIS applications to address your
real-world mapping scenarios
Hussein Nasser
in the GIS field since 2006. He is the author of three books in the ArcGIS technology:
Administering ArcGIS for Server, Learning ArcGIS Geodatabases, and Building Web
Applications with ArcGIS, all by Packt Publishing. In 2007, he won the first place at the
annual ArcGIS Server Code Challenge, conducted at the Esri Developer Summit in
Palm Springs, California. In 2014, he started the IGeometry YouTube channel, where
he periodically publishes educational GIS videos.
Preface
Over the last two years, I have written three books on ArcGIS technology. Each
book covers different topics and fields of this increasingly ubiquitous technology.
Although I used examples and various real-life project approaches to explain the
technology in all my books, this is the first book where the content evolves with the
help of examples. I have been working with Esri ArcGIS since 2005 when ArcGIS 9.1
was released, so writing this title from a technological point of view was not difficult.
In fact, it was thrilling. The challenging part was to come up with three unique reallife examples and to build them up as I wrote the book. Each example should target
certain features of the technology and explain them along the way.
These three examples are all from my own imagination and they are not linked to or
correlate with any actual projects that I personally worked on or witnessed. You will
not find any of these examples in Esri's help or on any online resource. All the code
that is available in this book is written from scratch for this book that you are holding
in your hands.
The title of this book was designed for those who want to start using the ArcGIS
technology or have been using it and want to learn more about how they can
customize ArcGIS to do more. There are going to be three themes running
throughout the book. The first theme covers Chapter 2, App 1 the Cell Tower Analysis
Tool, Chapter 3, Mapping Signal Strength, and Chapter 4, Real-time Maneuvering, which
are tailored for beginners and developers. It features a Cell Tower Analysis Tool
that displays a cell phone tower's signal range and signal strength on the map and
shows you how cell phones connectin simulated real timeto the tower with the
strongest signal, all on top of ArcGIS for Desktop. You will learn ArcGIS add-ins for
development.
Preface
The second theme covers Chapter 5, App 2 - Extending ArcObjects, Chapter 6, Reviews
and Ratings, and Chapter 7, Advanced Searching, and is targeted at those who want to
achieve more with ArcGIS. This theme features a restaurant mapping application
that will be used to filter, search, and interact with restaurants on the map; it will also
be used to view the reviews and the ratings of different users. You will learn how to
write some ArcObjects code to work with geodatabases, query feature classes, and
relationships. The last theme covers Chapter 8, App 3 Advanced ArcObjects, Chapter
9, Excavation Cost Calculation, and Chapter 10, Saving and Retrieving Excavation Designs
and is designed for those who are willing to try advanced programming. This theme
features an excavation planning manager application. This application will propel
the reader to the advanced stage, where they will write a real-life business-related
deployable application. The Excavation Planning Manager helps construction
workers plan their excavation for utilities and telecom networks beforehand in
a given area and at an estimated cost of excavation. The application analyses the
underlying soil type and green area to find out the cost of removing these areas
by doing extensive spatial analysis. You will be able to store multiple designs of
excavation and determine which is the cheapest or most applicable design. Chapter
1, Getting Started with ArcGIS ties all the chapters together and explains briefly what
you will learn in all of them. It will also help you get started with the installations
and will also tell you about the prerequisites.
In each of the themes, you will learn new features of ArcGIS and will be able to
harness these features in your own code to enhance and extend ArcGIS capability.
Preface
Chapter 3, Mapping Signal Strength, takes the application further to the next stage
where you will learn about proximity tools, how to use them to measure distances
between points, and perform analysis based on a result. This will help us in
determining the closest tower, which will eventually be the one with the strongest
signal. The signal strength can be calculated with the formula tower range-distance.
Chapter 4, Real-time Maneuvering, takes the application to a real-life scenario. In this
chapter, we simulate a cell phone that moves on the map and switches towers for the
best signal possible. The cell phone reads coordinates from a GPS textfile, which has
been produced previously. The active tower will keep flashing while the cell phone
is connected to that particular tower.
Chapter 5, App 2 Extending ArcObjects, introduces our second application, the
restaurant mapping application. You will create an application that will allow you
to filter, search, and interact with restaurants on the map. This will also help you to
view the reviews and ratings of different users. You will learn how to write some
ArcObjects code to work with geodatabase, query feature classes, and relationships.
Chapter 6, Reviews and Ratings, introduces you to the relationship queries, which
is a bit of an advanced topic that requires special care. You will be able to query
related tables, such as reviews and ratings, pull this information, and display it on
the application. A developer will learn how to highlight restaurants on the map by
selecting it from the application.
Chapter 7, Advanced Searching, takes the application to a higher level with the
advanced geodatabase search. In this chapter, we will introduce advanced spatial
queries, where the user of the application will select an area and the application
should display all the restaurants in the selected area according to their categories.
You will also perform an advanced interface technique, where the developer will add
a custom text box to the toolbar to search for restaurants and filter them accordingly
as the user types in the box.
Chapter 8, App 3 Advanced ArcObjects, will propel you to the advanced stage, where
you will write a real-life business-related deployable application. The Excavation
Planning Manager helps construction workers plan their excavation for utilities and
telecom networks beforehand in a given area and at an estimated cost of excavation.
The application analyses the underlying soil type and green area to find out the cost
of removing these areas by carrying out extensive spatial analysis. You will be able
to store multiple designs of excavation and determine which is the cheapest or most
applicable design.
Preface
Chapter 9, Excavation Cost Calculation, will help you use advanced spatial operations
to determine the estimated cost of a given excavation. The application will carry
out spatial analysis on the area under the excavation polygon, and based on the soil
type, the cost of removal of per 1 meter cube of soil might affect the overall cost of
excavation. For instance, a stony area is more difficult to excavate than a regular
sand area.
Chapter 10, Saving and Retrieving Excavation Designs, propels our application to the
real-life scenario. Before this chapter, excavations were scattered and ungrouped; in
this chapter, we will group excavations into designs. So here, a user can create a new
design and add multiple excavations for his/her design and calculate the total cost of
his/her design. A user will be able to search for a design, edit it, and delete it, along
with all its underlying features.
[1]
When the Web started to become ubiquitous in early 2000s, Esri adopted the Web by
rolling in ArcGIS for Server and gradually ArcGIS functionalities as web services so
that it could be supported on multiple platforms including mobile phones.
A decade later when the cloud solutions began to surface, Esri released its Software
as a Service (SaaS) solution ArcGIS Online. Designed to simplify the user
experience, ArcGIS Online hides all the ArcGIS "contraptions" and technologies to
relieve the user from maintaining the hardware and software, leaving the user to do
what they do best, mapping. Having everything in the cloud allows users to focus
on their work instead of worrying about configurations, spinning up servers and
databases, and running optimization checks.
SaaS, a cloud-based software distribution model where all
infrastructure, hardware, management software, and applications are
hosted in the cloud. Users consume the applications as services without
the need to have high-end terminal machines.
Today, Esri is pushing to enhance and enrich the user experience and support
multiple platforms by using the ArcGIS Online technology.
In this book, we target one of the core products of the ArcGIS familyArcGIS for
Desktop. By using real-life examples, we will demonstrate the power and flexibility of
this 16+ year-old product ArcGIS for Desktop. We are going to use the various tools at
our disposable to show how we can extend the functionality of ArcGIS for Desktop.
Chapter 1
ArcGIS for Desktop requires the .NET Framework 3.5 service pack 1 and Microsoft
Internet Explorer 9.0 or higher in order to run. The .NET Framework can be
downloaded from http://bit.ly/b04748_dotnet35. Some operating systems,
such as Windows Server can be configured to enable the .NET Framework,
instructions to do that can be found in the same link. The system requirements for
running ArcGIS for Desktop as of version 10.3 and full details on the system and
hardware requirements can be found at http://bit.ly/b04748_ags103sysreq.
[3]
In this book, I will be using Microsoft Windows 8.1 Pro with ArcGIS for Desktop
10.3. Feel free to use any version of Desktop (10 or higher) with the supported
version of Windows as per the system requirements in the following table:
Product
Version
Supported OS
Reference
ArcGIS 10.3
http://bit.ly/
b04748_ags103sysreq
ArcGIS 10.2.x
http://bit.ly/
b04748_ags102sysreq
ArcGIS 10.1
http://bit.ly/
b04748_ags101sysreq
ArcGIS 10.0
http://bit.ly/
b04748_ags10sysreq
ArcGIS 9.3.x
http://bit.ly/
b04748_ags93sysreq
ArcGIS 9.2.x
http://bit.ly/
b04748_ags92sysreq
The examples in this book can also be applied to older versions of ArcGIS (10.0, 10.1,
10.2.x). I will be providing designated copies of the data and map documents for
each version so that you can freely work with the version of ArcGIS you prefer.
ArcGIS versions prior to 10 won't be able to take advantage of the new
add-in feature.
Chapter 1
The ArcGIS geodatabase is the proprietary database for Esri. All Esri
geospatial software is built around this geodatabase.
There are a lot of spatial references tailored for different locations on the earth. There
are some standard references used universally, and among them is the WGS 84,
which we will be continuously using in this book.
Let us start using the software and get familiar with geodatabase components. Make
sure you have installed ArcGIS for Desktop and then follow these steps:
1. First of all, we want a geodatabase to work with. Create a new folder in your
root drive c:\ArcGISByExample\. In the supporting files for this chapter,
copy the B04847_01_Files folder to the C:\ArcGISbyExample folder.
2. From the Start menu, locate and run ArcCatalog 10.3 (or your version of
ArcCatalog). It is the one with the cabinet icon.
You can dock and pin ArcCatalog in your start menu to access it
quickly.
3. From the Catalog Tree window, right-click on Folder Connections and click
on Connect To Folder. This will establish a connection with the folder that
contains the geodatabase.
[5]
C:\ArcGISByExample\B04847_01_Files\Geodatabase\Restaurants.gdb,
[6]
Chapter 1
6. Make sure that the Content tab is active. You should see the different objects
that this geodatabase consists of. The first object is Food_and_Drinks, which
is the feature class of some restaurants. The Food_and_Drinks object has a
one-to-many relationship with VENUES_REVIEW which stores the reviews of a
given restaurant.
The feature class is one of the basic objects in a geodatabase. This object
is a table with a shape attribute that defines the location and geometry.
It could be a point, line, or a polygon.
7. You can view the content of the feature class by selecting it and clicking
on Preview, as shown in the following screenshot. The default preview is
Geography, which visually displays the points:
[7]
8. You can also display a tabular view by changing the Preview type to Table,
as illustrated in the following screenshot:
[8]
Chapter 1
12. Activate the Subtypes tab; here we can define multiple types for our feature
class. In our case, we have five different restaurant types number coded.
13. Click on OK to close the feature class properties.
14. Close ArcCatalog.
[9]
7. You will see that a new layer has been created under layers named Venues.
This is the representation of the feature class. You can see that the name of
the layer is actually the alias name of the feature class by default, which we
have renamed in the The ArcGIS geodatabase section. ArcMap creates this
layer wrapper to visual a feature class, change symbology, control labels,
scaling, and so many other things.
A layer is an ArcMap object and a visual representation of a physical
feature class. A layer does not exist by itself and needs a source dataset
to read data from.
A symbology is a notation for the features in a feature class. A given
feature class might have multiple symbologies based on its attributes.
8. Note that different symbologies have been assigned based on the restaurant
subtypes that we have mentioned in the The ArcGIS geodatabase section. See
the following screenshot:
9. We can change the symbology to make it more relevant; click on the point
next to Bar to change its symbol. This will bring up the Symbol Selector.
Type Bar in the search box and hit Enter. Select your favorite symbol and
click on OK, as shown in the next screenshot:
[ 10 ]
Chapter 1
10. You should see that the map has been refreshed with the new symbology, as
shown in the next screenshot. You can see how rich you can make your map
by using these built-in tools. Imagine what we can do if we could extend this
to the next level, as we will see in the next chapter.
ArcGIS for Desktop comes with great set of built-in tools that can help you solve
interesting mapping problems. However, there comes a time where your problem is a
complex one. This is where you might need to extend and customize the functionality
of ArcGIS to provide a suitable solution to your problem. The examples in this
book require customizations to tackle them. In this section, we discuss the different
customization approaches to set up our development environment. Another reason
to extend ArcGIS, for example, a certain functionality, might be available in ArcGIS,
but you need to perform 10 or 15 steps to achieve it, and customizing the product can
group and automate these steps so that you can default all of them in a few clicks.
The first attempted approach to providing customization for ArcGIS was through
VBA. This is similar to the macroscripts in Microsoft Word and Excel. You could
write an application and save it in the map document and later share this document,
and the person running your document could use your application. It was a
convenient approach for sharing mapping, but with many problems. The main
problem was the security. The document might contain malicious code that would
execute with user privileges and can potentially harm the user. That is why this
approach was discouraged and has been replaced with ArcGIS add-ins and the
extensions building approach. Today, you can still develop using VBA by installing
the VBA compatibility setup.
Customizing ArcGIS for Desktop requires that you either build add-ins or use the
classical Dynamic Link Library (DLL) approach and register it with ArcGIS for it to
work. Both approaches use ArcObjects as the underlying technology, however, the
final building technique is different.
These built approaches are not share-friendly, however, Esri came up with a
beautiful solution and platform for sharing, and that is ArcGIS Online. That
discussion though should be an entirely different book.
[ 12 ]
Chapter 1
In this book, we will be using Microsoft Visual Studio 2013 Express for Windows
Desktop as our IDE. The software can be downloaded for free from the official
Microsoft website at http://bit.ly/b04748_vs2013exp. This is quite a big
download and it will take some time depending on your Internet connection. When
you install ArcObjects SDK, the setup will detect your current Visual Studio and
install the plugins accordingly, as shown in the following screenshot:
[ 13 ]
You can also use Visual Studio 2012 with ArcObjects SDK 10.3. Just make sure
to install the Visual Studio before you install the ArcObjects SDK for .NET.
For a complete list of system requirements for ArcObjects SDK 10.3, follow
http://bit.ly/b04748_ao103sysreq.
If you are programming under different system configurations, take a look at the
following table to make sure you comply with the system requirement:
Product version
Supported IDE
Reference
VS2013, VS2012
http://bit.ly/b04748_ao103sysreq
VS2012, VS2010
http://bit.ly/b04748_ao102sysreq
VS2010
http://bit.ly/b04748_ao101sysreq
VS2008, VS2010
http://bit.ly/b04748_ao10sysreq
VS2008, VS2010
N/A
VS2005, VS2008
N/A
I couldn't find official online references to support my claims for 9.3.x and 9.2.x, but
from a personal experience, I did use ArcObjects with 2005 and 2008 on both the 9.2
and 9.3 systems and it was working flawlessly.
[ 14 ]
Chapter 1
[ 15 ]
TelZaViBA gave us a geodatabase with all their cell tower information on the
Boulevard du Montparnasse. Based on the tool's result, the telecom company can
then do what will be necessary, such as installing a stronger tower with a higher
range in the weak spot or relocating existing towers wherever it is feasible and
economical. What we have here is a geodatabase with information, and we need to
take this information to the next level by analyzing it.
This application will span into three chapters. Since this is the first example, we
will spend some time in Chapter 2, App 1 the Cell Tower Analysis Tool, to get you
familiar with ArcGIS add-ins and the ArcObjects interfaces before we dive into the
development. We will prepare the ground by talking about layers, feature classes,
features, and geometry. We will then learn how to do some topological operations
on the geometry to draw the signal range buffer. Then we will draw the signal range
based on the radius value that is stored as an attribute in the tower feature class.
In Chapter 3, Mapping Signal Strength, we map the tower's signal strength, which
is basically how many bars a particular cell phone has when it is in range of a cell
tower. We will measure the signal strength in percentages for simplicity and then we
will convert it to bars. To do all that, we first need to add a point to the map and then
find a distance between that point and one of the towers using the proximity tools in
ArcGIS. We will then use this knowledge to find and highlight the closest tower to
the point we just drew. Finally, we will display the signal strength on the point using
ArcGIS graphics.
In Chapter 4, Real-time Maneuvering, we do the real-time maneuvering and things get
interesting. We will simulate a person walking along the boulevard with a cell phone
and then use the logic we wrote in Chapter 3, Mapping Signal Strength, to establish the
signal strength and the closest tower. We will simulate this by reading the previously
recorded text file Global Positioning System (GPS) points and load them into our
tool. With each step the signal will get updated with the new value based on our
signal calculation algorithm. The active connected tower will be blinking on the map
along with the cell phone.
GPS provides the location and time information using satellites on the
earth. Nearly all new smart phones are equipped with GPS receivers
that can identify the device's location with respect to the earth.
TelZaViBa can use this tool to simulate cell phones and monitor the signal strength
on the boulevard and find the weak signal spots.
[ 16 ]
Chapter 1
[ 17 ]
[ 18 ]
Chapter 1
In Chapter 9, Excavation Cost Calculation, the actual advanced spatial analysis and cost
estimation happens. We will write this cost calculation module that uses the soil and
trees layers and excavation. This is why we require the Standard license to perform
such advanced spatial analysis.
In Chapter 10, Saving and Retrieving Excavation Designs, we will propel our application.
We will group multiple excavations into a design. We will then allow the user to
create multiple designs. The user can open, close, edit, compare, and delete designs.
Each design will be a dedicated geodatabase; therefore, we will be making copies
and dealing with multiple geodatabases at once. It will be a great experience.
Summary
In this chapter, you learned about the different components of ArcGIS for Desktop,
ArcMap, and ArcCatalog. You used ArcCatalog to learn more about ArcGIS like
geodatabase, spatial references, and feature classes. You also used ArcMap to add
a layer and change its symbology. After paving the way with these ArcGIS basic
concepts, you were briefly introduced to the three examples that you will be working
on through the course of this book. The first example talked about the basic spatial
customization. The second one taught you intermediate skills for working with
the geodatabase. The last example featured advanced geodatabase and mapping
techniques that combined will set you up to take your ArcGIS development skills to
the next level.
In the next chapter, you will learn how to develop using ArcGIS add-in for your first
example, the TelZaViBa cell tower analysis tool.
[ 19 ]
www.PacktPub.com
Stay Connected: