[Gdal-dev] OGRGeometry::Distance
Howard Butler
hobu at iastate.edu
Sun Sep 18 13:54:02 EDT 2005
Matthew,
It is just an oversight that the Python OGR.Geometry.Distance
function is not implemented in ogr.py. It *is* in the wrapper
though. Here is what I do to get a Distance function. I usually put
it after all of my imports at the top.
try:
ogr.Geometry.Distance
except AttributeError:
def Distance(self, other):
dist = _gdal.OGR_G_Distance(self._o, other._o);
return dist
ogr.Geometry.Distance = Distance
Howard
At 10:50 PM -0700 9/17/05, Matthew Perry wrote:
>Hi folks,
>
> I'm new to the list so I'll just introduce myself real quick. I've
>been doing GIS and cartography for 4 years at Humboldt State
>University as a Natural Resources major and, although it's not my
>background per se, I've been getting heavily into programming these
>past few months. Most of my web mapping stuff is PHP/Mapscript but
>I've begun really like python/OGR/GDAL for doing my data processing.
>
> Anyways, I've run into a bit of an issue with the
>OGRGeometry::Distance method. Check out the following script:
>
> import ogr
> # Create some test geometries
> wkt = 'POINT(1 1)'
> g1 = ogr.CreateGeometryFromWkt(wkt)
> wkt = 'POINT(2 1)'
> g2 = ogr.CreateGeometryFromWkt(wkt)
>
> b = g1.Buffer(2)
> # Works fine so we know geos is enabled
>
> d = g1.Distance(g2)
> # fails ... "Attribute Error: Geometry instance has no attribute
>'Distance'"
>
>According to the docs at
><http://gdal.maptools.org/ogr/classOGRGeometry.html>http://gdal.maptools.org/ogr/classOGRGeometry.html
>this should work, right? Or have there been recent changes that
>break this method? Are there any updated docs anywhere? I'm using
>gdal 1.3.0 packaged with FWTools 0.9.9 on ubuntu linux.
>
>Thanks for helping me out.
>
>--
>Matt Perry
><mailto:perrygeo at gmail.com>perrygeo at gmail.com
><http://www.perrygeo.net>http://www.perrygeo.net
>
>_______________________________________________
>Gdal-dev mailing list
>Gdal-dev at lists.maptools.org
>http://lists.maptools.org/mailman/listinfo/gdal-dev
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.osgeo.org/pipermail/gdal-dev/attachments/20050918/b038759e/attachment.html
More information about the Gdal-dev
mailing list