本文整理汇总了PHP中geoPHP::load方法的典型用法代码示例。如果您正苦于以下问题:PHP geoPHP::load方法的具体用法?PHP geoPHP::load怎么用?PHP geoPHP::load使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类geoPHP
的用法示例。
在下文中一共展示了geoPHP::load方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: 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);
}
}
}
}
}
示例2: 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);
}
示例3: wkb_to_json
function wkb_to_json($wkb)
{
$geom = geoPHP::load($wkb, 'wkb');
// echo $geom->out('json');
// exit();
return $geom->out('json');
}
示例4: nl_kml2wkt
/**
* Convert KML -> WKT.
*
* @param string $wkt The coverage.
* @return string|null The WKT.
*/
function nl_kml2wkt($kml)
{
$wkt = null;
// Is the input valid KML?
if (geoPHP::detectFormat($kml) == 'kml') {
$geo = geoPHP::load($kml);
$wkt = geoPHP::geometryReduce($geo)->out('wkt');
}
return $wkt;
}
示例5: 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;
}
示例6: 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;
}
示例7: 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']);
}
示例8: 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 . ')');
}
}
}
}
}
}
示例9: 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 . ')');
}
}
}
}
}
}
示例10: 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']);
}
示例11: testMethods
function testMethods()
{
$format = 'gpx';
$value = file_get_contents('./input/20120702.gpx');
$geometry = geoPHP::load($value, $format);
$methods = array(array('name' => 'area'), array('name' => 'boundary'), array('name' => 'getBBox'), array('name' => 'centroid'), array('name' => 'length'), array('name' => 'greatCircleLength', 'argument' => 6378137), array('name' => 'haversineLength'), array('name' => 'y'), array('name' => 'x'), array('name' => 'numGeometries'), array('name' => 'geometryN', 'argument' => '1'), array('name' => 'startPoint'), array('name' => 'endPoint'), array('name' => 'isRing'), array('name' => 'isClosed'), array('name' => 'numPoints'), array('name' => 'pointN', 'argument' => '1'), array('name' => 'exteriorRing'), array('name' => 'numInteriorRings'), array('name' => 'interiorRingN', 'argument' => '1'), array('name' => 'dimension'), array('name' => 'geometryType'), array('name' => 'SRID'), array('name' => 'setSRID', 'argument' => '4326'));
foreach ($methods as $method) {
$argument = NULL;
$method_name = $method['name'];
if (isset($method['argument'])) {
$argument = $method['argument'];
}
$this->_methods_tester($geometry, $method_name, $argument);
}
}
示例12: within
/**
*
*/
public function within(Request $request)
{
$start = microtime(true);
if (str_contains($request->path(), 'mongo')) {
$collection = $this->model->within($request->json('geometry.coordinates'));
$elapsed = microtime(true) - $start;
} else {
$geometry = \geoPHP::load($request->input('geometry'), 'wkt');
$collection = $this->model->within($geometry->asText('wkt'));
$elapsed = microtime(true) - $start;
}
$logMessage = 'ms to get %s data: %f in %s';
\Log::debug(sprintf($logMessage, str_contains($request->path(), 'mongo') ? 'Mongo' : 'PostGIS', $elapsed, 'within()'));
return Response::json(['points' => $collection, 'area' => 0]);
}
示例13: getBody
public static function getBody($dataObj)
{
// Check if the original data is not GeoJSON
if (!empty($dataObj->geo_formatted) && $dataObj->geo_formatted) {
if ($dataObj->source_definition['type'] == 'JSON') {
return json_encode($dataObj->data);
} elseif ($dataObj->source_definition['type'] == 'KML') {
$geom = \geoPHP::load($dataObj->data, 'kml');
return $geom->out('json');
}
}
// Build the body
$body = $dataObj->data;
if (is_object($body)) {
$body = get_object_vars($dataObj->data);
}
$features = array();
foreach ($body as $dataRow) {
if (is_object($dataRow)) {
$dataRow = get_object_vars($dataRow);
}
$geo = $dataObj->geo;
//Guess lat/lon if no geo information was given for this
if (empty($geo)) {
if ($lat_long = GeoHelper::findLatLong($dataRow)) {
$geo = array("latitude" => $lat_long[0], "longitude" => $lat_long[1]);
}
}
$geometric_ids = self::findGeometry($geo, $dataRow);
//Prevent geo information being duplicated in properties
foreach ($geometric_ids[0] as $geometric_id) {
unset($dataRow[$geometric_id]);
}
$feature = array('type' => 'Feature', 'geometry' => $geometric_ids[1], 'properties' => $dataRow);
$id_prop = @$dataObj->source_definition['map_property'];
if (!empty($id_prop) && !empty($dataRow[$id_prop])) {
$feature['id'] = $dataRow[$id_prop];
unset($dataRow[$id_prop]);
}
array_push($features, $feature);
}
$result = array('type' => 'FeatureCollection', 'features' => $features);
// Only add bounding box if we have features and are viewing the entire dataset.
if (!empty($features) && empty($dataObj->paging)) {
$result['bbox'] = self::boundingBox($features);
}
return json_encode($result);
}
示例14: test_postgis
function test_postgis($name, $type, $geom, $connection, $format)
{
global $table;
// Let's insert into the database using GeomFromWKB
$insert_string = pg_escape_bytea($geom->out($format));
pg_query($connection, "INSERT INTO {$table} (name, type, geom) values ('{$name}', '{$type}', GeomFromWKB('{$insert_string}'))");
// SELECT using asBinary PostGIS
$result = pg_fetch_all(pg_query($connection, "SELECT asBinary(geom) as geom FROM {$table} WHERE name='{$name}'"));
foreach ($result as $item) {
$wkb = pg_unescape_bytea($item['geom']);
// Make sure to unescape the hex blob
$geom = geoPHP::load($wkb, $format);
// We now a full geoPHP Geometry object
}
// SELECT and INSERT directly, with no wrapping functions
$result = pg_fetch_all(pg_query($connection, "SELECT geom as geom FROM {$table} WHERE name='{$name}'"));
foreach ($result as $item) {
$wkb = pack('H*', $item['geom']);
// Unpacking the hex blob
$geom = geoPHP::load($wkb, $format);
// We now have a geoPHP Geometry
// Let's re-insert directly into postGIS
// We need to unpack the WKB
$unpacked = unpack('H*', $geom->out($format));
$insert_string = $unpacked[1];
pg_query($connection, "INSERT INTO {$table} (name, type, geom) values ('{$name}', '{$type}', '{$insert_string}')");
}
// SELECT and INSERT using as EWKT (ST_GeomFromEWKT and ST_AsEWKT)
$result = pg_fetch_all(pg_query($connection, "SELECT ST_AsEWKT(geom) as geom FROM {$table} WHERE name='{$name}'"));
foreach ($result as $item) {
$wkt = $item['geom'];
// Make sure to unescape the hex blob
$geom = geoPHP::load($wkt, 'ewkt');
// We now a full geoPHP Geometry object
// Let's re-insert directly into postGIS
$insert_string = $geom->out('ewkt');
pg_query($connection, "INSERT INTO {$table} (name, type, geom) values ('{$name}', '{$type}', ST_GeomFromEWKT('{$insert_string}'))");
}
}
示例15: createGeoPHPGeometry
/**
* Convert an object into a GeoPHP Geometry object.
*
* The following rules will dictate the conversion:
* - Multi-value geofields of different types will be reduced to a
* GEOMETRYCOLLECTION.
* - Multi-value geofields of the same 'simple type' (POINT, LINESTRING or
* POLYGON) will be reduced to the MULTI* equivalent.
* - GEOMETRYCOLLECTION's containing multiple values of only one 'simple type'
* will be reduced to the MULTI* equvalent.
* - GEOMETRYCOLLECTION's or MULTI* values containing only one geometry will be
* reduced to that geometery.
*
* @param Traversable $object
* An object that represents a geometry or a (traversable) collection of
* such objects.
*
* @param Callable $to_geom
* A callback that takes your object and returns a GeoPHP Geometry object.
*
* @return
* A GeoPHP Geometry object representing the $object value
* converted according to the above rules.
*/
protected function createGeoPHPGeometry($object, $to_geom = NULL)
{
geophp_load();
if (empty($object)) {
return NULL;
}
if (!$to_geom) {
$to_geom = function ($wkt) {
return \geoPHP::load($wkt, 'wkt');
};
}
// TODO: This reflection sucks.
if (is_array($object) || $object instanceof \Traversable && $object instanceof \Countable && $object instanceof \ArrayAccess) {
foreach ($object as $delta => $value) {
$geometry = $this->createGeoPHPGeometry($value, $to_geom);
if ($geometry) {
$geom[] = $geometry;
}
}
} else {
$geom = $to_geom($object);
}
return \geoPHP::geometryReduce($geom);
}