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

Invalid Polygon Point value of type "double" #54

Closed
collmomo opened this issue Apr 5, 2015 · 3 comments
Closed

Invalid Polygon Point value of type "double" #54

collmomo opened this issue Apr 5, 2015 · 3 comments
Labels

Comments

@collmomo
Copy link

collmomo commented Apr 5, 2015

array:564 [
  0 => array:2 [
    0 => -73.698313
    1 => 45.546876
  ]
  1 => array:2 [
    0 => -73.69813
    1 => 45.546916
  ]
  2 => array:2 [
    0 => -73.697656
    1 => 45.546899
  ]
  3 => array:2 [
    0 => -73.697413
    1 => 45.546899
  ]

$poly = new Polygon($array);

What's the problem I don't understand at all, theres like no doc telling you how to create a polygon

@collmomo
Copy link
Author

collmomo commented Apr 5, 2015

I AM BECOMING CRAZY !!!

  $point = new Point(array($lng,$lat));
       dump($point);

       $dql = "SELECT q.geometryType, q.quartierName, "
            . "Contains(q.polygon, GeomFromText(:point)), "
            . "Contains(q.multiPolygon, GeomFromText(:point)), "
            . "MBRContains(q.polygon, GeomFromText(:point)), "
            . "MBRContains(q.multiPolygon, GeomFromText(:point)), "
            . "Disjoint(q.multiPolygon, GeomFromText(:point)), "
            . "Disjoint(q.polygon, GeomFromText(:point)), "
            . "MBRDisjoint(q.multiPolygon, GeomFromText(:point)), "
            . "MBRDisjoint(q.polygon, GeomFromText(:point)) "
            . "FROM {$this->getEntityName()} q ";
       $data = $this->_em->createQuery($dql)
               ->setHint(Query::HINT_CUSTOM_OUTPUT_WALKER, 'CrEOF\Spatial\ORM\Query\GeometryWalker')
               ->setParameter("point", $point, 'point')->getArrayResult();
       dump($data);

       $point = new Point(array($lat,$lng));
       dump($point);
       $dql = "SELECT q.geometryType, q.quartierName, "
            . "Contains(q.polygon, GeomFromText(:point)), "
            . "Contains(q.multiPolygon, GeomFromText(:point)), "
            . "MBRContains(q.polygon, GeomFromText(:point)), "
            . "MBRContains(q.multiPolygon, GeomFromText(:point)), "
            . "Disjoint(q.multiPolygon, GeomFromText(:point)), "
            . "Disjoint(q.polygon, GeomFromText(:point)), "
            . "MBRDisjoint(q.multiPolygon, GeomFromText(:point)), "
            . "MBRDisjoint(q.polygon, GeomFromText(:point)) "
            . "FROM {$this->getEntityName()} q ";
       $data = $this->_em->createQuery($dql)
               ->setHint(Query::HINT_CUSTOM_OUTPUT_WALKER, 'CrEOF\Spatial\ORM\Query\GeometryWalker')
               ->setParameter("point", $point, 'point')->getArrayResult();
       dump($data);

EVERY FUNCTION RETURNS NULL and I know for a fact this point IS in a polygon !!!!!!! omg, I need a break

For future references,for people like me, don't copy his tests, for some strange reasons they didn't wanna work,

use this instead
 $dql = "SELECT q.geometryType, q.quartierName, "
            . "Contains(q.polygon, GeomFromText('Point($lat $lng)')), "
            . "Contains(q.multiPolygon, GeomFromText('Point($lat $lng)')), "
            . "MBRContains(q.polygon, GeomFromText('Point($lat $lng)')), "
            . "MBRContains(q.multiPolygon, GeomFromText('Point($lat $lng)')), "
            . "Disjoint(q.multiPolygon, GeomFromText('Point($lat $lng)')), "
            . "Disjoint(q.polygon, GeomFromText('Point($lat $lng)')), "
            . "MBRDisjoint(q.multiPolygon, GeomFromText('Point($lat $lng)')), "
            . "MBRDisjoint(q.polygon, GeomFromText('Point($lat $lng)')) "
            . "FROM {$this->getEntityName()} q "
            . "WHERE q.quartierName='Le Plateau-Mont-Royal' ";

and now they return 0 or 1

@ddproxy
Copy link
Member

ddproxy commented Oct 15, 2015

@collmomo I'm working on better documentation and testing in my fork.

I'm assuming here the :point is actually being dropped into the query as a binary or self-represented geometry rather than the text representation. Have you tried without the GeomFromText method and would you happen to have a log of the actual query performed after doctrine sent it to the database?

@pluseg
Copy link

pluseg commented Jun 4, 2021

I had the same problem with returning NULL. It happens because of your Polygon wasn't closed up, I think. You have to duplicate first Point and add at the end. At least, it worked in database query.

SELECT ST_GeomFromText('POLYGON((28 26,28 0,84 0,84 42))');
// returns NULL

SELECT ST_GeomFromText('POLYGON((28 26,28 0,84 0,84 42,28 26))');
// returns Polygon

@sadortun sadortun closed this as completed Aug 8, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants