<!doctype html public "-//W3C//DTD W3 HTML//EN">
<html><head><style type="text/css"><!--
blockquote, dl, ul, ol, li { padding-top: 0 ; padding-bottom: 0 }
--></style><title>Re: [Gdal-dev]
OGRGeometry::Distance</title></head><body>
<div>Matthew,</div>
<div><br></div>
<div>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.</div>
<div><br></div>
<div>try:<br>
ogr.Geometry.Distance<br>
except AttributeError:<br>
def Distance(self, other):<br>
dist =
_gdal.OGR_G_Distance(self._o, other._o);<br>
return dist<br>
ogr.Geometry.Distance = Distance</div>
<div><br></div>
<div><br></div>
<div>Howard</div>
<div><br></div>
<div><br></div>
<div>At 10:50 PM -0700 9/17/05, Matthew Perry wrote:</div>
<blockquote type="cite" cite>Hi folks,<br>
<br>
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.<br>
<br>
Anyways, I've run into a bit of an issue with the
OGRGeometry::Distance method. Check out the following script:<br>
<br>
import ogr<br>
# Create some test geometries<br>
wkt = 'POINT(1 1)'<br>
g1 = ogr.CreateGeometryFromWkt(wkt)<br>
wkt = 'POINT(2 1)'<br>
g2 = ogr.CreateGeometryFromWkt(wkt)<br>
<br>
b = g1.Buffer(2)<br>
# Works fine so we know geos is enabled<br>
<br>
d = g1.Distance(g2)<br>
# fails ... "Attribute Error: Geometry
instance has no attribute 'Distance'"<br>
<br>
According to the docs at <a
href="http://gdal.maptools.org/ogr/classOGRGeometry.html"
>http://gdal.maptools.org/ogr/classOGRGeometry.html</a> 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.<br>
<br>
Thanks for helping me out.<br>
<br>
--<br>
Matt Perry<br>
<a href="mailto:perrygeo@gmail.com">perrygeo@gmail.com</a><br>
<a
href="http://www.perrygeo.net">http://www.perrygeo.net</a></blockquote>
<blockquote type="cite" cite><br>
_______________________________________________<br>
Gdal-dev mailing list<br>
Gdal-dev@lists.maptools.org<br>
http://lists.maptools.org/mailman/listinfo/gdal-dev</blockquote>
<div><br></div>
</body>
</html>