Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot get geometry object from data you send to the GEOMETRY field #200

Open
r8or0pz opened this issue May 23, 2019 · 3 comments
Open

Cannot get geometry object from data you send to the GEOMETRY field #200

r8or0pz opened this issue May 23, 2019 · 3 comments

Comments

@r8or0pz
Copy link

r8or0pz commented May 23, 2019

How do I store POINT type?

An exception occurred while executing 'INSERT INTO geo_point (address, coordinates) VALUES (?, ?)' with params ["Test", "POINT(-73.976683 40.760381)"]:

SQLSTATE[22003]: Numeric value out of range: 1416 Cannot get geometry object from data you send to the GEOMETRY field

Result query:

INSERT INTO geo_point (address, coordinates) VALUES ('Test', 'POINT(-73.976683 40.760381)');

My Entity:

namespace BackendLib\Entity;

use Doctrine\ORM\Mapping as ORM;
use CrEOF\Spatial\PHP\Types\Geometry\Point;

class GeoPoint
{
    /**
     * @ORM\Id()
     * @ORM\GeneratedValue()
     * @ORM\Column(type="integer")
     */
    private $id;

    /**
     * @ORM\Column(type="string", length=255, nullable=true)
     */
    private $address;

    /**
     * @ORM\Column(type="point", nullable=true)
     */
    private $point;

    public function getId(): ?int
    {
        return $this->id;
    }

    public function getAddress(): ?string
    {
        return $this->address;
    }

    public function setAddress(string $address): self
    {
        $this->address = $address;

        return $this;
    }

    public function setPoint(?Point $point): self
    {
        $this->point = $point;

        return $this;
    }

    public function getPoint(): ?Point
    {
        return $this->point;
    }
}

This is how I store it:

$obj = new GeoPoint();
$obj->setAddress('Test');
$obj->setPoint(new Point(40.7603807, -73.9766831));
$manager->persist($obj);
$manager->flush();
@holtkamp
Copy link

When looking at:

INSERT INTO geo_point (address, coordinates) VALUES ('Test', 'POINT(-73.976683 40.760381)');

It seems the POINT is handed over as a string, it should probably be:

INSERT INTO geo_point (address, coordinates) VALUES ('Test', POINT(-73.976683 40.760381));

Did you register the types and functions as done here:

$this->setUpTypes();
$this->setUpEntities();
$this->setUpFunctions();

@r8or0pz
Copy link
Author

r8or0pz commented May 24, 2019

I have found the reason. I use custom Quote Strategy class which adds quotes to table fields. Inspite it works with fields, somehow it affects values also. Here is the class: https://gist.github.com/lngphp/a6e9a5de1287604ad4ffb9d25c1abcb2

To be more specific, QuoteStrategy::getColumnName() is the reason.

@holtkamp
Copy link

So this issue can be closed then?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants