Programming in GIS 10'11'2005 Using geospatial data - PowerPoint PPT Presentation

1 / 33
About This Presentation
Title:

Programming in GIS 10'11'2005 Using geospatial data

Description:

... (interfaces) are used for different types of data (objects) inheritance ... Object is typically an opaque scalar, which can be used to invoke the methods ... – PowerPoint PPT presentation

Number of Views:25
Avg rating:3.0/5.0
Slides: 34
Provided by: AriJ3
Category:

less

Transcript and Presenter's Notes

Title: Programming in GIS 10'11'2005 Using geospatial data


1
Programming in GIS 10.11.2005Using geospatial
data
  • Object-oriented programming
  • Reading/writing rasters / vector data formats
  • Manipulating geospatial data

2
Object-oriented programming
  • Object
  • Usually a thing created by a program during its
    execution
  • An instance of a class, I.e. an object has an
    identity and a state, and its behaviour is
    defined by its class
  • Class
  • a declaration of data storage space
  • a declaration of a set of methods

3
Jargon
  • polymorphism
  • same definitions (interfaces) are used for
    different types of data (objects)
  • inheritance
  • forming new classes using classes that have
    already been defined
  • information hiding
  • access to object data is only through methods,
    not all methods can be called from everywhere
  • abstract classes
  • used to define generic interfaces

4
Associations between classes
  • inheritance
  • subclass (child c., derived c.) superclass
    (parent c., base c.)
  • multiple inheritance (e.g. not in Java but Java
    has interfaces)
  • hierarchy, inheritance structure
  • other associations
  • containment

5
Notes
  • Object-oriented analysis is an attempt to bring
    ideas from OOP to analysis
  • OOP does not require an OO programming language
  • for example GTK, an OO GUI library is written in
    C (not C)
  • Pure OO languages and hybrid languages

6
OOP in Perl
  • Pure Perl
  • Object is typically a hash blessed to a class
    (package)
  • Perl interface to a library
  • Object is typically an opaque scalar, which can
    be used to invoke the methods

7
Geospatial data and GDAL
8
Geospatial data
  • geospatial data is georeferenced points (places),
    paths (line strings), and areas (polygons) with
    associated attribute data
  • in practice we have raster data and vector data
  • we will use GDAL and OGR (which is a part of GDAL
    library) to access geospatial data

9
GDAL
  • GDAL is a translator library for raster
    geospatial data formats, and OGR provides similar
    capability for simple features vector data
  • GDALs homepage is www.gdal.org
  • current GDAL version is 1.3.1 and it is the first
    version which has the NG scripting language
    support
  • GDAL is the data access engine embedded into most
    of the free GIS programs

10
GDAL data model http//www.gdal.org/gdal_datamode
l.html
11
GDAL-Perl
  • http//map.hut.fi/gdal-perl/

12
XML and beyond
  • XML
  • Parsing XML
  • Schemas
  • GML

13
XML
  • structured document
  • markup (metadata)
  • content (data)
  • programmers point of view
  • nodes
  • node has a name and type
  • node may have attributes
  • node may have a parent, siblings (previous and
    next) and children
  • node may have a value

14
Parsing XML
  • Two main methods
  • parsing into a DOM (Document Object Model,
    w3.org/DOM)
  • which is a tree of nodes
  • event-based parsing (SAX, Simple API for XML,
    sax.sourceforge.net)
  • which reports events to the application through
    callback functions

15
Validity of XML 1
  • Validating input is often a pain
  • is this a number?
  • what about security?
  • what is univeristy?
  • well-formed XML
  • markup is ok
  • characters, tag names, attributes, elements
    close, etc
  • contents is ok
  • character set

16
Validity of XML 2
  • The benefit of a known structure
  • application knows what to look for
  • DTD, XML Schema, RELAX NG, SOX, Schematron
  • structure, context, data types, ...
  • application (its programmer) knows what to look
    for and what to expect

17
Shared ontologies
copy is sent
XML
XML
creates
interprets
XSD
receiver
uses
sender
uses
18
Namespaces 1
  • attribute xmlnssome_prefixsome_URI in the
    document element
  • shows the document creators intent that elements
    whose names are of form some_prefixSome_name are
    created according to certain rules
  • what the rules are, are assumed to be clear from
    the URI
  • further hints may be given with an attribute
    xsischemaLocationsome_URI name_of_the_schema
    (for example)
  • BTW Compare to namespaces in Perl

19
Namespaces 2
  • if everything works out ok,
  • the creator can use a validating parser to make
    sure she is sending a valid document and
  • the receiver can check the received document is
    ok for further processing
  • Remember the schema is in any case hard-coded
    into the applications using the schema

20
GML
  • A namespace with and associated XML schema
    document
  • the schema is written in XML Schema
  • a draft ISO standard
  • an OpenGIS Recommendation Paper
  • now in version 3.1
  • Note the usual xmlnsgmlhttp//www.opengis.net/
    gml does not tell which version is used
  • May be used
  • as one namespace in an XML document
  • as a basis for higher level schemas

21
DB Access
  • 1. Basic SQL and accessing RDBMSs
  • 2. Geographic extensions to SQL

22
Architecture
Server program
Client program
DB library
Data
files in /var/lib/pgsql/...
postmaster
psql
DBI, DBDPg
myprog.pl
www.postgresql.org, man DBI, man DBDPg
23
SQL (1)
  • Creating a table (CREATE TABLE...)
  • Adding a column to a table (ALTER TABLE)
  • Adding a row to a table (INSERT INTO...)
  • Deleting a row from a table (DELETE FROM...)
  • Updating the data in a table (UPDATE...)
  • Querying a table (SELECT...)

24
SQL (2)
  • Joins between tables
  • Aggregate functions
  • Views
  • Keys
  • Transactions
  • Inheritance

25
DB access from Perl
  • use DBI
  • dbh DBI?connect(dbiPgdbnamepingis)
  • die unless dbh
  • sql select from students
  • sth dbh?prepare(sql) or die
  • sth?execute or die
  • for (1..sth?rows)
  • _at_d sth?fetchrow_array

26
Design issues
  • Data model
  • No redundancy
  • Standards
  • Performance
  • Data interface
  • Stability
  • Performance
  • Program code
  • Division of labor with SQL
  • Error checking

27
ODBC
  • Open DataBase Connectivity
  • Standard database access method developed by the
    SQL Access group in 1992
  • Goal access any data from any application
  • Requires a driver for the database system and a
    driver for the application (programming language)
  • ODBC drivers exist for PostgreSQL and for DBI
    (DBDODBC)

28
Extensions to SQL for Geodata
  • Simple Features Specification for SQL
  • Open Geospatial Consortium 1999
  • New column types
  • Point, linestring, polygon, multipoint,
  • New functions
  • For spatial relations, spatial analysis

29
Basic usage
  • Spatial columns are added to tables using OGC
    "AddGeometryColumn" function
  • AddGeometryColumn(lttable_namegt, ltcolumn_namegt,
    ltsridgt, lttypegt, ltdimensiongt)
  • srid the id of the spatial reference system
    used for this coordinate geometry, or -1
  • type the geometry type
  • dimension 1,2,3, or 4

postgis.org
30
Two metadata tables
  • geometry_columns
  • Metadata about spatial columns
  • spatial_ref_sys
  • Spatial reference systems

31
Inserting spatial data
  • In INSERT Using function GeometryFromText(wkt,s
    rid)
  • wkt Well Known Text

32
Retrieving spatial data
  • in SELECT Using function AsText(geometry_column)

33
Design issues
  • Indexes
Write a Comment
User Comments (0)
About PowerShow.com