[postgis-users] Need help on basic concepts, I just need really simple calculations
Aaron Lewis
the.warl0ck.1989 at gmail.com
Sun Mar 22 07:42:09 PDT 2015
Thanks Nicolas,
I take a few tries, but it looks like ST_DWithin & ST_Distance all
deals in degrees, not meters ..:
gis=# select nick, ST_AsText(location), ST_Distance(location,
st_setsrid(st_makepoint (46.3, 36.10), 2600)) from users where
ST_DWithin(users.location, st_setsrid(st_makepoint (46.3, 36.10),
2600), 10);
nick | st_astext | st_distance
-------+------------------+------------------
user1 | POINT(45.2 35.1) | 1.48660687473185
user2 | POINT(45.2 35.2) | 1.42126704035518
user3 | POINT(45.5 35.3) | 1.13137084989848
I tried to cast it to geography type but:
ST_Distance(location::geography, st_setsrid(st_makepoint (46.3,
36.10), 2600)::geography)
Resulted in an error:
ERROR: Only lon/lat coordinate systems are supported in geography.
So how should I get this distance in meters?
On Sun, Mar 22, 2015 at 8:44 PM, Nicolas Ribot <nicolas.ribot at gmail.com> wrote:
> Hi Aaron,
>
> SRID is used to set a consistent coordinate system to the data. It refers to
> an EPSG Coordinate Reference System (CRS). For instance, EPSG:2600:
> (http://spatialreference.org/ref/epsg/2600/) is a metric CRS.
>
> Coordinates (146.0, 138.19) are not valid in SRID 2600 (nor in lat/long
> coordinates).
>
> You would use st_setSRID when the coordinates are already in the correct
> CRS, and st_transform() to reproject coordinates from one CRS to another:
>
> -- Search inside a 100m circle for a point already in SRID=2600:
> SELECT * FROM users
> WHERE ST_DWithin (users.location, st_setsrid(st_makepoint (508560, 6155116),
> 2600), 100);
>
> -- Search inside a 100m circle for a point in longitude/latitude, projected
> into SRID=2600:
> SELECT * FROM users
> WHERE ST_DWithin (users.location, st_transform(st_setsrid(st_makepoint (24.1
> 55.5), 4326), 2600), 100);
>
> (users.location SRID should be 2600 in these examples)
>
> Nicolas
>
>
>
> On 22 March 2015 at 12:09, Aaron Lewis <the.warl0ck.1989 at gmail.com> wrote:
>>
>> Hi,
>>
>> I've been searching online for days. Trying to understand why SRID is
>> required. So I picked some random value.
>>
>> Now I'm need to retrieve POINTs within a circle range, e.g a circle at
>> (146.0, 138.19) with radius of 100 meters:
>>
>> SELECT * FROM users
>> WHERE ST_DWithin (users.location, st_setsrid(st_makepoint (146.0,
>> 138.19), 2600), 100);
>>
>> It's very simple, but the result seems wrong. I have a record contains
>> a POINT(55 43) that matches this query.
>>
>> Anyone know what's wrong with it?
>>
>> --
>> Best Regards,
>> Aaron Lewis - PGP: 0x13714D33 - http://pgp.mit.edu/
>> Finger Print: 9F67 391B B770 8FF6 99DC D92D 87F6 2602 1371 4D33
>> _______________________________________________
>> postgis-users mailing list
>> postgis-users at lists.osgeo.org
>> http://lists.osgeo.org/cgi-bin/mailman/listinfo/postgis-users
>
>
>
> _______________________________________________
> postgis-users mailing list
> postgis-users at lists.osgeo.org
> http://lists.osgeo.org/cgi-bin/mailman/listinfo/postgis-users
--
Best Regards,
Aaron Lewis - PGP: 0x13714D33 - http://pgp.mit.edu/
Finger Print: 9F67 391B B770 8FF6 99DC D92D 87F6 2602 1371 4D33
More information about the postgis-users
mailing list