本文整理汇总了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;
}
示例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);
}
示例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);
}
}
}
}
}
示例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);
}
示例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);
}
示例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;
}
示例7: wkb_to_json
function wkb_to_json($wkb)
{
$geom = geoPHP::load($wkb, 'wkb');
// echo $geom->out('json');
// exit();
return $geom->out('json');
}
示例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;
}
示例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;
}
示例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']);
}
示例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 . ')';
}
示例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);
}
示例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 . ')');
}
}
}
}
}
}
示例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 . ')');
}
}
}
}
}
}
示例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']);
}