Spatial Intersection Data Definition

The new Spatial Intersection Data Definition will allow you to create a data definition that returns data in a different table from an entity based on a spatial intersection between the two.

The updated bundle can be downloaded from here

The implementation was developed under the assumption that it'll be used in BIRT reports to generate spatial drill down type reports and that there will generally be only one (or at worst a handful of) parent entities, and is not optimised to be used on large numbers of parent entities.

I'm making a note this because while you can create a <data:data> tag to allow display of the data generated on the client, which may be handy for testing/debugging, but if the user selects hundreds of parent entities and tries to display the joined data the process could take a long time to complete.
So it's recommended that, initially at least, this only be used in BIRT reports where a small number of parent entities can be enforced.
This is because the data is generated by iterating over the source entities and performing a spatial join for each row returned.

The basic spatial intersection data definition is something like the following:

Table join with output rows pulled from child table
<?xml version="1.0" encoding="UTF-8"?>
<config	xmlns = "urn:com.cohga.server.config#1.0" xmlns:data = "urn:com.cohga.server.data.database#1.0">
	<data:datadefinition id="spatial.join">
		<spatialintersectiondataconnection entity="parentEntityId" table="childTableName"/>
	</data:datadefinition>
</config>

You'll want to choose appropriate values for "spatial.join", "parentEntityId" and "childTableName".

What this will do is create a new data definition that you can use in a BIRT report to display data from a spatial table called "childTableName" (which would be something like "FLOOD_ZONES" or "WASTE_COLLECTION_DAY") based on the selected entities in the "parentEntityId" entity (which would be something like "property" or "parcel") and it does this based on the intersection of the geometry in the childTableName table and the parentEntityId entities.
Currently the child table needs to be in the same location as the underlying spatial table of the parent entity when specifying a child table directly.

By default the data definition will return all attributes from the underlying spatial table, but when it's added to BIRT you can select only those columns that you actually want to display, so that's not a big issue.

If you want to limit the columns returned then you can add "parameter" tags to describe the columns you want returned, e.g.

Table join with output columns specified directly
<?xml version="1.0" encoding="UTF-8"?>
<config	xmlns = "urn:com.cohga.server.config#1.0" xmlns:data = "urn:com.cohga.server.data.database#1.0">
	<data:datadefinition id="spatial.join">
		<spatialintersectiondataconnection entity="parentEntityId" table="childTableName">
			<parameter name="childColumn1" label="Child Column 1" column="CHILD_COLUMN1"/>
			<parameter name="childColumn2" label="Child Column 2" column="CHILD_COLUMN2"/>
		</spatialintersectiondataconnection>
	</data:datadefinition>
</config>

So then only the 2 columns listed will be returned.

Additionally you can specify a child entity rather than a child table if you already have an entity that represents the table that you're trying to join with, e.g.

Entity join with output columns pulled from child entity
<?xml version="1.0" encoding="UTF-8"?>
<config	xmlns = "urn:com.cohga.server.config#1.0" xmlns:data = "urn:com.cohga.server.data.database#1.0">
	<data:datadefinition id="spatial.join">
		<spatialintersectiondataconnection entity="parentEntityId" targetentity="childEntityId"/>
	</data:datadefinition>
</config>

or with parameters also defined directly

Entity join with output columns defined
<?xml version="1.0" encoding="UTF-8"?>
<config	xmlns = "urn:com.cohga.server.config#1.0" xmlns:data = "urn:com.cohga.server.data.database#1.0">
	<data:datadefinition id="spatial.join">
		<spatialintersectiondataconnection entity="parentEntityId" targetentity="childEntityId">
			<parameter name="childColumn1" label="Child Column 1" column="CHILD_COLUMN1"/>
			<parameter name="childColumn2" label="Child Column 2" column="CHILD_COLUMN2"/>
		</spatialintersectiondataconnection>
	</data:datadefinition>
</config>

Finally it's also possible to specify a buffer that can be applied to the parent geometry before using it to select the child rows, e.g.

Table join with buffer specified for source geometry
<?xml version="1.0" encoding="UTF-8"?>
<config	xmlns = "urn:com.cohga.server.config#1.0" xmlns:data = "urn:com.cohga.server.data.database#1.0">
	<data:datadefinition id="spatial.join">
		<spatialintersectiondataconnection entity="parentEntityId" table="childTableName" buffer="10" bufferUnits="m"/>
	</data:datadefinition>
</config>

Weave 2.6.10 it is possible to specify a bufferCrs value when setting using a buffer to specify what CRS should be used to generate the buffer.

In the above examples "parentEntityId" is the name of an entity that the data is being generated for, based on the selection for that entity, for example if it were "property" then the data will appear as though it's directly related to the "property" entity, even though it's coming from something different, for example a flood area polygon table.
The attributes that are returned come from the "childTableName" table or the table underlying the "childEntityId" entity (as specified by the spatial mapper associated with the child entity).

For information on how to use this data definition in a BIRT report to generate a parent-child drill down report please see the section on Linking Data Sets at Adding Data to BIRT Reports, as the process of creating a parent-child report is exactly the same as described there.