I am trying to transfer my MapQuest Static Map Formatter to custom module, as I know, that this probably won't be integrated to the main module. The problem is that I need to do some geometry operation for my custom formatter so I need to extend PostgisGeometrySet and PostgisGeometry classes. My code currently looks like this:


/**
 * @file
 * PostGIS MapQuest Static Map geometry classes. Extends postgis.geometry.inc file from PostGIS module.
 */

module_load_include('inc', 'postgis', 'includes/postgis.geometry.inc');

class PostgisMapquestStaticMapGeometrySet extends PostgisGeometrySet {
	
	function mapquest_static_map($result_type) {
    $mapquest_static_map = 0;
    foreach ($this->geometries as $geometry) {
      $mapquest_static_map = $geometry->mapquest_static_map($result_type);
    }
    return $mapquest_static_map;
  }
}

class PostgisMapquestStaticMapGeometry extends PostgisGeometry {
    
  function mapquest_static_map($result_type) {

    $geo = is_null($this->wkt) ? $this->geometry : $this->wkt;
    $centroid_x = db_query("SELECT ST_X(ST_Centroid(:geo))", array(':geo' => $geo))->fetchField();
    $centroid_y = db_query("SELECT ST_Y(ST_Centroid(:geo))", array(':geo' => $geo))->fetchField();
    $centroid= $centroid_y . ',' . $centroid_x;
    $geometry_type = db_query("SELECT ST_GeometryType(:geo)", array(':geo' => $geo))->fetchField();
    $flipped_wkt = db_query("SELECT ST_AsText(ST_FlipCoordinates(:geo))", array(':geo' => $geo))->fetchField();
    // Get lats and lons in format used by MapQuest API
    $latlons = preg_replace('|\s|',',',preg_replace('|.*\(\((.*)\)\)|','$1', $flipped_wkt));
    $bounding_box = db_query("SELECT concat_ws(',',ST_YMin(geo), ST_XMin(geo),ST_YMax(geo),ST_XMax(geo)) FROM (SELECT ST_Buffer(:geo,0.005) AS geo FROM geoserver_liniove_komunikace_view) AS bounding", array(':geo' => $geo))->fetchField();
    switch ($result_type) {
      case 'geometry_type':
        $result = $geometry_type;
        break;
      case 'centroid':
        $result = $centroid;
        break;
      case 'latlons':
        $result = $latlons;
        break;
      case 'bounding_box':
        $result = $bounding_box;
        break;
      default:
        # code...
        break;
    }
    return $result;
  }
}

When I try to use the formatter, I get:
Notice: Undefined property: PostgisMapquestStaticMapGeometrySet::$geometries in PostgisMapquestStaticMapGeometrySet->mapquest_static_map() (line 14 of /var/www/cartaro/sites/all/modules/postgis_mapquest_static_map/includes/postgis_mapquest_static_map.geometry.inc).

I noticed, that in postgis.geomtry.inc there are following property initializations:

class PostgisGeometrySet {

  private $geometries = array();
  private $cardinality, $type, $srid, $multi;

Shouldn't these be set to protected?

Can you, please, point me to an example of extending these classes? Many thanks.

Comments

milos.kroulik’s picture

Issue summary: View changes
milos.kroulik’s picture

Issue summary: View changes