Introduction
GeoBase is a high-performance Geospatial mapping engine designed for rapid development and low total cost of deployment. Services provided by GeoBase include:
- Street Mapping (with Satellite imagery overlays)
- Reverse Geocoding
- Geofencing
- Address Lookup (Geocoding)
- Routing & Route Optimization
- Navigation
- Data Import tools
The goal of this tutorial is to demonstrate the simplicity of using the GeoBase .NET component by adding address search capabilities and satellite imagery to a simple map application.
Prerequisites
This tutorial assumes familiarity with Microsoft's Visual Studio. You will need a copy of Visual Studio 2005 or later and a moderately-specified desktop computer. Experience with digital mapping technology is assumed at only a low level.
In addition to the above, it's assumed that you can add a map control to a Windows Forms application. This was covered in the Adding a Map to Your GeoBase Project tutorial.
Setup
Launch Visual Studio and create a new C# Windows Application.
- Choose an appropriate name and location for your project.
- Add a project reference to 'geobase.net.dll'.
- If you are using Visual Studio 2010, make sure that the target Framework is the full .NET framework and not a Client Profile
- Add a MapCtrl to the form and set its name to 'mapCtrl'.
- To simplify coding, add the following directive to the top of the 'Form1.cs' source file:
using Telogis.GeoBase;
Tip: If you have done the 'Adding a Map to Your GeoBase Project' tutorial, you can use that project as your starting point.
Adding Search Controls
Add a textbox and button to the bottom of your form, below the map control. These will be used to enable the user to search for an address. Name the new controls 'textBoxSearch' and 'buttonSearch', respectively. Change the button's Text property to 'Search',
Run your application. It should appear similar to the following image:
.png)
Note that this image uses the Adding a Map to your GeoBase Project tutorial as a starting point. Your map may show a different center or zoom level.
Searching for an Address
We will use the textbox and 'Search' button to let the user search for an address. This process is known as 'geocoding'. GeoBase offers advanced geocoding services using both natural-language and ordered parsing methods with the ability to take hints from cached location information and a vehicle heading to ensure an accurate geocode result. In this tutorial, we will use only simple geocoding.
Double click the 'Search' button in the Form Designer. You should be taken to a 'buttonSearch_click' method. This method is called when your 'Search' button is clicked.
Modify the 'buttonSearch_click' method to match the following code snippet:
private void buttonSearch_Click(object sender, EventArgs e)
{
// perform a geocode and retrieve a selection of results
// --- you may need to change Country.USA to match your country
GeocodeAddress[] results =
GeoCoder.GeoCode(textBoxSearch.Text, Country.USA);
// we need at least one result to center and zoom the map
if (results.Length > 0)
{
mapCtrl.Center = results[0].Location;
mapCtrl.Zoom = 0.8;
}
// if we didn't get any results, alert the user
else
{
MessageBox.Show("Your search didn't return any results");
}
}
In some instances, the geocoder will return multiple results. This usually occurs when a number of similarly-named streets exist, or when the user enters a 'vague' search address. GeoBase ranks the results in descending order of precision. It may be wise to display, say, the top five addresses and ask the user to make a selection, but in this tutorial we will simply center and zoom the map on the top result.
Test the geocoder by running your application and entering an address, such as '1 infinite loop, ca' and clicking 'Search'.
Adding Satellite Imagery
Satellite imagery is delivered through GeoStream, which is a technology that provides GeoBase functionality over the internet. GeoStream consists of an integrated server, and either a JavaScript or .NET client. using emerging technologies like AJAX and JSON remotely, GeoStream provides performance equal to or better than a thick-client solution delivered over the web to a number of different development environments, languages, and targets. GeoStream .NET uses the same API as the core GeoBase library, allowing you to develop from a single code base and deploy the map data and GeoBase engine either remotely or locally, depending on your requirements.
Adding a checkbox to the form
From the toolbox, select the 'Checkbox' control and place it on your form. Name the checkbox control 'checkBoxSatellite' and change its Text property from 'checkBox1' to 'Satellite ON'. The form should now look similar to the image below:
.png)
Switching to GeoStream mode
Open the main program file ('Program.cs'), and add the following 'using' directive to the top:
using Telogis.GeoBase.Repositories;
Now add the following line of code to your Main() function, before the call to Application.Run. This will instruct your application to retrieve data from a local GeoStream server.
Repository.Default = new GeoStreamRepository(http://localhost/GeoStream); Application.Run(new Form1());
Turning satellite imagery on and off
Double click the 'checkBoxSatellite' checkbox. This will take you to the 'CheckChanged' event handler. Add the following code to swap between standard map view and satellite imagery view:
private void checkBoxSatellite_CheckedChanged(object sender, EventArgs e)
{
mapCtrl.Satellite = checkBoxSatellite.Checked;
}
Run the application
You are now ready to run your application. With the 'Satellite ON' checkbox checked, the image you should see should look like the following:
.png)
That's it!
For more tutorials and examples, browse the 'GeoBase Tutorials' and 'Common Concepts' sections of the GeoBase reference documentation that is included with the GeoBase SDK. You can also view the documentation and tutorials online.
If you have any queries, please don't hesitate to contact us. We trust that you will enjoy the simplicity and ease-of-use afforded by the GeoBase .NET component.
Published, Jun 20th 2010, 20:15
Tagged under: dotnet satellite imagery forward geocoding
