geo icon indicating copy to clipboard operation
geo copied to clipboard

Add geometry and geography from text Doctrine functions

Open Kolyunya opened this issue 4 years ago • 6 comments

I found myself using these functions extensively. They seem to be quite commonly used to me, that's why I wonder whether they can be included into the library.

Kolyunya avatar Jan 07 '21 08:01 Kolyunya

Hi, they can be useful indeed, though Geography is PostGIS-specific, so I'm not comfortable with including this function in the library.

I'd love to think about transparently supporting Geography first, as at the moment everything is calculated as a Geometry, and thus calculations with GPS coordinates cannot be performed in meters in PostGIS with brick/geo, AFAIK.

I'm not sure how brick/geo could support geographies transparently. In MySQL it is simpler, as some SRIDs (4326) will make calculations happen in meters, whereas to get the same result, you have to use Geography in PostGIS instead, if I'm not mistaken.

Maybe it would just be a matter on transparently using ST_GeographyFromText instead of ST_GeomFromText in the database engine for specific SRIDs?

BenMorel avatar Jan 21 '21 13:01 BenMorel

calculations with GPS coordinates cannot be performed in meters in PostGIS with brick/geo.

@BenMorel calculations can be performed in meters. You just have to convert at least one parameter of a calculation function to a geography.

For example if you pass some st_GeographyFromText(...) and some geometry column to ST_DWithin it's going to convert it to the geography automatically and the calculations will be performed in meters.

Kolyunya avatar Jan 24 '21 10:01 Kolyunya

That's what I mean, brick/geo needs to explicitly use geographies (ST_GeographyFromText instead of ST_GeomFromText in the engine) when you want meters, but when? Should we do that automatically for SRID 4326, for example?

PostGIS may be the only GIS engine that distinguishes between Geometry and Geography; MySQL has a single Geometry type, and whether the calculations are performed in meters depends on the SRID. Not sure about SpatiaLite & GEOS, I'd be interested to see how it's handled there.

BenMorel avatar Jan 24 '21 21:01 BenMorel

Should we do that automatically for SRID 4326, for example?

@BenMorel not sure. What is someone needs to use another SRID with geographies?

Kolyunya avatar Jan 27 '21 09:01 Kolyunya

What is someone needs to use another SRID with geographies?

Geographies imply using GPS coordinates, so there aren't many SRIDs that match. These could be hardcoded in the library to use Geographies instead of Geometries on PostGIS.

I'm not sure this is the best idea though, I'm open to suggestions!

BenMorel avatar Jan 27 '21 12:01 BenMorel

Sorry, at this point I can not suggest any generic solution for that problem. In my project I solved it by manually casting geometries to geographies.

Kolyunya avatar Feb 02 '21 13:02 Kolyunya