4

I'm using shapely to check if a point is in a polygon, but I also need to check if a point is in a circle. Checking the docs, I don't see how do that...

Maybe I could create a circle?

circle = (x,y).buffer(R)

But it doesn't seem to work using R in miles distance to set the ratio...

Is it possible? Or is there another lib to get it?

3

Christian, you can't have your circle center and point in long,lat space and have R with mile units. Computational geometry algorithms require you to choose one coordinate system. Latitude and longitude is not a good one to work in, by the way unless your objects are very small in extent. After you transform your points to a local coordinate system and scale R to the units of that systems (meters, say), your test with shapely is like this:

Point(cx, cy).distance(Point(px, py)) <= R

where cx, cy is the center of your circle and px, py is your point. In units of the local coordinate system, not long/lat.

  • wow, you are right Sean... I'm working over it, Thanks.. – chespinoza Jan 15 '13 at 18:37
3

You can use the distance_lte function in geodjango to check if your point is in a circle or not. It is the same as ST_Distance method in PostGIS.

The method which I have mentioned is drawing a 5 meter radius of a circle to find points from Zipcode models.

Returns models where the distance to the geometry field from the lookup geometry is less than or equal to the given distance value.

Example:

Zipcode.objects.filter(poly__distance_lte=(geom, D(m=5)))

I hope it helps you...

  • Thanks Aragon, but not in all cases I have a zip code for the location, instead I need use a (latitude,longitude) format to set the point. – chespinoza Jan 10 '13 at 12:36
  • @Christian_Espinoza, this is an example code for you to seeing it how the function is using. you can create your own model from lon,lat to check them all. – Aragon Jan 10 '13 at 12:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.