\section{The \name\ Abstract Data Type}
\label{sec:proposal}

In this section, we propose \name, an ADT to handle vague spatial objects in a spatial DBMS. \name\ was implemented by using the C language and the extensibility provided by the PostgreSQL internal library. It is based on VASA, and thus, we make use of the spatial operations provided by PostGIS and GEOS to implement the vague spatial data types and their operations. GEOS\footnote{http://trac.osgeo.org/geos/} is a C/C++ library that implements crisp spatial data types and their crisp spatial operations according to the OGC specifications\footnote{http://www.opengeospatial.org/}. A detailed documentation of \name\ is available at \url{http://gbd.dc.ufscar.br/vaguegeometry/}.

This section introduces \name\ as follows. Section~\ref{subsec:representation} details the \name\ data types and their textual and binary representations, while Section~\ref{subsec:operationsPredicates} summarizes the main vague spatial operations and Section~\ref{subsec:nativeSQL} introduces the SQL operators. Finally, Section~\ref{subsec:using} shows examples of using \name\ in a spatial application.

%%%%%%%%%%%%%%%%%%%%%%%

\subsection{Representation of Vague Spatial Objects}
\label{subsec:representation}

Figure~\ref{fig:vaguegeometry_datatypes} depicts vague spatial data types of \name, which can be simple or complex. Simple vague spatial data types named \emph{vague point}, \emph{vague linestring}, and \emph{vague polygon} denote simple vague points, simple vague lines, and simple vague regions, respectively. Complex vague spatial data types named \emph{vague multipoint}, \emph{vague multilinestring}, and \emph{vague multipolygon} denote complex vague points, complex vague lines, and complex vague regions, respectively. We employ this notation to follow the same notation used by the OGC specification for crisp spatial objects. Note that a vague spatial object of \name\ is composed of a pair of disjoint or adjacent crisp spatial objects of the same spatial data type, which are showed in gray in Figure~\ref{fig:vaguegeometry_datatypes}. Figure~\ref{fig:vaguegeometry_objects} shows examples of \name\ objects, that is, instances of vague spatial data types. For vague points and vague regions, black objects denote the kernel part, while gray objects denote the conjecture part. For vague lines, solid lines denote the kernel part, while dashed lines denote the conjecture part.

\begin{figure}[t]
	\begin{center}		
		\includegraphics[width=0.995\textwidth]{figs/vaguegeometry_datatypes}
		\caption{\label{fig:vaguegeometry_datatypes} The vague spatial data types of \name.}
	\end{center}	
\end{figure}

\begin{figure}[t]
	\begin{center}
		\begin{tabular}{c@{\hspace{0.12cm}}c@{\hspace{0.12cm}}c@{\hspace{0.12cm}}c@{\hspace{0.12cm}}c@{\hspace{0.12cm}}c}
			\begin{tabular}{c}
				\includegraphics[scale=0.35]{figs/simple_vaguepoint}
			\end{tabular}
			& \begin{tabular}{c}
				\includegraphics[scale=0.35]{figs/simple_vagueline}
			\end{tabular}
			& \begin{tabular}{c}
				\includegraphics[scale=0.35]{figs/simple_vagueregion}
			\end{tabular}
            & \begin{tabular}{c}
				\includegraphics[scale=0.35]{figs/complex_vaguepoint}
			\end{tabular}
			& \begin{tabular}{c}
				\includegraphics[scale=0.35]{figs/complex_vagueline}
			\end{tabular}
			& \begin{tabular}{c}
				\includegraphics[scale=0.35]{figs/complex_vagueregion}
			\end{tabular} \\
			(a)
			& (b)
			& (c)			
			& (d)
			& (e)
			& (f)
		\end{tabular}
		\caption{\label{fig:vaguegeometry_objects} Examples of \name\ objects according to its data type (Figure~\ref{fig:vaguegeometry_datatypes}): a vague point object (a), a vague linestring object (b), a vague polygon object (c), a vague multipoint object (d), a vague multilinestring object (e), and a vague multipolygon object (f).}
	\end{center}
\end{figure}

In order to insert and retrieve \name\ objects, we propose textual and binary representations for vague spatial objects. We present our proposed representations by first detailing the \emph{textual representations}. They are: (i) \textit{Vague Well-Known Text} (VWKT), (ii) \textit{Vague Geography Markup Language} (VGML), (iii) \textit{Vague Keyhole Markup Language} (VKML), and (iv) \textit{Vague Geographic JavaScript Object Notation} (vGeoJSON). These textual representations are based on the OGC specifications that use the following textual representations for crisp spatial objects: Well-Known Text (WKT), Geography Markup Language (GML), Keyhole Markup Language (KML), and Geographic JavaScript Object Notation (GeoJSON).

The VWKT, VGML, VKML, and vGeoJSON representations are defined as follows. Let $A$ be a VagueGeometry object, which can assume different data types (Figure~\ref{fig:vaguegeometry_datatypes}), formed by the kernel $A_k$ and the conjecture $A_c$. Let $\mathit{name}$ be a function that returns a keyword representing the data type of $A$. For instance, $\mathit{name}(A)$ returns the keyword \texttt{VAGUEPOINT} if $A$ is a vague point object. Finally, let \emph{WKT}, \emph{GML}, \emph{KML}, and \emph{GeoJSON} be functions that get a crisp spatial object as input and return its respective textual representation. The textual representations for a VagueGeometry object $A$ are defined as follows.
%
\begin{ldef}[l@{\hspace{1mm}}r@{\hspace{1mm}}l]
\textrm{(i)}    & \mathit{VWKT}(A) = & \mathit{name}(A)(\mathit{WKT}(A_k); \mathit{WKT}(A_c)) \\
\textrm{(ii)}   & \mathit{VGML}(A) = & \text{$<$vgml:$\mathit{name}(A)$$>$$<$vgml:Kernel$>$$\mathit{GML}(A_k)$$<$/vgml:Kernel$>$}\\
                &                    & \text{$<$vgml:Conjecture$>$$\mathit{GML}(A_c)$$<$/vgml:Conjecture$>$$<$/vgml:$\mathit{name}(A)$$>$} \\
\textrm{(iii)}  & \mathit{VKML}(A) = & \text{$<$vkml:$\mathit{name}(A)$$>$$<$vkml:Kernel$>$$\mathit{KML}(A_k)$$<$/vkml:Kernel$>$}\\
                &                    &
                \text{$<$vkml:Conjecture$>$$\mathit{KML}(A_c)$$<$/vkml:Conjecture$>$$<$/vkml:$\mathit{name}(A)$$>$}\\
\textrm{(iv)}   & \mathit{vGeoJSON}(A) = & \text{\{``type'': ``$\mathit{name}(A)$'', ``kernel'': $\mathit{GeoJSON}(A_k)$, ``conjecture'': $\mathit{GeoJSON}(A_c)$\}}
\end{ldef}
%

Additionally, textual representations can contain the Spatial Reference System Identifier (SRID), which is an unique numerical value that identifies the spatial coordinate system definitions. For the VWKT representation, the SRID is specified by adding its number at the beginning of its representation, and thus, an \emph{Extended}-VWKT format is obtained. For the VGML representation, the SRID is specified by adding the attribute \emph{srsName} in the tag that indicates the \name\ data type. Finally, for the vGeoJSON representation, the SRID is specified by adding the attribute \emph{crs}.

We now move our discussion to the proposed \emph{binary representation}, called \textit{Vague Well-Known Binary} (VWKB). It is based on the Well-Known Binary (WKB) representation for crisp spatial objects documented in the OGC specification. Our VWKB representation is defined as follows. Let $\mathit{id}$ be a function that returns an integer in the binary format symbolizing the data type of $A$. For instance, $\mathit{id}(A)$ returns 1, in the binary format, if $A$ is a vague point object. Let \emph{WKB} be a function that gets a crisp spatial object as input and returns its respective WKB representation. Let $\mathit{endianess}$ be an flag that indicates the way in which the bytes are organized in main memory (that is, either \textit{big-endian} or \textit{little-endian}). The VWKB representation for a VagueGeometry object $A$ is defined as follows.
%
\begin{flushleft}
\begin{ldef}[l@{}l]
\mathit{VWKB}(A) = \mathit{endianess} + \mathit{id}(A) + \mathit{WKB}(A_k) + \mathit{WKB}(A_c),
\end{ldef}
where $+$ denotes the union between the serialized data.
\end{flushleft}

\name\ supports textual and binary representations to allow its use in different spatial applications. Hence, spatial applications based on XML or web services that use XML as communication are able to use the VGML and VKML representations. Web applications that utilize JavaScript as main language are able to use the vGeoJSON representation. Applications that manage binary files are able to use the VWKB representation. Finally, for general purpose, applications can make use of the VWKT representation. It is important to note that these representations also provide interoperability between applications since a vague spatial object has an unique representation. For each \name\ data type (Figure~\ref{fig:vaguegeometry_datatypes}), Tables~\ref{tab:vwkt} and~\ref{tab:vgeojson} show examples of VWKT and vGeoJSON representations, respectively. Note that the same \name\ objects are used in these tables in order to visualize them in different representations. For instance, the same vague point object is used in the tables (first line of each table).

\begin{table}[b]
	\begin{center}
	\caption{\label{tab:vwkt} Examples of VWKT representations.}
		\begin{tabular}{m{3cm}  m{11.5cm}}
		\toprule
		\centering\textbf{\name\ Data Type}		&	\centering\textbf{VWKT Representation of a Vague Spatial Object} \tabularnewline
       \midrule
	   \centering Vague Point					&		
VAGUEPOINT(POINT(0 0); POINT(1 1))\tabularnewline \hline
        \centering Vague LineString					&		
VAGUELINESTRING(LINESTRING(0 0, 1 1, 2 2); LINESTRING(2 2, 3 3))\tabularnewline \hline
        \centering \multirow{2}{*}{Vague Polygon}					&		
VAGUEPOLYGON(POLYGON((1 1, 2 1, 2 2, 1 2, 1 1));\tabularnewline
& ~~~~POLYGON((1 1, 0 1, 0 2, 1 2, 1 1)))\tabularnewline \hline
            \centering Vague MultiPoint					&		
VAGUEMULTIPOINT(MULTIPOINT(1 1, 3 3); MULTIPOINT(2 2, 5 5))\tabularnewline \hline
            \centering \multirow{2}{*}{Vague MultiLineString}					&		
VAGUEMULTILINESTRING(MULTILINESTRING((1 1, 2 2), (3 3, 4 4));\tabularnewline
& ~~~~MULTILINESTRING((2 2, 3 3), (5 5, 6 6)))\tabularnewline \hline
            \centering \multirow{2}{*}{Vague MultiPolygon}					&		
VAGUEMULTIPOLYGON(MULTIPOLYGON(((1 1, 0 1, 0 2, 1 2, 1 1)), ((10 10, 0 10, 0 20, 10 20, 10 10))); \tabularnewline
& ~~~~MULTIPOLYGON(((1 1, 2 1, 2 2, 1 2, 1 1)), ((10 10, 20 10, 20 20, 10 20, 10 10))))\tabularnewline
   \bottomrule 			
		\end{tabular}
	\end{center}
\end{table}


\begin{table}[tb]
	\begin{center}
	\caption{\label{tab:vgeojson} Examples of vGeoJSON representations.}
		\begin{tabular}{m{3cm}  m{11.5cm}}
		\toprule
		\centering\textbf{\name\ Data Type}		&	\centering\textbf{vGeoJSON Representation of a Vague Spatial Object} \tabularnewline
       \midrule
	   \centering \multirow{3}{*}{Vague Point}					&		
$\{$``type'':``VaguePoint'', ``crs'':$\{$``type'':``name'', ``properties'':$\{$``name'':``EPSG:4326''$\}\}$, \tabularnewline
& ~~``kernel'': $\{$``type'': ``Point'', ``coordinates'': [0,0]$\}$, \tabularnewline
& ~~``conjecture'': $\{$``type'': ``Point'', ``coordinates'': [1,1]$\}\}$\tabularnewline \hline
        \centering \multirow{3}{*}{Vague LineString}					&		
$\{$``type'':``VagueLineString'', ``crs'':$\{$``type'':``name'', ``properties'':$\{$``name'':``EPSG:4326''$\}\}$, \tabularnewline
& ~~``kernel'': $\{$``type'': ``LineString'', ``coordinates'': [[0,0],[1,1],[2,2]]$\}$, \tabularnewline
& ~~``conjecture'': $\{$``type'': ``LineString'', ``coordinates'': [[2,2],[3,3]]$\}\}$\tabularnewline \hline
        \centering \multirow{3}{*}{Vague Polygon}					&		
$\{$``type'':``VaguePolygon'', ``crs'':$\{$``type'':``name'', ``properties'':$\{$``name'':``EPSG:4326''$\}\}$, \tabularnewline
& ~~``kernel'': $\{$``type'': ``Polygon'', ``coordinates'': [[[1,1],[2,1],[2,2],[1,2],[1,1]]]$\}$, \tabularnewline
& ~~``conjecture'': $\{$``type'': ``Polygon'', ``coordinates'': [[[1,1],[0,1],[0,2],[1,2],[1,1]]]$\}\}$\tabularnewline \hline
            \centering \multirow{3}{*}{Vague MultiPoint}					&		
$\{$``type'':``VagueMultiPoint'', ``crs'':$\{$``type'':``name'', ``properties'':$\{$``name'':``EPSG:4326''$\}\}$, \tabularnewline
& ~~``kernel'': $\{$``type'': ``MultiPoint'', ``coordinates'': [[1,1],[3,3]]$\}$, \tabularnewline
& ~~``conjecture'': $\{$``type'': ``MultiPoint'', ``coordinates'': [[2,2],[5,5]]$\}\}$\tabularnewline \hline
            \centering \multirow{3}{*}{Vague MultiLineString}					&		
$\{$``type'':``VagueMultiLineString'', ``crs'':$\{$``type'':``name'', ``properties'':$\{$``name'':``EPSG:4326''$\}\}$, \tabularnewline
& ~~``kernel'': $\{$``type'': ``MultiLineString'', ``coordinates'': [[[1,1],[2,2]],[[3,3],[4,4]]]$\}$, \tabularnewline
& ~~``conjecture'': $\{$``type'': ``MultiLineString'', ``coordinates'': [[[2,2],[3,3]],[[5,5],[6,6]]]$\}\}$\tabularnewline \hline
            \centering \multirow{5}{*}{Vague MultiPolygon}					&		
$\{$``type'':``VagueMultiPolygon'', ``crs'':$\{$``type'':``name'', ``properties'':$\{$``name'':``EPSG:4326''$\}\}$, \tabularnewline
& ~~``kernel'': $\{$``type'': ``MultiPolygon'', \tabularnewline
& ~~~~``coordinates'': [[[[1,1],[0,1],[0,2],[1,2],[1,1]]],[[[10,10],[0,10],[0,20],[10,20],[10,10]]]]$\}$, \tabularnewline
& ~~``conjecture'': $\{$``type'': ``MultiPolygon'', \tabularnewline
& ~~~~``coordinates'': [[[[1,1],[2,1],[2,2],[1,2],[1,1]]],[[[10,10],[20,10],[20,20],[10,20],[10,10]]]]$\}\}$\tabularnewline
   \bottomrule 			
		\end{tabular}
	\end{center}
\end{table}

\subsection{Vague Spatial Operations}
\label{subsec:operationsPredicates}

\name\ provides support to \emph{input and output operations}, \emph{vague geometric set operations}, \emph{vague topological predicates}, \emph{vague numerical operations}, and \emph{type-dependent vague spatial operations}. While \emph{input operations} transform textual or binary representations into a VagueGeometry object, \emph{output operations} transform a VagueGeometry object into a textual or binary representation. The SQL signatures for input operations, that consider the VWKT, VGML, VKML, vGeoJSON, and VWKB representations as input, are defined as follows, respectively.
%
\begin{enumerate}[(i)]
	\item \emph{VG\_VagueGeomFromText}(text $\mathit{VWKT}$, integer $\mathit{SRID}$) $\rightarrow$ VagueGeometry
	\item \emph{VG\_VagueGeomFromVGML}(text $\mathit{VGML}$) $\rightarrow$ VagueGeometry
	\item \emph{VG\_VagueGeomFromVKML}(text $\mathit{VKML}$) $\rightarrow$ VagueGeometry
	\item \emph{VG\_VagueGeomFromvGeoJSON}(text $\mathit{vGeoJSON}$) $\rightarrow$ VagueGeometry
	\item \emph{VG\_VagueGeomFromVWKB}(bytea $\mathit{VWKB}$, integer $\mathit{SRID}$) $\rightarrow$ VagueGeometry
\end{enumerate}

The SQL signatures for output operations of the VWKT, VGML, VKML, vGeoJSON, and VWKB representations are defined as follows, respectively.

\begin{enumerate}[(i)]
	\item \emph{VG\_AsText}(VagueGeometry $\mathit{vg}$) $\rightarrow$ text
	\item \emph{VG\_AsVGML}(VagueGeometry $\mathit{vg}$) $\rightarrow$ text
	\item \emph{VG\_AsVKML}(VagueGeometry $\mathit{vg}$) $\rightarrow$ text
	\item \emph{VG\_AsVGeoJSON}(VagueGeometry $\mathit{vg}$) $\rightarrow$ text
	\item \emph{VG\_AsVWKB}(VagueGeometry $\mathit{vg}$) $\rightarrow$ bytea
\end{enumerate}

Vague geometric set operations get two VagueGeometry objects as input and yield another VagueGeometry object. \name\ implements \emph{vague geometric union}, \emph{vague geometric intersection}, and \emph{vague geometric difference}. These operations have the following SQL signatures. Note that we are able to use the vague geometric union operation in (ii) as an aggregation function.

\begin{enumerate}[(i)]
	\item \emph{VG\_Union}(VagueGeometry $\mathit{vg1}$, VagueGeometry $\mathit{vg2}$) $\rightarrow$ VagueGeometry
	\item \emph{VG\_Union}(VagueGeometry $\mathit{vg}$) $\rightarrow$ VagueGeometry
	\item \emph{VG\_Intersection}(VagueGeometry $\mathit{vg1}$, VagueGeometry $\mathit{vg2}$) $\rightarrow$ VagueGeometry
	\item \emph{VG\_Difference}(VagueGeometry $\mathit{vg1}$, VagueGeometry $\mathit{vg2}$) $\rightarrow$ VagueGeometry
\end{enumerate}

Regarding vague topological predicates, \name\ supports \emph{vague contains}, \emph{vague coveredBy}, \emph{vague covers}, \emph{vague crosses}, \emph{vague disjoint}, \emph{vague equals}, \emph{vague inside}, \emph{vague intersects}, \emph{vague meets}, and \emph{vague overlap}. These predicates are based on the three-valued logic, and can return \emph{true}, \emph{false}, or \emph{maybe}. A predicate returns \emph{true} if a relationship \emph{certainly} occurs, \emph{false} if a relationship \emph{certainly not} occurs, and \emph{maybe} if a relationship \emph{occurs to some extent}. To deal with it, \name\ also includes the VagueBool data type. As a result, a VagueBool object can assume \emph{true}, \emph{false}, or \emph{maybe} as value, which correspond to the possible return values of vague topological predicates. In addition, it is possible to use crisp spatial objects as input, which is handled as a vague spatial object containing only the kernel part. The vague topological predicates have the following SQL signatures.

\begin{enumerate}[(i)]
	\item \emph{VG\_Contains}(VagueGeometry $\mathit{vg1}$, VagueGeometry $\mathit{vg2}$) $\rightarrow$ VagueBool
	\item \emph{VG\_CoveredBy}(VagueGeometry $\mathit{vg1}$, VagueGeometry $\mathit{vg2}$) $\rightarrow$ VagueBool
	\item \emph{VG\_Covers}(VagueGeometry $\mathit{vg1}$, VagueGeometry $\mathit{vg2}$) $\rightarrow$ VagueBool
	\item \emph{VG\_Crosses}(VagueGeometry $\mathit{vg1}$, VagueGeometry $\mathit{vg2}$) $\rightarrow$ VagueBool
	\item \emph{VG\_Disjoint}(VagueGeometry $\mathit{vg1}$, VagueGeometry $\mathit{vg2}$) $\rightarrow$ VagueBool
	\item \emph{VG\_Equals}(VagueGeometry $\mathit{vg1}$, VagueGeometry $\mathit{vg2}$) $\rightarrow$ VagueBool
	\item \emph{VG\_Inside}(VagueGeometry $\mathit{vg1}$, VagueGeometry $\mathit{vg2}$) $\rightarrow$ VagueBool
	\item \emph{VG\_Intersects}(VagueGeometry $\mathit{vg1}$, VagueGeometry $\mathit{vg2}$) $\rightarrow$ VagueBool
	\item \emph{VG\_Meets}(VagueGeometry $\mathit{vg1}$, VagueGeometry $\mathit{vg2}$) $\rightarrow$ VagueBool
	\item \emph{VG\_Overlap}(VagueGeometry $\mathit{vg1}$, VagueGeometry $\mathit{vg2}$) $\rightarrow$ VagueBool
\end{enumerate}

Vague numerical operations supported by \name\ are: \emph{vague area of a vague region object}, \emph{vague length of a vague line object}, and \emph{farthest} and \emph{nearest distance between two vague spatial objects}. These operations return two numeric values, which symbolize the minimum and the maximum values of an operation. To deal with it, \name\ also includes the VagueNumeric data type. As a result, a VagueNumeric object is composed of a pair of double values, which correspond to the minimum and the maximum values returned by vague numerical operations. The vague numerical operations have the following SQL signatures.

\begin{enumerate}[(i)]
	\item \emph{VG\_Area}(VagueGeometry $\mathit{r}$) $\rightarrow$ VagueNumeric
	\item \emph{VG\_Length}(VagueGeometry $\mathit{l}$) $\rightarrow$ VagueNumeric
	\item \emph{VG\_NearestDistance}(VagueGeometry $\mathit{vg1}$, VagueGeometry $\mathit{vg2}$) $\rightarrow$ VagueNumeric
	\item \emph{VG\_FarthestDistance}(VagueGeometry $\mathit{vg1}$, VagueGeometry $\mathit{vg2}$) $\rightarrow$ VagueNumeric
\end{enumerate}

Finally, regarding type-dependent vague spatial operations, \name\ supports \emph{common border between two vague region objects} and \emph{common points between two vague line objects}. They have the following SQL signatures.

\begin{enumerate}[(i)]
	\item \emph{VG\_CommonBorder}(VagueGeometry $\mathit{r}$, VagueGeometry $\mathit{r}$) $\rightarrow$ VagueGeometry
	\item \emph{VG\_CommonPoints}(VagueGeometry $\mathit{l}$, VagueGeometry $\mathit{l}$) $\rightarrow$ VagueGeometry
\end{enumerate}

As can be noted, our proposed \name\ implements an expressive set of vague spatial operations, which includes the specification of vague geometric set operations, vague topological predicates, vague numerical operations, and type-dependent vague spatial operations.

\subsection{SQL Operators}
\label{subsec:nativeSQL}

We propose SQL operators to handle VagueBool and VagueNumeric objects, that is, the result of vague topological predicates and vague numerical operations, respectively. For the vague topological predicates, we propose the \emph{logical operators} \emph{and} (\&\&), \emph{or} ($||$), and \emph{not} ($!$), and the \emph{boolean operators} $\sim$, $\sim\sim$, and $\&$. Logical operators employ the three-valued logic, which is showed in Table~\ref{tab:tvl}. They get VagueBool objects as input and yield another VagueBool object.

\begin{table}[bt]
	\begin{center}
	\caption{\label{tab:tvl} Truth tables of the three-valued logic. The logical operators \emph{and} (\&\&) and \emph{or} ($||$) are commutative and showed in (a) while the operator \emph{not} ($!$) is showed in (b).}
		\begin{tabular}{c@{\hspace{1cm}}c}
			\begin{tabular}{c c c c}	
       \toprule	
		       \centering\textbf{VagueBool \emph{a}} & \centering\textbf{VagueBool \emph{b}} & \textbf{\emph{a}} \&\& \textbf{\emph{b}} & \textbf{\emph{a}} $||$ \textbf{\emph{b}}\tabularnewline
       \midrule
	           true    & true   & true     & true\tabularnewline
               true    & false  & false    & true\tabularnewline
               true    & maybe  & maybe    & true\tabularnewline
               false   & false  & false    & false\tabularnewline
               maybe   & maybe  & maybe    & maybe\tabularnewline
       \bottomrule 			
		   \end{tabular}
			& \begin{tabular}{c c c c}	
       \toprule	
		       \centering\textbf{VagueBool \emph{a}} & \centering\textbf{$!$\emph{a}}\tabularnewline
       \midrule
	           true    & false \tabularnewline
               false   & true  \tabularnewline
               maybe   & maybe \tabularnewline
       \bottomrule 			
		   \end{tabular} \\
			(a)
			& (b)
		\end{tabular}
	\end{center}
\end{table}

Boolean operators are unary operators that get a VagueBool object as input and have true or false as possible return values. Hence, a boolean operator transforms a vague topological predicate into a boolean condition. Let $a$ be a VagueBool object. The operator $\sim$ yields true if the $a$ is \emph{true} or \emph{maybe}, and false otherwise. The operator $\sim\sim$ yields true if $a$ is \emph{maybe}, and false otherwise. The operator \& yields true if $a$ is \emph{true}, and false otherwise.

By using logical and boolean operators, we are able to use them in SQL queries. For instance, we can evaluate if two VagueGeometry objects \emph{maybe} overlap by specifying the condition ``$\sim\sim$\textit{VG\_Overlap}(\textit{vg1}, \textit{vg2})''. We can even combine logical and boolean operators in an unique condition. For instance, the condition ``$\sim$(\textit{VG\_Meets}(\textit{vg1}, \textit{vg2}) $||$ \textit{VG\_Overlap}(\textit{vg1}, \textit{vg2}))'' indicates that the VagueGeometry objects $vg1$ and $vg2$ possibly meet \emph{or} overlap.

Regarding the vague numerical operations, we propose the binary operators~$=$~and~$\sim$, which get a VagueNumeric object and a numeric value as inputs and yield true or false. Let $v$ be a VagueNumeric object. Let $n$ be a numeric value. The operator~$=$~yields true if $n$ is equal to the minimum value of $v$, and false otherwise. The operator~$\sim$~yields true if $n$ is between the minimum and the maximum value of $v$, and false otherwise. For instance, users can use this operator to specify the condition ``\textit{VG\_Area}($\mathit{r}$) $\sim$ 800'' in a SQL query to restrict vague region objects in the attribute $r$ that have approximately 800 of area.

\subsection{Running Example}
\label{subsec:using}

In this section, we introduce a running example in order to show how to use the \name\ ADT in a spatial application. Figure~\ref{fig:re} depicts our running example, which is based on an agriculture environment. This application manages soil textures, farms, lakes, animal routes, and plagues that are represented by the relational table schemas \emph{texture}, \emph{farm}, \emph{lake}, \emph{animal}, and \emph{plague}, respectively. Soil textures, farms, and lakes are represented by complex vague region objects, while animal routes are represented by complex vague line objects and plagues are represented by complex vague point objects. Each table has an attribute \emph{id} as primary key and an attribute \emph{geo} to store its \name\ object. In the following, we show the SQL command to create the table \emph{plague}. Note that the data type of the attribute \emph{geo} is vague multipoint since a plague is represented by a complex vague point object. We specify this by using the name of the \name\ data type between parentheses.
%
\begin{quote}
\begin{verbatim}
CREATE TABLE plague (
  id INTEGER PRIMARY KEY,
  geo VAGUEGEOMETRY(VAGUEMULTIPOINT))
\end{verbatim}
\end{quote}

\begin{figure}[t]
	\begin{center}		
		\includegraphics[width=0.75\textwidth]{figs/runningexample}
		\caption{\label{fig:re} Running example based on an agriculture environment. Darker colors and solid lines denote kernel parts while lighter colors and dashed lines denote conjecture parts.}
	\end{center}	
\end{figure}

We are able to similarly define the other tables, that is, \emph{texture}, \emph{farm}, \emph{lake}, and \emph{animal}. Once we have defined all the tables, we are able to insert \name\ objects by using textual or binary representations (Section~\ref{subsec:representation}) in SQL insert commands. For instance, in the following SQL command, we insert the vague multipoint object from Table~\ref{tab:vwkt} in the table \emph{plague}.
%
\begin{quote}
\begin{verbatim}
INSERT INTO plague(1, VG_VagueGeomFromText(
         'VAGUEMULTIPOINT(MULTIPOINT(1 1, 3 3); MULTIPOINT(2 2, 5 5))', 4326))
\end{verbatim}
\end{quote}

Once we have inserted \name\ objects, we are able to handle them in SQL queries. The first query asks for all points in each farm threatened by plagues. This query employs the vague geometric union as an aggregate function on the all plagues. Then, we perform the intersection between this result and each farm. Finally, we show the result by using the VWKT representation.
%
\begin{quote}
\begin{verbatim}
SELECT VG_AsText(VG_Intersection(U.mp, F.geo)), F.id
FROM (SELECT VG_Union(geo) as mp FROM plague) as U, farm as F
\end{verbatim}
\end{quote}

The following query returns the common borders and intersection parts between farms and lakes. This means that the common border operation yields lines, while the vague geometric intersection yields regions. The result of these operations are represented by the vGeoJSON representation and indicate critical places for the farms since the water of a lake can invade a farm.
%
\begin{quote}
\begin{verbatim}
SELECT VG_AsVGeoJSON(VG_CommonBorder(F.geo, L.geo)),
       VG_AsVGeoJSON(VG_Intersection(F.geo, L.geo))
FROM farm as F, lake as L
\end{verbatim}
\end{quote}

The next query asks for the all farms that could be threatened by animal routes since the nearest distance between them is approximately 500. To restrict this, we make use of the operator $\sim$.
%
\begin{quote}
\begin{verbatim}
SELECT F.id, A.id
FROM farm as F, animal as A
WHERE VG_NearestDistance(F.geo, A.geo) ~ 500
\end{verbatim}
\end{quote}

The next query is a \emph{vague spatial range query} that returns the soil textures that maybe or certainly intersects with a window query $QW$. The window query $QW$ is a \name\ object, which can be composed of one or more objects in the kernel part and one or more objects in the conjecture part. Further, they are rectangular shaped. Aiming to restrict the returning value of the predicate, we employ the boolean operator $\sim$.
%
\begin{quote}
\begin{verbatim}
SELECT T.id
FROM texture as T
WHERE ~VG_Intersects(T.texture, QW)
\end{verbatim}
\end{quote}

The final query is a \emph{vague spatial join} that returns all pairs of farms and animal routes that certainly overlap, which means that these farms and animals need to be carefully examined. For this query, we employ the boolean operator \& to specify that the result be equal to true.
%
\begin{quote}
\begin{verbatim}
SELECT F.id, A.id
FROM farm as F, plague as P, animal as A
WHERE &VG_Contains(F.geo, A.route)
\end{verbatim}
\end{quote} 