<!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.&nbsp; It *is* in the wrapper
though.&nbsp; Here is what I do to get a Distance function.&nbsp; I
usually put it after all of my imports at the top.</div>
<div><br></div>
<div>try:<br>
&nbsp;&nbsp;&nbsp; ogr.Geometry.Distance<br>
except AttributeError:<br>
&nbsp;&nbsp;&nbsp; def Distance(self, other):<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; dist =
_gdal.OGR_G_Distance(self._o, other._o);<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return dist<br>
&nbsp;&nbsp;&nbsp; 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>
&nbsp; 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>
&nbsp; Anyways, I've run into a bit of an issue with the
OGRGeometry::Distance method. Check out the following script:<br>
<br>
&nbsp;&nbsp;&nbsp; import ogr<br>
&nbsp;&nbsp;&nbsp; # Create some test geometries<br>
&nbsp;&nbsp;&nbsp; wkt = 'POINT(1 1)'<br>
&nbsp;&nbsp;&nbsp; g1 = ogr.CreateGeometryFromWkt(wkt)<br>
&nbsp;&nbsp;&nbsp; wkt = 'POINT(2 1)'<br>
&nbsp;&nbsp;&nbsp; g2 = ogr.CreateGeometryFromWkt(wkt)<br>
<br>
&nbsp;&nbsp;&nbsp; b = g1.Buffer(2)<br>
&nbsp;&nbsp;&nbsp; # Works fine so we know geos is enabled<br>
&nbsp;<br>
&nbsp;&nbsp;&nbsp; d = g1.Distance(g2)<br>
&nbsp;&nbsp;&nbsp; # fails ... &quot;Attribute Error: Geometry
instance has no attribute 'Distance'&quot;<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>