public function test() { $this->initContext(); $this->assertEquals(false, RestoGeometryUtil::isValidGeoJSONFeature(null)); $this->assertEquals(false, RestoGeometryUtil::isValidGeoJSONFeature(array('type' => 'toto'))); $this->assertEquals(false, RestoGeometryUtil::isValidGeoJSONFeature(array('type' => 'Feature', 'geometry' => 'toto'))); $this->assertEquals(false, RestoGeometryUtil::isValidGeoJSONFeature(array('type' => 'Feature', 'geometry' => array()))); $this->assertEquals(false, RestoGeometryUtil::isValidGeoJSONFeature(array('type' => 'Feature', 'geometry' => array(), 'properties' => 'toto'))); $this->assertEquals(true, RestoGeometryUtil::isValidGeoJSONFeature(array('type' => 'Feature', 'geometry' => array(), 'properties' => array()))); $this->assertEquals(null, RestoGeometryUtil::geoJSONGeometryToWKT(array('type' => 'toto', 'coordinates' => array()))); $this->assertEquals('POINT()', RestoGeometryUtil::geoJSONGeometryToWKT(array('type' => 'POINT', 'coordinates' => array()))); $this->assertEquals('MULTIPOINT()', RestoGeometryUtil::geoJSONGeometryToWKT(array('type' => 'MULTIPOINT', 'coordinates' => array()))); $this->assertEquals('LINESTRING()', RestoGeometryUtil::geoJSONGeometryToWKT(array('type' => 'LINESTRING', 'coordinates' => array()))); $this->assertEquals('MULTILINESTRING()', RestoGeometryUtil::geoJSONGeometryToWKT(array('type' => 'MULTILINESTRING', 'coordinates' => array()))); $this->assertEquals('POLYGON()', RestoGeometryUtil::geoJSONGeometryToWKT(array('type' => 'POLYGON', 'coordinates' => array()))); $this->assertEquals('MULTIPOLYGON()', RestoGeometryUtil::geoJSONGeometryToWKT(array('type' => 'MULTIPOLYGON', 'coordinates' => array()))); $this->assertEquals(8.863358410694E-5, RestoGeometryUtil::radiusInDegrees(10, 10)); $this->assertEquals(array(8.9831528424457E-5, 0.00017966305685804), RestoGeometryUtil::inverseMercator(array(10, 20))); $this->assertEquals(null, RestoGeometryUtil::inverseMercator(array(10))); $this->assertEquals(null, RestoGeometryUtil::inverseMercator('toto')); $this->assertEquals(null, RestoGeometryUtil::forwardMercator('toto')); $this->assertEquals(null, RestoGeometryUtil::forwardMercator(array(90, -90))); $this->assertEquals(null, RestoGeometryUtil::forwardMercator(array(90, 90))); $this->assertEquals(null, RestoGeometryUtil::bboxToMercator(null)); $this->assertEquals('1113194.9077778,1118889.9747022,1113194.9077778,1118889.9747022', RestoGeometryUtil::bboxToMercator('10,10,10,10')); }
/** * Return a RESTo keywords array from an iTag Hierarchical feature * * @param array $properties * @param array $geometry (GeoJSON) */ private function keywordsFromITag($properties, $geometry) { /* * Initialize keywords array from faceted properties */ $keywords = array(); /* * Compute keywords from iTag */ if (isset($this->options['iTag'])) { $iTag = new iTag(array('dbh' => $this->getDatabaseHandler(isset($this->options['iTag']['database']) ? $this->options['iTag']['database'] : null))); $metadata = array('footprint' => RestoGeometryUtil::geoJSONGeometryToWKT($geometry), 'timestamp' => isset($properties['startDate']) ? $properties['startDate'] : null); $iTagFeature = $iTag->tag($metadata, isset($this->options['iTag']['taggers']) ? $this->options['iTag']['taggers'] : array()); } if (!isset($iTagFeature) || !isset($iTagFeature['content'])) { return $keywords; } /* * Continents, countries, regions and states */ if (isset($iTagFeature['content']['political'])) { $keywords = $this->getPoliticalKeywords($iTagFeature['content']['political']); } /* * Physical data */ if (isset($iTagFeature['content']['physical'])) { $keywords = array_merge($keywords, $this->getPhysicalKeywords($iTagFeature['content']['physical'])); } /* * Landuse and landuse details */ if (isset($iTagFeature['content']['landCover'])) { $keywords = array_merge($keywords, $this->getLandCoverKeywords($iTagFeature['content']['landCover'])); } /* * Population */ if (isset($iTagFeature['content']['population'])) { $keywords = array_merge($keywords, $this->getPopulationKeywords($iTagFeature['content']['population'])); } /* * Keywords */ if (isset($iTagFeature['content']['keywords'])) { $keywords = array_merge($keywords, $this->getAlwaysKeywords($iTagFeature['content']['keywords'])); } return $keywords; }
/** * Convert feature array to database column/value pairs * * @param RestoCollection $collection * @param array $featureArray * @throws Exception */ private function getColumnsAndValues($collection, $featureArray) { /* * Initialize columns array */ $wkt = RestoGeometryUtil::geoJSONGeometryToWKT($featureArray['geometry']); $extent = RestoGeometryUtil::getExtent($wkt); /* * Compute "in house centroid" to avoid -180/180 date line issue */ $factor = 1; if (abs($extent[2] - $extent[0]) >= 180) { $factor = -1; } $columns = array_merge(array($collection->model->getDbKey('identifier') => '\'' . $featureArray['id'] . '\'', $collection->model->getDbKey('collection') => '\'' . $collection->name . '\'', $collection->model->getDbKey('geometry') => 'ST_GeomFromText(\'' . $wkt . '\', 4326)', '_geometry' => 'ST_SplitDateLine(ST_GeomFromText(\'' . $wkt . '\', 4326))', $collection->model->getDbKey('centroid') => 'ST_GeomFromText(\'POINT(' . ($extent[2] + $extent[0] * $factor) / 2.0 . ' ' . ($extent[3] + $extent[1]) / 2.0 . ')\', 4326)', 'updated' => 'now()', 'published' => 'now()'), $this->propertiesToColumns($collection, $featureArray['properties'])); return $columns; }