PMA\libraries\Util::asWKT PHP Method

asWKT() public static method

Converts GIS data to Well Known Text format
public static asWKT ( string $data, boolean $includeSRID = false ) : string
$data string GIS data
$includeSRID boolean Add SRID to the WKT
return string GIS data in Well Know Text format
    public static function asWKT($data, $includeSRID = false)
    {
        // Convert to WKT format
        $hex = bin2hex($data);
        $wktsql = "SELECT ASTEXT(x'" . $hex . "')";
        if ($includeSRID) {
            $wktsql .= ", SRID(x'" . $hex . "')";
        }
        $wktresult = $GLOBALS['dbi']->tryQuery($wktsql, null, DatabaseInterface::QUERY_STORE);
        $wktarr = $GLOBALS['dbi']->fetchRow($wktresult, 0);
        $wktval = $wktarr[0];
        if ($includeSRID) {
            $srid = $wktarr[1];
            $wktval = "'" . $wktval . "'," . $srid;
        }
        @$GLOBALS['dbi']->freeResult($wktresult);
        return $wktval;
    }

Usage Example

コード例 #1
0
 /**
  * Get data cell for geometry type fields
  *
  * @param string        $column                the relevant column in data row
  * @param string        $class                 the html class for column
  * @param object        $meta                  the meta-information about
  *                                             this field
  * @param array         $map                   the list of relations
  * @param array         $_url_params           the parameters for generate url
  * @param boolean       $condition_field       the column should highlighted
  *                                             or not
  * @param object|string $transformation_plugin the name of transformation
  *                                             function
  * @param string        $default_function      the default transformation
  *                                             function
  * @param string        $transform_options     the transformation parameters
  * @param array         $analyzed_sql_results  the analyzed query
  *
  * @return  string  $cell                  the prepared data cell, html content
  *
  * @access  private
  *
  * @see     _getTableBody()
  */
 private function _getDataCellForGeometryColumns($column, $class, $meta, $map, $_url_params, $condition_field, $transformation_plugin, $default_function, $transform_options, $analyzed_sql_results)
 {
     if (!isset($column) || is_null($column)) {
         $cell = $this->_buildNullDisplay($class, $condition_field, $meta);
         return $cell;
     }
     if ($column == '') {
         $cell = $this->_buildEmptyDisplay($class, $condition_field, $meta);
         return $cell;
     }
     // Display as [GEOMETRY - (size)]
     if ($_SESSION['tmpval']['geoOption'] == self::GEOMETRY_DISP_GEOM) {
         $geometry_text = $this->_handleNonPrintableContents(strtoupper(self::GEOMETRY_FIELD), $column, $transformation_plugin, $transform_options, $default_function, $meta, $_url_params);
         $cell = $this->_buildValueDisplay($class, $condition_field, $geometry_text);
         return $cell;
     }
     if ($_SESSION['tmpval']['geoOption'] == self::GEOMETRY_DISP_WKT) {
         // Prepare in Well Known Text(WKT) format.
         $where_comparison = ' = ' . $column;
         // Convert to WKT format
         $wktval = Util::asWKT($column);
         list($is_field_truncated, $wktval, ) = $this->_getPartialText($wktval);
         $cell = $this->_getRowData($class, $condition_field, $analyzed_sql_results, $meta, $map, $wktval, $transformation_plugin, $default_function, '', $where_comparison, $transform_options, $is_field_truncated, '');
         return $cell;
     }
     // Prepare in  Well Known Binary (WKB) format.
     if ($_SESSION['tmpval']['display_binary']) {
         $where_comparison = ' = ' . $column;
         $wkbval = substr(bin2hex($column), 8);
         list($is_field_truncated, $wkbval, ) = $this->_getPartialText($wkbval);
         $cell = $this->_getRowData($class, $condition_field, $analyzed_sql_results, $meta, $map, $wkbval, $transformation_plugin, $default_function, '', $where_comparison, $transform_options, $is_field_truncated, '');
         return $cell;
     }
     $wkbval = $this->_handleNonPrintableContents(self::BINARY_FIELD, $column, $transformation_plugin, $transform_options, $default_function, $meta, $_url_params);
     $cell = $this->_buildValueDisplay($class, $condition_field, $wkbval);
     return $cell;
 }
Util