
\title{GeoSIPAM}
\subtitle{Free and Open Source Software Applied to the Protection of the Brazilian Amazon}
\author{Luis Fernando Bueno, Weberson Gabriel, Pablo Filetti Moreira, Artur Henrique Villa Real F. Ramos, Fabio Augusto das Dores Silva, Marcelo Campos Brito}

\maketitle

\textit{\textbf{Keywords:} Spatial Data, Brazilian Amazon, SIPAM, Infrastructure, GeoSIPAM}


\section{Abstract}
\label{sec:abstract}

This paper presents the infrastructure implemented and maintained by the System of Protection of Amazon - SIPAM for storage and distribution of spatial data called GeoSIPAM. The use of free and open source applications for the storage and distribution of the spatial data was chosen.  The relational database PostgreSQL was chosen, with the PostGIS extension for spatial data storage and manipulation. Several applications (GeoServer, GeoNetwork and InterMap) have been customized for use by SIPAM. The implemented customizations involved procedure development which enhanced the tools used in daily tasks played by the collaborators. The application interface of the GeoNetwork and InterMap were altered aiming at making them accessible and adding features. Care was taken that the infrastructure was adjusted to spatial data storage, manipulation and distribution. The customizations allowed the applications to be merged into SIPAM\'s organizational environment. It was also verified that the use of OGC standards were complied with for interoperability on diverse systems. 

\section{Introduction}
\label{sec:intro}

The database of the System of Protection of Amazon - SIPAM integrates information brought up to date on the Brazilian Legal Amazon. The use of these information in projects developed for the SIPAM and agency partners provides the generation of knowledge that assists the planning and coordination of global actions of government, aiming at the protection, social inclusion and sustainable development of the region. 

This work presents the infrastructure implemented and maintained for SIPAM for storage and distribution of spatial data called GeoSIPAM.  GeoSIPAM aims at providing integration and evaluation of data to aid the planning and the coordination of the actions of the developed public politics in the Brazilian Legal Amazon. Specifically, the objectives of GeoSIPAM are: to display through Internet or Intranet the metadata referring to the projects carried through for SIPAM; to make available Internet maps, geocoded images and related literal information; to visualize maps, images and relevant information for other institutions, through the use of standard compliant Open Geospatial Consortium - OGC \cite{Bueno:2007} protocols

\section{Free and Open Source Software in GeoSIPAM}
\label{sec:FOSS}
The development and use of free software for geoinformatics has made available an increasing number of software tools.  In the designing of GeoSIPAM it was opted to use free and open source software for the storage and distribution of the spatial data. The tools chosen include:

\begin{itemize}
\item PostgreSQL\: Object-relational database management system
\item PostGIS\: Spatial database extension for PostgreSQL
\item GeoServer\: OpenGIS Transactional Web Feature Server
\item GeoNetwork\: Catalog application to manage spatially referenced resources through the web
\item InterMap\: Map viewer, generally configured to operate  of form integrated to the GeoNetwork
\end{itemize}

\section{Infrastructure for Spatial Analysis}
The chosen software architecture was organized in layers involving 
\begin{itemize}
\item a Database Management System (DBMS) for data storage, management and manipulation
\item maps and catalogues servers for data distribution and information
\item as well as interfaces for data access based on the standards established for the OGC.  
\end{itemize}

The PostgreSQL DBMS was chosen, with the PostGIS extension for storage and manipulation of spatial data. The GeoNetwork and InterMap applications interface had undergone alterations aiming to make them accessible and unique.

\begin{figure*}[htb]
  \centering
  \includegraphics[height=0.4\textheight]{proceedings/bueno/intermap.png}
  \caption{Interactive map visualization, usage of the customized InterMap software interface}
  \label{fig:intermap}
\end{figure*}

Figure ~\ref{fig:intermap} presents the visualization of an interactive map in the customized interface of InterMap software.

The GeoServer, GeoNetwork and InterMap, applications are tools developed in Java and implement the Web Map Services (WMS), Web Feature Services (WFS) and Catalogue Service Web (CSW) standards. These were customized for use at SIPAM.  The implemented customizations involved development of procedures that enabled collaborators to carry out daily played tasks. Following are some customizations implemented by the GeoSIPAM team.

Originally InterMap Open Source used to attend the requirements of the standard WMS / OGC, but did not attend to the standard WFS / OGC, both offered by GeoServer. In InterMap Open Source a service was created to carry through WFS service solicitations to GeoServer, making it possible to download raster files.  In this way, an option for the WFS GetFeature service call was developed, in the SHAPE - ZIP format and the service services.map.DownloadService was implemented. Also a corresponding button in the layer toolbar was created, as demonstrated in figure ~\ref{fig:download}.  This functionality was implemented by source code changes, involving JavaScript, XSL and Java programming.

\begin{footnotesize}
\begin{smallverbatim}
public Element exec(Element params, 
      ServiceContext context) throws Exception
{
// Get request parameters
int id = Integer.parseInt(
    params.getChildText(
        Constants.MAP_SERVICE_ID
    ));
	
// Get the MapMerger object from the user session
	MapMerger mm = MapUtil.getMapMerger(context);

// Get the layer name 
	String nome = mm.getService(id).getName();
// Get the WMS server url 
	String serverUrl = mm.getService(id).getServerURL();

// Declare and set the WFS server url
	int pos = serverUrl.indexOf("/wms")+1;
	String WfsFeatureInfoUrl = serverUrl.substring(0, pos) +       "wfs?request=GetFeature&service=WFS&version=1.0.0&outputformat=SHAPE-ZIP&typename=" + nome; 
	Element el = WmsGetCapClient.getCapabilities(serverUrl);

// Return the necessary information for 
// the service execution
	return new Element("response")
	.addContent(WmsGetCapClient.getCapabilities(serverUrl))
	.addContent(new Element("serviceName").setText(nome))
	.addContent(
  new Element(
    Constants.URL).setText(
      WfsFeatureInfoUrl));
}
\end{smallverbatim}
\end{footnotesize}


\begin{figure}[htb]
   \centering
   \includegraphics[width=1\textwidth]{proceedings/bueno/download.png}
   \caption{Customized InterMap interface for the download of layers}
   \label{fig:download}
\end{figure}

The option to offer the layer for download is configured through service WFS. The WFS GetFeature service allows download indiscriminately all the available layers in the server. The option was created to allow/deny the layer download in the cadastre screen of the FeatureType in the GeoServer. This information is also sent to WMS customer through the service getCapabilities. The Download button will be shown in the InterMap whenever the corresponding option is qualified in the GeoServer, as demonstrated in figure ~\ref{fig:customized}.  The functionality was implemented through changes in the GeoServer source code, which is written in Java.

\begin{figure*}[htb]
   \centering
   \includegraphics[width=0.7\textwidth]{proceedings/bueno/customized.png}
   \caption{Customized GeoServer interface for enabling download}
   \label{fig:customized}
\end{figure*}

Another implemented functionality allows the visualization of the data together with images provided by Google Earth API. An inserted button in the InterMap toolbar sets in motion a floating window that shows the spatial data, synchronizing the GeoServer\'s raster data with the Google\'s API images. The position and zoom are kept synchronized even after changes in the Google API window or InterMap maps` window.  The InterMap layers are displayed in the  Google\'s API window in transparent shades, allowing simultaneous viewing of Google\'s images. Figure ~\ref{fig:google} presents the Google API window implemented in InterMap.
This functionality was implemented by the inclusion of JavaScript code in the file im\_main.xsl.  The code line below shows the reference to the Google API, in the file im\_main.xsl:

\begin{footnotesize}
\begin{smallverbatim}
<script 
 src="http://maps.google.com/maps? \
    file=api&v=2&key=GOOGLE_API_KEY" 
 type="text/javascript">
</script>
\end{smallverbatim}
\end{footnotesize}


The term GOOGLE\_API\_KEY should be replaced by the key obtained on the Google API site\footnote{Google API site:  \url{http://www.google.com/apis/maps/}}. To obtain the key you should access the site and provide the server URL where InterMap is installed. The key is sent to the email address of the applicant, who must have a GMail account.
The functions ``addWMS'' and ``montaMapa'' were coded and added to the file im\_main.xsl. The function ``addWMS'' is used to rebuild the list of layers to show the Google API, always when a new layer is added in InterMap. The function ``montaMapa'', is used to construct the Google map. Below is shown the source code of the functions ``addWMS'' and ``montaMapa''.

\begin{footnotesize}
\begin{smallverbatim}
// Add WMS servers and layers types
function addWMS(servidor, camada){
 achou = false;
//Check if the server exists. 
// If it does, add a new layer. 
// If it does not register a new
// server and layer
for (contador = 0; wmsurl.length>contador; contador++){
	if( wmsurl[contador] == servidor) {
// server found.. add layer 
	layersG[contador] = layersG[contador] + ',' + camada
	achou = true;
	}
}
if(!achou) {	
// server not found, register in the vector
	pos = wmsurl.length;
	wmsurl[pos] = servidor;
	layersG[pos] = camada;
	}
	listalayers = listalayers + camada
}

// Set up the google map on the screen
function montaMapa() {
	var camadaWMS = new Array();
	if( visivelG ) {
		mapG = new GMap2(document.getElementById("mapaG"));

// A handler is called when a 
// map movement break event is called
		GEvent.addListener(mapG, "moveend", function() {
// If the movement was done at the Google map, 
// the Intermap map changes too
	if( actOrigem == '' ){
		var center = mapG.getCenter();
		// Obtain the center 
		main.map.zMapCenLat = center.lat();
		// in LatLong
		main.map.zMapCenLng = center.lng();		
		main.map.moveIntermap();
		// moves the Intermap map	
	}
	actOrigem = '';
	if(navm){setTimeout("pngfix()",1000); }
		});
// Handler is called 
// when a drag action event is called
	GEvent.addListener(mapG, "dragstart", function() {
		actOrigem=''
		});

// Handler is called 
// when a zoom event is called
	GEvent.addListener(mapG, "zoomend",  \
	    function(zoomant, zoomatu) {
	if( actOrigem == '') {
		var bbox = mapG.getBounds();
		// Obtain the center
		main.map.zmapminlat = bbox.getSouthWest().lat();
		// em latitude e longitude
		main.map.zmapminlng = bbox.getSouthWest().lng();
		// e move o mapa
		main.map.zmapmaxlat = bbox.getNorthEast().lat();
		main.map.zmapmaxlng = bbox.getNorthEast().lng();
		main.map.zoomIntermap(zoomant, zoomatu);
		// no intermap	
	}
	if (actOrigem != 'X'){actOrigem = '';}
		});
	
// Handler is called 
// when a drag action event is called
		
	var layer1=[G_SATELLITE_MAP.getTileLayers()[0], \ 
	    G_HYBRID_MAP.getTileLayers()[1]];
	var custommap1 = new GMapType(layer1, \ 
	    G_SATELLITE_MAP.getProjection(), \ 
	    "Google", G_SATELLITE_MAP);

	var layer3=[G_SATELLITE_MAP.getTileLayers()[0], \ 
	    G_HYBRID_MAP.getTileLayers()[1]];
			for( contador=0; wmsurl.length > contador; \ 
			contador++){
	// create tile layers
	camadaWMS[contador]= new GTileLayer( \ 
	    new GCopyrightCollection(""),1,17);
	if( wmsurl[contador] != '' ) 
	{ if( layersG[contador] != '') {
		camadaWMS[contador].myLayers=layersG[contador]; 
		camadaWMS[contador].myBaseURL=wmsurl[contador];
		camadaWMS[contador].getTileUrl=CustomGetTileUrl;
		if(navm) {camadaWMS[contador].myFormat='image/png'}
	} }
	layer3[contador+2] = camadaWMS[contador];
	}
	
	var custommap3 = new GMapType(layer3, \ 
	    G_SATELLITE_MAP.getProjection(), \
	    "Intermap", G_SATELLITE_MAP);
		
	mapG.getMapTypes().length = 0;
	mapG.addMapType(custommap3);
	mapG.addMapType(custommap1);
	SWLatLng = new GLatLng(SWLat, SWLng)
	NELatLng = new GLatLng(NELat, NELng)
	bbox     = new GLatLngBounds(SWLatLng, NELatLng)
	zoom     = mapG.getBoundsZoomLevel(bbox)
	gmapt = mapG.getMapTypes()
	zoomMax = \
	    gmapt[1].getMaximumResolution(mapG.getCenter())
	if( zoom > zoomMax) {zoom = zoomMax;}
		actOrigem = 'X'
		mapG.setCenter(bbox.getCenter(),zoom);
		mapG.addControl(new GLargeMapControl());
		mapG.addControl(new GMapTypeControl());
		with(document.getElementById( \ 
		    "google").style){top = "113px";left = "239px";} 
			actOrigem = '' } }
\end{smallverbatim}
\end{footnotesize}


\begin{figure}[htb]
   \centering
   \includegraphics[width=1\textwidth]{proceedings/bueno/googleapi.png}
   \caption{Customized InterMap software interface with Google API}
   \label{fig:google} 
\end{figure}

Because of the great number of layers available in WMS servers, the list layers visualization, when shown as a flat list, becomes inadequate. The display of layers was modified to be loaded in tree form with options of ``collapse'' and ``expand''.  The functionality was implemented by the inclusion of JavaScript code in the file im\_get\_services.xsl. It employed the dTree API, a free JavaScript tree menu. dTree JavaScript can be obtained online.\footnote{dTree JavaScript API: \url{http://www.destroydrop.com/javascripts/tree/}}.  In this case, the strategy adopted was entering the WMS server layers in an array. Thus, the layers tree is mounted by dTree from this array. Figure ~\ref{fig:layers}  demonstrates the layers visualization organized in tree form.

\begin{figure*}[htb]
   \centering
   \includegraphics[width=0.8\textwidth]{proceedings/bueno/layers.png}
   \caption{Customized InterMap interface with list layers vizualization}
   \label{fig:layers} 
\end{figure*}

\section{Results}
\label{sec:results}
An infrastructure was chosen and implemented that insured the capabilities for spatial data storage, manipulation and distribution.  The database was populated with spatial data regarding the Legal Brazilian Amazonia, including topics such as hydrography, geology, use and occupation of land, mineral resources, administrative boundaries, roads, soil, etc. Spatial data from SIPAM\'s other partners, such as the National Agency of Water (ANA) and Brazilian Geological Service (CPRM), Brazilian Institute of Geography and Statistics, IBGE was also stored in GeoSIPAM. The volume of data stored grows every day. Local customizations to available FOSS GIS packages allowed implementing some features into SIPAM which were particular to organizational environment.
It was also verified that the use of OGC standards ensures interoperability with diverse systems. The spatial data and products elaborated for the operational team of the SIPAM are being registered in a cadastre and stored in the GeoSIPAM system.
This information is being distributed in the internal net and also for the public in general, through the SIPAM\'s web portal over the Internet. Among the main partners which constantly access the site are the Environment Secretaries of the State Governments of Amazonia, the Environmental Police, regional universities and others. Implemented statistics controls have logged more than 100,000 hits to GeoSIPAM.


\begin{footnotesize}
\begin{thebibliography}{99}

\bibitem{Bueno:2007} Bueno, L.F., P.G. Zuza e W. Gabriel. GeoSIPAM: Manual do Usu\'{a}rio. Presid\^{e}ncia da Rep\'{u}blica, CENSIPAM, CTO/Pv, 2007, 52 p\'{a}ginas.
\bibitem{Camara:2001} C\^{a}mara G.; C. Davis, e A.M.V. Monteiro. 
\newblock Introdu\c{c}\~{a}o \`{a} Ci\^{e}ncia da Geoinforma\c{c}\~{a}o.  (online). 2001. \url{http://www.dpi.inpe.br/gilberto/livro/introd/}. 14 April 2007
\bibitem{Garnett:2007a} Garnett, J. e C. Holmes. 
\newblock What is Geoserver. (online). 2007. \url{http://docs.codehaus.org/display/GEOS/Home} 10 May 2007.
\bibitem{Geonetwork:2007a} GeoNetwork opensource Community website. (online). 2007. \url{http://geonetwork-opensource.org/} 19 March 2007.
\bibitem{Lamdro:2003} Landr\"{o}, Geir. dTree. (online). 2003. \url{http://www.destroydrop.com/javascripts/tree/} 05 Setembro 2007
\bibitem{Postgresqla} PostgreSQL Global Development Group. 
\newblock PostgreSQL 8.1.0 Documentation. (online). 2005. \url{http://www.postgresql.org/docs/manuals/} 05 May 2007
\bibitem{PostGISa} Refractions Research. PostGIS Manual. (online). 2005. \url{http://postgis.refractions.net/documentation/} 27 March 2007
\bibitem{Wheeler:2007} Wheeler, D.A. 
\newblock Why Open Source Software/Free Software (OSS/FS, FLOSS, or FOSS)? Look at the Numbers! (on line) 
\newblock \url{http://www.dwheeler.com/oss\_fs\_why.html} 03 June 2007


\end{thebibliography}
\end{footnotesize}


\address{Luis Fernando Bueno\\
  System of Protection of Amazon - SIPAM\\
  SPO \'{A}rea 05, Quadra 03, Bloco "K" Bras\'{i}lia - DF\\
  CEP 70610 - 200\\
  \email{luis.bueno AT sipam.gov.br}}

\address{Weberson Gabriel\\
\email{weberson.gabriel AT sipam.gov.br}}

\address{Pablo Filetti Moreira\\
\email{pablo.moreira AT sipam.gov.br}}

\address{Artur Henrique Villa Real F. Ramos\\
\email{artur.ramos AT sipam.gov.br}}

\address{Fabio Augusto das Dores Silva\\
\email{fabio.silva AT sipam.gov.br}}

\address{Marcelo Campos Brito\\
\email{marcelo.brito AT sipam.gov.br}}
