310 likes | 438 Views
GIS 4107 – Day 9. Base data for Canada. The following is perhaps the best link to vector topographic base data for Canada http://geogratis.gc.ca/geogratis/DownloadDirectory Contains CanVec (1:10k – 1:50k), NTDB (1:50k, 1:250k standard topo maps), 1:1M ( VMap Level 0 – based on DCW).
E N D
Base data for Canada The following is perhaps the best link to vector topographic base data for Canada • http://geogratis.gc.ca/geogratis/DownloadDirectory Contains • CanVec (1:10k – 1:50k), • NTDB (1:50k, 1:250k standard topo maps), • 1:1M (VMap Level 0 – based on DCW)
Canada KissMap http://canadakissmap.com/
Overview • The Basics – Python classes and objects • Procedural vs OO Programming • Entity modelling • Operations / methods • Program flow • OOP Concepts and user-defined classes / objects • Class • Object • Python’s self parameter • Overrideable methods __init__ and __str__ • Accessor and mutator methods(“Getter” and “Setter” methods) • Class diagrams in UML
Python programs • A Python program is a sequence of Python statements in one or more files • When a Python program is executing, everything in a Python program is an object • Each object has a type Program output:
Object and Class Object’s type = Class used to create the object Object can also be referred to as an instance of a class.
Each object has … • A type (class that created it) • Identity (location in computer memory) • Data attributes (variables in a class) and/or methods (functions in a class) • Special data attributes and/or methods prefixed and suffixed with a double underscore (e.g. __doc__)
Variables and objects • Variables are names associated with objects • The object's data attributes and methods can be accessed using the dot operator with the name of the data attribute or method dot operator
Special data attributes and methods • Data attributes (e.g. __doc__, __class__, etc) • Methods (e.g. __add__, __str__, etc) NOTE:
Mutable and Immutable objects • If object data attributes can be changed, the object is mutable • If object data attributes cannot be changed, the object is immutable
One object with many names Assignment of variables to the same values means the variables will be associated with the same objects (same identity and type) Output:
Variables with immutable and mutable types • Assigning variables of immutable types to another and then changing either value creates a new object • Assigning variables of mutable types to one another and then changing either value will modify the value of both immutable mutable
The is operator and isinstance function • The is operator checks to see if the identity of the operands is the same • The isinstance(object, class | type | tuple) built-in function returns True or False
To get a list of standard Python classes, etc. help('__builtin__') provides list of built-in classes, functions, and data
Overview • The Basics – Python classes and objects • Procedural vs OO Programming • Entity modelling • Operations / methods • Program flow • OOP Concepts and user-defined classes / objects • Class • Object • Python’s self parameter • Overrideable methods __init__ and __str__ • Accessor and mutator methods(“Getter” and “Setter” methods) • Class diagrams in UML
Procedural Programming Object Oriented Programming(OOP) Proc vs OOP Good for simple programs with simple flows and models Good for complex programs with complex models and interactions. Not good for modelling real-world objects and interactions. Overkill for simple programs.
Entity representation Procedural Programming Object Oriented Programming(OOP) Entities represented by groups of variables Entities represented by abstractions of real-world objects
Methods Procedural Programming Object Oriented Programming(OOP) Operations represented by functions available at module level Operations represented by object methods available at object level Object properties and methods are encapsulated by the object instance.
Procedural Programming Object Oriented Programming(OOP) Program flow Procedural-OOP Hybrid: Program flow controlled by order of creating objects, calling its methods, and setting its properties. OOP: Program flow controlled by messages sent between objects and/or events raised by an object, code that responds to those events. Program flow controlled by order of setting variables, calling functions, and passing data between functions.
OOP Concepts - Class A class is a template for an object. The class defines the data attributes (properties) and methods (functions in a class) that will be common to all objects created from it. Create user-defined classes using classkeyword.
OOP Concepts - Object Instance of a classcreated when the class definition is executed. Every instance of the class will have thesame attributes -- properties and methods -- but can have different data (property values)
Python’s (self) parameter It is a parameter that gets assigned “automatically” to the object being processed. “self” is the first, and sometimes only, parameter in methods Name “self” is Python convention. Could beanything.
__init__ ( self [,params] ) It is the first method run when the class is called. The initialization method or constructor.
__str__( self ) Another of many methods that are common to all classes in Python that you can override(replace default behaviour with your own) Others include: __len__ __add__ __eq__ __lt__ etc.
Accessor (“getter”) method Control getting property values (object data) __private No accessor.
Mutator (“setter”) method Control setting property values (object data) Dice __color : str __value : int setColor(color : str) getColor() : str roll() : void getValue() : int
Class Diagram in UML Key Class name Properties (data attributes) Methods Dice __color : str __value : int setColor(color : str) getColor() : str roll() : void getValue() : int
Overview • The Basics – Python classes and objects • Procedural vs OO Programming • Entity modelling • Operations / methods • Program flow • OOP Concepts and user-defined classes / objects • Class • Object • Python’s self parameter • Overrideable methods __init__ and __str__ • Accessor and mutator methods(“Getter” and “Setter” methods) • Class diagrams in UML