Closed yurtesen closed 6 years ago
It looks like you're mixing up something between the two libraries. IIRC, creof/doctrine2-spatial
converts the binary representations in their DBAL types, while jsor/doctrine-postgis
does that on the database level via ST_AsEWKT
.
All I did was to setup event subscriber in config.yml in symfony3
# Doctrine PostGIS (Jsor\Doctrine)
services:
jsor_doctrine_postgis_doctrine_orm_schema_subscriber:
class: 'Jsor\Doctrine\PostGIS\Event\ORMSchemaEventSubscriber'
public: false
tags:
- { name: doctrine.event_subscriber, connection: default }
Then setup a table with:
/**
* @var Point $coords
*
* @ORM\Column(name="coords", type="geography", options={"geometry_type"="POINT", "srid"=4326})
*/
private $coords;
Then I used EasyAdmin (also Sonata Admin Bundles does same) to enter a row to database. I enter it as text POINT(0 0) and it works perfectly and creates the row. This tells me I should have setup things correctly, no?
Now the problem is when I go to list view. I see the HEX representation at coords
field instead of the ST_AsEWKT
result.
I can't see what I may have mixed here?
Do you have creof/doctrine2-spatial
also enabled?
It is installed but I commented out all lines related to creof/doctrine2-spatial
from config.yml
doctrine section. IF it was enabled, I would have received a Point()
object, not hex text?
Also if creof/doctrine2-spatial
was enabled AFAIK it shouldnt accept POINT(0 0)
as text when creating a row?
I should perhaps test this with a clean symfony installation. But now I have some time sensitive issues to deal with until next week.
I'm not sure, i guessed there'd be some conflict with DBAL types because both libs register the same type names.
A clean install would probably the best to ensure its not some lib conflict.
Do I have to register ST_AsEWKT
function ? Could that be the problem because I did not register any functions?
BTW you plan to give option to accept and return for example Point() objects like creof/doctrine2-spatial
? I think having that option would be great. It allows easier manipulation of the data.
Anyway, I will return back when I test this with clean symfony3 installation but next week earliest.
Do I have to register ST_AsEWKT function ? Could that be the problem because I did not register any functions?
No
BTW you plan to give option to accept and return for example Point() objects like
creof/doctrine2-spatial
? I think having that option would be great. It allows easier manipulation of the data.
No, that'd be for a higher-level library which may build on top of doctrine-postgis.
Anyway, I will return back when I test this with clean symfony3 installation but next week earliest.
👍
@jsor it is simply another data type For example doctrine supports array types, json etc. even php object type. With same logic, the doctrine developers should say json or php object is not defined in SQL standard so it must be implemented at a higher-level library. Isnt it?
In my opinion, your library is the "higher-level" library :smile The problem is that if I receive data as WKT, I will always need to convert it myself. Wouldn't it conflict with your library if somebody tried to change the field type defined by your library? I am not a doctrine expert but I think it would require hijacking your 'geography' type to accomplish this goal? Doesn't this make it impossible to build a higher level library based on this restriction?
I tried it with fresh symfony and result is same. Here is the link to whole symfony project and the animated gif showing the problem. So why is it doing this?
Ah yes, the old problem again (see #31 for example). You need to register the types in the Symfony config: https://github.com/jsor/doctrine-postgis#symfony
And for using Geometry objects instead of WKT strings: I've setup a gist with a simple example build on top of jsor/doctrine-postgis, geo-io/geometry, geo-io/wkt-parser and geo-io/wkt-generator which uses a customized GeometryType
.
https://gist.github.com/jsor/7149309ceaf7fdae1051a49a06797f63
Even with types registered in config, the listing is empty. I mean the page where the rows are listed. It shows ID, and COORDS is empty. Although now it shows the correct view in edit page. Documentation is not clear, it says I would need to register them IF I have problems with schema tool. I do not AFAIK. From what it looks like, the types MUST be registered.
Too many problems... I feel somebody should come out and combine creof/doctrine2-spatial
and jsor/doctrine-postgis
. Actually creof/doctrine2-spatial
is working perfectly, so far the only fault I found in there was that it does not create spatial indices.
Both projects are open source. If you feel there's something missing for your sepcific use case, just implement it and open a PR.
As for EasyAdmin not showing the value in the list. That was easily resolvable by reading the docs. Since the property has the type geometry
, EasyAdmin doesn't know how to display that type. You need to configure it to show that property in the config:
easy_admin:
entities:
Store:
class: AppBundle\Entity\Store
list:
fields:
- 'id'
- { property: 'coords', type: 'string' }
That tells EasyAdmin to show the coords
property as string.
Yes, the thing is... EasyAdmin is able to detect all the other types automatically, including ones introduced by creof/doctrine2-spatial
. I do not have to tell it how to print fields. That is if I remember correctly, because since then I moved to SonataAdminBundle.
This is probably because the Point type in creof/doctrine2-spatial
supports function called getType()
(amongst others) and you are simply returning a simple string. I might be wrong, I am not an expert on how doctrine/easyadmin works.
As I mentioned, I like some things in jsor/doctrine-postgis
and some things in creof/doctrine2-spatial
but after trying both, creof/doctrine2-spatial
seem to function much better. Don't get me wrong, I am just giving feedback so hopefully you improve your package.
I was going back and forth between
jsor/doctrine-postgis
andcreof/doctrine2-spatial
I like the way that
creof/doctrine2-spatial
works. I work with a Point() type and it returns me a Point() object. Can also use the same when entering data. Which is awesome... But it does not support spatial indexes AFAIK.Anyway, about
jsor/doctrine-postgis
, entering data as WKT is not a big problem. But I receive response in text and not in EWKT ("0101000020E610000000000000000000000000000000000000") instead of POINT(X,Y)What am I doing wrong?