I'm trying to figure out how to take two Point objects and determine
the distance between them.
I have a set of Point objects, and I'd like to compute the distance
in
miles for each.
For Point objects a, b, one can "a.distance(b)", however, a number is
returned not a Distance object. I'm having trouble finding
documentation on what this value represents (I could perhaps plug it
into D(????=a.distance(b)).mi).
If my research is correct, a UTM zone can be determined by the srid
and the lat/long (which, coincidentally are the items passed into the
constructor of a Point).
As an example, I'll take a point in SF (37.8N, 122.4W):
>>> x = Point(-122.4, 37.8, srid=4326)
...and a point further south (37.4N, 122.1W):
>>> y = Point(-122.1, 37.4, srid=4326)
Before calling transform:
>>> D(m=x.distance(y))
Distance(m=0.5)
>>> D(m=x.distance(y)).mi
0.00031068559611867048
After transform:
>>> x.transform(32610)
>>> y.transform(32610)
>>> D(m=x.distance(y)).mi
0.00031068559611867048
[[ I do find it amusing/aggravating that transform() has different
behavior depending on whether another (unreferenced by my code)
library is installed. ]]
I imagine there exists a function to perform this transform
automagically? I don't really follow the UTM zones to well, but it
seems to me that given a lat/long and srid, it's possible to compute
the UTM zone. It seems to me that based on this, given two Point
objects with those three data points (each), the distance should be
computable without having to add set of calls for the user (to
transform). Am I misunderstanding?
The current behavior transforms the geometry if GDAL is present and does
nothing if it isn't present. In other words, no data corruption or
other "Bad Things" occur -- the geometry remains untransformed (because
it _can't_ be, there's no GDAL available to morph the vertices).
In hindsight, an exception probably should've been raised -- but if a
ticket is opened for this 'feature', then there will be
backwards-compatibility issues to address.
-Justin
The current behavior transforms the geometry if GDAL is present and does nothing if it isn't present. In other words, no data corruption or other "Bad Things" occur -- the geometry remains untransformed (because it _can't_ be, there's no GDAL available to morph the vertices).
In hindsight, an exception probably should've been raised -- but if a ticket is opened for this 'feature', then there will be backwards-compatibility issues to address.
Good points about the clone keyword and the burden placed on user for
error checking (after all frameworks should make things easier).
Someone please open a ticket for this.
Once again, an abstraction leakage is the root cause of this
side-effect. GEOS, the library, has no concept of coordinate systems
other than the integer SRID. In other words, `GEOSGeom_transform`
doesn't exist. I added `GEOSGeometry.transform` as a convenience
method, but GEOS as doesn't perform transformations, the code asks GDAL
to perform the transform -- and if GDAL isn't around then nothing
happens, which is the root cause of this thread.
(Rob knows this already, but writing it down so others may follow)
> Idea 1 - issue 2 warnings?
> - a Warning that transform() is doing nothing.
> - a FutureWarning, that semantics will change from 1.5& an error will be
> raised.
>
> Idea 2 - I can't actually see any use cases where a user would want
> transform() to no-op unless the srids match - can anybody else? In which
> case I think it *could* be classed as a bug and hence ignore the deprecation
> policy if:
> - transform() no-ops if source& destination SRIDs match
> - we deal with geometry.srid being None to start with - i just noticed
> that case no-op's as well... maybe that could raise a FutureWarning too?
>
Agreed on no-op when appropriate, and exception after if GDAL not
present. This will break backwards-compatibility, but at same time will
inform users of potential problems in their code. Trade-off seems
acceptable to me, but only if the incompatible change is thoroughly
documented. In other words, an acceptable patch will have to note this
in the `transform` docs as well as mention the backwards-incompatibility
in future 1.3 release notes.
A tougher question is whether we backport to 1.2.X.
-Justin
The root cause of the thread is about why the user would need to
perform additional transform() calls on two points to measure the
distance between them, when the parameter to transform() is something
of a (small, static) table lookup based on the three parameters to
point (lat, lon, srid). It seems rather inconvenient...
Good points about the clone keyword and the burden placed on user for error checking (after all frameworks should make things easier). Someone please open a ticket for this.