TDDP Spatial Module
TDDP spatial module is a plugin to ANDS registry software. It basically contains two classes, Metadata and Region.
The TERN spatial module is located at registry/registry_object/modules folder. ANDS registry software searches this folder for any modules and then add metadata values returned by theses modules to their standard json API output.
Metadata Class
The Metadata class collects TERN specific information from solr index and mysql spatial module using solr search query and mysql spatial query. These information will be appended to ANDS api json documents.
append_roapi()
This function collects the registry objects' modified date, description and licence type from MySQL database and append these information to ANDS existing JSON document returned by ANDS API query. The values collected are TERN specific.
append_index()
This function is similar to append_roapi(). Instead of querying MySQL database, it queries Solr index for the required values. This is because the values needed only available in solr index.
getRegion()
Each record in TDDP belongs to one or more predefined regions. This function returns all the regions id for this registry record. This function is called when creating solr index during harvest.
populateIndex()
This function populates the registry record with all standard metadata value except those TERN specific ones.
getDateModified()
Collects the modified date for TERN data.
getLicenceType()
Get TERN licence type for registry record.
getDescription()
Get description for a registry record
doIntersect()
Each registry record which has a spatial coordinate belongs to one or more regions. The spatial coordinates could be a line, point or a shape. If the spatial coordinates intersect a region's coordinates, that region id will be returned. This spatial query is performed in Solr thus, all query syntax must be solr readable.
intersect()
This function takes in a lat,lon value and an optional layer id as parameter. It uses MySQL query. If layer id is provided, it returns the regions within the layer. If layer id is absent, it will return regions across all layers.
intersectLine()
It uses MySQL LINESTRING to build a line based on the given coordinates and returns all regions which intersects with the line. If layer id is provided in the parameter, it will only return regions within the layer.
intersectPoly()
Similar to intersectLine, but it builds a polygon instead of line.
Region Class
The Region class take cares of region based search. It currently contains two functions getRegion()and searchPoly().
The getRegion function is mainly used by the region facet in TDDP portal. By passing the TDDP region layer IDs to this function, it will query mysql database 'tern_spatial' and return all the region names and IDs.
function getRegion($l_id) { $sql = 'SELECT r_id, r_name from regions WHERE l_id=? ORDER BY r_name ASC'; $q = $this->sdb->query($sql, array($l_id)); if($q->num_rows() > 0) return $q->result(); else return array(); }
The searchPoly function returns all records within a given geometry. It queries the solr index using lucene syntax. When user draw a polygon or rectangle bounding box on the map, the geometry of the polygon is then passed to this function.
function searchPoly($geometry){ $ci =&get_instance(); $ci->load->library('Solr'); $ci->solr ->init() ->setOpt('fq', '+class:collection') ->setOpt('fq', '+spatial_coverage_extents:"Contains(Polygon(('.$geometry.'))) distErrPct=0"') ->setOpt('rows', 100) ->setOpt('fl', '*,score'); $result = $ci->solr->executeSearch(true); if ($result['response']['numFound'] > 0) { return $result['response']['docs']; } else { return null; } }