Basic of Programming in GIS - PowerPoint PPT Presentation

1 / 33
About This Presentation
Title:

Basic of Programming in GIS

Description:

VBScript. VBA. Macros in Excel. Marcos is Arc GIS. Outline (cont'd) ... Byte 1 Byte Stores 0 to 255 only. Boolean 1 Boolean Stores ... VBScript. Based on ... – PowerPoint PPT presentation

Number of Views:80
Avg rating:3.0/5.0
Slides: 34
Provided by: mayan
Category:

less

Transcript and Presenter's Notes

Title: Basic of Programming in GIS


1
Basic of Programming in GIS
  • Presentation by Programming Group (3)
  • Jon Remo
  • Mayank Srivastava
  • Zhigang Wang

2
Outline
  • Programming Basics
  • Data types
  • Variables
  • Arrays and Matrices
  • Loop Structures
  • Decision Structures
  • Functions and Subroutines
  • Visual Basic Applications
  • VBScript
  • VBA
  • Macros in Excel
  • Marcos is Arc GIS

3
Outline (contd)
  • Programming and GIS
  • AML
  • Avenue
  • Arc Objects
  • MapInfo
  • MapBasic Window

4
DATA TYPES
  • Data field types Size VBType
    Comments
  • Integer 2
    Integer 32768
  • Long 8
    Long 2147483648
  • Single 4
    Single
  • Double 8
    Double Floating Points
  • Currency 8
    Currency Fixed point
    calculation

5
Data Types Contd..
  • String V String
    Text Character
  • Byte 1 Byte
    Stores 0 to 255 only
  • Boolean 1 Boolean
    Stores 0 or 1 only
  • Date 8 Date/Time
    Date left-decimal-time right
  • Object 4 Object Holds programming
    statement.
  • An element from VB program
  • Variant 16 Variant Numeric 16 bytes and text
    22 bytes.

6
Declaring Variables and Scope
  • Variables - used to hold and manipulate values or
    data needed by an application.
  • In VB a variable must be declared before it is
    used in the code.
  • Variable can only hold the declared data type.
    (exception variant data type)

7
Declaring Variables and Scope
  • Scope
  • Refers to the availability of a variable from
    within the application's code.
  • Variable scope and procedure scope
  • Variable scopes in keywords DIM, Public,
    Private, ReDim, Static, Type.
  • Procedure scopes in keywords Private, Public,
    Friend and static

8
Declaring Variables and Scope
  • Variable Scope
  • DIM declares the variables by assessing them a
    name and data type.
  • DIM Number as Integer
  • Public Keyword makes a variable global through
    out the entire application.
  • Private Variable (Local) only visible in a
    procedure in which you declare it.
  • ReDim- reallocate storage space for dynamic array
    variables
  • Static preserve its value between procedure
    calls.
  • Type declare a user type

9
Declaring Variables and Scope
  • Procedure Scope
  • Private specify a subroutine or function is
    private to the modules or forms in which it is
    declared.
  • Private Function Return()
  • Dim Retval as Integer
  • Retval 7
  • RetvalRetval 2
  • Msgbox Retval
  • End Function
  • Public specify a subroutine or function is
    global to all forms and modules.

10
Declaring Variables and Scope
  • Constants a numeric or string value that does
    not change through the execution of a program.
  • Declared by command CONST
  • Const MAXMARK as INTEGER 100
  • Public Const ROAD1 as string Stewart
  • Option Explicit
  • Statement tells Visual Basic that the rest of the
    code in this module is to declare all variable
    before they are used. ( e.g. catch variable name
    error)
  • To force variable declarations to be explicit
    (i.e. each variable be declared), add option
    explicit statement at the module or form level.

11
Arrays and Matrices
  • Array -variable containing multiple values.
  • Values that all have the same data type in an
    array.
  • Matrices Multidimensional arrays - one name,
    can only hold one data type declared in the
    matrices.

12
Arrays and Matrices
  • Examples
  • Single Dimension Arrays
  • Dim Vals(3) as Integer
  • Vals(0)10
  • Vals(1)30
  • Vals(2)50
  • Matrices (multidimensional arrays)
  • Dim Vals(2, 2) as Integer
  • Vals(0, 0) 10
  • Vals(0, 1) 20
  • Vals(1, 0) 30
  • Vals(1, 1) 40

13
Arrays and Matrices
  • Option Base statement sets the lower bound for
    all arrays.
  • Default value 0 (option base 0)
  • Option Base 1 Set the lower bound value of the
    array as 1.
  • Upper and lower bounds Give a range to array
    indexing.

14
Arrays and Matrices
  • Getting Data into and out of Arrays.
  • Private Sub Command1_Click()
  • Dim Vals(3) As Integer
  • Vals(0) 10
  • Vals(1) 30
  • Vals(2) 50
  • Vals(3) Vals(0) Vals(1) Vals(2)
  • MsgBox Vals(3)
  • End Sub

15
Visual Basic
  • Based on - BASIC
  • (Beginners all purpose symbolic instruction
    codes)
  • Interpreted and compiled language- allows to run
  • programs as it is written.
  • More suited to windowed environment
  • Graphic Based

16
Visual Basic Interface

17
VBScript
  • Based on Visual Basic
  • It is a medium through which HTML documents
    locates and executes Visual Basic ActiveX
    applications.

18
Loops Structures
  • For Next Loop
  • Do Loop
  • Do while.. Loop
  • Do . Loop While
  • Do Until Stop
  • Do . Loop Until

19
Loops Structures ( example)
  • I1
  • S0
  • For I1 to 10
  • ss1
  • Print S
  • Next I


20
Decision Structures
  • If Then
  • If Then Else
  • Select Case
  • Combining Structures

21
Decision Structures (Example)
  • If condition1 then
  • outcome1
  • Else
  • If condition2 then
  • Outcome 2
  • End If

22
Functions and Subroutines
  • Function sends a value called a return value to
    another location in the program when called upon.
  • Subroutines does not send a return value, but
    does perform work through its code.

23
Visual Basic for Application
  • Macro in Excel

24
Macros ArcGIS
  • Visual Basic for Applications (VBA) - embedded in
    ArcMap and ArcCatalog.
  • Allows for writing, debug, and testing of the
    Marco immediately.

25
Example of Marcos in ArcGIS
26
AML (Arc Macro Language)
  • Procedural language
  • Tasks are carried out in a serial order.
  • Used with ArcInfo.

27
AML Example
  • / --------
  • / beep.aml
  • / --------
  • /
  • / Produces an audible 'beep', useful to attract
    attention to errors, etc.
  • /
  • / History
  • / October 1998 Original coding - Stephen Lead
  • /
  • / -----------------------------------------------
    ----------------------------
  • / We need to know what operating system we're
    using.
  • s system extract 1 show os
  • / If it's Windows we use G, which is
    achieved by typing ALT-007.
  • if system Windows_NT then sys echo
  • / For UNIX, the following command will do it.
  • else sys /usr/bin/echo "\07"

28
Avenue
  • Arc View GISs scripting language.
  • An object oriented program language.
  • Provides a higher degree of uniformity, stability
    and reusability.
  • Encapsulation
  • Polymorphism
  • Inheritance

29
Example of Avenue
30
ArcObjects
  • The development plate form for the ArcGIS family
    of applications.
  • Provides an infrastructure for application
    customization
  • Built using Microsofts Object Model technology.

31
Alternatives to ArcGIS
  • MapInfo
  • Software package designed to associate with
    geographical or spatial locations.
  • Used more wide spread in business applications.
  • MapBasic
  • A development environment containing a text
    editor, compiler, linker and online help.
  • The language is structured after VB

32
Alternatives to ArcGIS
  • MapBasic Window

33
References
  • http//www.esri.com/, 2004.
  • Environmental Systems Research Institute, Inc.,
    1997 Understanding GIS The ARC\INFO Method 4th
    eds., Redlands, California.
  • Ralston, B. A., 2002, Developing GIS Solutions
    with MapObjects and Visual Basic OnWord Press,
    Albany, New York.
  • Razavi, A. M., 1999, ArcView GIS/Avenue
    Developers Guide 3rd ed., OnWorld Press,
    Albany, New York.
  • Wells, E., and Harshbarger, S., 1997, Microsoft
    Excel 1997 Developers Handbook Microsoft Press,
    Redmond Washington.
  • Whitener, A., Ryker, B., 1997, MapBasic
    Developers Guide OnWord Press, Santa Fe, New
    Mexico.
Write a Comment
User Comments (0)
About PowerShow.com