Re: GIS Distance from Point to Geometry Collection

2012-01-31 Thread Jeff Heard
It should return whatever the units are in the coordinate system you have
set.  You will probably want to transform the geometry to UTM first.
 Something that treats the geometry as flat and sets distance to be in
meters or similar.  srid=3857 or 900913 will do this nicely (caveat
emptor).

-- Jeff

On Tue, Jan 31, 2012 at 9:07 PM, Alex Kopp  wrote:

> Yes Jeff, this is what I want to do. I wasn't sure if there was an easier
> way. What units does the distance function return? I tried this and it
> seems to return the distance in units of 10km, is this correct?
>
>  Thanks again!
>
>
> On Tue, Jan 31, 2012 at 9:04 PM, Jeff Heard 
> wrote:
>
>> Got it.  So what you want to do is a list comprehension over the geometry
>> object, which *should* give you individual geometries is what it sounds
>> like.  Then you can calculate distance() from each of these.  Something
>> like this?
>>
>> interesting_point = Point(x, y)
>> collection = result.geom
>> min_dist = min([g.distance(interesting_point) for g in collection])
>>
>> or for every geometrycollection in a queryset:
>>
>> result = MyModel.objects.all()
>> min_dist = min([min([g.distance(interesting_point) for g in coll]) for
>> coll in result])
>>
>> Brute force and thus a bit slow, but it should work if I understand you
>> correctly...
>>
>> -- Jeff
>>
>>
>> On Tue, Jan 31, 2012 at 8:45 PM, Alex Kopp  wrote:
>>
>>> Here's a more concrete example, say I am storing shapes of all
>>> countries. Now, the US can't be stored in one polygon (we have hawaii and
>>> alaska), therefore I have to store the many polygons in one
>>> geometrycollection.
>>>
>>> Now, say I have another point on the map, I would like to know how ar it
>>> is from ANY of the polygons...
>>>
>>>
>>> On Tue, Jan 31, 2012 at 8:41 PM, Alex Kopp  wrote:
>>>
 Perhaps I didn't explain it well, Jeff. I am just trying to get the
 smallest distance from one point to any of the points, lines, or polygons
 inside of a queryset. The data I am receiving from the queryset is a
 geometrycollection already... That is how it is being stored in the
 database.

 On Tue, Jan 31, 2012 at 8:36 PM, Jeff Heard <
 jefferson.r.he...@gmail.com> wrote:

> You should be able to create a geometrycollection object from a
> queryset (you may have to use a list comprehension for this), then
> calculate the centroid and take the distance from that. Taking the 
> distance
> from the edge should only be a little more
> Complicated.  Check the django GEOS API docs For complete details
>
>
>
> On Jan 31, 2012, at 6:36 PM, Loafer  wrote:
>
> > I have a model that currently stores a Geographic Point (Using Django
> > GIS (GeoDjango)) and another model that has a field to store a
> > geometry collection (A collection of polygons, lines, and or points).
> >
> > I am trying to find the distance from the point to any one of the
> > shapes in the geometry collection. Apparently the distance function
> > only works on single shapes, not a collection. Are there any
> > workarounds to this?
> >
> > Any help is appreciated.
> >
> > Thanks.
> >
> > --
> > You received this message because you are subscribed to the Google
> Groups "Django users" group.
> > To post to this group, send email to django-users@googlegroups.com.
> > To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com.
> > For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
> >
>
> --
> You received this message because you are subscribed to the Google
> Groups "Django users" group.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>
>

>>>  --
>>> You received this message because you are subscribed to the Google
>>> Groups "Django users" group.
>>> To post to this group, send email to django-users@googlegroups.com.
>>> To unsubscribe from this group, send email to
>>> django-users+unsubscr...@googlegroups.com.
>>> For more options, visit this group at
>>> http://groups.google.com/group/django-users?hl=en.
>>>
>>
>>  --
>> You received this message because you are subscribed to the Google Groups
>> "Django users" group.
>> To post to this group, send email to django-users@googlegroups.com.
>> To unsubscribe from this group, send email to
>> django-users+unsubscr...@googlegroups.com.
>> For more options, visit this group at
>> http://groups.google.com/group/django-users?hl=en.
>>
>
>  --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send 

Re: GIS Distance from Point to Geometry Collection

2012-01-31 Thread Alex Kopp
Yes Jeff, this is what I want to do. I wasn't sure if there was an easier
way. What units does the distance function return? I tried this and it
seems to return the distance in units of 10km, is this correct?

Thanks again!

On Tue, Jan 31, 2012 at 9:04 PM, Jeff Heard wrote:

> Got it.  So what you want to do is a list comprehension over the geometry
> object, which *should* give you individual geometries is what it sounds
> like.  Then you can calculate distance() from each of these.  Something
> like this?
>
> interesting_point = Point(x, y)
> collection = result.geom
> min_dist = min([g.distance(interesting_point) for g in collection])
>
> or for every geometrycollection in a queryset:
>
> result = MyModel.objects.all()
> min_dist = min([min([g.distance(interesting_point) for g in coll]) for
> coll in result])
>
> Brute force and thus a bit slow, but it should work if I understand you
> correctly...
>
> -- Jeff
>
>
> On Tue, Jan 31, 2012 at 8:45 PM, Alex Kopp  wrote:
>
>> Here's a more concrete example, say I am storing shapes of all
>> countries. Now, the US can't be stored in one polygon (we have hawaii and
>> alaska), therefore I have to store the many polygons in one
>> geometrycollection.
>>
>> Now, say I have another point on the map, I would like to know how ar it
>> is from ANY of the polygons...
>>
>>
>> On Tue, Jan 31, 2012 at 8:41 PM, Alex Kopp  wrote:
>>
>>> Perhaps I didn't explain it well, Jeff. I am just trying to get the
>>> smallest distance from one point to any of the points, lines, or polygons
>>> inside of a queryset. The data I am receiving from the queryset is a
>>> geometrycollection already... That is how it is being stored in the
>>> database.
>>>
>>> On Tue, Jan 31, 2012 at 8:36 PM, Jeff Heard >> > wrote:
>>>
 You should be able to create a geometrycollection object from a
 queryset (you may have to use a list comprehension for this), then
 calculate the centroid and take the distance from that. Taking the distance
 from the edge should only be a little more
 Complicated.  Check the django GEOS API docs For complete details



 On Jan 31, 2012, at 6:36 PM, Loafer  wrote:

 > I have a model that currently stores a Geographic Point (Using Django
 > GIS (GeoDjango)) and another model that has a field to store a
 > geometry collection (A collection of polygons, lines, and or points).
 >
 > I am trying to find the distance from the point to any one of the
 > shapes in the geometry collection. Apparently the distance function
 > only works on single shapes, not a collection. Are there any
 > workarounds to this?
 >
 > Any help is appreciated.
 >
 > Thanks.
 >
 > --
 > You received this message because you are subscribed to the Google
 Groups "Django users" group.
 > To post to this group, send email to django-users@googlegroups.com.
 > To unsubscribe from this group, send email to
 django-users+unsubscr...@googlegroups.com.
 > For more options, visit this group at
 http://groups.google.com/group/django-users?hl=en.
 >

 --
 You received this message because you are subscribed to the Google
 Groups "Django users" group.
 To post to this group, send email to django-users@googlegroups.com.
 To unsubscribe from this group, send email to
 django-users+unsubscr...@googlegroups.com.
 For more options, visit this group at
 http://groups.google.com/group/django-users?hl=en.


>>>
>>  --
>> You received this message because you are subscribed to the Google Groups
>> "Django users" group.
>> To post to this group, send email to django-users@googlegroups.com.
>> To unsubscribe from this group, send email to
>> django-users+unsubscr...@googlegroups.com.
>> For more options, visit this group at
>> http://groups.google.com/group/django-users?hl=en.
>>
>
>  --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: GIS Distance from Point to Geometry Collection

2012-01-31 Thread Jeff Heard
Got it.  So what you want to do is a list comprehension over the geometry
object, which *should* give you individual geometries is what it sounds
like.  Then you can calculate distance() from each of these.  Something
like this?

interesting_point = Point(x, y)
collection = result.geom
min_dist = min([g.distance(interesting_point) for g in collection])

or for every geometrycollection in a queryset:

result = MyModel.objects.all()
min_dist = min([min([g.distance(interesting_point) for g in coll]) for coll
in result])

Brute force and thus a bit slow, but it should work if I understand you
correctly...

-- Jeff


On Tue, Jan 31, 2012 at 8:45 PM, Alex Kopp  wrote:

> Here's a more concrete example, say I am storing shapes of all
> countries. Now, the US can't be stored in one polygon (we have hawaii and
> alaska), therefore I have to store the many polygons in one
> geometrycollection.
>
> Now, say I have another point on the map, I would like to know how ar it
> is from ANY of the polygons...
>
>
> On Tue, Jan 31, 2012 at 8:41 PM, Alex Kopp  wrote:
>
>> Perhaps I didn't explain it well, Jeff. I am just trying to get the
>> smallest distance from one point to any of the points, lines, or polygons
>> inside of a queryset. The data I am receiving from the queryset is a
>> geometrycollection already... That is how it is being stored in the
>> database.
>>
>> On Tue, Jan 31, 2012 at 8:36 PM, Jeff Heard 
>> wrote:
>>
>>> You should be able to create a geometrycollection object from a queryset
>>> (you may have to use a list comprehension for this), then calculate the
>>> centroid and take the distance from that. Taking the distance from the edge
>>> should only be a little more
>>> Complicated.  Check the django GEOS API docs For complete details
>>>
>>>
>>>
>>> On Jan 31, 2012, at 6:36 PM, Loafer  wrote:
>>>
>>> > I have a model that currently stores a Geographic Point (Using Django
>>> > GIS (GeoDjango)) and another model that has a field to store a
>>> > geometry collection (A collection of polygons, lines, and or points).
>>> >
>>> > I am trying to find the distance from the point to any one of the
>>> > shapes in the geometry collection. Apparently the distance function
>>> > only works on single shapes, not a collection. Are there any
>>> > workarounds to this?
>>> >
>>> > Any help is appreciated.
>>> >
>>> > Thanks.
>>> >
>>> > --
>>> > You received this message because you are subscribed to the Google
>>> Groups "Django users" group.
>>> > To post to this group, send email to django-users@googlegroups.com.
>>> > To unsubscribe from this group, send email to
>>> django-users+unsubscr...@googlegroups.com.
>>> > For more options, visit this group at
>>> http://groups.google.com/group/django-users?hl=en.
>>> >
>>>
>>> --
>>> You received this message because you are subscribed to the Google
>>> Groups "Django users" group.
>>> To post to this group, send email to django-users@googlegroups.com.
>>> To unsubscribe from this group, send email to
>>> django-users+unsubscr...@googlegroups.com.
>>> For more options, visit this group at
>>> http://groups.google.com/group/django-users?hl=en.
>>>
>>>
>>
>  --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: GIS Distance from Point to Geometry Collection

2012-01-31 Thread Alex Kopp
Here's a more concrete example, say I am storing shapes of all
countries. Now, the US can't be stored in one polygon (we have hawaii and
alaska), therefore I have to store the many polygons in one
geometrycollection.

Now, say I have another point on the map, I would like to know how ar it is
from ANY of the polygons...

On Tue, Jan 31, 2012 at 8:41 PM, Alex Kopp  wrote:

> Perhaps I didn't explain it well, Jeff. I am just trying to get the
> smallest distance from one point to any of the points, lines, or polygons
> inside of a queryset. The data I am receiving from the queryset is a
> geometrycollection already... That is how it is being stored in the
> database.
>
> On Tue, Jan 31, 2012 at 8:36 PM, Jeff Heard 
> wrote:
>
>> You should be able to create a geometrycollection object from a queryset
>> (you may have to use a list comprehension for this), then calculate the
>> centroid and take the distance from that. Taking the distance from the edge
>> should only be a little more
>> Complicated.  Check the django GEOS API docs For complete details
>>
>>
>>
>> On Jan 31, 2012, at 6:36 PM, Loafer  wrote:
>>
>> > I have a model that currently stores a Geographic Point (Using Django
>> > GIS (GeoDjango)) and another model that has a field to store a
>> > geometry collection (A collection of polygons, lines, and or points).
>> >
>> > I am trying to find the distance from the point to any one of the
>> > shapes in the geometry collection. Apparently the distance function
>> > only works on single shapes, not a collection. Are there any
>> > workarounds to this?
>> >
>> > Any help is appreciated.
>> >
>> > Thanks.
>> >
>> > --
>> > You received this message because you are subscribed to the Google
>> Groups "Django users" group.
>> > To post to this group, send email to django-users@googlegroups.com.
>> > To unsubscribe from this group, send email to
>> django-users+unsubscr...@googlegroups.com.
>> > For more options, visit this group at
>> http://groups.google.com/group/django-users?hl=en.
>> >
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Django users" group.
>> To post to this group, send email to django-users@googlegroups.com.
>> To unsubscribe from this group, send email to
>> django-users+unsubscr...@googlegroups.com.
>> For more options, visit this group at
>> http://groups.google.com/group/django-users?hl=en.
>>
>>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: GIS Distance from Point to Geometry Collection

2012-01-31 Thread Alex Kopp
Perhaps I didn't explain it well, Jeff. I am just trying to get the
smallest distance from one point to any of the points, lines, or polygons
inside of a queryset. The data I am receiving from the queryset is a
geometrycollection already... That is how it is being stored in the
database.

On Tue, Jan 31, 2012 at 8:36 PM, Jeff Heard wrote:

> You should be able to create a geometrycollection object from a queryset
> (you may have to use a list comprehension for this), then calculate the
> centroid and take the distance from that. Taking the distance from the edge
> should only be a little more
> Complicated.  Check the django GEOS API docs For complete details
>
>
>
> On Jan 31, 2012, at 6:36 PM, Loafer  wrote:
>
> > I have a model that currently stores a Geographic Point (Using Django
> > GIS (GeoDjango)) and another model that has a field to store a
> > geometry collection (A collection of polygons, lines, and or points).
> >
> > I am trying to find the distance from the point to any one of the
> > shapes in the geometry collection. Apparently the distance function
> > only works on single shapes, not a collection. Are there any
> > workarounds to this?
> >
> > Any help is appreciated.
> >
> > Thanks.
> >
> > --
> > You received this message because you are subscribed to the Google
> Groups "Django users" group.
> > To post to this group, send email to django-users@googlegroups.com.
> > To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com.
> > For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
> >
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: GIS Distance from Point to Geometry Collection

2012-01-31 Thread Jeff Heard
You should be able to create a geometrycollection object from a queryset (you 
may have to use a list comprehension for this), then calculate the centroid and 
take the distance from that. Taking the distance from the edge should only be a 
little more
Complicated.  Check the django GEOS API docs For complete details



On Jan 31, 2012, at 6:36 PM, Loafer  wrote:

> I have a model that currently stores a Geographic Point (Using Django
> GIS (GeoDjango)) and another model that has a field to store a
> geometry collection (A collection of polygons, lines, and or points).
> 
> I am trying to find the distance from the point to any one of the
> shapes in the geometry collection. Apparently the distance function
> only works on single shapes, not a collection. Are there any
> workarounds to this?
> 
> Any help is appreciated.
> 
> Thanks.
> 
> -- 
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to 
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at 
> http://groups.google.com/group/django-users?hl=en.
> 

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



GIS Distance from Point to Geometry Collection

2012-01-31 Thread Loafer
I have a model that currently stores a Geographic Point (Using Django
GIS (GeoDjango)) and another model that has a field to store a
geometry collection (A collection of polygons, lines, and or points).

I am trying to find the distance from the point to any one of the
shapes in the geometry collection. Apparently the distance function
only works on single shapes, not a collection. Are there any
workarounds to this?

Any help is appreciated.

Thanks.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.