Skip to content

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

@r8or0pz

Description

@r8or0pz

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();

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions