developing a geographic information system

Upload: koy-martinez

Post on 07-Apr-2018

218 views

Category:

Documents


0 download

TRANSCRIPT

  • 8/4/2019 Developing a Geographic Information System

    1/50

    DEVELOPING A GEOGRAPHIC INFORMATION SYSTEM (GIS)

    TOOL FOR EXTENSION PURPOSES IN MAURITIUS

    M Chung Tze Cheong, R Appave and S Jamala

    Mauritius Sugar Industry Research Institute

    ABSTRACTGeographic Information System is essentially a tool to help visualize information in a

    spatial way. This paper illustrates how extension officers can use GIS to manage

    individual farmers plots, in the large and often remote areas under their responsibility. This application product is a prototype developed, using Visual Basic, map objects and

    map files

    generated from ARCInfo. It has a set of menus and buttons with which officers mayquery the

    geographic database of the project area. In this instance, data files supplied by the

    Farmers Service Centre, responsible of farmers fields in St Felix factory area, have been

    integrated with the map files prepared by MSIRI into a geographic database. Monitoring

    of yield with respect to the current practice may then be followed and handy documentsproduced for field visits. Observations from field visits may also be fed into the database

    so that information accessible to officers as well as decision-makers can be updated.This pilot project is an example applicable to crops other than cane. As illustrated in this

    study, it

    allows a dynamic evolution of the system with almost 'real-time' feedback at field level.Specific

    extension goals set for the target farmers could then be grouped geographically viz,

    irrigation, ripener application and mechanization projects.

    Keywords: Geographic Information System, farmers' plots, extension officers,

    decision-makers

    INTRODUCTIONIn an effort to increase the sugar cane production of small planters, inclusion of

    information technology (IT) as part of the extension tool for field officers is becoming a

    necessity, as extension officers are called upon to cover geographically remote anddispersed areas. Data collection on their part, and their organisation into an appropriate

    format can therefore be very tedious; consequently the development of a tailored,

    process-based GIS application will be of great help to the extension officers.As a result of meetings and discussions held with the officers of St. Felix Farmers Service

    Centre

    (FSC) on their current needs in data manipulation, it became clear that the extension

    officers are not all familiar with the computer environment, and do not have much time tolearn the GIS software. To develop the application screens, the design of the GIS

    prototype has therefore been focused on spatial

    data query, display, and printing and the fact that no prerequisite knowledge of GIS isnecessary.

  • 8/4/2019 Developing a Geographic Information System

    2/50

    MATERIALS AND METHODS

    Data preparation

    The source data, which comprised of paper maps and excel files with farmers' data, wereprovided by

    the St. Felix FSC for three sub-blocks of St. Felix Factory Area. The spatial data were

    prepared withthe Arc/Info GIS software. Minor changes in the geographic database were then done in

    the desktop

    module ARCView, as the map files were linked with descriptive database for shape files

    creation

    through a common key id.

    Database structureThe databases received as excel files were imported in Microsoft Access 97, and classified according to

    years and locality sub-blocks. The key id is devised through the concatenation of factory area, locality

    sub-block and plot number to represent a unique identity for each record (Table 1, Figure 1). The

    same uniqueness is applicable to the rest of factory areas of the country. A similar key was applied to

    the map files or shape files.

    Table 1 Database structure for farmers plots as received from the FSC

  • 8/4/2019 Developing a Geographic Information System

    3/50

    Figure 1 Database files in Access

    Application development environmentThe customisation development makes use of the object-oriented approach, in aninfrastructure data model, whereby data files like maps and tables, the object libraries of

    standard office packages like Excel and ACCESS, and of Map Objects , are considered as

    objects and components of the application development project. The existing

    functionalities like charting, table display, colour palette of other software are tapped forgraphic display through referencing, and queries performed through the Structured Query

    Language (SQL), made available in the Visual Basic (VB) development platform,

    and a multitasked Windows environment. The Visual Basic programming language(Aitken 1998) has been used as a control container to assemble the multiple controls and

    components for a rapid application development (RAD) (Figure 2)

  • 8/4/2019 Developing a Geographic Information System

    4/50

    Figure 2 Concept of Infrastructure Model used in the application development

    (adapted from R. Hartman, 1997)

    Map objects are an ESRI (Environmental Systems Research Institute 1999) product,

    consisting of a

    collection of mapping components (viz., Map objects OCX and other programmable

    ActiveXautomation) for application developers. It provides the possibility to create customised

    solutions so asto meet the desktop mapping, and GIS needs of common users, through the following

    facilities:

    Access to a wide range of data formats ranging from standard GIS formats(ARCInfo coverages and ESRI shapefiles) to CAD formats (DXF, DWG, andDGN) to perform spatial queries.

    Display data using classifications (regrouping/categorisation), graduatedsymbols, and labeling.

    Pan and zoom through multiple map layers. Queries features displayed on the map

    By means of map objects.OCX and a data connection string, the directory containing thedifferent map

    files, and their related databases are retrieved and read. (Figure 3)

  • 8/4/2019 Developing a Geographic Information System

    5/50

    List of OCX (Object Controls) used

    Map control (mo02.ocx): a box in which map layers (shape files) are loaded. ADO (ActiveX Data Object): Data control which establishes data connection

    using ODBC

    (Open Database connectivity) drivers with the database, and Structured Query Language(SQL) for data query. MSHFlexgrid : Hierarchical Flexgrid control which displays the database Text boxes: data is bound with the respective database for display results Combo boxes: offers possible choice for selection Check boxes: Click for display Command button: To execute the different functions or events allocated. Listbox: To select and display data

  • 8/4/2019 Developing a Geographic Information System

    6/50

    RESULTS AND DISCUSSION

    Application portabilityThe whole project, namely the data files (map and tables), program and system files, all

    ActiveX controls (MapObjects' and VB's), and VBs Data Dynamic Links (*.dll), arebundled into a distributable package such as a setup program.

    This has been possible through the package and deployment tool of Visual Basic 6.0version enterprise (Microsoft Corporation). Therefore the application installation does not

    require additional training or resource investment from the users. It is a sort of 'plug-n-

    play' tool.The installation is done through the set up file, which when double clicked, will auto

    install the files into their respective folders: system and dynamic link files (*.dll) as well

    as data files. Further the automatic shortcut installation on the desktop invites the user tostart the application program.

    Minimum System requirements for this application installation

    Operating system: Windows 95 or windows 98

    Memory space: 16 MB RAMFree Hard disk space: 50MB

    Microsoft Excel 97Microsoft Access 97

    Data files: 5 MB

    System & program files: 10 MBTotal disk space for setup: 15 MB

    * the size may vary with amount of detail collected, and is expected to increase with time.

    Application overviewIt consists of a user-friendly interface, based on WYSIWYG where the user easily moves

    across the

    different screens, with the help of clickable icons, combo boxes, pull down menus for

    dynamicmapping of the area of interest, and eventual hard prints output

  • 8/4/2019 Developing a Geographic Information System

    7/50

    Screens sequence

    Screen 1 - Welcome Form

    Screen 2 - Choice of factory area

  • 8/4/2019 Developing a Geographic Information System

    8/50

    Screen 3 - Data retrieval from project area locality sub-blocks

    Screen 4 - Data analysis

  • 8/4/2019 Developing a Geographic Information System

    9/50

    Screen 5 - Spatial query

    Advantages of such development1. Minimum IT investment. The existing desktop environment: Windows and Microsoft

    Office package is sufficient.

    2. A minimum GIS tool is made available, through screen navigation for visual and / orhard prints output. No training is required.

    3. No disruption of existing practice. The users may continue with their usual data entry

    and update with the standard office packages like Excel, or Access, or in simple relational

    database like Dbase as these components are embedded in the application.4. Minimum developers intervention.5. Participation of extension officers in their GIS needs.

    6. The ease of information retrieval facilitates decision-making at all levels (field officers,management)

    Constraints encountered

    1. Incomplete descriptive data sets on farmers records caused delays in data matching.2. Mismatching of field plans with records from the descriptive files.

    3. Availability of updated field plans. This implies more ground truthing, and longer time

    lag to compile and to finalise the spatial data. Conversion of field plan to spatial digital

    file is still onerous. Sale of updated digital files by the Ministry Of Housing and Lands at

    a competitive price on the market will give a definite boost to application development ofthis kind.

  • 8/4/2019 Developing a Geographic Information System

    10/50

    Future development

    1. Possibility to link different years data with the map files of the same factory area.2. Possibility of file editing(both map, and data) through customised menus / buttons e.g

    editing of fields viz., deleting, merging and adding fields as shape files.

    3. Extension of the project on a national scale through plug-ins of remaining map files

    andrelated data files of all FSCs.4. Privileged Internet access (Brandon 1997) for FSC officers for data analysis.

    CONCLUSIONThis new paradigm of GIS moving to an open platform, where it is an equal component

    with other third party software, brings new avenues to common users, and application

    developers. The GIS products become more affordable, when no more confined to theexclusive environment of professional GIS software, which is usually quite costly, and

    requires training and skills.

    This application development is but an example of the infinite technical possibilities of

    GIS applications, brought about by this breakthrough.

    REFERENCES

    AITKEN, GP. 1998. Visual Basic 6 Programming. Blue Book Fast-Paced Learning.Coriolis

    Technology Press. pp. 700.

    BRANDON, P. 1997. GIS Online: information retrieval, mapping, and the Internet.Onward Press. pp

    311.

    ENVIRONMENTAL SYSTEMS RESEARCH INSTITUTE. 1999. MapObjects V.2.0

    Technicalbrochure. pp4. http://www.esri.com/software/mapobjects/description.htm

    HARTMAN, R. 1997. Focus on GIS component software. Featuring ESRI's Map

    Objects. Onword Press. pp. 340

    MICROSOFT CORPORATION. 1996. Microsoft Visual Basic 6.0. Programmer's GuideWashington: Microsoft Corporation. pp. 1000.

    GLOSSARY

    FSC : Farmers Service CentreGIS : Geographic Information System

    IT : Information technology

    Mo: MapObjects

    OCX : ActiveX Components Objects

    Shape files are simple, non-topological format for storing the geometric location and

    attributeinformation of geographic features.

    SQL: Structured Query Language

    VB : Visual Basic

    WYSIWYG : What You See Is What You Get

  • 8/4/2019 Developing a Geographic Information System

    11/50

    An Approach to Interactive Social Network

    Geo-MappingIIT.SRC 2010, Bratislava, April 21, 2010, pp. 18.

    An Approach to Interactive Social Network

    Geo-MappingAnton BENI, Roman MSZRO, Roman PANENKA, Mrius AJGALK *Slovak University of Technology

    Faculty of Informatics and Information Technologies

    Ilkoviova 3, 842 16 Bratislava, [email protected]

    Abstract. People nowadays have too many useful items, which they find useless. Thispaper presents a concept of helping people to recycle these items by giving and lending

    these items. It is based on map interface and presenting information about other users and

    items in system via its geographical location. Data are evaluated base on cooperation withexisting social network and it does not have any need to build up its own social network.

    The system uses web services to provide information from the server. It operates as a web

    application as well as a mobile application.

    1 Introduction

    There are many social networks spread around the world nowadays. Visualization of

    these networks represent often complicated graphs that are hard to read. Other

    solutions use text interface. We decided to provide a map interface support for social

    networks visualization. Our solution is aimed on graphical representation of social

    networks. To illustrate this idea we have built a system for lending and giving old and

    useless items. We use external social networks to be visualized on the map, so we do

    not build our own social network but we use item-giving and item-lending data as our

    own social network.

    To express ideas about geographical mapping of social networks in cooperation

    with evaluation system we developed system called Save.

    The core part of Save is geographical map of the real world. This map is used to

    visualize all the things and people necessary. But we cannot show the user all the

    things and people on the map, because it might be chaotic, so we also developed our

    * Bachelor degree study programmer in field: Informatics Supervisor: Professor Mria

    Bielikov, Institute of Informatics and Software Engineering,

    Faculty of Informatics and Information Technologies STU in Bratislava

  • 8/4/2019 Developing a Geographic Information System

    12/50

    Own evaluating system that will sort out people and things due to the current usersactivities. We do not have only static data on the map, because giving and lending

    items is activity where an item is moved between two points and we decided to

    visualize this. As well as visualizing single transfer we show stories of the items,

    where a user can see how many people wanted that thing and they can see its evaluation.Save aims to have as many people as possible and to empower that idea we use

    external social networks, where the information about Save and information from Save

    are spread. Social networks are also used for people to compete and to motivate them

    to use the system. People can see also some of the activities of their friends and many

    users find that interesting.

    2 User Interface

    The user interface consists of four main parts:

    - the top control panel,

    - side tab panels,- window interface,

    - and the map.

    The top control panel provides the user with basic information, such as which accounts

    are connected or whether there was anything new of an interest to him since his last

    visit. The side tab panels provide the user with access to the most common

    functionality, while the window system is used to show the more detailed content.

    While none of the three mentioned parts are meant to be dominant the map is

    supposed to be the main navigation control. The map has two view levels. First one is

    the static view, where the user can choose between showing the people or the items. Inboth people and items view, the user can consequently navigate through items and their

    owners by pointing and clicking the mouse over the dynamic content that appears as

    the user navigates. This view level uses IntelliView, which is a map content management

    algorithm and will be discussed in the following section.

    The second level adds dynamics to the map, by displaying the activity of others.

    This activity is shown on top of the static view, be it either people or items, while the

    IntelliView algorithm takes care of freeing space on the map and appropriate

    positioning of the animation. This level can be used to show either the past activity to

    visually inform the user of what has happened since his last visit or the activity in near

    real-time using RealView, which is described in the section five

  • 8/4/2019 Developing a Geographic Information System

    13/50

    3 IntelliView

    Basic concept of presentation is to visualize as many information as possible on map

    [1,2]. Map is intended to serve as an information presenter for displaying friend lists,

    search results, history logs, routes, etc. In order to fulfil these requirements, IntelliView

    An Approach to Interactive Social Network Geo-Mapping 3

    Provides set of functions, which manage visualization. Besides geo coding, that is

    inevitable to find specific location, main stress is laid in choosing and organizing

    elements on map.

    Due to enormous number of items to be displayed, IntelliView must choose only

    some subset of these items in order to maintain lucid view. To accomplish this, items

    are sorted by priority. Priority is defined as single number and its computation varies

    with type of item, which is described later asItem evaluation in more details.

    Prioritization as well as some other principles, which are mentioned later, is based onmost common visualization techniques that can be found in Bing Maps, Google maps,

    and also in well-known ESRIs geographic information system (GIS) softwareproducts.

    With list of items sorted by priority, IntelliView aims to achieve following basic

    goals:

    display as many information as possible, display items with higher priority first, illustrate density of items, maintain simplicity of view.

    We proposed two main methods for displaying items, each of them with its own pros

    and cons. First, probably most intuitive method is depicted on Figure 1 and Figure 2.

    Items are iterated over by their priority and every time there is a check, if there is a

    collision. If not, the item is displayed. If there is a collision, the item is considered to

    be displayed with less importance and in order not to overlay those already displayed

    (which have evidently higher priority), their size is reduced and opacity decreased.

    Ordered by importance, they are grouped into several levels of importance. Visually,

    displayed items differ based on level, which they are included in. To maintain lucid

    view, items distribution is pushed to the last level, which is not displayed. Thus, visual

    differences among levels can be less significant. Presence of hidden items in the lastlevel is represented by background colour of appropriate topmost item. In this manner,

    density can be viewed as well. Advantage of this method is accurate projection of item

    location, but considering priority order, items in higher levels can have lower priority

    than those in lower levels.

  • 8/4/2019 Developing a Geographic Information System

    14/50

    Figure 1. IntelliView in action

  • 8/4/2019 Developing a Geographic Information System

    15/50

    Figure 2. IntelliView in action

    Second method tries to achieve greater accuracy of displaying priority by dividing

    whole viewport into grid and considering items isolated, individually in each cell.

    Thus, each cell has its own representative, which is dominating in the centre of this

    cell. Items in lower levels of importance are displayed similarly as in preceding method

    around cell's representative. While having improved accuracy of priority order depiction,

    this method has also better performance in calculation following principles of divide and

    conquers.

    However, in this case, location of item cannot be determined due to error caused

    by centralization within cell. The goal of centralization is to avoid collision problems

    on neighbouring cell's bounds. As a positive side effect, due to uniform distribution of

    items on the map, this view is symmetric and more readable, too.

  • 8/4/2019 Developing a Geographic Information System

    16/50

    4 RealView

    The integration of social networks and the visual representation have the purpose to

    make the system attractive and alive over time. RealView brings the activity to the end

    users by showing them actions performed by others in near real time. The RealView

    algorithm processes actions that other users perform within the viewing area and displays

    them as animations on the map.

    The algorithm could just show all or at least majority of the actions, but it would

    not be practical for a couple of reasons. First of all with rising number of actions, the

    traffic is rising too. Second, the purpose of this dynamic view is to bring the user activity

    to encourage him to be active as well, but overwhelming him with animations

    would rather be counterproductive. That is why we implemented a filtering system,

    whose purpose is to select which actions will be delivered to the individual users.

    The decision process is time sensitive and is based on a modified version of the

    relevancy system that is used in IntelliView.

    The time sensitivity means that despite of not showing all of the actions in the viewingarea, the algorithm still has to be aware of the rate at which the actions happen. When

    implementing the mentioned features, we cannot work in true real-time. The basic idea is

    to stack the animations in a list, putting a delay interval between them that reflects theactivity rate.

    We briefly introduce two specific implementations of this concept. The first

    algorithm maintains an ordered list of actions and the number of actions from the last

    animation. Then every time a given number of actions are processed, it picks the first

    one and displays its animation.

    The ordering is performed in a following way:

    when an action is intercepted, its relevancy value is calculated, all actions with lower relevancy are dismissed from the list, the processed action is added to the end of the list.

    This ensures that the first action in the list has always the highest relevancy and that we

    keep all consequent animations.

    The second algorithm is a simplification of the first one. It stores only one, most

    relevant action and the number of actions from the last animation. Then every time a

    given number of actions were processed it displays the stored animation.

  • 8/4/2019 Developing a Geographic Information System

    17/50

    5 Social networks

    The system does not build its own social network, it uses external networks of

    Facebook, Live or Twitter. On the other hand, we maintain our own action-built

    network. In this network users are connected by its same interest in some sort of things.

    To provide recommendations, we use keywords of the current item and its synonyms.

    Users and items are also user-evaluated.Currently, we aim our main focus to the biggest social networkFacebook. Sinceour system is designed to be open to other social networks, it is easy to integrate them

    in the future and to extend system availability. Integration of social network is twoway.

    The user can authenticate with his social network credentials and use our system

    with the same friends. But on the other hand there is sort of integration to his Facebook

    account. Our system provides triggered updates to user's wall including photos of

    things he has provided, things he has borrowed or lent, and events he has done etc. and

    regular updates with user statistics, social impact information and posts about

    successful stories. All these updates are controlled and adjustable, to lower the measure

    of spam.In addition to common statistics of the user activity, there are statistics provided

    by user geographical location. They include amount of welfare done in his location,

    statistics of users from his neighborhood and especially comparison with neighboring

    regions and countries. This indirectly leads to geo competition and bigger interest in

    our system.

    6 Save the system for recycling items in social networks

    The system core was designed as a WCF (Windows Communication Foundation) web

    service that can be used by different clients to provide functionality to the end user(see

    6 Roman Mszro et al.

    Figure 3). The client list consists of a Silverlight application that provides most of the

    system core functionality, a mobile application that is intended for quick access to

    some of the main functions and a Windows gadget that will just inform the user of

    various events in the system. Since the functionality is fully in hands of a web service,

    the system is open for new clients. The only thing that the client is required to

    imlement is the authentication process, briefly described below.

    To simplify the registration and authentication process and to make it more

    attractive for a new user to join the community as well, we have optioned for a login

    system, where the user can use his existing account form other web service to

    authenticate himself. Since our aim is to encourage people to help and we intent to

    promote this help through currently most intensive services - social networks, we have

    chosen Facebook and Twitter service to provide this autentication. This base can be

    further extended in the future. The process of authentication mostly involves the client

    application that takes care of acquiring the valid session keys from the credentials

    provider and provides them to the service core.

  • 8/4/2019 Developing a Geographic Information System

    18/50

    Figure 3.System architecture

    6.1 Web services

    The system uses service-oriented architecture [3] using Windows Communication

    Foundation. This way client can abstract from the functionality that is provided by

    server. Using web services avoids client from manipulating with data directly, because

    the connection to the database is provided by them. Because business logic is moved

    into one place (server), it is far easier to modify that code only once. It also provides

    the interface that can be used by plenty of applications. Our system is both a web-based

    application and a mobile application and it is also integrated into Facebook by editingits source code via proxy or the web browser, but the business logic itself is contained

    into web services used.

    6.2 System extensions

    Users are informed about recent news without being on system web site also. They can

    use add-ons to various browsers, widgets on operating system desktops or install small

    applications to their mobile phones. In all these extensions there is provided lower

    functionality with basic but significant information. More complicated tasks are

    redirected to main web application.

    When a user uses our browser add-on, communication with the server isredirected through our proxy server. The proxy server augments our system integration

    to the Facebook. More relevant information can be seen, better information structure

    can be seen and better Facebook layout is provided.

  • 8/4/2019 Developing a Geographic Information System

    19/50

    6.3 Item Evaluating

    Our system works with many items and many users with different point of interest.

    Apart from standard searching for items, the system has to provide ordering of items,

    which is based on interests and categories of current user and also similar users,

    evaluation of items in system and evaluation and score of the user, which wants or

    offers the item.First of all we aim on the point of interest [5] of the current user. We check his

    activity in the system and things he get or gave the system recommends items from the

    same item category, parent category or the system finds items based on key words and

    words connected using synonymic dictionary. This is performed by Spreading

    activation algorithm [6] with the current user or any of his items as source and we

    spread the initial energy from there.

    Second of all is looking for similar users [5]. Similar user is the user, who looks

    for the same categories of things and searches for the same keywords. Based on the

    similar user, we assume that things wanted by the similar user might be wanted by

    current user also. We used HITS algorithm [7] assuming the current user. Therefore theitems he references are assumed to be trustful as well. Next we find a user that references

    these trustful items and we consider him trustful also and then we recommend the current

    user the items, other trusted users referenced.

    After checking for similar user we filter items based on the items evaluation by other users. Every user is free to evaluate items offered by other users. They can evaluate

    these items by number, which is used for the purpose of the system, and by comment,

    which is far more useful for other users to communicate. Items are evaluated by usersrating and they are also evaluated by number of visitors. These states are handled by

    PageRank algorithm that assumes, that the item or user is that better that more times it is

    referenced [8].

    The last part is to order these items by the offering or wanting users evaluation by other system users and by his activities done in system. Users that have betterevaluation are more competent and responsible and items provided by them will be

    sorted before irresponsible users with miserable evaluation.

    VII. Conclusion

    This paper presents new modern ways of presenting information from social network

    via map interface. Our system demonstrates usage of this information in cooperation

    with giving subsystem. That concept can be easily changed to track some other

    information connected to these users.

    This paper also described our system that is used as a mediator between users, one donor

    and another one, acceptor. The system aims on solving problem of recycling items

    making them cycle again and not just go to trash and it aims on helping people in

    need as well. The system is also designed to provide lending service between users a

    tracing the items given and lent.

  • 8/4/2019 Developing a Geographic Information System

    20/50

    Acknowledgement: This project was supported by Faculty of Informatics and

    Information Technology as Imagine Cup 2010 Software design category project.

    This work was partially supported by the Cultural and Educational Grant Agency of

    the Slovak Republic, grant No. KEGA 028-025STU-4/2010.

    References

    [1] Gibbon, D. et al.: GeoTracker: Geospatial and Temporal RSS Navigation. In:

    Proc. ofWWW 2007, ACM Press, (2007), Banff, Canada, pp. 4150.[2] MacEachren, Alan M.: How maps work: representation, visualization, and

    design. The Guilford Press, (2004).

    [3] Datz, T.: What you need to know about service-oriented architecture. CIO,

    (2004).

    [4] Barla, M.,Bielikov, M.:Wild web personalization: adaptive proxy server. In:

    Proc. Of 4th Workshop on Intelligent and Knowledge oriented Technologies,Herany, Slovakia, (2009), pp. 48-51(in Slovak)[5] Chawla, A. et al.: Group Recommendation: Semantics and Efficiency. In: Proc.

    of VLDB 2009, ACM Press, (2009), pp. 754765.[6] Crestani F.: Application of spreading activation techniques in information

    retrieval. In: Artif. Intell. Rev., Springer, (2004),pp. 453482.[7] Liu, B.: Web Data Mining: Exploring Hyperlinks, Contents, and Usage Data

    (Data-Centric Systems and Applications). Springer-Verlag, New York, NJ, USA,

    (2006).

    [8] Page, L., Brin, S., Motwani, R., Winograd T.: The PageRank citation ranking:

    Bringing order to the web. In: Proc. of the 7th International World Wide Web

    Conference, Brisbane, Australia, (1998), pp. 161172.

  • 8/4/2019 Developing a Geographic Information System

    21/50

    Map Control Using Visual Basic

    In this introductory document you will use the ESRI Map control andMicrosoft Visual Basic to build an application that uses maps. Along the way you will

    learn how to

    Display a map with multiple layers.

    Control panning and zooming. Create a Toolbar control. Display map layers based on scale. Perform spatial and logical queries. Draw simple graphics on the map. Display features with thematic renderers. Dynamically display real-time event tracking. Programmatically add data to a map. Add Identify and Query commands from the sample AfCommandsVB library.

    Loading the Map controlStart Visual Basic and select New project from the dialog

    box. Select Components from the Project menu or press

    Ctrl+T.

    Find ESRI ArcObjects Controls 8.1 in the list of availablecontrols and check the box beside it. Click OK to close the

    dialog. Notice that a new tool appears in the Visual BasicToolbox. This new tool is the ArcObjects Controls Version 8.1 Map control

  • 8/4/2019 Developing a Geographic Information System

    22/50

    Getting help

    The Map control is an ActiveX control that is provided byESRI as part of the ArcObjects development toolkit.

    To find out about the available methods, properties, and

    events that are provided with the Map control, click the

    Object Browser button in the Visual Basic toolbar (or hit F2). Pull down theProject/Library boxand chooseesriControlsCtl.

    The esriControls objects and constants are listed in the

    Classes bottom left-hand list.

    Click on the Map control object in the list, and its propertiesand methods are listed in the Members list to the right.

    Likewise, click on a method in the right-hand list to see the method signature. The details

    will appear in the space at thebottom of the Object Browser.

    The ArcObjects online help system is also integrated withthe Visual Basic Object Browser.

    1. Click MapControl in the Classes/Modules list.2. Click VisibleRegion in the Methods/Properties list.

    3. Click the help (question mark) button.

  • 8/4/2019 Developing a Geographic Information System

    23/50

    Adding the ESRI Object Library

    To fully access all available ArcObjects components in yourVisual Basic project, you will need to add a Reference to

    the ESRI Object Library to your project. To do this, pull down the Project menu and selectReferences. Find and check ESRI Object Library in the list of available references.

    Again, from within the Object Browser, you can see all the available objects and components in

    ArcObjects by

    selecting esriCore from the Project/Library box.

  • 8/4/2019 Developing a Geographic Information System

    24/50

    Using the Map control

    The Map control allows you to load map data from a variety of data sources including

    ArcSDE layers, ArcInfo coverages, shapefiles, and raster files. You can also loadArcMap documents (*.mxd) into your Map control. Loading an ArcMap document into the Map control will add each of the referenced layers into the control, complete with

    saved definitions such as extents and renderers. You can also load individual layer files(*.lyr) in this way.

    The Map control also provides you with a number of helper methods such asTrackRectangle and AddLayer. We shall use some of these as we progress through this

    book. The Map control also has properties that expose references to the internal interfaces

    used by the Map control such as the IMap, IActiveView, and ILayer interfaces. Usingthese properties will give you a hook into the rich functionality available within theArcObjects Object Model.

    Add the Map control to the form

    1. Double-click the MapControl button in the toolbox to add anew map to the form.

    2. Resize the map to fill the form.

  • 8/4/2019 Developing a Geographic Information System

    25/50

    Select the data to display on the map

    You can specify the data that is displayed on the map by

    setting properties in the MapControls Property Page.1. Right-click the mouse on the map to display the context

    menu.

    2. Choose Properties to display the Property Pages.3. Click the Add button and locate the folder containing the

    states sample data.

    4. Click the states.shp file and then click Add.5. Add the file ushigh.shp in the same manner.

    6. Use the Up and Down arrows to ensure that the ushigh layer

    is at the top of the list.

    You can also specify how the data is displayed on the Map

    by using this Property Page.

  • 8/4/2019 Developing a Geographic Information System

    26/50

    Set properties for the layers

    1. Click the ushigh layer in the Layers list and then click Properties.2. Modify the ushigh layer symbology: Click on the Symbology tab. Click the Symbol

    button. Select a red color and click OK to dismiss the Layer Properties dialog.

    3. Now define a renderer for the States layer: Select States from the list of layers. Click

    on the Symbology tab.In the Symbology tab select Categories and then click on Unique values.

    Make SUB_REGION the Value field and click on the Add AllValues button.

    You can double-click on the colors to display the Colordialog box.

    4. Click OK to close the Property Page.

    Save the project1. Click the File menu and then click Save Project.

    2. Browse to a suitable folder, then in the File Name box type StarterMap.frm.

    3. Click Save.4. In the second Save dialog, type StarterMap.vbp in the File Name box.

    5. Click Save.

    Test your application1. Click the Run button in the Visual Basic toolbar.

    2. To stop running your application and return to design mode,

    click the Stop button in the Visual Basic toolbar.

  • 8/4/2019 Developing a Geographic Information System

    27/50

    Adding pan and zoom controls

    At this point your application can display the map at its fullextent. In this section you will add some simple pan and

    zoom controls that your application will activate in response

    to mouse clicks inside the map. You will write some code

    that the application will execute in response to theOnMouseDown event on the map.

    Respond to the MouseDown event1. Double-click on the Map control to display the Visual Basic

    code window.

    2. Add code to MapControl1s OnMouseDown procedure.Private Sub MapControl1_OnMouseDown(

    ByVal button As Long, _

    ByVal shift As Long, _

    ByVal x As Long, _

    ByVal y As Long, _ByVal mapX As Double, _

    ByVal mapY As Double)

    MapControl1.Extent = _ MapControl1.TrackRectangle

    End Sub

    TrackRectangle is a method that applies to the Map control. It tracks the movement of themouse while the user keeps the mouse button pressed, rubber-banding a rectangle at thesame time. When the user releases the mouse button, the TrackRectangle method returns

    an IEnvelope object that the application then assigns to the Extent property of the map,

    causing the map to be redrawn with a new map extent.

    Test your change

    1. Click the Run button in the Visual Basic toolbar.2. Click the map with the left mouse button and drag out a

    rectangle.

  • 8/4/2019 Developing a Geographic Information System

    28/50

    3. Release the mouse button and notice that the map is

    redrawn at the location you specified.4. Click the Stop button in Visual Basic to return to design

    mode.

    Add panning1. Double-click the map to display the Visual Basic code

    window again.

    2. Change the code for the OnMouseDown event.

    Private Sub MapControl1_OnMouseDown(

    ByVal button As Long, _

    ByVal shift As Long, _

    ByVal x As Long, _

    ByVal y As Long, _

    ByVal mapX As Double, _

    ByVal mapY As Double)

    If Button = vbLeftButton Then

    MapControl1.Extent = _

    MapControl1.TrackRectangle

    ElseIf Button = vbRightButton Then

    MapControl1.Pan

    End If

    End Sub

    If the Button parameter is equal to vbLeftButton when the

    OnMouseDown event occurs, then the zooming code from

    the previous step will be executed. Otherwise, the code will

    call another Map control method, Pan. If the user clicks theleft mouse button, the Button parameter will be

    vbLeftButton. If the user clicks the right mouse button, the

    value of Button will be vbRightButton.

    Add a FullExtent button

    Your application now supports panning and zooming but,once the user has zoomed into the map, there is no way to

    get back to the full extent again. In this section you will add

    a button to the form that zooms the map to the full extent.

    1. Double-click the CommandButton button in the Toolbox to

    add a button to the form.2. Move the button to the upper right of the form.

    3. Press F4 to display the Properties window.

    4. Click in the Caption box and type Full Extent to change the

    buttons caption.

  • 8/4/2019 Developing a Geographic Information System

    29/50

    5. Resize the Map control so that it is not obscured by the button.

    6. Double-click the Full Extent button to display the code window.

    7. Add code for the Click event.

    Private Sub Command1_Click()

    MapControl1.Extent = MapControl1.FullExtent

    End Sub8. Finally, when you are in Design mode, use the Visual Basic Properties box to change

    two properties of the Map controlset ShowScrollBars to False and choose a color forMapControls BackColor property.The FullExtent property of the Map returns a reference to an IEnvelope that defines the

    bounding box ofall the layers in the Map.

    Test your change1. Click the Run button in the Visual Basic toolbar.

    2. Click the map with the left mouse button and drag out a rectangle.

    3. Release the mouse button to redraw the map.

    4. Click the map with the right mouse button and drag to pan the map.5. Release the mouse button to redraw the map.

    6. Click the Full Extent button to redraw the map at the full extent.

    Save the project1. Click the Stop button in the Visual Basic toolbar to return to

    design mode.2. Click the Save Project button in the Visual Basic toolbar to

    save your changes.

    Adding a toolbar

    Visual Basic includes a Toolbar control that can be used inconjunction with an ImageList control to display a collection of buttons at the top of a

    form. We shall use the Visual Basic Toolbar for this starter application. The current

    applications pan and zoom functionality is somewhat hidden from the user. In thissection, you will create a toolbar with Pan and Zoom buttons.

  • 8/4/2019 Developing a Geographic Information System

    30/50

    Adding a toolbar

    1. Delete the Full Extent button from the form.2. Bring up the Components dialog by pressing Ctrl+T. Select

    Microsoft Windows Common Controls. You will notice new

    tools are added to your toolbox.

    3. Double-click the Toolbar button in the toolbox to add aToolbar control to the form.

    4. Double-click the ImageList button in the toolbox to add an

    ImageList control to the form.5. Resize the map so that it is not obscured by the toolbar.

    The ImageList control may obscure the map; however, thisis not a problem because the ImageList control will not be

    visible when your application is running.

    Adding images to the ImageList control

    1. Right-click the ImageList control to display the context menu.

    2. Click Properties to display the Property Pages.3. Click the Images tab.

    4. Click Insert Picture and locate the folder that contains the sample bitmaps. This should

    be the Icons directory within the ArcGIS Bin folder.

    5. Click the zoom_in_tool_1.bmp file and then click Open.6. Add a descriptive Key, for example, Zoom. This will correspond with Keys that willbe used when adding buttons to the Toolbar control.

  • 8/4/2019 Developing a Geographic Information System

    31/50

    7. Add the files pan_1.bmp, globe_3.bmp, select_by_polygon.bmp, flag.bmp,

    information.bmp, and selection_1.bmp in the same manner. The Keys should be

    FullExtent, SelectByPolygon, TrackEvent, Identify, and Query, respectively.

    Set the MaskColor of the ImageList

    Setting the MaskColor property of an ImageList control specifies a color that will act as amask for any images contained by the control. The mask color will not be drawn,

    resulting in an image with a transparent background.

    1. Click the Color tab.2. In the Properties list, click MaskColor.

    3. Click Magenta in the Color Palette list and then click OK todismiss the Property Pages.

    Associate the ImageList with the toolbarYou can associate the Toolbar control with an ImageList

    control to provide the graphic images for the buttons.

    1. Right-click the Toolbar control to display the context menu

    2. Click Properties to display the Property Pages.

    3. In the ImageList box, click the arrow and then click ImageList1. This associates thetoolbar with the ImageList control.

  • 8/4/2019 Developing a Geographic Information System

    32/50

    Adding buttons to the Toolbar control

    In this section you will add seven buttons to the toolbar.1. In the Toolbar Control Properties dialog, click the Buttons tab, then click Insert Button.

    2. Set the buttons style to ButtonGroup, its Image to Zoom, itsKey to Zoom, and itsValue to Pressed. Add suitable Tool Tips.

    3. Add a second button and set its Style to ButtonGroup, its Image to 2, and its Key toPan.4. Add five more buttons and associate them with the remaining images in the ImageList,

    setting their Style to ButtonGroup (add Separators if you wish). The Keys should beFullExtent, SelectByPolygon, TrackEvent, Identify, andQuery, respectively.5. Click OK to dismiss the Property Pages

    Change the OnMouseDown event1. Double-click the map to display the Visual Basic code window.

    2. Completely replace the code in the MapControl1s OnMouseDown event handler withthe following:

    With Toolbar1.Buttons

    If .Item("Zoom").Value = tbrPressed ThenMapControl1.Extent = MapControl1.TrackRectangle

    ElseIf .Item("Pan").Value = tbrPressed Then

    MapControl1.Pan

    End If

    End WithSelecting the first button in the toolbar sets the mouse to be

    a zoom tool; selecting the second button lets you use themouse to pan.

  • 8/4/2019 Developing a Geographic Information System

    33/50

    The Toolbar ButtonClick Event Handler

    In this section you will implement the handler for theButtonClick event that is generated whenever a click

    occurs on a button in the toolbar.

    We will add code to change the MapControls

    MousePointer depending on what tool has been selected,providing useful feedback to the user. We shall also

    reimplement the Full Extent button that you deleted. Within the event handler we will be

    using a Case statementwith switches, depending on the Key value of the button

    that you defined earlier.

    1. Double-click the toolbar to display the code window.2. Add the following code to Toolbar1s ButtonClick event.Private Sub Toolbar1_ButtonClick(ByVal Button _

    As MSComCtlLib.Button)

    With MapControl1

    Select Case Button.KeyCase "Zoom"

    .MousePointer = esriPointerZoomIn

    Case "Pan"

    .MousePointer = esriPointerPan

    Case "FullExtent"

    .MousePointer = esriPointerDefault

    .Extent = MapControl1.FullExtent

    End Select

    End With

    End Sub

    Test and save your changes

    1. Click the Run button in the Visual Basic toolbar.2. Drag a rectangle to zoom in.

    3. Click the pan button in your applications toolbar.

    4. Click somewhere on the map and then drag to pan.

    5. Click on the Full Extent button (the globe) in your applications toolbar.

  • 8/4/2019 Developing a Geographic Information System

    34/50

    Creating a find toolIn this section you will add additional controls to yourapplication to implement a simple function for locating a

    state by name. Once the State is located you will zoom to it.

    Add controls to the form1. Double-click the Label button in the toolbox to add a label to

    the form.

    2. Reposition the label in the lower left corner of the form.3. Display the Properties window by pressing F4 and set the

    caption of the label to be State:.

    4. Double-click the TextBox button in the toolbox to add aTextBox to the form and position it next to the label.

    5. Clear the Text property of the TextBox using the Properties

    window.

    6. Resize the map so that it is not obscured by the new controls

    Attach code to the TextBox

    You will use the text the user types into the TextBox toperform a logical query.

    1. Double-click the TextBox to show the code window.

    2. Add code to Text1s KeyPress procedure by selectingKeyPress from the right-hand dropdown list:

    Private Sub Text1_KeyPress(KeyAscii As Integer)

    If KeyAscii = vbKeyReturn Then

    ' Find the States layer

    Dim i As IntegerDim pFeatLyr As IFeatureLayer

    For i = 0 To MapControl1.LayerCount - 1

    Set pFeatLyr = MapControl1.Layer(i)

    If pFeatLyr.Name = "states" Then

    ' Found it and exit loop

    Exit For

    End If

  • 8/4/2019 Developing a Geographic Information System

    35/50

    Next i

    ' Create a string to use in the query

    Dim queryStr As String

    queryStr = "STATE_NAME = '" & Text1.Text & "'"

    ' Create the query filter

    Dim pQueryFltr As IQueryFilterSet pQueryFltr = New QueryFilter

    pQueryFltr.WhereClause = queryStr

    ' Perform the selection

    Dim pFeatSeln As IFeatureSelection

    ' QI for IFeatureSelection from the

    ' IFeatureLayer

    Set pFeatSeln = pFeatLyr

    pFeatSeln.SelectFeatures _

    pQueryFltr, esriSelectionResultNew, False

    ' Get the selection setDim pSelSet As ISelectionSet

    Set pSelSet = pFeatSeln.SelectionSet

    ' Get the cursor from the selection set

    Dim pFeatCursor As IFeatureCursor

    pSelSet.Search Nothing, True, pFeatCursor

    ' Assume only one feature

    Dim pFeature As IFeature

    Set pFeature = pFeatCursor.NextFeature

    If Not pFeature Is Nothing Then

    ' Get the extent of the selected feature

    Dim pExtent As IEnvelope

    Set pExtent = pFeature.Shape.Envelope

    ' And set the Map control's extent

    MapControl1.Extent = pFeature.Shape.Envelope

    End If

    End If

    End Sub

  • 8/4/2019 Developing a Geographic Information System

    36/50

    Test and save your changes

    1. Run your application.2. Type the name of a state, for example, New Jersey, into the

    TextBox.

    3. Press the Enter key.

    4. When you are finished running your application, click theStop button in the Visual Basic toolbar and Save your

    application.

    The code locates the States layer and defines a simple SQL query expression using the value of

    the Text property of the TextBox. The States layers IFeatureSelection uses this query to searchfor the specified value. You can obtain an IFeatureCursor that contains all features from the

    IFeatureSelection. Here we assume the cursor contains only one feature, from which we willderive the geometry and its extent envelope. We will use this envelope to reset the MapControlsExtent.

    Handling resize

    When you run your application and resize the form, you will

    notice that the map is not automatically resized.

    Respond to the Resize event1. Double-click the form to display the code window.

    2. Add code to the forms Resize procedure by selecting Resize from the right-hand dropdown list:

    Private Sub Form_Resize()

    If (ScaleWidth 0) Then

    ' y coord for Text and Label

    Dim yFind As Integer

    ' a constant spacing

    Dim space As Integer

    space = Text1.Top - (MapControl1.Top _

  • 8/4/2019 Developing a Geographic Information System

    37/50

    + MapControl1.Height)

    yFind = ScaleHeight - Text1.Height - space

    ' x coord for Text and Label

    Dim xFind As Integer

    xFind = ScaleWidth - Text1.Width

    Dim mapTop As IntegermapTop = Toolbar1.Top + Toolbar1.Height

    Dim mapHeight As Integer

    mapHeight = yFind - space - mapTop

    If (mapHeight > 0) Then

    ' move all the controls

    Text1.Move xFind, yFind

    Label1.Move xFind - _

    Label1.Width - 20, yFind

    MapControl1.Move 0, mapTop, _

    ScaleWidth, mapHeight

    End IfEnd If

    End Sub

    3. Double-click the form to show the code window.

    4. Add code to the forms Load procedure.

    Private Sub Form_Load()

    Form_Resize

    End Sub

  • 8/4/2019 Developing a Geographic Information System

    38/50

    When the user resizes the form, the code resizes the controls using the Move method.Notice that when you run your application it redraws the map twice initially. This is due

    to the fact that controls on the form are initially displayed using the size and position

    specified during design time. To fix this problem, you will resize the controls when theform is initialized. You have already written the code to resize the controls, so you just

    need to call the procedure.

    Test and save your changes1. Run your application. Notice that it does not draw the

    Counties layer.

    2. Zoom into New England and the Counties layer becomes

    3. Click the FullExtent button and the Counties are no longer

    visible.

    Adding a spatial query toolIn this section you will add a new tool to the toolbar that

    performs spatial queries on the map and also add code that

    draws the results. We have already added the button to theToolbar, so we just need to add code to implement its

    functionality. We will use the SelectByPolygon button, the

    fourth button on the toolbar. When the SelectByPolygon

    button is clicked, we will handle the OnMouseDown eventdifferently, calling a procedure called SearchShape to

    actually peform the spatial selection.

  • 8/4/2019 Developing a Geographic Information System

    39/50

    Implement the SearchShape procedure

    Private Sub SearchShape()

    Dim pSearchShape As IPolygon

    ' Create the search shape

    Set pSearchShape = MapControl1.TrackPolygon' Do the actual selection

    With MapControl1

    .Map.ClearSelection

    .Refresh esriViewGeoSelection

    .Map.SelectByShape pSearchShape, Nothing, False

    ' And refresh the map.Refresh esriViewGeoSelection

    End With

    End Sub

    Call the SearchShape procedure1. Modify MapControl1s OnMouseDown procedure and insertthe following:ElseIf .Item("SelectByPolygon").Value =_

    tbrPressed Then

    SearchShape2. Finally, modify the Toolbar_ButtonClick procedure to change

    the MapControls Mousepointer.Case "SelectByPolygon"

    .MousePointer = esriPointerCrosshair

    Test and save your changes1. Run your application and zoom into an area so that the Counties layer becomes visible.

    2. Click the spatial query tool, then digitize a polygon. Doubleclick to end. You should

    see that counties that intersect with the polygon are highlighted. Optionally, from theProperty Pages, display the Layer

    Properties dialog to modify the default Selection Symbol for

    each layer. Set it to a yellow solid fill.

  • 8/4/2019 Developing a Geographic Information System

    40/50

    Event tracking

    Some applications must display geographic entities on top of the map, especially if thoseentities have a tendency to move.

    For example, a vehicle tracking system would want to display vehicles on the map at the

    appropriate locations and update those locations over time without redrawing all the

    underlying layers of the map each time a vehicle changes location.In this section, you will add event tracking layer elements to your application to facilitate

    this requirement. We have already added the required toolbar button (the Flag at toolbar

    button number five), and now we shall implement the tool.

    Implement the Event tool

    1. Add a private member variable to the General section of the Forms code window.This will be an ElementCollection that will be used to hold your events.

    Private m_pElementCollection As IElementCollection

    2. In the Form_Load method, initialize the collection: Set m_pElementCollection = New

    ElementCollection

    3. Modify the Toolbar1_ButtonClick procedure to change the MapControlsMousepointer. Case "TrackEvent"MapControl1.MousePointer = esriPointerHotLink

    4. Modify the MapControl1s OnMouseDown procedure to call AddGeoEvent, passing inthe mapX and mapY coordinates.

    These are already in Map units.ElseIf .Item("TrackEvent").Value = tbrPressed Then

    AddGeoEvent mapX, mapY

    Implement the AddGeoEvent procedureThe AddGeoEvent procedure adds a new element where

    the mouse click occurred. Add the following code to the

    General section of the Forms code window.

    Private Sub AddGeoEvent(mapX As Double, mapY As Double)

    ' Make the point

    Dim pPoint As IPointSet pPoint = New Point

    pPoint.PutCoords mapX, mapY

    ' Make the elementDim pElement As IElement

    Set pElement = New MarkerElement

    pElement.Geometry = pPoint

    ' Add the element to the collectionm_pElementCollection.Add pElement

    ' And finally redraw the map

    MapControl1.Refresh esriViewForegroundEnd Sub

  • 8/4/2019 Developing a Geographic Information System

    41/50

    Drawing the events

    After the layers draw, we iterate through the collection of

    events to draw each, in turn, using the MapControlsDrawShape method. Add this code to the OnAfterDraw

    Event procedure.

    Private Sub MapControl1_OnAfterDraw(ByVal display AsesriCore.IDisplay, ByVal phase As

    esriCore.esriViewDrawPhase)

    If (phase = esriViewForeground) ThenDim pElement As IElement

    Dim i As Integer

    For i = 0 To m_pElementCollection.Count - 1m_pElementCollection.QueryItem i, pElement

    MapControl1.DrawShape pElement.Geometry

    Next

    End If

    End Sub

    Test and save the Event tool1. Run your application.

    2. Zoom into an area.

    3. Click the event tool, then click in the map to add events.4. Click the Stop button on the Visual Basic toolbar and save

    your project.

    Add a timer to your formTo trigger the movement of the events, a Timer control will

    be used. The Visual Basic function Rnd is used togenerate a random number to move the events in a random

    manner.1. Double-click the Timer button in the toolbox to add a timer to

    the form. The Timer control will not be visible when your

    application is running.2. Double-click the timer to display the code window.

    3. Add code to the timer procedure.

    Private Sub Timer1_Timer()

    Dim maxDist As Double

    Dim nEventCount As Integer

    Dim pt As IPointmaxDist = MapControl1.Extent.Width / 20

    nEventCount = m_pElementCollection.Count

    Dim newX As DoubleDim newY As Double

    Dim i As Integer

    ' If the collection is not empty

  • 8/4/2019 Developing a Geographic Information System

    42/50

    If (nEventCount > 0) Then

    Dim pGeometry As IPointDim pElement As IElement

    ' Iterate the collection

    For i = 0 To nEventCount - 1

    m_pElementColn.QueryItem i, pElementSet pGeometry = pElement.Geometry

    ' Generate a new random position

    newX = pGeometry.x - (maxDist * (Rnd - 0.5))newY = pGeometry.y - (maxDist * (Rnd - 0.5))

    ' And update the element

    pGeometry.PutCoords newX, newYpElement.Geometry = pGeometry

    Next i

    MapControl1.Refresh esriViewForeground

    End If

    End Sub

    Add a CheckBox to your formTo turn the timer on or off, you will add a CheckBox control

    to your application.

    1. Double-click the CheckBox button in the toolbox to add aCheckBox to the form.

    2. Move the CheckBox to the lower left corner of the form.

    3. Open the Properties window and set the Caption to DataCollection.4. Double-click the CheckBox control to open the code window.

    5. Add code to Check1s Click procedure.Private Sub Check1_Click()

    Timer1.Interval = Check1.Value * 500End Sub

    Modify Form_ResizeModify the Form_Resize method to move the CheckBox when the form is resized. Just

    before the Text1 and Label1 controls are moved, insert the code for moving the Check1

    control.' Move all the controls

    Check1.Move 0, yFind

    Text1.Move xFind, yFind

    Test your changes1. Run your application.

    2. Zoom into an area.

    3. Click the event tool, then click in the map to add events.4. Click the Data collection check box. Notice that the events

    start moving randomly on top of the map.

    5. Click the check box again to stop the events.

  • 8/4/2019 Developing a Geographic Information System

    43/50

    Adding layers programmaticallyIn each of the previous sections, you have worked with Layer objects that were specified

    interactively using the MapControls Property Pages. In this section, you will add code toyour application that creates Layer objects programmatically. There are a number ofmethods that you can use to programmatically add layers to your Map control:

    LoadMxFileThis method will load an ArcMap document (an MXD file). If theArcMap document contains multiple maps, then it is possible to state which one you want

    to load by passing in an index. Each map can contain multiple layers, and all layer

    properties (such as renderers) will be retained. Note that if you want to use an ArcMap

    document to add layers to your Map control, then this method should be called before anyadditional layers are added.

    AddLayerFromFileUsing this method you can add a layer that has previously beensaved to a layer file (lyr). You can also optionally specify an index to force the new

    layers position within currently loaded layers. All symbology for the layer that wasdefined within ArcMap is also honored within the Map control.

    AddShapeFileThis method allows you to add shapefiles by specifying the path and the

    shapefile name. The new layer is added on top of any previously loaded layers. Default

    symbology is provided by ArcObjects.

    AddLayerThis method takes as parameters a reference to an ILayer and an optionalindex value. This allows you to create and load layers that come from different data

    formatsfor example, Coverages, TIN, Raster, or ArcSDE. See theArcObjectsDevelopers online reference, theExploringArcObjects book, or theArcObjects Class

    Help online for further details on creating layers.

  • 8/4/2019 Developing a Geographic Information System

    44/50

    The example code that follows loads three layers using two of the above methods. Ensure

    that you change the paths to the data to match your installation.

    Remove the existing layers

    1. Right-click the mouse on the map to display the context menu.

    2. Choose Properties to display the Property Pages.3. Click on the ushigh layer, then click Delete to remove the layer.

    4. Remove counties and states in the same manner, then click OK.

    Add a procedure that will initialize the map1. Double-click the form to display the code window.

    2. In the General section, declare a procedure.

    Sub InitializeMap()

    ' Change the paths to reflect your installation

    Dim pFactory As IWorkspaceFactory

    Dim pWorkspace As IFeatureWorkspaceDim pFeatLayer As IFeatureLayer

    ' Create a new ShapefileWorkspaceFactory objectSet pFactory = New ShapefileWorkspaceFactory

    Set pWorkspace = pFactory.OpenFromFile("C:\Data\USA", 0)

    ' Create a new FeatureLayer and assign a shapefile to itSet pFeatLayer = New FeatureLayer

    Set pFeatLayer.FeatureClass =

    pWorkspace.OpenFeatureClass("States")

    pFeatLayer.Name = pFeatLayer.FeatureClass.AliasName' Add the FeatureLayer to the map

    With MapControl1

    .AddLayer pFeatLayer

    .AddShapeFile "C:\Data\USA", "counties

    .AddShapeFile "C:\Data\USA", "USHigh"

    End With

    End Sub

  • 8/4/2019 Developing a Geographic Information System

    45/50

    Modify the Form_Load procedure

    1. Immediately after the call to Form_Resize and before the section of code that sets theminimum and maximum display scales for the layers, insert the following line:

    InitializeMap

    2. To ensure that the MapControls MousePointer correctly reflects the startup status of

    the Toolbar, insert the following line after the call to InitializeMap:MapControl1.MousePointer = esriPointerZoomIn

    Test and save your changes

    1. Run your application. The map should appear as before, but default colors andrenderers are used and therefore may be different than the colors you previously selected

    in the Layer Properties dialog box.

    2. Click the Stop button in the Visual Basic toolbar and save your project. Working withRasterLayer objects In each of the previous sections, you worked with MapLayer objects

    based on vector data sources. In this section, you will see how to add layers to your map

    that are based on images. ArcObjects allows you to use a wide range of image types as

    RasterLayers including such common image types as windows bitmaps (.bmp), tagged

    image file format (.tiff), and CompuServe bitmaps (.gif).

    Select an image layer to display on the mapYou can specify an image to display as a RasterLayer by setting properties in the

    MapControls Property Pages.1. Right-click the mouse on the map to display the context menu.2. Choose Properties to display the Property Pages.

    3. Click the Add button and then select Raster datasets from the Show of type combobox.

    4. Navigate to a data folder that contains raster datasets. If you have the ESRI Data &Maps CD, you can use the sample image wsiearth.tif.5. Click on the raster dataset file, then click Add.

    6. If you still have other datasets listed in your Property Pages, use the arrow buttons to

    ensure that the raster data is at the bottom of the list.

    Test your changes1. Click the Run button in the Visual Basic toolbar.

    2. To stop running your application and return to design mode,click the Stop button on the Visual Basic toolbar.

  • 8/4/2019 Developing a Geographic Information System

    46/50

    Adding a RasterLayer programmatically

    Previously, you added feature layers programmatically; now you will add a RasterLayerprogrammatically.

    Remove the existing layers

    1. Right-click the mouse on the map to display the context menu and click on Properties

    to display the Property Pages.2. Select wsiearth.tif (or the raster dataset you selected), then click Delete.

    Modify the procedure that initializes the map

    1. Double-click the form to display the code window.2. Modify the InitializeMap procedure by inserting the following

    after all existing code:

    ' Add RasterLayer to the map underneath all' existing layers

    Dim pRasterLayer As IRasterLayer

    Set pRasterLayer = New RasterLayer

    pRasterLayer.CreateFromFilePath _"E:\World\wsiearth.tif"

    ' Note that we are passing in an index valueMapControl1.AddLayer pRasterLayer,

    _MapControl1.LayerCount

    Test and save your changes1. Click the Run button in the Visual Basic toolbar.

    2. Click the Stop button in the Visual Basic toolbar and save your project.

    Using ESRI tools and commandsThe ArcGIS installation provides you with a set of sample commands and tools thatyou can use to customize ArcMap or in conjunction with your Map control. These tools

    implement ICommand and/or ITool, providing functionality to identify and select

    features and to produce attribute reports, editing commands (including StartEditing,StopEditing, Undo, Redo), and tools to add and reorganize layers. In the Bin subfolder of

    your ArcGIS installation, you will see two DLLs called AfCommands andAfCommandsVB. These two DLLs contain the library of supplied sample tools that =can be used directly with the Map control. The source code for the sample tools isavailable as part of the ArcObjects Developers Kit. The following section illustrates how

    to use two of these commands to provide an Identify tool and a Query tool.

    Adding an Identify toolAdd the ESRI AF Commands (VB) reference to yourVB project.

    1. Pull down the Project menu and select References.

    2. In the list of available references, find and check ESRI AF Commands(VB).3. Ensure that the ESRI Object Library appears above ESRI AF Commands(VB).We have already added an Identify button on the toolbar.

    Now we need to make three modifications. Firstly, wedefine a Private member variable to hold our Command.

    The second change is in the Form_Load event where we

    instantiate the private member variable, and the finalchange involves handling the clicking of the toolbar.

  • 8/4/2019 Developing a Geographic Information System

    47/50

    1. Firstly, add a private member variable to your project by adding the following code to

    the Forms code window General section. Private m_pCommand As ICommand 2. Immediately after the call to InitializeMap, insert the following

    lines to create an Identify tool and pass it a reference to the Map control.

    Set m_pCommand = New AfCommandsVB.Identify

    ' Pass the Map control as the hookm_pCommand.OnCreate MapControl1.Object

    3. Modify the Toolbar1_ButtonClick procedure to associate the Map control with the

    Identify command using the CurrentTool property.

    Private Sub Toolbar1_ButtonClick(ByVal Button As

    MSComCtlLib.Button)Set MapControl1.CurrentTool = Nothing

    With MapControl1

    Select Case Button.Key

    Case "Zoom"

    .MousePointer = esriPointerZoomInCase "Pan"

    .MousePointer = esriPointerPanCase "FullExtent"

    .MousePointer = esriPointerDefault

    .Extent = MapControl1.FullExtentCase "SelectByPolygon"

    .MousePointer = esriPointerCrosshair

    Case "TrackEvent"

    .MousePointer = esriPointerHotLinkCase "Identify"

    .MousePointer = esriPointerDefault

    Set MapControl1.CurrentTool = m_pCommand

    End SelectEnd Sub

    For the Map control to be able to set the CurrentTool, the target tool must support theITool interface, which the supplied Identify tool does. Internally, once the Map control

    has been associated with the CurrentTool, it forwards all MouseDown events directly tothe CurrentTool first and fires the OnMouseDown event as before. If another operation

    has been selected from the Toolbar, for example, the Pan, we need to reset the

    CurrentTool to Nothing to indicate that no tool should be used. We do this at the

    beginning of the procedure.

  • 8/4/2019 Developing a Geographic Information System

    48/50

    Test your changes

    1. Click the Run button in the Visual Basic toolbar.2. Select the Identify tool from the Toolbar. Notice that the MousePointer has changed.

    Click on an individual feature or drag a rectangle and an attribute dialog box will pop up.

    3. To stop running your application and return to design mode,

    click the Stop button in the Visual Basic toolbar.

    Adding a Query toolThe AF Commands library also comes with a very useful Query tool. This tool enables

    you to query a specified layer using a spatial and/or attribute query. The results can be

    Added, Kept, or Discarded to or from the Maps SelectionSet. To correctly use the Querytool (and all other tools that only implement the ICommand interface), we need to create

    our tool and load it into a global variable. If we create the command using the OnCreate

    method and then fire its OnClick method entirely within one procedure, it will quickly go

    out of scope, and an error will be raised. Storing the command in a global variable solvesthe problem.

    Alternatively, you can use a Collection to manage your tools

    instead of a global variable.1. Firstly, add a private member variable to your project by

    adding the following code to the Forms code windowGeneral section:Private m_pQuery as ICommand

    2. Next, modify the Form_Load procedure and add the

    following lines to create a new Query command and pass it a

    reference to the Map control.

    ' Use the AfCommandsVB Query toolSet m_pQuery = New AfCommandsVB.Query

    m_pQuery.OnCreate MapControl1.Object3. Modify the Toolbar1_ButtonClick procedure as shown below.

    Case "Query"

    .MousePointer = esriPointerDefault

    ' Fire the query command

    m_pQuery.OnClick

  • 8/4/2019 Developing a Geographic Information System

    49/50

    Change the Feature Selection Color

    4. Finally, modify the Form_Load procedure to change the default color that is used tohighlight selected features. We shall change it so that selected features are shown in red.

    Add the following code in the Form_Load procedure after all layers have been added and

    their MinimumScale and MaximumScale properties have been set.

    ' Create a red color objectDim pColor As IColor

    Set pColor = New RgbColor

    pColor.RGB = 255Dim pFeatSeln As IFeatureSelection

    ' Iterate layers and set the color

    For i = 0 To MapControl1.LayerCount - 1Set pLayer = MapControl1.Layer(i)

    ' Work only with feature layers

    If (TypeOf pLayer Is IFeatureLayer) Then

    ' QI for the FeatureSelection

    Set pFeatSeln = pLayerSet pFeatSeln.SelectionColor = pColor

    End If

    Next i

    Only feature layers have a SelectionColor. To check what type of layer we have, we use the

    TypeOf keyword. After we have worked out if the current map layer is an IFeatureLayer, we QI

    directly to the IFeatureSelection interface and set its SelectionColor property.

    Test and save your changes

    1. Click the Run button in the Visual Basic toolbar.2. Select the Query tool from the Toolbar and a dialog box will

    pop up. Build an attribute query by first clicking on the states

    layer in the Class tab. Now click on the Attribute tab andselect STATE_NAME from the list of available Attributes. Enter

    Alabama in the Attribute Value box and click Apply.

  • 8/4/2019 Developing a Geographic Information System

    50/50

    3. Now try the Spatial Constraint. First, zoom into the Map so that the counties are

    drawn. In the Query dialog, click on the counties layer in the Class tab, then click on theSpatial Constraint tab. For the Spatial Extent, click on the icon for digitizing an area and

    then click on the map to draw a polygon. Select the Intersects Spatial Operator andfinally click on the Apply button.

    4. To stop running your application and return to design mode, click the Stop button inthe Visual Basic toolbar