Finding if point is within a circle / radius

6 messages Options
Embed this post
Permalink
Alex-29

Finding if point is within a circle / radius

Reply Threaded More More options
Print post
Permalink
Hi all,

I am trying to figure out how I could query for all Points that are within a given radius using HibernateSpatial and JTS.

Let me explain :

I have a many Points Of Interrest in a database. What I want to do is :
Given Point A (which contains latitude longitude coordinates) and radius R (in meters), retrieve all the Points Of Interrest that are inside Circle of center A with radius R.

I don't think it is possible to create a Circle geometry to do this ... maybe an approximation such as a Circular Polygon...

Any Help would be greatly appreciated

Thanks in advance.

Cheers

Alex

_______________________________________________
hibernatespatial-users mailing list
[hidden email]
http://www.hibernatespatial.org/cgi-bin/mailman/listinfo/hibernatespatial-users
josegar74

Re: Finding if point is within a circle / radius

Reply Threaded More More options
Print post
Permalink
Some javascript/style in this post has been disabled (why?)
Hi

Look at http://docs.codehaus.org/display/GEOTDOC/03+How+to+Transform+a+Geometry

You can convert the point from lat/lon (4326) to UTM (32360) with geotools, create the buffer with the point and the radio , and convert the buffer again to lat/lon to make the Spatial Query using it.

Bye.

2008/4/8, az lists <[hidden email]>:
Hi all,

I am trying to figure out how I could query for all Points that are within a given radius using HibernateSpatial and JTS.

Let me explain :

I have a many Points Of Interrest in a database. What I want to do is :
Given Point A (which contains latitude longitude coordinates) and radius R (in meters), retrieve all the Points Of Interrest that are inside Circle of center A with radius R.

I don't think it is possible to create a Circle geometry to do this ... maybe an approximation such as a Circular Polygon...

Any Help would be greatly appreciated

Thanks in advance.

Cheers

Alex

_______________________________________________
hibernatespatial-users mailing list
[hidden email]
http://www.hibernatespatial.org/cgi-bin/mailman/listinfo/hibernatespatial-users



_______________________________________________
hibernatespatial-users mailing list
[hidden email]
http://www.hibernatespatial.org/cgi-bin/mailman/listinfo/hibernatespatial-users
Karel Maesen

Re: Finding if point is within a circle / radius

Reply Threaded More More options
Print post
Permalink
Alex,

In case you're using Hibernate Spatial with Oracle Spatial, you could  
also use the OracleSpatialRestrictions.SDOWithinDistance method  
(which has the same arguments as the SDO_WITHIN_DISTANCE operator.

Regards,

Karel

On 08 Apr 2008, at 20:12, jose garcia wrote:

> Hi
>
> Look at http://docs.codehaus.org/display/GEOTDOC/03+How+to+Transform 
> +a+Geometry
>
> You can convert the point from lat/lon (4326) to UTM (32360) with  
> geotools, create the buffer with the point and the radio , and  
> convert the buffer again to lat/lon to make the Spatial Query using  
> it.
>
> Bye.
>
> 2008/4/8, az lists <[hidden email]>: Hi all,
>
> I am trying to figure out how I could query for all Points that are  
> within a given radius using HibernateSpatial and JTS.
>
> Let me explain :
>
> I have a many Points Of Interrest in a database. What I want to do  
> is :
> Given Point A (which contains latitude longitude coordinates) and  
> radius R (in meters), retrieve all the Points Of Interrest that are  
> inside Circle of center A with radius R.
>
> I don't think it is possible to create a Circle geometry to do  
> this ... maybe an approximation such as a Circular Polygon...
>
> Any Help would be greatly appreciated
>
> Thanks in advance.
>
> Cheers
>
> Alex
>
> _______________________________________________
> hibernatespatial-users mailing list
> [hidden email]
> http://www.hibernatespatial.org/cgi-bin/mailman/listinfo/ 
> hibernatespatial-users
>
>
> _______________________________________________
> hibernatespatial-users mailing list
> [hidden email]
> http://www.hibernatespatial.org/cgi-bin/mailman/listinfo/ 
> hibernatespatial-users

_______________________________________________
hibernatespatial-users mailing list
[hidden email]
http://www.hibernatespatial.org/cgi-bin/mailman/listinfo/hibernatespatial-users
Alex-29

Re: Finding if point is within a circle / radius

Reply Threaded More More options
Print post
Permalink
Hi Karel,

Unfortunately I'm using MySQL as my database and maybe in some poin tin the future PostGIS.
So I can't use the Oracle Spatial solution.

Any other idea ?

On Tue, Apr 8, 2008 at 9:05 PM, Karel Maesen <[hidden email]> wrote:
Alex,

In case you're using Hibernate Spatial with Oracle Spatial, you could
also use the OracleSpatialRestrictions.SDOWithinDistance method
(which has the same arguments as the SDO_WITHIN_DISTANCE operator.

Regards,

Karel

On 08 Apr 2008, at 20:12, jose garcia wrote:
> Hi
>
> Look at http://docs.codehaus.org/display/GEOTDOC/03+How+to+Transform
> +a+Geometry
>
> You can convert the point from lat/lon (4326) to UTM (32360) with
> geotools, create the buffer with the point and the radio , and
> convert the buffer again to lat/lon to make the Spatial Query using
> it.
>
> Bye.
>
> 2008/4/8, az lists <[hidden email]>: Hi all,
>
> I am trying to figure out how I could query for all Points that are
> within a given radius using HibernateSpatial and JTS.
>
> Let me explain :
>
> I have a many Points Of Interrest in a database. What I want to do
> is :
> Given Point A (which contains latitude longitude coordinates) and
> radius R (in meters), retrieve all the Points Of Interrest that are
> inside Circle of center A with radius R.
>
> I don't think it is possible to create a Circle geometry to do
> this ... maybe an approximation such as a Circular Polygon...
>
> Any Help would be greatly appreciated
>
> Thanks in advance.
>
> Cheers
>
> Alex
>
> _______________________________________________
> hibernatespatial-users mailing list
> [hidden email]
> http://www.hibernatespatial.org/cgi-bin/mailman/listinfo/
> hibernatespatial-users
>
>
> _______________________________________________
> hibernatespatial-users mailing list
> [hidden email]
> http://www.hibernatespatial.org/cgi-bin/mailman/listinfo/
> hibernatespatial-users

_______________________________________________
hibernatespatial-users mailing list
[hidden email]
http://www.hibernatespatial.org/cgi-bin/mailman/listinfo/hibernatespatial-users


_______________________________________________
hibernatespatial-users mailing list
[hidden email]
http://www.hibernatespatial.org/cgi-bin/mailman/listinfo/hibernatespatial-users
Alex-29

Re: Finding if point is within a circle / radius

Reply Threaded More More options
Print post
Permalink
In reply to this post by josegar74
Thank you Jose for your answer,

however I'm not sure I understand your solution.

Why would I want to convert to UTM first ?
Besides I'm not really familiar with geotools ... it's still pretty complicated for me and there are so many jars and docs in the distribution I get lost very quickly..

Would you be kind enough to give me a short example of what you had in mind ?

Thanks in advance

Cheers,

Alex

.

On Tue, Apr 8, 2008 at 8:12 PM, jose garcia <[hidden email]> wrote:
Hi

Look at http://docs.codehaus.org/display/GEOTDOC/03+How+to+Transform+a+Geometry

You can convert the point from lat/lon (4326) to UTM (32360) with geotools, create the buffer with the point and the radio , and convert the buffer again to lat/lon to make the Spatial Query using it.

Bye.

2008/4/8, az lists <[hidden email]>:
Hi all,

I am trying to figure out how I could query for all Points that are within a given radius using HibernateSpatial and JTS.

Let me explain :

I have a many Points Of Interrest in a database. What I want to do is :
Given Point A (which contains latitude longitude coordinates) and radius R (in meters), retrieve all the Points Of Interrest that are inside Circle of center A with radius R.

I don't think it is possible to create a Circle geometry to do this ... maybe an approximation such as a Circular Polygon...

Any Help would be greatly appreciated

Thanks in advance.

Cheers

Alex

_______________________________________________
hibernatespatial-users mailing list
[hidden email]
http://www.hibernatespatial.org/cgi-bin/mailman/listinfo/hibernatespatial-users



_______________________________________________
hibernatespatial-users mailing list
[hidden email]
http://www.hibernatespatial.org/cgi-bin/mailman/listinfo/hibernatespatial-users



_______________________________________________
hibernatespatial-users mailing list
[hidden email]
http://www.hibernatespatial.org/cgi-bin/mailman/listinfo/hibernatespatial-users
josegar74

Re: Finding if point is within a circle / radius

Reply Threaded More More options
Print post
Permalink
Some javascript/style in this post has been disabled (why?)
Hi

You need to convert to UTM first because the radio is in meters and (if i'm not wrong) you can't  convert the distance to lat/lon directly. First you convert the point to UTM and generate the buffer in UTM (meters). Then, this polygon buffer can be converted to lat/lon and use it to select the other points that are in lat/lon coordinates.

Point point = ...
double radio = ....

CoordinateReferenceSystem geoCRS = CRS.decode("EPSG:4326");
CoordinateReferenceSystem utmCRS = CRS.decode("EPSG:32630");

MathTransform transformToUtm = CRS.findMathTransform(geoCRS, utmCRS);

Geometry targetGeometry = JTS.transform( point, transformToUtm);
Geometry buffer = targetGeometry.buffer(radio);
buffer.setSRID(32630);

MathTransform transformToGeo = CRS.findMathTransform(utmCRS, geoCRS);
Geometry bufferGeo = JTS.transform( buffer, transformToGeo);
bufferGeo.setSRID(4326);

bufferGeo is a lat/lon buffer of 100 meters centered in the origin point

You're right, geotools has  too many jars and it's a bit complicate. One solution, not optimal, it's to configure log4j and see what NoClassFoundError exceptions appear. Fortunately, geootols javadoc says you in which jar are the classes.

Bye.
 

2008/4/9, az lists <[hidden email]>:
Thank you Jose for your answer,

however I'm not sure I understand your solution.

Why would I want to convert to UTM first ?
Besides I'm not really familiar with geotools ... it's still pretty complicated for me and there are so many jars and docs in the distribution I get lost very quickly..

Would you be kind enough to give me a short example of what you had in mind ?

Thanks in advance

Cheers,

Alex

.

On Tue, Apr 8, 2008 at 8:12 PM, jose garcia <[hidden email]> wrote:
Hi

Look at http://docs.codehaus.org/display/GEOTDOC/03+How+to+Transform+a+Geometry

You can convert the point from lat/lon (4326) to UTM (32360) with geotools, create the buffer with the point and the radio , and convert the buffer again to lat/lon to make the Spatial Query using it.

Bye.

2008/4/8, az lists <[hidden email]>:
Hi all,

I am trying to figure out how I could query for all Points that are within a given radius using HibernateSpatial and JTS.

Let me explain :

I have a many Points Of Interrest in a database. What I want to do is :
Given Point A (which contains latitude longitude coordinates) and radius R (in meters), retrieve all the Points Of Interrest that are inside Circle of center A with radius R.

I don't think it is possible to create a Circle geometry to do this ... maybe an approximation such as a Circular Polygon...

Any Help would be greatly appreciated

Thanks in advance.

Cheers

Alex

_______________________________________________
hibernatespatial-users mailing list
[hidden email]
http://www.hibernatespatial.org/cgi-bin/mailman/listinfo/hibernatespatial-users



_______________________________________________
hibernatespatial-users mailing list
[hidden email]
http://www.hibernatespatial.org/cgi-bin/mailman/listinfo/hibernatespatial-users



_______________________________________________
hibernatespatial-users mailing list
[hidden email]
http://www.hibernatespatial.org/cgi-bin/mailman/listinfo/hibernatespatial-users



_______________________________________________
hibernatespatial-users mailing list
[hidden email]
http://www.hibernatespatial.org/cgi-bin/mailman/listinfo/hibernatespatial-users