GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GitHub - cakephp-bakeoff/geospatial: CakePHP Table Behavior for geospatial columns

BranchesTags
Open more actions menu

Latest commit

 

History

3 Commits
3 Commits

Folders and files

NameName
Last commit message
Last commit date
src
src
 
 
.gitignore
.gitignore
 
 
README.md
README.md
 
 
composer.json
composer.json
 
 

Repository files navigation

CakePHP 5: Geospatial Behavior for Tables

CakePHP 5.1.0 introduced limited support for geospatial types.

The geometry, point, linestring, and polygon types are also known as the “geospatial types”. CakePHP offers limited support for geospatial columns. Currently they can be defined in migrations, read in schema reflection, and have values set as text.

Because internally all of the above are typemapped to \Cake\Database\Type\StringType, CakePHP:

  • reads them as string, resulting in binary gibberish;
  • writes them as literal string ('POINT(0 0)'), resulting in database errors ("SQLSTATE[22003]: Numeric value out of range: 1416 Cannot get geometry object from data you send to the GEOMETRY field").

This plugin offers a quick Behavior you can attach to your tables having geospatial columns. In the spirit of convention over configuration, these geospatial columns will be detected automatically, so you don't have to explicitly configure anything. It will then become much simpler and faster to read from, and write to them.

Note: right now this plugin supports the POINT type only.

Setting up

Install:

composer require bakeoff/geospatial

In your Table classes:

$this->addBehavior('Bakeoff/Geospatial.Geospatial');

Reading POINT

Get your entities as usual. The geospatial columns will be parsed.

$entity = $myTable->get(123);
debug($entity->position);
[
    'order' => (int) 1,
    'type' => (int) 1,
    'x' => (float) 12.34,
    'y' => (float) 56.78,
]

Writing POINT

$data = $this->getRequest()->getData();
// Provide the POINT information as array with two elements
$data['position'] = array($position_x, $position_y);
$entity = $myTable->patchEntity($entity, $data);
$result = $myTable->save($entity);

About

CakePHP Table Behavior for geospatial columns

Topics

cakephpcakephp-plugincakephp5geospatialphp

Resources

Readme
Activity
Custom properties

Stars

0 stars

Watchers

0 watching

Forks

0 forks
Report repository

Releases

Contributors

Languages

You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.