Showing posts with label Spatial. Show all posts
Showing posts with label Spatial. Show all posts

Wednesday, March 5, 2008

Oracle Maps in JDeveloper 11g - Perfectly Fits into Enterprise

Let's get back to Oracle Maps topic again, in this post I will describe how spatial logic in JDeveloper 11g can be combined with traditional non-spatial operations. Before reading this post, I suggest to read my previous post - Oracle Maps in JDeveloper 11g - Even More Simple, I describe there how to develop and run basic Oracle Maps application.

Developed sample application - OraMaps11.zip, demonstrates how Search functionality can be implemented with Spatial technology. I'm using MVDEMO datasource for this application, you can download this datasource from OTN. Sample application implements a form with a table for search results, however there is no traditional search parameters in this form. Search criteria is defined using Oracle Maps functionality. Based on this criteria, query in database is executed and table with results is refreshed. It also allowed to update rows available in results table, changes are reflected in generated map as well.

Ok, let's describe this with pictures. Here you see Oracle Maps screen and table with Search results:


Oracle Maps comes with Circular selection tool, you don't need to develop it, just use it. So, five customers are selected spatially - results table is refreshed and shows information only about those five selected customers:


Now let's select only one customer - EMBARCADERO CENTER 3, Sales here are around 181:


If row contained in results table is updated, related point on the map is updated as well. I have updated Sales to 70, and you can notice it's reflected on the map:


Oracle Maps comes not only with Circular selection, but with Rectangular, Multy-Point and simple Click selection. Rectangular selection:


And refreshed table with selection results:


And it's really not complex to develop all this stuff. There are three main points:

1. Map Theme Selection Listener

I have defined Selection Listener for Customers theme. This listener receives all events related to Customers theme selection:


You can find code for this listener in Backing bean class. Developed code manages keys for selected points, invokes query and executes results table visual refresh.

2. Search results table refresh

When keys for selected points are prepared, selectCustomers method in Model layer is executed to query database and refresh View object:


This method is defined in Page Definition file and is invoked from Backing bean class:


In order to refresh table visually, from Selection Listener available in Backing bean class, it's enough to use only one line of code:

AdfFacesContext.getCurrentInstance().addPartialTarget(this.getTable1());

3. Search results editing

To update edited rows in Search results table, standard Commit action is used. However, it's important here to refresh both after Commit action is done - table and map. So, I have enabled PartialSubmit for Save button and provided PartialTriggering for table and map components pointing to Save button.

In my future posts, I will describe more sample application related to Spatial functionality.

Thursday, February 21, 2008

Oracle Maps in JDeveloper 11g - Even More Simple

With JDeveloper 11g we have standard support for Databound Geographic Maps. This means we don't need anymore to be GIS (Geographic Information System) specialists to enable Location-Based functionality in our enterprise applications. It sounds cool? Yes, but also it works :). It took for me 10 minutes (or little bit more) to develop sample application for this blog post.

Before I will start to describe implemented application, let's remember little bit how it was in JDeveloper 10g. You can check my older blog post - JavaScript in ADF Faces - Oracle Maps. It was easy as well, but it wasn't so elegant as it is now. In JDeveloper 11g you don't need to care about JavaScript or Oracle Maps API, it's because you don't need to develop - just use provided components. And most important, there is no need to deploy developed application on the same OC4J, where Oracle MapViewer is deployed.

You can download developed application - OraMapsSimple11.zip and run it directly from JDeveloper 11g TP3. Base map in this sample is retrieved from open Oracle service - http://elocation.oracle.com/mapviewer, so in order to run application you need to have Internet connection. In this sample I'm using Customers point theme, data for this theme is retrieved from MVDEMO datasource. You can download this datasource from Oracle MapViewer page on OTN.

When I was developing sample application, I discovered that MDSYS.SDO_GEOMETRY object type is not supported yet by map component in current JDeveloper 11g Technology Preview. But no matter of this I wanted to use point theme from my database, so I applied workaround. Workaround is to add two read-only attributes for X and Y coordinates:


As you can notice, I'm accessing information from spatial column directly - using LOCATION.SDO_POINT.X and LOCATION.SDO_POINT.Y definition.

I have generated map area in View layer using steps described in section 25.6 Creating Databound Geographic Maps from Oracle Fusion Middleware Fusion Developer's Guide for Oracle Application Development Framework 11g Release 1. To add point theme to the map, it's needed only to provide required values and click Ok:


If you will not be lazy to run developed sample application, you will notice how cool are Oracle Maps in JDeveloper 11g. To run this application, you need to open it in JDeveloper 11g TP3 and select Run for main.jspx page, you will get similar view:


All functionality available in this screen, comes with standard component in JDeveloper 11g, you don't need to develop it, you can just use it:

Wednesday, December 19, 2007

Oracle Spatial and TopLink 11g

This spring I was blogging about Oracle Spatial object type oracle.spatial.geometry.JGeometry support in TopLink Essentials JPA - Oracle Spatial and TopLink Essentials JPA. But time dont wait, and we already have TopLink 11g that comes with Oracle JDeveloper 11g Technical Preview 2. In TopLink 11g support for JGeometry object type is much simplified and can be used in more convenient way.

Developed sample application - SpatialTopLinkJPA11.zip, contains Model and ViewController projects. In Model part, TopLink 11g is used to build persistence layer. In ViewController part, User Interface is developed with ADF Faces Rich Client. In order to run developed sample application you need to have Oracle MapViewer demo dataset MVDEMO in your database. You can download dataset from OTN and install it into your database as separate schema.

So, what are the main changes comparing to my previous post. Main news - support for Oracle Spatial object type oracle.spatial.geometry.JGeometry mapping and querying is provided out of the box by TopLink 11g. However, its important to know that this support is available with TopLink libraries and not with TopLink Essentials. What you need to do is to:

1. Configure a StructConverter with annotation on any of your entities. This configuration is performed only once for all entities.

@StructConverter(name = "JGeometry", converter = "oracle.toplink.platform.database.oracle.converters.JGeometryConverter")

2. For any attribute that you want to map to a type converted by specified StructConverter, @Convert annotation must be used:

@Convert("JGeometry")
private JGeometry location;

You can find this configuration I have done in Cities entity:


And in fact, its everything related about what developer should care when converting oracle.sql.Struct to oracle.spatial.geometry.JGeometry. Simple, isn't it? :-)

Sample application contains the same logic as one developed previously, queryCitiesSpatially() method in Session bean receives 4 parameters from Client and invokes named query - Cities.sampleQuery:


Named query Cities.sampleQuery is defined in separate class - Cities_SessionCustomizer. This class implements SessionCustomizer and creates expression with SDO_RELATE spatial operator. Class code:


Class with named query should be declared as Session Customizer Class in persistence.xml:


In ViewController project I have used ADF Faces Rich Client that comes with JDeveloper 11g, really amazing thing. One important thing related to ViewController, when I developed everything and was trying to Run application, I got exception - oracle.spatial.geometry.JGeometry class not found. It was quite strange to me, since I have added this library in Model project. Solution was to put sdoapi.jar into this directory - jdevstudio1111\lib\java\shared\oracle.toplink.ojdbc\11.1.1.0.0.

Developed User Interface part looks pretty cool. You can enter values and get result for spatial operator in table below:


In Cities data table you can notice Detach button, this button allows to open table in separate window. However, its not pop-up functionality, its function provided by ADF Faces Rich Client. This function allows to have in the same window several screens:


I think, such simplified Oracle Spatial object type usage in Object-Relational mapping, can greatly improve Spatial integration into enterprise systems.

Monday, November 12, 2007

San Francisco - Oracle OpenWorld

Today is my first day in San Francisco, Oracle OpenWorld Conference. It's amazing, city lives with Oracle spirit during conference days.


My day have started with presentation - Integrating Spatial into Enterprise with Standard Frameworks, I have delivered this presentation at Oracle Spatial SIG meeting. Right after it I was participating in Oracle ACE Director briefing. Topics covered there:
  • Oracle Fusion Middleware Platform Overview
  • Grid Enabled SOA. What's New in SOA
  • Oracle Identity Management
  • Oracle WebCenter
  • Oracle ACE Director Roundtable Discussion
  • Oracle Database Briefing

Monday, November 5, 2007

Presentation at Oracle Spatial SIG during Oracle OpenWorld

During Oracle OpenWorld in San Francisco I will participate in Oracle Spatial SIG meeting. My presentation title - Integrating Spatial into Enterprise with Standard Frameworks. It will be focused mostly on demonstrations of my blog content about JDeveloper, WebCenter, and MapViewer. I will show and explain how Oracle Spatial plugs into Oracle Fusion Middleware.

Meeting time: Sunday, November 11th at 10:00 am - 11:30 am
Meeting place: Moscone West, San Francisco, CA
Room: 2008
Session Code: S292934

Sunday, April 22, 2007

Oracle Spatial and TopLink Essentials JPA

It seems Oracle Spatial functionality can be used successfully with TopLink Essentials JPA also. I have reviewed in detail Doug Clarke (Principal Product Manager for Oracle TopLink) post about how it looks in theory - Oracle Spatial using TopLink Essentials JPA. And, have implemented described steps in practice. I have faced some issues, but final result is successful, I will describe below how I have created sample application for today post - SpatialTopLinkJPA.zip.

Sample application is based on standard schema - MVDEMO, schema contains tables with spatial columns. I'm using CITIES table, this table contains spatial column - LOCATION, column have MDSYS.SDO_GEOMETRY type assigned.

I have passed all three steps described in Doug blog without any problems. I have modified class for mapping customization - name for mapping attribute was changed. Also, I have changed named query definition a little bit - just to adjust it to Cities entity. Of course, you should not forget to change in Cities entity, type for location attribute from String to oracle.spatial.geometry.JGeometry. After that, I have generated Session bean and added a method similar to presented in Doug blog:


The differences are only such, that I'm passing arguments dynamically and returning result using List type. Cities.sampleQuery executes MDSYS.SDO_RELATE spatial operator.

Ok, now we can test implemented Model layer. Everything should be ok, but Oracle JDeveloper 10.1.3.2 gives error when trying to run created sample application:


Upss..., this is quite strange - class defined in persistence.xml configuration file can't be loaded. But, it is possible to solve everything - I have found Issue #: 2432 on glassfish project page, it seems this issue is directly related to my problem and it is solved in Build 37. I have downloaded glassfish JAR file from project download page. I have overwrited TopLink Essentials JPA JAR files available in jdevstudio10132\toplink\jlib directory with Build 37 JAR files. After that I have restarted Oracle JDeveloper 10.1.3.2 - and I got it, there are no errors anymore.

Additionally, I have developed View layer using Oracle ADF Faces components. In View layer it is possible to provide Xmin, Ymin, Xmax and Ymax values, according to provided values Cities data will spatially filtered and returned into table.

Now I will show how it works. At first, we need to know MBR (Minimal-Bounding-Rectangle) of data stored in CITIES table. It is possible to calculate MBR using MDSYS.SDO_AGGR_MBR function. I have executed this function in SQLPlus, also COUNT(*) on CITIES is executed - there are 195 rows in CITIES table:


It is time to start-up OC4J and test application from browser. Here I'm testing with rectangle, whose dimensions are bigger than MBR dimensions - all 195 rows are returned:


Now I have defined smaller window to show how spatial filter works - only 31 rows are returned:


So, there should not be any problems to use spatial functionality in TopLink Essentials JPA. And, this or similar support will be available in the next release of Oracle TopLink, as it is mentioned in Doug Clarke blog post.

When running sample application, don't forget to add adf-faces-impl.jar and jsf-impl.jar to application's WEB-INF\lib directory.

Sunday, April 15, 2007

Oracle Maps portlet in Oracle WebCenter

Oracle WebCenter is a framework, that allows using standard portlets in your Oracle ADF application. Oracle Maps product is a part of Oracle MapViewer, Oracle Maps functionality can be used by provided JavaScript API. It was interesting for me - how it is possible to integrate both? I mean - develop portlet with Oracle Maps functionality and integrate it into Oracle ADF application JSPX page. It seems, this is possible and it works perfectly. So, with Oracle WebCenter you can use spatially enabled portlets directly in Oracle ADF. Download developed sample - MapViewerPortlet.zip.

If you are new to Oracle Maps, it would be helpful to review my previous post - JavaScript in ADF Faces - Oracle Maps. For this sample is used the same spatial datasource - MVDEMO. However, instead of Oracle MapViewer Quickstart Kit, I'm using mapviewer.ear application deployed to WebCenter Preconfigured OC4J. Everything you may need for developing spatially enabled applications can be downloaded from OTN. Detailed information about how to use Oracle WebCenter framework you can find in Oracle WebCenter Framework Tutorial.

Oracle Maps functionality is implemented in portlet view.jsp file using JavaScript code. In view.jsp Oracle Maps JavaScript API file is included, style for map window and it's ID is defined, and lastly map creation code is provided. When those steps are done, developed portlet is integrated and created on map.jspx in standard way, like any other portlet used in Oracle WebCenter framework. Oracle Maps API used in this sample is really simple:


When deploying and running developed application, you should carefully follow steps described in Oracle WebCenter Framework Tutorial - 9 Deploying Your WebCenter Application.

Developed spatial portlet used in Oracle ADF should look similar:


It is possible to refresh or hide it. This functionality is provided by Oracle WebCenter framework.

When running sample application, don't forget to add adf-faces-impl.jar, jsf-impl.jar, custComps.jar and portlet-client-adf.jar to application's WEB-INF\lib directory.

Saturday, February 24, 2007

Oracle Object Types in Oracle ADF

While browsing through OTN JDeveloper forum, I have found a question about how to use Oracle Spatial MDSYS.SDO_GEOMETRY object type with ADF BC. MDSYS.SDO_GEOMETRY object type is described in Oracle Spatial documentation - SDO_GEOMETRY Object Type. So, I have tried to implement support for it in ADF BC using ADF BC Domains - Creating Domains for Oracle Object Types When Useful. It seems, there is enough to generate Entity object from database table - ADF BC domains for spatial column are generated automatically.

I have developed sample application, that shows how to use MDSYS.SDO_GEOMETRY object type in ADF BC applications - ObjectTypeDomain.zip. However, all principles described in this sample, can be applied when using other Oracle Object Types in your applications. Developed sample use standard MVDEMO schema CITIES table, this schema can be downloaded from - Oracle MapViewer Demo Data Set. Model layer is developed using ADF Business Components, in View layer ADF Faces components are used.

When Entity object for CITIES table is created, type for spatial column is generated - SdoGeometry domain. Additionally, SdoPointType domain is generated. SdoPointType is a subdomain for SdoGeometry.


If we will look deeper, and review Java classes generated by Oracle ADF Business Components Design Time, we could find initStructureDef() method in both - SdoGeometry.java and SdoPointType.java. Code in this method represent object type structure. initStructureDef() method code for SdoGeometry domain:


initStructureDef() method code for SdoPointType domain:


There is no any modifications in ADF BC View object and Application Module, everything is created using default properties.

Ok, now we can switch to the View layer and review how users can edit and update data represented by ADF BC domains. Let's start from Data Control Palette - MDSYS.SDO_GEOMETRY object type is included into Data Control, we can explore and use it. Data Control with domain for object type looks like:


Developed sample application contains two pages - cities.jspx and sdoPointEdit.jspx. First page displays attribute cities data, in sdoPointEdit.jspx spatial data for selected city can be updated. Cities table content:


Let's select San Diego city and press 'Edit Geometry' button. Edit form for spatial information (X, Y) is displayed:


For example, we can change Y value to 33.815 and update SanDiego city geographical location ;-).


Ok, how to be sure, and check that spatial data is really updated. I think, we can use good old SQL*Plus and execute a query - 'SELECT C.LOCATION.SDO_POINT.Y FROM CITIES C WHERE C.RANK90 = 6', on CITIES table. Returned result is as we have expected: 33.815. So, operations on Oracle Object Types in ADF BC application can be implemented really easy. SQL*Plus shell window:

Saturday, January 13, 2007

Oracle Maps and ADF Faces af:table component

In this post I will describe how to develop spatially enabled data table using Oracle ADF. If you are new to Oracle Maps and want to know more about this product, you could check my previous post - JavaScript in ADF Faces - Oracle Maps, where I'm describing how to configure Oracle Maps and develop simple spatial application using Oracle ADF, also you will find links to external resources.

Business logic of developed sample - OraMapsWithTable.zip, is to provide a possibility of browsing through a table with cities data and to show selected city on the map. For the data source is used CITIES table from MVDEMO schema. Geometry theme for the CITIES table is declared using Oracle MapBuilder product. Oracle MapViewer, Oracle MapBuilder, MVDEMO schema and other spatial products you can download from - OTN. In the application Model layer EJB and TopLink are used, and ADF Faces components in the View layer.

Ok, if you have successfully deployed and configured MVDEMO schema, Oracle MapViewer and Oracle MapBuidler, it is time to describe how I have developed this sample application.

As you may notice, I'm using cities data, however cities geometry theme declaration doesn't come with MVDEMO. So, we need to declare it. You can declare it in the less than a minute, just use Oracle MapBuilder tool. There are two main things you should define, when declaring geometry theme for cities - hidden info field and query condition. In the hidden info field you should define all fields you want to show in pop-up window when city's point on the map will be clicked. In the query condition, data selection criteria is defined. More information on this topic is available in MapViewer User's Guide section - 8.3.1 Theme-Based FOI Layers. Shortly, cities geometry theme declaration for this application should look like this:


Application Model layer is generated using JDeveloper wizards, and there is no any custom code added. However, I have deleted default session definition and created - oramaps session definition with data source location pointed to jdbc/OraMapsDS data source.

Application View layer contains cities table and map image. Cities table row selection is implemented using af:commandLink component for #{row.city} field. Partial submit is enabled on af:commandLink and partial trigger points to af:panelHorizontal that contains map image. There is no any action or action listener defined on #{row.city} field, for map image update is used JavaScript onclick functionality onclick="showCity(#{row.rank90})". You should notice, that in ADF Faces it is possible to pass value from binding expression, as JavaScript function parameter. showCity(param) function is used to display selected city, function logic is implemented using JavaScript Oracle Maps API. Function source:


I have tested this sample on standalone Oracle Application Server (deployment profile is included into application workspace). Finally, we have a table and a map:


Let's say, we select Milwaukee city in the cities table, then similar map will be displayed:


So, what is better - to have a table or to have spatially enabled table? ;-)

Saturday, January 6, 2007

JavaScript in ADF Faces - Oracle Maps

Inspired by Jeroen van Schaijk article, I have developed simple application with Oracle Maps functionality, that shows how it is easy to use JavaScript in ADF Faces JSPX page. OraMapsSimple.zip, is developed using steps described in tutorial supplied with Oracle Maps. To develop this application, I have used spatial MVDEMO datasource and Oracle MapViewer 10.1.3.1 Quickstart kit, both available on OTN.

Spatial datasource comes with detailed instructions and there was no problem to install it on my Oracle XE (XE supports spatial functionality). When you start Quickstart kit for the first time, Oracle MapViewer deployment process is completed automatically. You can find instructions in Quickstart readme file about how to open Oracle MapViewer homepage and then according to the tutorial - Learning Oracle Maps by Example (it comes with Oracle MapViewer), configure Oracle Maps settings.

So, what about JavaScript? Oracle Maps functionality is reached from JavaScript code, so we need to place a portion of JavaScript somewhere between ADF Faces components. It is quite easy, just include div element for map image and surround it using f:verbatim tag. Script for displaying a map is straightforward (do not forget to include oraclemaps.js, this script comes with Oracle MapViewer).


And, finally we have a map, that displays population density by counties:


With sample application comes deployment profile, which you can use if deploying to Oracle Application Server.

Tuesday, January 2, 2007

Countries boundary data in Oracle Database 11g

It seems, according to the document on OTN - Oracle FAQ: NAVTEQ Digital Map Data for Oracle and to OTN Forum post - Oracle & Navteq FAQ & Countries boundaries, that with Oracle Database 11g will be shipped countries boundary data provided by Navteq. Also, the same map data will be available on OTN for download.

Great! I think, it will be even more easier than now, for non-GIS people to start building BI applications with included Oracle Spatial technology functionality. Developer will have everything out of the box - from data to tools.

Saturday, December 9, 2006

Oracle Spatial and Network Data Model

During this week, a student from university where I'm achieving my master degree - Vincent, have asked me how to create SDO network data model in Oracle Spatial. Before asking me, he has already developed his own network model, but validation error was generated when using SDO_NET.VALIDATE_NETWORK function. When reviewing his data model definition, I have found that network metadata was declared incorrectly.

I have developed a short tutorial, which may be useful when working with Oracle Spatial Network Data Model. Scripts developed for SDO network data model definition - network.zip. Contents of the network.zip archive are:
  1. nodes.sql - creates empty table to store network nodes;
  2. nodes_data.sql - data to be stored in nodes table;
  3. links.sql - creates empty table to store network links;
  4. links_data.sql - data to be stored in links table;
  5. path.sql - creates empty table to store paths data;
  6. path_links - creates empty table to store path links data;
  7. medata.sql - defines metadata for nodes, links and paths spatial columns and metadata for spatial network;
  8. indexes.sql - creates indexes for nodes, links and paths spatial columns;
  9. validate.sql - performs test for network validity, result should be TRUE
When defining SDO network data model, ensure that you have stored correct spatial information in nodes, links and paths tables. And, do not forget to define metadata correctly.

Resources for Oracle Spatial technology: