[postgis-users] How to get the distance between geometry inmeters?
R H
enoop at hotmail.com
Thu Mar 20 12:54:42 PDT 2008
My explanation wasn't that great. Below is what I did.
26912 projection is in meters (right?)select AddGeometryColumn('table','geocode', 26912, 'POINT', 2);
update tableset geocode = PointFromText('POINT(' || longitude || ' ' || latitude || ')', 26912);
distance(geocode, geocode) returns degrees
ALTER TABLE property DROP COLUMN geocode
4269 projection in degreesselect AddGeometryColumn('table','geocode', 4269, 'POINT', 2);
update tableset geocode = PointFromText('POINT(' || longitude || ' ' || latitude || ')', 4269);
distance(transform(geocode, 26912), transform(geocode,26912)) returns meters
I would prefer not to do the transform() if don't have to speed and accuracy reasons. Thanks for help. : }
> Date: Thu, 20 Mar 2008 11:07:34 -0700> From: kneufeld at refractions.net> To: postgis-users at postgis.refractions.net> Subject: Re: [postgis-users] How to get the distance between geometry inmeters?> > Hi R H,> > Are you certain that your input geometries are in a meter projection? > David is correct. Distance() always returns the cartesian distance in > the *same* units as the input. It's impossible to input something in > meters in this function and get something in degrees.> > Looking at your SQL you posted earlier, I have the suspicion that your > input geometries are in lat/long (4269) and you simply updated the srid > of the geometries to be 26912, thinking that this would change the > projection of your geometries. Am I off here? To verify, can you post > the ewkt representation of a small geometry here?> > Cheers,> Kevin> > R H wrote:> > sorry in the example I said "returns cartesian distance", I meant > > degrees. So my input was in a meter projection and was returning degrees.> >> > ------------------------------------------------------------------------> > Date: Thu, 20 Mar 2008 12:08:11 -0500> > From: david.bitner at gmail.com> > To: postgis-users at postgis.refractions.net> > Subject: Re: [postgis-users] How to get the distance between> > geometry inmeters?> >> > Distance() always returns "cartesian distance" in whatever units> > it is fed. If it is fed data that is in meters -- the output will> > be in meters. If it is fed degrees -- the output will be in> > degrees and totally useless. I don't quite understand the problem> > that you are having> >> > On Thu, Mar 20, 2008 at 11:15 AM, R H <enoop at hotmail.com> > <mailto:enoop at hotmail.com>> wrote:> >> > Thanks for the reply. I think I got it figured out. The> > projections I was putting into distance() where in meters. I> > used a projection that is in degrees and then transformed to> > meters. It appears to be working now.> > > > I'm not sure I understand why?> > This is what I had previously> > geom = sird(26912) meter projection> > > > select distance(geom,geom) returns cartesian distance> > select distance(transform(geom, 26912), transform(geom,> > 26912)) returns cartesian distance> > > > then I changed geom = sird(4269) degree projection> > select distance(transform(geom, 26912), transform(geom,> > 26912)) returns meter> > > > How are any of these statements different? Based on order of> > operations isn't the inner most parentheses executed first? > > Therefore being exactly the same as the first select? I guess> > it's working so I will stop worrying about it.> >> > ------------------------------------------------------------------------> > From: lr at pcorp.us <mailto:lr at pcorp.us>> >> > To: postgis-users at postgis.refractions.net> > <mailto:postgis-users at postgis.refractions.net>> > Subject: RE: [postgis-users] How to get the distance> > between geometry inmeters?> > Date: Thu, 20 Mar 2008 05:37:30 -0400> >> >> > RH,> > > > Yes this is the same as putting 2 geoms with the *same> > *meter projection into ST_Distance. The transform> > effectively flattens out a small section of space so you> > are measuring in cartesian space which is actually what> > you want to do since it simplifies the math.> > > > Your example below transform(st_distance(geom,geom),srid) > > should give you an error since you are effectively taking> > a distance (which would be in double precision) and then> > trying to transform that. You can only transform> > geometries not distances.> > > > What sort of error are you getting with ST_Distance and> > ST_DWithin? Keep in mind that both your geometries have> > to be in the same meter projection otherwise an error> > would be thrown.> > > > Hope that helps,> > Leo & Regina> > > > > >> > ------------------------------------------------------------------------> > *From:* postgis-users-bounces at postgis.refractions.net> > <mailto:postgis-users-bounces at postgis.refractions.net>> > [mailto:postgis-users-bounces at postgis.refractions.net> > <mailto:postgis-users-bounces at postgis.refractions.net>]> > *On Behalf Of *R H> > *Sent:* Wednesday, March 19, 2008 6:03 PM> > *To:* PostGIS Users Discussion> > *Subject:* RE: [postgis-users] How to get the distance> > between geometry inmeters?> >> > isn't this the same as putting two geom w/ a meter> > projection into st_distance(), st_distance() still returns> > a cartesian distance not a distances in meters? Wouldn't> > you need to do something like...> > transform(st_distance(geom,geom),srid)??? > > > > I only ask because I am having a simular problem. My> > projections are in a meter projection, but I can't get> > st_distance() or st_dwithin() to use meters? any thoughts?> >> >> > ------------------------------------------------------------------------> > Subject: RE: [postgis-users] How to get the distance> > between geometry in meters?> > Date: Wed, 19 Mar 2008 06:56:24 -0400> > From: robe.dnd at cityofboston.gov> > <mailto:robe.dnd at cityofboston.gov>> > To: postgis-users at postgis.refractions.net> > <mailto:postgis-users at postgis.refractions.net>> >> > You'll need to transform to a meter based projection> > to do that. If for example you are in the U.S, SRID> > 2163 US National Atlas Equal Area works pretty good> > for measurement. It is not as accurate as UTM or> > State Plane, but its pretty good and covers all of US> > I believe and probably works for some of Canada as> > well (not sure about non-continental e.g. Hawaii,> > Alaska). > > > > e.g.> > > > SELECT road.rd_name, ht.ht_name,> > ST_Distance(ST_Transform(roads.the_geom,2163) ,> > ST_Transform(hotel.the_geom,2163)) as dist_meters> > FROM road, hotel> > WHERE <some criteria here>> > > > If you are somewhere else and your locations are> > within that projection, you can use that. Look at the> > utmzone function in the wiki that will help you> > determing the right UTM zone SRID for your data> > > > http://postgis.refractions.net/support/wiki/index.php?plpgsqlfunctions> > > > So you would use something liek> > SELECT utmzone(ST_Centroid(the_geom)) as srid> > > > to get the right UTM zone SRID> > > > > > Hope that helps,> > Regina> > > > > >> > ------------------------------------------------------------------------> > *From:* postgis-users-bounces at postgis.refractions.net> > <mailto:postgis-users-bounces at postgis.refractions.net>> > [mailto:postgis-users-bounces at postgis.refractions.net> > <mailto:postgis-users-bounces at postgis.refractions.net>]> > *On Behalf Of *Sinboy Chang> > *Sent:* Wednesday, March 19, 2008 3:09 AM> > *To:* postgis-users at postgis.refractions.net> > <mailto:postgis-users at postgis.refractions.net>> > *Subject:* [postgis-users] How to get the distance> > between geometry in meters?> >> > i want to get the distance between geometry,just like> > road or hotel poi,but ST_Distance() return the result> > in /cartesian dintance./> > So how can get the distance() by meters?> > ------------------------------------------------------------------------> >> > *The substance of this message, including any> > attachments, may be confidential, legally privileged> > and/or exempt from disclosure pursuant to> > Massachusetts law. It is intended solely for the> > addressee. If you received this in error, please> > contact the sender and delete the material from any> > computer. *> > ------------------------------------------------------------------------> >> > *Help make the earth a greener place. If at all> > possible resist printing this email and join us in> > saving paper.> > *> >> >> >> > _______________________________________________> > postgis-users mailing list> > postgis-users at postgis.refractions.net> > <mailto:postgis-users at postgis.refractions.net>> > http://postgis.refractions.net/mailman/listinfo/postgis-users> >> >> >> >> > -- > > ************************************> > David William Bitner > >> > ------------------------------------------------------------------------> >> > _______________________________________________> > postgis-users mailing list> > postgis-users at postgis.refractions.net> > http://postgis.refractions.net/mailman/listinfo/postgis-users> > > _______________________________________________> postgis-users mailing list> postgis-users at postgis.refractions.net> http://postgis.refractions.net/mailman/listinfo/postgis-users
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/postgis-users/attachments/20080320/59f89e4e/attachment.html>
More information about the postgis-users
mailing list