function getData($simplify = true)
 {
     App::import('model', 'DB');
     // App::import('Vendor', 'geoPHP', array('file' => '/phayes/geophp/geoPHP.inc'));
     $this->DB = new DB();
     $data = $this->DB->selectAssocs("SELECT `sid`, GROUP_CONCAT(AsText(polygon_4) SEPARATOR \"\n\") as 'wkts' FROM `pl_gminy_obszary` GROUP BY `sid`");
     $features = array();
     foreach ($data as $d) {
         $wkts = explode("\n", $d['wkts']);
         $geom = geoPHP::load($wkts[0], 'wkt');
         for ($i = 1; $i < count($wkts); $i++) {
             $geom = $geom->union(geoPHP::load($wkts[$i], 'wkt'));
         }
         if ($simplify) {
             // w tej postaci bedzie to nierównomiernie robił w pioniie i poziomie ze względu na CRS (ale roznica wymiarow tylko 2x)
             $geom = $geom->simplify(0.006, true);
         }
         $geojsonConverter = new GeoJSON();
         $geojson = $geojsonConverter->write($geom, true);
         /// debug( $geojson ); die();
         // MpUtils::transposeCoordinates($geojson);
         // debug( $geojson ); die();
         $features[] = array("type" => "Feature", "id" => $d['sid'], "properties" => array(), "geometry" => $geojson);
     }
     $featc = array("type" => "FeatureCollection", "features" => $features);
     MpUtils::geoStampCRS($featc);
     return $featc;
 }
/**
* Zwraca obiekt GeoJson Feature zawierający obszar województwa (cache w redis) wraz z dynamicznie dociąganymi właściwościami
*/
App::import('Vendor', 'geoPHP', array('file' => '/phayes/geophp/geoPHP.inc'));
App::import('model', 'MPCache');
// Try cache
$cacheKey = 'geojson/wojewodztwo/' . $id . ($simplify ? 's' : '');
$cache = new MPCache();
$cacheClient = $cache->getDataSource()->getRedisClient();
if ($cacheClient->exists($cacheKey)) {
    $geojson = json_decode($cache->get($cacheKey));
} else {
    // Build geojson
    $wkt = $this->DB->selectAssoc("SELECT AsWKT(spat) AS wkt FROM wojewodztwa WHERE id = {$id}");
    if (!$wkt['wkt']) {
        return null;
    }
    $spat = geoPHP::load($wkt['wkt'], 'wkt');
    if ($simplify) {
        // w tej postaci bedzie to nierównomiernie robił w pioniie i poziomie ze względu na CRS (ale roznica wymiarow tylko 2x)
        $spat = $spat->simplify(0.005, true);
    }
    $geojsonConverter = new GeoJSON();
    $geojson = $geojsonConverter->write($spat, true);
    MpUtils::transposeCoordinates($geojson);
    // Put in cache
    $cacheClient->set($cacheKey, json_encode($geojson));
}
$feat = array("type" => "Feature", "id" => $this->data['_id'], "properties" => $this->data['data'], "geometry" => $geojson);
MpUtils::geoStampCRS($feat);
return $feat;