Code Monkey home page Code Monkey logo

Comments (3)

pluseg avatar pluseg commented on August 16, 2024 1

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

from doctrine2-spatial.

collmomo avatar collmomo commented on August 16, 2024

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

from doctrine2-spatial.

ddproxy avatar ddproxy commented on August 16, 2024

@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?

from doctrine2-spatial.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.