当前位置: 首页>>代码示例>>PHP>>正文


PHP geoPHP类代码示例

本文整理汇总了PHP中geoPHP的典型用法代码示例。如果您正苦于以下问题:PHP geoPHP类的具体用法?PHP geoPHP怎么用?PHP geoPHP使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了geoPHP类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: toInstance

 /**
  * Converts an stdClass object into a Geometry based on its 'type' property
  * Converts an stdClass object into a Geometry, based on its 'type' property
  *
  * @param stdClass $obj Object resulting from json decoding a GeoJSON string
  *
  * @return object Object from class eometry
  */
 private static function toInstance($obj)
 {
     if (is_null($obj)) {
         return null;
     }
     if (!isset($obj->type)) {
         self::checkType($obj);
     }
     if ($obj->type == 'Feature') {
         $instance = self::toGeomInstance($obj->geometry);
     } else {
         if ($obj->type == 'FeatureCollection') {
             $geometries = array();
             foreach ($obj->features as $feature) {
                 $geometries[] = self::toGeomInstance($feature->geometry);
             }
             // Get a geometryCollection or MultiGeometry out of the the provided geometries
             $instance = geoPHP::geometryReduce($geometries);
         } else {
             // It's a geometry
             $instance = self::toGeomInstance($obj);
         }
     }
     return $instance;
 }
开发者ID:happy-code-com,项目名称:PHP5-Shape-File-Parser,代码行数:33,代码来源:GeoJSON.class.php

示例2: geomFromXML

 protected function geomFromXML()
 {
     $geometries = array();
     $geometries = array_merge($geometries, $this->parseWaypoints());
     $geometries = array_merge($geometries, $this->parseTracks());
     $geometries = array_merge($geometries, $this->parseRoutes());
     if (empty($geometries)) {
         throw new Exception("Invalid / Empty GPX");
     }
     return geoPHP::geometryReduce($geometries);
 }
开发者ID:FaddliLWibowo,项目名称:Leaflet-demo,代码行数:11,代码来源:GPX.class.php

示例3: testPlaceholders

 function testPlaceholders()
 {
     foreach (scandir('./input') as $file) {
         $parts = explode('.', $file);
         if ($parts[0]) {
             $format = $parts[1];
             $value = file_get_contents('./input/' . $file);
             $geometry = geoPHP::load($value, $format);
             $placeholders = array(array('name' => 'hasZ'), array('name' => 'is3D'), array('name' => 'isMeasured'), array('name' => 'isEmpty'), array('name' => 'coordinateDimension'), array('name' => 'z'), array('name' => 'm'));
             foreach ($placeholders as $method) {
                 $argument = NULL;
                 $method_name = $method['name'];
                 if (isset($method['argument'])) {
                     $argument = $method['argument'];
                 }
                 switch ($method_name) {
                     case 'm':
                     case 'z':
                         if ($geometry->geometryType() == 'Point') {
                             $this->assertNotNull($geometry->{$method_name}($argument), 'Failed on ' . $method_name);
                         }
                         if ($geometry->geometryType() == 'LineString') {
                             $this->assertNotNull($geometry->{$method_name}($argument), 'Failed on ' . $method_name);
                         }
                         if ($geometry->geometryType() == 'MultiLineString') {
                             $this->assertNull($geometry->{$method_name}($argument), 'Failed on ' . $method_name);
                         }
                         break;
                     case 'coordinateDimension':
                     case 'isEmpty':
                     case 'isMeasured':
                     case 'is3D':
                     case 'hasZ':
                         if ($geometry->geometryType() == 'Point') {
                             $this->assertNotNull($geometry->{$method_name}($argument), 'Failed on ' . $method_name);
                         }
                         if ($geometry->geometryType() == 'LineString') {
                             $this->assertNotNull($geometry->{$method_name}($argument), 'Failed on ' . $method_name);
                         }
                         if ($geometry->geometryType() == 'MultiLineString') {
                             $this->assertNotNull($geometry->{$method_name}($argument), 'Failed on ' . $method_name);
                         }
                         break;
                     default:
                         $this->assertTrue($geometry->{$method_name}($argument), 'Failed on ' . $method_name);
                 }
             }
         }
     }
 }
开发者ID:drupdateio,项目名称:gvj,代码行数:50,代码来源:placeholdersTest.php

示例4: read

 /**
  * Given an object or a string, return a Geometry
  *
  * @param mixed $input The GeoJSON string or object
  *
  * @return object Geometry
  */
 public function read($input)
 {
     if (is_string($input)) {
         $input = json_decode($input);
     }
     if (!is_object($input)) {
         throw new Exception('Invalid JSON');
     }
     if (!is_string($input->type)) {
         throw new Exception('Invalid JSON');
     }
     // Check to see if it's a FeatureCollection
     if ($input->type == 'FeatureCollection') {
         $geoms = array();
         foreach ($input->features as $feature) {
             $geoms[] = $this->read($feature);
         }
         return geoPHP::geometryReduce($geoms);
     }
     // Check to see if it's a Feature
     if ($input->type == 'Feature') {
         return $this->read($input->geometry);
     }
     // It's a geometry - process it
     return $this->objToGeom($input);
 }
开发者ID:tijdmedia,项目名称:geophp,代码行数:33,代码来源:GeoJSON.php

示例5: sql2json

 public function sql2json($SQL, $shape_column, $popup_content = NULL, $label = NULL)
 {
     require_once APPPATH . '../modules/' . $this->cms_module_path('gofrendi.gis.core') . '/classes/geoPHP/geoPHP.inc';
     $map_region = $this->input->post('map_region');
     $map_zoom = $this->input->post('map_zoom');
     $search = array('@map_region', '@map_zoom');
     $replace = array($map_region, $map_zoom);
     $SQL = $this->replace($SQL, $search, $replace);
     $features = array();
     $query = $this->db->query($SQL);
     foreach ($query->result_array() as $row) {
         $geom = geoPHP::load($row[$shape_column], 'wkt');
         $json = $geom->out('json');
         $real_popup_content = "";
         $real_label = "";
         $search = array();
         $replace = array();
         foreach ($row as $column => $value) {
             $search[] = '@' . $column;
             $replace[] = $value;
         }
         if (isset($popup_content)) {
             $real_popup_content = $this->replace($popup_content, $search, $replace);
         }
         if (isset($label)) {
             $real_label = $this->replace($label, $search, $replace);
         }
         $features[] = array("type" => "Feature", "properties" => array("popupContent" => $real_popup_content, "label" => $real_label), "geometry" => json_decode($json));
     }
     $feature_collection = array("type" => "FeatureCollection", "features" => $features);
     return json_encode($feature_collection);
 }
开发者ID:AlvaCorp,项目名称:gis-module,代码行数:32,代码来源:geoformat.php

示例6: centroid

 public function centroid()
 {
     if ($this->isEmpty()) {
         return NULL;
     }
     if ($this->geos()) {
         return geoPHP::geosToGeometry($this->geos()->centroid());
     }
     $exterior_ring = $this->components[0];
     $pts = $exterior_ring->getComponents();
     $c = count($pts);
     if ((int) $c == '0') {
         return NULL;
     }
     $cn = array('x' => '0', 'y' => '0');
     $a = $this->area(TRUE, TRUE);
     // If this is a polygon with no area. Just return the first point.
     if ($a == 0) {
         return $this->exteriorRing()->pointN(1);
     }
     foreach ($pts as $k => $p) {
         $j = ($k + 1) % $c;
         $P = $p->getX() * $pts[$j]->getY() - $p->getY() * $pts[$j]->getX();
         $cn['x'] = $cn['x'] + ($p->getX() + $pts[$j]->getX()) * $P;
         $cn['y'] = $cn['y'] + ($p->getY() + $pts[$j]->getY()) * $P;
     }
     $cn['x'] = $cn['x'] / (6 * $a);
     $cn['y'] = $cn['y'] / (6 * $a);
     $centroid = new Point($cn['x'], $cn['y']);
     return $centroid;
 }
开发者ID:drupdateio,项目名称:gvj,代码行数:31,代码来源:Polygon.class.php

示例7: wkb_to_json

function wkb_to_json($wkb)
{
    $geom = geoPHP::load($wkb, 'wkb');
    // echo $geom->out('json');
    // exit();
    return $geom->out('json');
}
开发者ID:Poshan,项目名称:hanssolo,代码行数:7,代码来源:togeojsonopening2.php

示例8: nl_extractWkt

/**
 * Convert a raw coverage value to WKT.
 *
 * @param string $coverage The raw coverage.
 * @return string|null The WKT.
 */
function nl_extractWkt($coverage)
{
    $wkt = null;
    // Get coverage format.
    $format = geoPHP::detectFormat($coverage);
    // Convert / reduce to WKT.
    if (in_array($format, array('wkt', 'kml'))) {
        $wkt = geoPHP::load($coverage)->out('wkt');
    }
    return $wkt;
}
开发者ID:HCDigitalScholarship,项目名称:scattergoodjournals,代码行数:17,代码来源:Coverage.php

示例9: tap_geo_tourml_asset

/**
 * Implements hook_tourml_asset()
 *
 * @param $asset.
 *
 * @return $asset. An altered asset object
 *
 * Use this hook to render assets.  The geofield
 * module stores its data in $asset['wkt'] so
 * we can check against this value to determine
 * that we have a geofield, and act upon it.
 */
function tap_geo_tourml_asset($asset)
{
    // Handle geofield fields
    if (isset($asset['wkt'])) {
        geofield_load_geophp();
        $geometry = geoPHP::load($asset['wkt'], 'wkt');
        if ($geometry) {
            $asset['value'] = $geometry->out('json');
        }
    }
    return $asset;
}
开发者ID:veades,项目名称:tap-cms,代码行数:24,代码来源:tap.api.php

示例10: testInsertGeometry

 protected function testInsertGeometry(Connection $connection)
 {
     $i = 0;
     $connection->beginTransaction();
     $collection = \geoPHP::load(file_get_contents(self::$kml), 'kml');
     $collection->setSRID(4326);
     $connection->insert('test_table', array('id' => $i++, 'name' => 'test_' . $i, 'geometry' => $collection), array('integer', 'string', 'geometry'));
     $connection->commit();
     $data = $connection->fetchAll('SELECT * FROM test_table');
     $this->assertEquals(1, count($data));
     $this->assertEquals(0, $data[0]['id']);
     $this->assertEquals('test_1', $data[0]['name']);
 }
开发者ID:agnetsolutions,项目名称:dbal,代码行数:13,代码来源:AbstractGeometryTypeTest.php

示例11: write

 /**
  * Serialize geometries into a WKT string.
  *
  * @param Geometry $geometry
  *
  * @return string The WKT string representation of the input geometries
  */
 public function write(Geometry $geometry)
 {
     // If geos is installed, then we take a shortcut and let it write the WKT
     if (geoPHP::geosInstalled()) {
         $writer = new GEOSWKTWriter();
         return $writer->write($geometry->geos());
     }
     $type = strtolower($geometry->geometryType());
     if (is_null($data = $this->extract($geometry))) {
         return null;
     }
     return strtoupper($type) . ' (' . $data . ')';
 }
开发者ID:happy-code-com,项目名称:PHP5-Shape-File-Parser,代码行数:20,代码来源:WKT.class.php

示例12: geomFromXML

 protected function geomFromXML()
 {
     $geometries = array();
     $geometries = array_merge($geometries, $this->parsePoints());
     $geometries = array_merge($geometries, $this->parseLines());
     $geometries = array_merge($geometries, $this->parsePolygons());
     $geometries = array_merge($geometries, $this->parseBoxes());
     $geometries = array_merge($geometries, $this->parseCircles());
     if (empty($geometries)) {
         throw new Exception("Invalid / Empty GeoRSS");
     }
     return geoPHP::geometryReduce($geometries);
 }
开发者ID:EarthTeam,项目名称:earthteam.net,代码行数:13,代码来源:GeoRSS.class.php

示例13: testAdapters

 function testAdapters()
 {
     foreach (scandir('./input', SCANDIR_SORT_NONE) as $file) {
         $parts = explode('.', $file);
         if ($parts[0]) {
             $format = $parts[1];
             $input = file_get_contents('./input/' . $file);
             echo "\nloading: " . $file . " for format: " . $format;
             $geometry = geoPHP::load($input, $format);
             // Test adapter output and input. Do a round-trip and re-test
             foreach (geoPHP::getAdapterMap() as $adapter_key => $adapter_class) {
                 if ($adapter_key != 'google_geocode') {
                     //Don't test google geocoder regularily. Uncomment to test
                     $output = $geometry->out($adapter_key);
                     $this->assertNotNull($output, "Empty output on " . $adapter_key);
                     if ($output) {
                         $adapter_loader = new $adapter_class();
                         $test_geom_1 = $adapter_loader->read($output);
                         $test_geom_2 = $adapter_loader->read($test_geom_1->out($adapter_key));
                         $this->assertEquals($test_geom_1->out('wkt'), $test_geom_2->out('wkt'), "Mismatched adapter output in " . $adapter_class . ' (test file: ' . $file . ')');
                     }
                 }
             }
             // Test to make sure adapter work the same wether GEOS is ON or OFF
             // Cannot test methods if GEOS is not intstalled
             if (!geoPHP::geosInstalled()) {
                 return;
             }
             foreach (geoPHP::getAdapterMap() as $adapter_key => $adapter_class) {
                 if ($adapter_key != 'google_geocode') {
                     //Don't test google geocoder regularily. Uncomment to test
                     // Turn GEOS on
                     geoPHP::geosInstalled(TRUE);
                     $output = $geometry->out($adapter_key);
                     if ($output) {
                         $adapter_loader = new $adapter_class();
                         $test_geom_1 = $adapter_loader->read($output);
                         // Turn GEOS off
                         geoPHP::geosInstalled(FALSE);
                         $test_geom_2 = $adapter_loader->read($output);
                         // Turn GEOS back On
                         geoPHP::geosInstalled(TRUE);
                         // Check to make sure a both are the same with geos and without
                         $this->assertEquals($test_geom_1->out('wkt'), $test_geom_2->out('wkt'), "Mismatched adapter output between GEOS and NORM in " . $adapter_class . ' (test file: ' . $file . ')');
                     }
                 }
             }
         }
     }
 }
开发者ID:bekirduz,项目名称:wordpress_4_1_1,代码行数:50,代码来源:adaptersTest.php

示例14: testGeos

 function testGeos()
 {
     if (!geoPHP::geosInstalled()) {
         echo "Skipping GEOS -- not installed";
         return;
     }
     foreach (scandir('./input') as $file) {
         $parts = explode('.', $file);
         if ($parts[0]) {
             $format = $parts[1];
             $value = file_get_contents('./input/' . $file);
             echo "\nloading: " . $file . " for format: " . $format;
             $geometry = geoPHP::load($value, $format);
             $geosMethods = array(array('name' => 'geos'), array('name' => 'setGeos', 'argument' => $geometry->geos()), array('name' => 'PointOnSurface'), array('name' => 'equals', 'argument' => $geometry), array('name' => 'equalsExact', 'argument' => $geometry), array('name' => 'relate', 'argument' => $geometry), array('name' => 'checkValidity'), array('name' => 'isSimple'), array('name' => 'buffer', 'argument' => '10'), array('name' => 'intersection', 'argument' => $geometry), array('name' => 'convexHull'), array('name' => 'difference', 'argument' => $geometry), array('name' => 'symDifference', 'argument' => $geometry), array('name' => 'union', 'argument' => $geometry), array('name' => 'simplify', 'argument' => '0'), array('name' => 'disjoint', 'argument' => $geometry), array('name' => 'touches', 'argument' => $geometry), array('name' => 'intersects', 'argument' => $geometry), array('name' => 'crosses', 'argument' => $geometry), array('name' => 'within', 'argument' => $geometry), array('name' => 'contains', 'argument' => $geometry), array('name' => 'overlaps', 'argument' => $geometry), array('name' => 'covers', 'argument' => $geometry), array('name' => 'coveredBy', 'argument' => $geometry), array('name' => 'distance', 'argument' => $geometry), array('name' => 'hausdorffDistance', 'argument' => $geometry));
             foreach ($geosMethods as $method) {
                 $argument = NULL;
                 $method_name = $method['name'];
                 if (isset($method['argument'])) {
                     $argument = $method['argument'];
                 }
                 switch ($method_name) {
                     case 'isSimple':
                     case 'equals':
                     case 'geos':
                         if ($geometry->geometryType() == 'Point') {
                             $this->assertNotNull($geometry->{$method_name}($argument), 'Failed on ' . $method_name . ' (test file: ' . $file . ')');
                         }
                         if ($geometry->geometryType() == 'LineString') {
                             $this->assertNotNull($geometry->{$method_name}($argument), 'Failed on ' . $method_name . ' (test file: ' . $file . ')');
                         }
                         if ($geometry->geometryType() == 'MultiLineString') {
                             $this->assertNotNull($geometry->{$method_name}($argument), 'Failed on ' . $method_name . ' (test file: ' . $file . ')');
                         }
                         break;
                     default:
                         if ($geometry->geometryType() == 'Point') {
                             $this->assertNotNull($geometry->{$method_name}($argument), 'Failed on ' . $method_name . ' (test file: ' . $file . ')');
                         }
                         if ($geometry->geometryType() == 'LineString') {
                             $this->assertNotNull($geometry->{$method_name}($argument), 'Failed on ' . $method_name . ' (test file: ' . $file . ')');
                         }
                         if ($geometry->geometryType() == 'MultiLineString') {
                             $this->assertNull($geometry->{$method_name}($argument), 'Failed on ' . $method_name . ' (test file: ' . $file . ')');
                         }
                 }
             }
         }
     }
 }
开发者ID:EarthTeam,项目名称:earthteam.net,代码行数:49,代码来源:geosTest.php

示例15: get_bbox

 function get_bbox($gpx_str)
 {
     require_once "geoPHP/geoPHP.inc";
     $geom = geoPHP::load($gpx_str, 'gpx');
     $bbox = $geom->getBBox();
     $tl = $this->is_taiwan($bbox['minx'], $bbox['maxy']);
     $br = $this->is_taiwan($bbox['maxx'], $bbox['miny']);
     if ($tl != $br) {
         $this->taiwan = 0;
     }
     $this->taiwan = $tl;
     // 0 or 1 or 2
     //echo "lon $minlon $maxlon, lat $maxlat $minlat\n"; exit;
     return array($bbox['minx'], $bbox['maxy'], $bbox['maxx'], $bbox['miny']);
 }
开发者ID:KevinStoneCode,项目名称:twmap,代码行数:15,代码来源:svglib.php


注:本文中的geoPHP类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。