1

Re: Questions on locations

Hi,

we want to try out the 'location' entity of indicia. We have some defined sample areas, e.g. monitoring areas. We put the shape files in indicia.
Creating a sample with just a location_id worked, but there is now no geomtry saved with the sample. Is this a bug, or is it meant to be like this? Spatial queries would now require a join on the location table.

Regards

Daniel

2

Re: Questions on locations

I'd normally expect you to submit a sample geometry as well as the location Id. For example, a location might be a large national park, but the sample geometry would be a precise spatial reference. But I guess in your case we could code it so that if the sample geometry is null but there is a location ID then we copy the geometry from the location record. If you want to submit a patch I can't see that causing any problems.
Best wishes

John van Breda
Biodiverse IT

3

Re: Questions on locations

Hi John,

I found time to work on the location/sample thing again. I've decided to post the geom along with the geometry.

My questions are:
* the geometry (geom parameter) must be a WKB?
* the geometry (geom parameter) must be in epsg:900913 or in the one provided with the entered_sref_system parameter?
* i must send a eneterd_seref along with the geomtrey?

I managed to save samples with a geometry, but its never displayed in the backend where I would expect it.

Regards

Daniel

4

Re: Questions on locations

Hi Daniel,

I thought I would try to answer your question to increase my understanding of things but we may need John's help.

When submitting to the warehouse your request is handled by the data service (modules/indicia_svc_data/controllers/services/data.php). It passes through the save, submit and submit_single functions whereupon the appropriate model is instantiated and its submit method called.

The submit method is in the ORM class (application/libraries/MY_ORM.php) which Sample_Model extends. This calls inner_submit which calls preSubmit then validateAndSubmit which calls validate.

Looking at the Sample_Model preSubmit function we see that geom will be calculated from entered_sref and entered_sref_system if it is missing. The value calculated is in WKT using the internal spatial reference system declared in the configuration (application/config/sref_notations.php) which, by default, is 900913.

Looking at the Sample_Model (application/models/sample.php) validate function, we see that there must be an entered_sref, entered_sref_system and geom. There are also validation rules that ensure entered_sref_system is recognised and that entered_sref is valid for that system. (Alternatively a location_id alone will suffice.)

The Sample_Model validate method calls its parent functions and, in ORM_Core::validate, (system/libraries/ORM.php) after validation has actually happened, values are saved in the object before being saved to the database. When values are saved or retrieved from the ORM it uses PHP magic methods, __get and __set which are overloaded in Sample_Model to ensure that while we always handle WKT, the database actually stores WKB.

Typically you would use the functions in the client_helpers library to build a data entry form. Using the the data_entry_helper::sref_textbox and map_helper::map_panel, a hidden control is populated with the geom when the map is clicked. It may be used with the data_entry_helper::sref_system_select if you need to choose between spatial reference systems. I find the comments in the code file the most up to date source of information about the options that can be used with these controls.

If you look at the javascript behind the map panel (media/js/jquery.indiciaMapPanel.js) and find the click handler you'll see that the click point is transformed to the indiciaProjection to create the WKT. The indiciaProjection is hard coded as EPSG:3857 which is the same as 900913. If the entered_sref_system is not the same as the map projection then the Indicia spatial services are called (modules/indicia_svc_spatial/controllers/services/spatial.php) which can transform a point WKT in to a grid square polygon but still represented in 900913.

So, hopefully that allows you to understand the execution path and we have answered your questions in passing:
  - the geom must be in WKT
  - the geom must be in EPSG:900913 unless you have changed the internal spatial reference system.
  - an entered_sref and an entered_sref_system must be sent with a geom but you don't need to send the geom as it will be calculated from the other two values.

I have deduced the above just by reading the code. If I have made a mistake I hope John will correct me.

Jim Bacon.

5

Re: Questions on locations

Spot on Jim, thanks. Sounds like this could be a handy Wiki page...

John van Breda
Biodiverse IT