SPATIAL-YAP. David Vaz, Michel Ferreira, Ricardo Lopes. DCC-FC & LIACC University of Porto, Portugal

Similar documents
Secrets of the JTS Topology Suite

Analytical and Computer Cartography Winter Lecture 9: Geometric Map Transformations

SVENSK STANDARD SS-ISO :2004. Geografisk information Hantering av enklare objekt Del 1: Arkitektur (ISO :2004, IDT)

Introduction. Computer Vision & Digital Image Processing. Preview. Basic Concepts from Set Theory

pine cone Ratio = 13:8 or 8:5

PostGIS: future developments

09/11/2017. Morphological image processing. Morphological image processing. Morphological image processing. Morphological image processing (binary)

CS 559 Computer Graphics Midterm Exam March 22, :30-3:45 pm

Dgp _ lecture 2. Curves

Measurement and Geometry (M&G3)

Introduction to the Dimensionally Extended 9 Intersection Model (DE-9IM) in PostgreSQL/PostGIS Tutorial

ISO INTERNATIONAL STANDARD. Geographic information Simple feature access Part 1: Common architecture

layers in a raster model

Planar Graphs. 1 Graphs and maps. 1.1 Planarity and duality

Computational Geometry

Graphics and Java 2D Introduction OBJECTIVES. One picture is worth ten thousand words.

Announcements. Data Sources a list of data files and their sources, an example of what I am looking for:

CSCI 4620/8626. Computer Graphics Clipping Algorithms (Chapter 8-5 )

Anoka Hennepin K-12 Curriculum plan

Mathematics 308 Geometry. Chapter 9. Drawing three dimensional objects

You will have the entire period (until 9:00pm) to complete the exam, although the exam is designed to take less time.

Computational Geometry Algorithmische Geometrie

L1-Spatial Concepts L1 - Spatial Concepts

Lofting 3D Shapes. Abstract

CSCI 4620/8626. Coordinate Reference Frames

CS443: Digital Imaging and Multimedia Binary Image Analysis. Spring 2008 Ahmed Elgammal Dept. of Computer Science Rutgers University

M. Andrea Rodríguez-Tastets. I Semester 2008

Curve and Surface Basics

Which n-venn diagrams can be drawn with convex k-gons?

Acute Triangulations of Polygons

morphology on binary images

5 Graphs

Applied Databases. Sebastian Maneth. Lecture 9 Spacial Queries and Indexes. University of Edinburgh - February 13th, 2017

MA 323 Geometric Modelling Course Notes: Day 21 Three Dimensional Bezier Curves, Projections and Rational Bezier Curves

Math 366 Lecture Notes Section 11.4 Geometry in Three Dimensions

Motion Planning. O Rourke, Chapter 8

CS3621 Midterm Solution (Fall 2005) 150 points

5. Introduction to Procedures

Beyond PostGIS. New developments in Open Source Spatial Databases. Karsten Vennemann. Seattle

Practical Linear Algebra: A Geometry Toolbox

Partitioning Orthogonal Polygons by Extension of All Edges Incident to Reflex Vertices: lower and upper bounds on the number of pieces

Geometric Modeling Mortenson Chapter 11. Complex Model Construction

2D rendering takes a photo of the 2D scene with a virtual camera that selects an axis aligned rectangle from the scene. The photograph is placed into

Package geoops. March 19, 2018

Elementary Planar Geometry

Scalar Field Visualization I

Geometry Chapter 8 Test Review

Curriki Geometry Glossary

Geoapplications development Control work 1 (2017, Fall)

Building Models. Objectives Introduce simple data structures for building polygonal models. Vertex lists Edge lists

Computational Geometry. Geometry Cross Product Convex Hull Problem Sweep Line Algorithm

Three applications of Euler s formula. Chapter 10

Grade 6 Math Circles February 19th/20th. Tessellations

Lecture IV Bézier Curves

CS 325 Computer Graphics

9. Three Dimensional Object Representations

EULER S FORMULA AND THE FIVE COLOR THEOREM

γ 2 γ 3 γ 1 R 2 (b) a bounded Yin set (a) an unbounded Yin set

Microsoft SQL Server CLR Types Serialization Formats

Lecture overview. Visualisatie BMT. Fundamental algorithms. Visualization pipeline. Structural classification - 1. Structural classification - 2

Package transformr. December 9, 2018

Intersection of an Oriented Box and a Cone

HMMT February 2018 February 10, 2018

The National Strategies Secondary Mathematics exemplification: Y8, 9

SPACE - A Manifold Exploration Program

Week 7 Convex Hulls in 3D

Simultaneously flippable edges in triangulations

Microsoft SQL Server CLR Types Serialization Formats

TOWARDS A 3D SPATIAL QUERY LANGUAGE FOR BUILDING INFORMATION MODELS

Standard 2.0 Knowledge of Geometry: Students will apply the properties of one-,

Understanding and Working with the OGC Geopackage. Keith Ryden Lance Shipman

Learning Task: Exploring Reflections and Rotations

Glossary of dictionary terms in the AP geometry units

Chapter 8. Properties of Triangles and Quadrilaterals. 02/2017 LSowatsky

Acknowledgement: Scott, Foresman. Geometry. SIMILAR TRIANGLES. 1. Definition: A ratio represents the comparison of two quantities.

Voronoi Diagrams in the Plane. Chapter 5 of O Rourke text Chapter 7 and 9 of course text

Graphics and Interaction Rendering pipeline & object modelling

Abstract We proved in this paper that 14 triangles are necessary to triangulate a square with every angle no more than 72, answering an unsolved probl

EXAMINATIONS 2016 TRIMESTER 2

Course Number: Course Title: Geometry

THE LABELLED PEER CODE FOR KNOT AND LINK DIAGRAMS 26th February, 2015

Tangencies between disjoint regions in the plane

We have set up our axioms to deal with the geometry of space but have not yet developed these ideas much. Let s redress that imbalance.

TWO CONTRIBUTIONS OF EULER

Microsoft SQL Server CLR Types Serialization Formats

Killingly Public Schools. Grades Draft Sept. 2002

3. Here is a stem and leaf plot of the Weights of students in East Junior High Algebra I Class

Representing 2D Transformations as Matrices

CS 763 F16. Moving objects in space with obstacles/constraints.

TEACHER CERTIFICATION STUDY GUIDE KNOWLEDGE OF MATHEMATICS THROUGH SOLVING...1

Unit 3 Transformations and Clipping

Derrick Stolee. April 12,

arxiv: v1 [cs.cg] 2 Jul 2016

Differential Geometry: Circle Patterns (Part 1) [Discrete Conformal Mappinngs via Circle Patterns. Kharevych, Springborn and Schröder]

3D graphics, raster and colors CS312 Fall 2010

Computing NodeTrix Representations of Clustered Graphs

Combining Isometries- The Symmetry Group of a Square

Package sfdct. August 29, 2017

Boundary descriptors. Representation REPRESENTATION & DESCRIPTION. Descriptors. Moore boundary tracking

Geometry. Zachary Friggstad. Programming Club Meeting

Transcription:

SPATIAL-YAP David Vaz, Michel Ferreira, Ricardo Lopes DCC-FC & LIACC University of Porto, Portugal 1 Introduction Spatial Yap results from a interface between three components. The MYDDAS interface, with support to OGC Geometry types, a spatial operators library OGC and a visualization component SIMPLEGRAPHICS. We will next describe the spatial terms and the spatial predicates component, and then the SIMPLE- GRAPHICS component. MYDDAS is already well documented and therefor we will not explain its use. 2 Spatial Terms and Operators The spatial objects, or geometry objects, in prolog follows the OpenGIS standard [?]. The geometry types follow an object oriented scheme described in Figure 1. The attributes, methods, restrictions and prolog representation will be explained next. To use the following predicates we need to load the OGC library, using use module(library(ogc)) prolog call. Geometry Point Curve Surface Geometry Collection Linestring Polygon MultiCurve MultiPoint MultiSurface MultiLinestring MultiPolygon Fig.1. Geometry-types (abstract types in gray). 2.1 Geometry Geometry is root class of the hierarchy, although it is an abstract type all the geometric objects inherits the methods from geometry.

Basic on Geometry ogc envelope(+geometry,-polygon) Returns the rectangle bounding the Geometry as a Polygon. The polygon is defined by the corner points of the bounding box ((MINX,MINY), (MAXX,MINY), (MAXX,MAXY), (MINX,MAXY), (MINX,MINY)). ogc is empty(+geometry) Succeeds if the Geometry corresponds to the empty set. ogc is simple(+geometry) Succeeds if the Geometry is simple. ogc boundary(+geometry,-boundary) Returns the Geometry Boundary. for testing Spatial Relations between geometric objects ogc equals(+geometry1,+geometry2) Succeeds if Geometry1 and Geometry2 are spatially equal. ogc disjoint(+geometry1,+geometry2) Succeeds if Geometry1 and Geometry2 are spatially disjoint, i.e., if the given geometry s do no intersect. ogc touches(+geometry1,+geometry2) Succeeds if Geometry1 spatially touches Geometry2. Two geometries spatially touch if the interior of both geometries do not intersect, but the boundary of one of the geometries intersects either the boundary or the interior of the other. ogc within(+geometry1,+geometry2) Succeeds if Geometry1 is completely within Geometry2. ogc overlaps(+geometry1,+geometry2) Succeeds if Geometry1 spatially overlaps Geometry2. The term spatially overlaps is used if two geometries intersect and their intersection results in a geometry of the same dimension but not equal to either of the given geometries. ogc crosses(+geometry1,+geometry2) Succeeds if Geometry1 spatially crosses Geometry2. The term spatially crosses denotes a spatial relation when two given geometries intersect, and their intersection results in a geometry that has a dimension that is one less than the maximum dimension of the two given geometries, and the intersection is not equal to any of the two given geometries. ogc intersects(+geometry1,+geometry2) Succeeds if Geometry1 spatially intersects Geometry2. ogc contains(+geometry1,+geometry2) Succeeds if Geometry1 is completely contained in Geometry2. that support Spatial Analysis ogc distance(+geometry1,+geometry2,-distance) Returns the shortest Distance between any two points in the two geometries.

ogc buffer(+geometry,+distance,-buffer) Returns a geometry (Buffer) that represents all points whose distance from this Geometry is less than or equal to Distance. ogc convex hull(+geometry,-convexhull) Returns a geometry (ConvexHull) that is the convex hull of this Geometry. ogc intersection(+geometry1,+geometry2,-geometry) Returns the Geometry that represents the point set intersection of Geometry1 with Geometry2. ogc union(+geometry1,+geometry2,-geometry) Returns the Geometry that represents the point set union of Geometry1 and Geometry2. ogc difference(+geometry1,+geometry2,-geometry) Returns the Geometry that represents the point set difference of Geometry1 and Geometry2. ogc symmetric difference(+geometry1,+geometry2,-geometry) Returns the Geometry that represents the point set symmetric difference of Geometry1 and Geometry2. 2.2 Point A Point is a zero-dimensional spatial object, that represents a single location and have two coordinates (x,y). The boundary of a point is empty. In prolog point(x,y). 2.3 Linestring A Linestring is a one-dimensional spatial object and is defined as a list of points with linear interpolation. The list must have at least two points. A Linestring is simple if if does not pass through the same point twice. A Linestring is closed if the start point is equal to the end point. A simple and closed Linestring is a linear ring. The boundary of a Linestring are the end points, except with a closed Linestring where the boundary is empty. In prolog linestring([(x1,y1),(x2,y2) ]), Figure 2 shows some examples of linestrings. ogc length(+linestring,-length) Returns the Length of the Linestring. ogc is closed(+linestring) Succeeds if the Linestring is closed. ogc is ring(+linestring) Succeeds if the Linestring is a ring.

linestring([(1,1),(-1,0),(0,-1),(0,0)]) is simple. linestring([(1,1),(-1,0),(0,-1),(0,1)]) is non-simple. linestring([(1,1),(-1,0),(0,-1),(1,1)]) is simple and closed (linear ring). Fig.2. Examples of linestrings. 2.4 Polygon A Polygon is a two-dimensional spatial object that defines a planar surface. It is defined by one exterior boundary and zero or more interior boundaries. Each interior boundary defines a hole in the Polygon. The Polygon boundaries are defined by linear rings. The boundary of a Polygon consists of the set of linear rings that defines it. There are some more assertions on how to define a valid polygon that can be found in OpenGis standard??. The Prolog representation uses a list of linear rings with at least one linear ring the exterior boundary, which is always the first in the list. Eg. polygon( [Exterior Holes]) see Figure 3 for examples. polygon([[(3,0),(5,3),(6,7),(0,9), (3,7),(3,3),(0,4),(3,0)]]) polygon([[(3,0),(6,3),(6,7),(3,10), (0,7),(0,3),(3,0)], [(3,3),(2,4),(2,6), (3,8),(4,5),(3,3)]]) Fig.3. Examples of polygons ogc area(+polygon,-area) Returns the Area of the Polygon. ogc centroid(+polygon,-point) Returns the mathematical centroid for this Polygon as a Point. The result is not guaranteed to be on this Polygon.

ogc point on surface(+polygon,-point) Returns a Point guaranteed to be on this Polygon. 2.5 Multipoint A Multipoint is a zero-dimensional spatial object, consisting of a list of points with at least one point. A Multipoint is simple if there are no duplicates in the list of points. The boundary of a Multipoint is empty. In Prolog multipoint([point ]), E.g. multipoint([(3,0),(5,3),(6,7), (0,9),(3,7),(3,3),(0,4),(3,0)]). 2.6 Multilinestring A Multilinestring is a one-dimensional spatial object, consisting of a list of linestrings. A Multilinestring is simple if and only if all of its elements are simple and the only intersections between any two elements occur in the elements boundaries. The boundary of a Multilinestring is the set of Points that are boundaries of an odd number of elements. A Multilinestring is closed if all of its elements are closed. In Prolog multilinestring([linestring ]). ogc length(+multilinestring,-length) Returns the Length of the Multilinestring, which is equal to the sum of the lengths of the Multilinestring elements. ogc is closed(+multilinestring) Succeeds if the Multilinestring is closed. 2.7 Multipolygon Multipolygon is a two-dimensional spatial object, consisting of a list of polygons. The Boundary of a Multipolygon is the set of boundaries of its elements. As with Polygon there are some more assertions on how to define a valid Multipolygon that can be found in OpenGis standard??. In Prolog multipolygon([polygon ]). ogc area(+multipolygon,-area) Returns the Area of the Multipolygon, which is equal to the sum of the areas of the Multipolygon elements. ogc centroid(+multipolygon,-point) Returns the mathematical centroid for this Multipolygon as a Point. The result is not guaranteed to be on this Multipolygon. ogc point on surface(+multipolygon,-point) Returns a Point guaranteed to be on this Multipolygon.

2.8 Geometrycollection Geometrycollection is a spatial object consisting of a list of zero or more spatial objects. A Geometrycollection with zero elements represents the empty set. In Prolog geometrycollection([ ]). geometrycollection([ linestring([(0,0),(0,7),(9,7),(9,0),(0,0)]), multilinestring([[(0,3),(1,3)],[(7,3),(9,3)], [(4,6),(4,7)]]), multipolygon([ [[(0,0),(3,0),(1,2),(0,2),(0,0)]], [[(5,0),(7,2),(9,2),(9,0),(5,0)]], [[(0,4),(1,4),(3,6),(3,7),(0,7),(0,4)]], [[(5,7),(9,7),(9,4),(7,4),(5,6),(5,7)]], [[(7,3),(6.4,2.8),(6.4,3.2),(7,3)]], [[(1,3),(1.6,2.8),(1.6,3.2),(1,3)]]]), polygon([[(3,3),(4,4),(5,3),(4,2),(3,3)], [(3.6,3.4),(3.6,2.6),(4.4,2.6), (4.4,3.4),(3.6,3.4)]]) ]) Fig.4. Example of a geometrycollection 3 Visualization of spatial data with simplegraphics This section describes how to visualize spatial data, first we need to load the library using use module(library(simplegraphics)). The module has three major modes, OpenGl, Allegro and Postscript. For now only PostScript is recommended, given that OpenGL and Allegro are not stable. 3.1 Module Initialization and Shutdown sg initialize(+options) This is a backtracable predicate, in the first call it initializes the Spatial module and creates the window where the objects will be displayed. The second call will terminate the use of the window and the module, failing. Options is a list with possibly none of the following options: system(+system) System defines the window type, either opengl, allegro or nowindow (defaults to nowindow); size(+x,+y) defining the window, or the postscript size (defaults to 800x600). color(+r,+g,+b) defining the default color (defaults to white). background(+r,+g,+b) defining the background color (defaults to black) sg shutdown Shutdown the spatial module, and window interface. sg recenter Recenters the spatial module, based in the spatial objects created. sg export(+type,+file) For now only ps is supported as export type. This predicate exports the spatial objects to a postscript file File.

3.2 Drawing spatial Terms Spatial objects are stored in a list, used to display them in the window. They are drawn using the same order as they where created, so the later object will be drawn in front of a previous one. sg create(+geometry) sg create is the main predicate to create spatial objects. Geometry must be a valid spatial object, as described in the previous section. This is a backtracable predicate, but with only two alternatives, the first one inserts the object in the list, the second removes the object from the list, failing. sg color(+red,+green,+blue) Changes the color. The color components are in RGB format varying from 0 to 255. As with the sg create and transformations this is a backtracable predicate, and is also inserted in the list, so only objects inserted afterward are affected by sg color. There are also some alias to the following colors: black, white, red, green, blue, yellow, magenta and cyan. Color alias can be used with sg color/1. 3.3 Transformations We also allow the use of transformations, to simplify the programming process. The transformations are also stored in the list, in the same order as they are inserted, so the transformations will affect all objects created afterward, including other transformations, this will be better explained bellow. All the predicates are similar to sg create, as they are backtracable and have the same alternatives. sg translate(+x,+y) Translates by (X,Y). Arguments must be numbers. sg rotate(+angle) Rotates the objects by Angle in a counter-clockwise direction. Angle is in degrees. sg scale(+x,+y) Scales by (X,Y). sg identity Resets previous transformations, so the next objects or transformations are not affected by them. Transformations order can be tricky, especially in the first approach. Imagine a square centered in the origin, what will be the result of applying a rotation of

1 - Rotate, 2 - Translate. draw :- draw_square, sg_translate(4,0), sg_rotate(45), draw_square. 1 - Translate, 2 - Rotate. draw :- draw_square, sg_rotate(45), sg_translate(4,0), draw_square. Fig.5. Rotating and Translating orders 45 degrees and a translation, and if we apply the translation first? In Figure 5 we have the result. Now lets think about how to specify the transformations. This API was greatly influenced by OpenGL and its matrix scheme. In fact in the software approach we emulate the matrix transformations. Transformations are specified in the reverse order, so the closer transformation is applied first, in Figure 5 the second square to be drawn exemplifies precisely this. 3.4 Interaction between YAP and SPATIAL-YAP Being the window one of the main components of SPATIAL-YAP, we have created a simple way of manipulation of the display aspect. We allow zooming and padding, so it is possible to change the view of the objects. This also releases the programmer from the task of defining the best display of the objects. To have this manipulation we need to have the window working in the same time as YAP, otherwise we would need to pause YAP for displaying purposes, which is not a good idea. Having both systems working in the same time, prolog can be being evaluated in the same time as the user manipulates the window, allowing to have an interactive view of the objects. sg pause, sg pause(+n) Pauses the display for 1/N frame/s. sg yield Gives control to the window, pausing the execution of YAP. When the user presses y in the window, YAP continues, from the point where it was yield.

sg repeat Similar to the standard Prolog repeat. The difference is that it only succeeds while the window exists. 3.5 Examples Hanoi Puzzle We will now show how to animate a simple algorithm with spatial-yap, a typical prolog program to solve Hanoi puzzle is given in Figure 6. hanoi :- move(3, left, right, center). move(0, _, _, _) :-!. move(n, X, Y, Z) :- M is N-1, move(m, X, Z, Y), inform(x, Y), move(m, Z, Y, X). inform(x, Y) :- write( move a disc from the ), write(x), write( pole to the ), write(y), write( pole ), nl. Fig.6. Hanoi Puzzle in Prolog To have this animated, we need to draw poles and disks. Poles can be simple linestrings and disks can be rectangles, this is done with draw pole/0 and draw disk/1 in Figure 7. You might notice that we are creating poles and disks in a generic form, the true position will be given by the transformations. For example, draw base/0 draws the three poles using translations and resets all the transformations with sg identity/1 at the end. The algorithm in Figure 6 does not need to have the global state of the poles. However, to graphically display the disks positions and the transitions from pole to pole we need to have the state of each pole. Also instead of informing the disks changes we will actually change disks from pole to pole. So move/3 will be changed to move/5 receiving a pole list and returning the updated one. At the beginning the state is [1-[1,2,3],2-[],3-[]]. The new move/5 can be seen in Figure 8. Now we only need to draw the solving process. As we want to have an animated version we need to clear the disks positions after any change. We display the disks positions, pause for some time and then fail, to clear the display. We use draw step/1 for this purpose, and display the disks state after each manipulation. In the end we display the disks state and yield the control to the graphics subsystem. The complete code is in Figure 9.

draw_pole :- sg_create(linestring([(0,0),(0,4)])), sg_create(linestring([(-4,0),(4,0)])). draw_disk(n) :- NN is -N, sg_create(polygon([[(nn,0),(n,0),(n,1),(nn,1),(nn,0)]])). draw_base :- draw_pole, sg_translate(8,0), draw_pole, sg_translate(8,0), draw_pole, sg_identity. Fig. 7. Base drawing for Hanoi. move(0, _, _, _, L, L) :-!. move(n, X, Y, Z, LIn, LOut) :- M is N-1, move(m, X, Z, Y, LIn, L1), move_disk(x, Y, L1, L2), move(m, Z, Y, X, L2, LOut). Fig. 8. New move/5.

draw_pole :- sg_create(linestring([(0,0),(0,4)])), sg_create(linestring([(-4,0),(4,0)])). draw_base :- sg_color(red), draw_pole, sg_translate(8,0), draw_pole, sg_translate(8,0), draw_pole, sg_identity, sg_color(white). draw_disk(n) :- NN is -N, sg_create(polygon([[(nn,0),(n,0),(n,1),(nn,1),(nn,0)]])). draw_disks([]). draw_disks([h T]) :- draw_disks(t), draw_disk(h), sg_translate(0,1). draw_disks_list([]). draw_disks_list([_-l T]) :- draw_disks(l), length(l,ll), NLL is -LL, sg_translate(8,nll), draw_disks_list(t). draw_step(l) :- draw_disks_list(l), sg_pause(10), fail. draw_step(_). move_(x,y,[x-[y T] Ts],[X-T Ts]) :-!. move_(x,y,[h T],[H NT]) :- move_(x,y,t,nt). move_disk(x,y,l,nl) :- move_(x,d,l,nl1), move_(y,d,nl,nl1). move(0, _, _, _, L, L) :-!. move(n, X, Y, Z, LIn, LOut) :- M is N-1, move(m, X, Z, Y, LIn, L1), draw_step(l1), move_disk(x, Y, L1, L2), draw_step(l2), move(m, Z, Y, X, L2, LOut), draw_step(lout). hanoi :- sg_initialize([system(allegro)]), draw_base, sg_recenter, L = [1-[1,2,3],2-[],3-[]], move(3,1,2,3,l,sol), draw_disks_list(sol), sg_yield, sg_shutdown. Fig.9. Hanoi Puzzle with spatial yap