Calculating distance between Lat Long points
I'm wondering if anyone out there has done this before in LabVIEW. Does anyone have a model of the "Great Circle" calculation? I have a file of lat/long points that I need to calculate the distance between. Any help??
V/r,
Chris
I haven't done it in LV, but if you go to Wikipedia and search for Great Circle Distance you'll find the formual and an example.
Similar Messages
-
Calculating distance between lat long coordinates best possible way?
Hi,
Am proposing to have a table A with latitude and longitude values along with some other info for that lat lon in it. The number of rows of data will be more and it will be growing day by day. i am having one application which will provide a latitude and longitude value and this i have to compare with all the lat lon of the table A and fetch the nearest (distance wise) information from other columns corresponding to that lat long in table A.
what is the best method available to implement this so as to reduce the time required to compare lat lon supplied with all rows of data in table A.
Thanks in advance.Have a look at the spatial option from oracle. Also there is a forum dedicated to this type of questions.
http://www.oracle.com/technetwork/database/options/spatial/index.html
especially: http://download.oracle.com/otndocs/products/spatial/pdf/locator11g_feature_overview.pdf
Edited by: Sven W. on Nov 30, 2010 5:53 PM -
Distance between two GPS points
Is there an inbuilt function in PL/SQL for calulating the distance between two GPS (lat/long) points?
I'm using Oracle 9i. There's a thing called SDO_GEOM available, but I'm not sure if this is what its used for or if it's the best option.If the earth is a complete globe and its circumference is 40000km,
I make the function as follows.
create ore replace
function distance
(a_lat number,a_lon number,b_lat number, b_lon number)
return number is
circum number := 40000; -- kilometers
pai number := acos(-1);
a_nx number;
a_ny number;
a_nz number;
b_nx number;
b_ny number;
b_nz number;
inner_product number;
begin
if (a_lat=b_lat) and (a_lon=b_lon) then
return 0;
else
a_nx := cos(a_lat*pai/180) * cos(a_lon*pai/180);
a_ny := cos(a_lat*pai/180) * sin(a_lon*pai/180);
a_nz := sin(a_lat*pai/180);
b_nx := cos(b_lat*pai/180) * co s(b_lon*pai/180);
b_ny := cos(b_lat*pai/180) * sin(b_lon*pai/180);
b_nz := sin(b_lat*pai/180);
inner_product := a_nx*b_nx + a_ny*b_ny + a_nz*b_nz;
if inner_product > 1 then
return 0;
else
return (circum*acos(inner_product))/(2*pai);
end if;
end if;
end;
I rewrite it by using the factorization and the triangle function's sum and difference formulas:
cos(x-y) = cos(x)cos(y)+sin(x)sin(y)
As result, this function is same to the 1st method of Billy Verreynne.
create or replace
function distance
(a_lat number,a_lon number,b_lat number, b_lon number)
return number is
circum number := 40000; -- kilometers
pai number := acos(-1);
dz number;
dx2y2 number;
inner_product number;
begin
if (a_lat=b_lat) and (a_lon=b_lon) then
return 0;
else
dz := sin(a_lat*pai/180)*sin(b_lat*pai/180);
dx2y2 := cos(a_lat*pai/180)*cos(b_lat*pai/180)*cos((a_lon-b_lon)*pai/180);
inner_product := dz*dz + dx2y2;
if inner_product > 1 then
return 0;
else
return (circum*acos(inner_product))/(2*pai);
end if;
end if;
end;
Message was edited by:
ushitaki -
Calculating Distance given a 4 point 2D image
Hi All,
3d n00b so play nice :-)
I'm trying to use a Wii remote camera to calculate real world distance from an object in Java.
The Wiimote will supply me the x and y coordinates of the 4 point object, which is actually 4 lights on the floor in this configuration.
I know the exact measurements of the 4 objects and the distance between them in the real world.
I know the 2D co-ordinates as represented on a 1024x768 screen.
I know the Angle of the Wiimote.
The lights will only ever be on a flat horizontal plane.
Is there anyway to reverse transform the 2D image from the camera back into 3D, taking into account the fact that the image may be rotated, and thus calculate the distance in the real world?
I'm guessing its some clever trig and some wizzy transformations although its been 20 years since I was in school! :-)
If you need any more explenation I'd be happy to attach some drawings.
Thanks in advance.
Uzerfriendlyhi
did you ever find out anything regarding your query?
i was trying to solve maybe a similar problem
though i'm not sure
how can i calculate the distance of an object of a known size (say, a person) that appears in a picture
presupposing the picture was image is not magnified or is somehow "sstandardized" or somehow "like" human vision
does it make any sense?
be happy to hear
thanks
doron -
Calculating distance between polyons in a donut
Is there any easy way of measure the nearest distance between the outer ring of a donut and the inner ring?
I've split the polygons into two discrete objects and tried sdo_distance but always get 0.00.
Any help would be appreciated?Hi David,
In Oracle10g there is a function sdo_util.polygontoline.
If you extract each of the elements of interest, you can convert them to lines, then the distance will work for you.
If you keep the geometries as polygons, then the distance is 0 because one polygon is inside the other polygon.
Hope this helps, and all is well with you.
Dan -
Find driving distance between two points without using API by use of Lat & Long?
Using Google geocode API : http://maps.googleapis.com/maps/api/geocode/xml?address=thane&sensor=true
We performed get distance between search criteria entered by user and all related clubs by lat & long stored at db.
2. Two different points such as
(origin: Lat1 & Long1) and (destination: Lat2 & Long2)
We tried for to get distance between these two points,
(Lat2 & Long2) to (Lat1 & Long1)
But distance which we get by calculation is simple straight line distance
Origin Destination
(Lat1 & Long1) (Lat2 & Long2)
3. This is not driving distance as google shows in exact Km
4. For that Google provide another API (distancematrix API)
http://maps.googleapis.com/maps/api/distancematrix/xml?origins=Thane&sensor=true&destinations=khopat&mode=driving&language=en%20-%20EN
5. But there is limit for DistanceMatrix-Service without ClientID and client key
100 elements per query.
100 elements per 10 seconds.
2 500 elements per 24 hour period.
But as element request exceeds it shows : OVER_QUERY_LIMIT error
6. In case of Client ID and Client key
In Distance Matrix 100 000 elements per 24 hour period,a maximum of 625 elements per query and a maximum of 1 000 elements per 10 seconds.
As per this one there is option to get purchase these API but basic question is remain same for us if we are requesting single origin and multiple destination then how element calculation done by google?
But in document google says :
Elements
The information about each origin-destination pairing is returned in an element entry. An element contains the following fields:
Status: See Status Codes for a list of possible status codes.
Duration: The duration of this route, expressed in seconds (the value field) and as text. The textual representation is localized according to
the query's language parameter.
Distance: The total distance of this route, expressed in meters (value) and as text. The textual value uses the unit system specified with the
unit parameter of the original request, or the origin's region.Any information that you see in a google map webpage can be retrieved using the API. The best way of finding the tags on the webpage is to manually perform the query using an IE webpage. Then capture the source and save to a file so you
can use a text editor to look at results. I often on a webpage use the menu : View - Source and then copy the source to a text file.
jdweng -
MInimun Distance between points
Hi all, can you help me understand this program so that I can started:
public static int[] minDistance(int[] x,
int[] y)
Given N points in the plane with integer coordinates, determine the minimum distance between two distinct points in the input. The points will be given by two arrays of the same length, one containing the x-coordinates and the other containing the y-coordinates. Return the indices in the array of a pair of points at minimum (positive) distance from each other, least index first. If more than one pair of points have the minimum distance from each other, return the lexicographically first pair (i,j) of indices of closest points.
Constraints The two arrays will have the same length N, which will be at least two. The numbers in the input arrays will be between -10000 and 10000. Note that you are not guaranteed that there will be no duplicates in the list, but the requirements state that only positive distances are compared.
Examples
(1) { 0,1}, {0,1}. This input represents the two points (0,0) and (1,1). Return {0,1}.
(2) { 0,1,0}, {0,1,0}. Return {0,1} as before, not {0,2}. The point (0,0) occurs twice in the input list, but this does not cause the minimum distance to be zero.
(3) {0,1,2,3,4,5,6,7,8,9,10}, {0,12,34,-48,15,347,8,5,3,2,1}. Return {8,9}; the points with those indices are (8,3) and (9,2).
(3a) {0,1,2,3,4,5,6,9,8,7,10}, {0,12,34,-48,15,347,8,2,3,5,1}. Return {7,8}
Thanks..........BTW, what's Sedgewick?He's an author.
http://www.cs.princeton.edu/~rs/
A little googling on my part reminds me that it was "divide and conquer" that he was talking about (too many) years ago.
http://www.facweb.iitkgp.ernet.in/~arijit/courses/autumn2006/cs60001/lec-compugeo-2.pdf -
Calculate distance between Latitude and Longitude
Hi All,
I have one Latitude and Longitude points. I need to calculate distance between them.
Right now we are using HAVERSINE formula but the query takes longer time to complete.
Reference: http://www.movable-type.co.uk/scripts/latlong.html
Please assist on this.
Thanks in advance.Check this link...
http://www.mrexcel.com/forum/excel-questions/202255-calculating-distance-between-two-latitude-longitude-points.html
I never did this before, but gave it a try using the formula mentioned in that link..
Data:
Lat Long R = 6,371 (Radius of earth (approximated))
Origin: 44.844263(B2) -92.914803(C2)
Destination: 44.822075(B3) -92.912498(C3)
Formula used:
A: =SIN(ABS(B3-B2)*PI()/180/2)^2+COS(B2*PI()/180)*COS(B3*PI()/180)*SIN(ABS(C3-C2)*PI()/180/2)^2
B: =2*ATAN2(SQRT(1-A),SQRT(A))
C: =R*B ---> DISTANCE!!!!
WITH t AS
(SELECT POWER (
SIN (ABS (44.822075 - 44.844263) * ( (22 / 7) / 180 / 2)),
2)
+ COS (44.844263 * ( (22 / 7) / 180))
* COS (44.822075 * ( (22 / 7) / 180))
* POWER (
SIN (
ABS (-92.912498 - (-92.914803))
* ( (22 / 7) / 180 / 2)),
2)
E2
FROM DUAL)
SELECT (2 * ATAN2 (SQRT ( (1 - E2)), SQRT (E2))) * 6371
FROM t;
Check if this gives correct values... (I did not verify this properly.. ) And this is faster in my opinion..
Please post your code for better suggestions from volunteers...
Cheers,
Manik. -
Accurate distance between points, lat/long to miles?
Hi,
I have a bunch of points as lat/long data in SRID 8307 format. From reading this forum, I understand than in Oracle 8.1.7 to get accurate distances I need to transform these points into a cartesian coordinate system.
My data is US-based, so I am using SRID 32775 in a command like the following:
EXECUTE SDO_CS.TRANSFORM_LAYER('restaurant_locations', 'location', 'restaurant_locations_32775', 32775);
This creates a new table with new point geometries and a rowid that I assume points back to the original 8307 table.
I've tried creating an index on the new table with cartesian coordinates, but I get this error:
CREATE INDEX restaurant_csp_idx
ON restaurant_locations_32775(geometry)
INDEXTYPE IS MDSYS.SPATIAL_INDEX
PARAMETERS('SDO_LEVEL=9 sdo_commit_interval=1000 layer_gtype=POINT' );
2 3 4 CREATE INDEX restaurant_csp_idx
ERROR at line 1:
ORA-29855: error occurred in the execution of ODCIINDEXCREATE routine
ORA-13200: internal error [POINT] in spatial indexing.
ORA-29400: data cartridge error
ORA-13003: the specified range for a dimension is invalid
ORA-06512: at "MDSYS.MD", line 1673
ORA-06512: at line 1
ORA-13003: the specified range for a dimension is invalid
ORA-06512: at "MDSYS.MD", line 1673
ORA-06512: at line 1
ORA-06512: at "MDSYS.SDO_INDEX_METHOD", line 8
ORA-06512: at line 1
Here's the entry for the 32775-transformed points in the metadata table:
INSERT INTO USER_SDO_GEOM_METADATA
VALUES (
'restaurant_locations_32775',
'geometry',
MDSYS.SDO_DIM_ARRAY( -- 20X20 grid, virtually zero tolerance
MDSYS.SDO_DIM_ELEMENT('X', 1951908.05, 16230214.8, 0.005),
MDSYS.SDO_DIM_ELEMENT('Y', -6858801, 13168375.5, 0.005)
32775 -- SRID (reserved for future Spatial releases)
My questions are;
Do I need to build a new spatial index? It seems like once I transform the lat/long data to cartesian I need to build a new index as well ( on the 32775-transformed table ).
Is this the best way to approach distance queries with lat/long data? It seems like a lot of work, plus the second index and table really add to the overhead if a location changes.
Any ideas on why I can't build an index on the output table from my SDO_CS.TRANSFORM_LAYER() call? I used SDO_TUNE.ESTIMATE_TILING_LEVEL() and SDO_GEOM.VALIDATE_GEOMETRY() and got no complaints. I'm at a loss.
I also can't seem to get set autotrace to work. It works fine for any non-spatial query, but if I try to trace a spatial query, I get this error:
SQL> SELECT /*+ INDEX(restaurant_locations restaurant_sp_idx) */ r_a.restaurant_id
FROM restaurant_locations r_a, restaurant_locations r_b, user_sdo_geom_metadata m
WHERE r_b.restaurant_id != r_a.restaurant_id
AND SDO_GEOM.WITHIN_DISTANCE(r_a.location, m.diminfo, 1, r_b.location, m.diminfo) = 'TRUE'
AND r_b.restaurant_id = '5999';
2 3 4 5
RESTAURANT_ID
456999
456999
Execution Plan
ERROR:
ORA-01031: insufficient privileges
SP2-0612: Error generating AUTOTRACE EXPLAIN report
Statistics
49 recursive calls
28 db block gets
83 consistent gets
0 physical reads
0 redo size
415 bytes sent via SQL*Net to client
425 bytes received via SQL*Net from client
2 SQL*Net roundtrips to/from client
11 sorts (memory)
0 sorts (disk)
2 rows processed
I've looked at the arraysize, and I've made sure to run the trace-enabling sql and granted plustrace to my DB user.
Thanks for any help,
_jasonHi Jason,
The error on the index create is likely due to data being outside the bounds of the coordinate system as specified in user_sdo_geom_metadata.
If the data is stored in the point field then you can check the bounds by doing queries like the following, altering them for your table/column name (my table is cities_test, the geometry column name is location):
SQL> select min(a.location.sdo_point.x) from cities_test a;
MIN(A.LOCATION.SDO_POINT.X)
-157.80423
SQL> select max(a.location.sdo_point.x) from cities_test a;
MAX(A.LOCATION.SDO_POINT.X)
-71.017892
SQL> select max(a.location.sdo_point.y) from cities_test a;
MAX(A.LOCATION.SDO_POINT.Y)
61.178368
SQL> select min(a.location.sdo_point.y) from cities_test a;
MIN(A.LOCATION.SDO_POINT.Y)
21.31725
Do you need to build a spatial index?
Only if you are going to use spatial operators such as sdo_filter, sdo_relate, sdo_within_distance, and sdo_nn. If you have no requirements for these operators, then there is no reason to build a spatial index. From the trace query at the end of the posting, I suspect that you will need to have a spatial index.
Is this the best approach? Maybe, it depends on what your requirements are. If the data is static and performance is your highest priority, then maybe it is. If you have a requirement for a spatial index, then certainly it is. If you are only getting the distance between a few few known geometries, and you don't care about the time it takes to convert data on the fly, then you can use the sdo_cs.transform function within the sdo_geom.sdo_distance function to convert both geometries to the equal area projection.
The validation routines should have caught this - I checked and they do not for 8.1.7, and they do for 9i.
Regarding the set autotrace command, I'm not sure why it isn't working for you. It works for my generic scott/tiger account from a typical install.
hope some of this is useful.
dan
null -
Excel formula to calculate the distance between multiple points using lat/lon coordinates
I'm currently drawing up a mock database schema with two tables: Booking and Waypoint.
Booking stores the taxi booking information.
Waypoint stores the pickup and drop off points during the journey, along with the lat lon position. Each sequence is a stop in the journey.
How would I calculate the distance between the different stops in each journey (using the lat/lon data) in Excel?
Is there a way to programmatically define this in Excel, i.e. so that a formula can be placed into the mileagecolumn
(Booking table),
lookup the matching sequence (via bookingId)
for that journey in the Waypointtable
and return a result?
Example 1:
A journey with 2 stops:
1 1 1 MK4 4FL, 2, Levens Hall Drive, Westcroft, Milton Keynes 52.002529 -0.797623
2 1 2 MK2 2RD, 55, Westfield Road, Bletchley, Milton Keynes 51.992571 -0.72753
4.1 miles according to Google, entry made in mileage column
in Booking table
where id
= 1
Example 2:
A journey with 3 stops:
6 3 1 MK7 7DT, 2, Spearmint Close, Walnut Tree, Milton Keynes 52.017486 -0.690113
7 3 2 MK18 1JL, H S B C, Market Hill, Buckingham 52.000674 -0.987062
8 3 1 MK17 0FE, 1, Maids Close, Mursley, Milton Keynes 52.040622 -0.759417
27.7 miles according to Google, entry made in mileage column
in Booking table
where id
= 3
I understand that 100% accuracy is not possible, so it will not be an issue.http://www.cpearson.com/excel/LatLong.aspx
and
http://www.contextures.com/excellatitudelongitude.html -
Calculating a distance between random points.
Hi everyone,
so my situation is like this :
1) I have created a graph containing random points (3 different series). And the graph have three buttons .The first button will plot 30 random points on the chart. the second and third button will plot random point with different colour.
What I am trying to do now is I need to choose one random point from the 30 points, and calculate the distance from the chosen point to the qrand or qinit..
How can I do that? I really have no idea. Help!
public void ForBtn1()
Random qrand = new Random();
int[,] points = new int[100, 2];
int qinitx, qinity;
for (int i = 0; i < 30; i++)
int pointx = qrand.Next(0, 100);
int pointy = qrand.Next(0, 100);
points[i, 0] = pointx;
points[i, 1] = pointy;
qinitx = points[0,0];
qinity = points[0, 1];
chart1.Series["Initial Point"].Points.AddXY(pointx, pointy);
chart1.Series["Initial Location"].Points.AddXY(qinitx,qinity);
//To initialize random points and initial point
private void button1_Click(object sender, EventArgs e)
ForBtn1();
private void chart1_Click(object sender, EventArgs e)
//To initialize rand_config
private void button2_Click(object sender, EventArgs e)
Random qrand = new Random();
int[,] points = new int[100, 2];
int qrandx, qrandy;
qrandx = qrand.Next(0,100);
qrandy = qrand.Next(0,100);
chart1.Series["Random Configuration"].Points.AddXY(qrandx, qrandy);
private void button3_Click(object sender, EventArgs e)i cannot attach the photo here .. i dont know why. but here's the photo . check this link.. i uploaded it to fb..
https://fbcdn-sphotos-e-a.akamaihd.net/hphotos-ak-xpa1/v/t1.0-9/11054299_811876005567689_3794441462666954824_n.jpg?oh=7c9576e4f1f9b2a7e2ac9cf744383051&oe=55AC5BD5&__gda__=1438193773_becbb041c6c51cfc4db4b38c2d18e7a2 -
Dist between two lat/long's in USA
Hello,
Can anyone please give me the function(Oracle or some other function) to find the distance between two points(Both of them are in lat/longs). Both the points are within the boundary of US.
Thanks,Hi,
In Oracle 8.1.6, we have Beta support
for Coordinate Systems. There is
Beta users guide available under PRODUCTS/SPATIAL.
With this functionality, you can calculate
the distance between two points
very accuratly.
Here is an example. I will go into details
below. Hope this helps. Thanks.
Dan
======
SAMPLE SQL: (sorry about the formatting)
select
mdsys.sdo_geom.sdo_length (
mdsys.sdo_cs.transform (
mdsys.sdo_geometry (2002, 8307, null,
mdsys.sdo_elem_info_array (1,2,1),
mdsys.sdo_ordinate_array (
-73.983014309,
40.749544981,
a.geometry.sdo_point.x,
a.geometry.sdo_point.y)),
MDSYS.SDO_DIM_ARRAY(
MDSYS.SDO_DIM_ELEMENT(
'X', -180, 180, .00000005),
MDSYS.SDO_DIM_ELEMENT(
'Y', -90, 90, .00000005)),
41004),
.00000005) * 6.213712e-04 DISTANCE_IN_MILES
from test_abi a
where
mdsys.sdo_nn (
a.geometry,
mdsys.sdo_geometry (
1, 8307,
mdsys.sdo_point_type (-73.983014309,
40.749544981,
null),
null, null),
'SDO_NUM_RES = 1') = 'TRUE';
DESCRIPTION:
============
1) The above query is returning the
nearest point to
(-73.983014309, 40.749544981)
and also returning the distance in miles.
TEST_ABI.geometry is stored in
longitude/latitude with 8307
as the SRID.
Note, if you set the SRID in the
SDO_GEOMETRY object, you must also
set the SRID in USER_SDO_GEOM_METADATA.
To find out more info on SRID 8307,
you can execute the following:
select wktext
from mdsys.cs_srs
where srid = 8307;
SDO_NN is the operator used to find
the nearest neighbor.
For nearest neighbor queries, you
may want to try using RTREE indexes,
also Beta in 8.1.6.
To create an RTREE index, omit
SDO_LEVEL and SDO_NUMTILES from
the create index statement of your
spatial index.
We plan to fully profile RTREE indexes
in 8.1.7 and recommend them when
appropriate. Nearest neighbor is an
excellent candidate for an RTREE index.
2) In the SELECT clause, we are calling
two functions:
SDO_LENGTH
SDO_CS.TRANSFORM
The first argument passed into SDO_LENGTH
is the return value from
CS_TRANSFORM (which will be a
projected SDO_GEOMETRY object).
The second argument to SDO_LENGTH
is an SDO_TOLERANCE.
3) The first argument to CS_TRANSFORM
is an SDO_GEOMETRY constructor for a
line string, where the first point of
the linestring is
(-73.983014309, 40.749544981),
and the second point is the nearest
neighbor resulting from SDO_NN.
This goal here is to project the
linestring so we can get an accurate
result from SDO_LENGTH.
The second argument to CS_TRANSFORM
a dim_array.
The third argument to CS_TRANSFORM
is the target SRID. In this example,
SRID 41004 is used. This will be
fairly accurate for the continental US.
The geometry constructor for the
linestring will be projected to
SRID 41004.
If more accurate results are desired,
you should use an SRID that corresponds
to a specific state plane projection.
Query the WKTEXT column in MDSYS.CS_SRS
to pick appropriate SRID's for projection.
i.e. If I knew my nearest neighbor result
is going to be in Georgia, I might
use SRID 1001 instead of 41004.
4) In the result of the select list, I am
multiplying by 6.213712e-04,
the conversion factor from meters to
miles.
Hope this helps. Thanks.
Dan -
I have an application where I am collecting GPS data and all is well, had no problem writing the drivers for gps communication but now I need to calculate displacement between my long and lat readings. Is there a labview function developed to do this or do I need to figure out the calculations and code it myself. I am trying to not reinvent the wheel.
Paul
Paul Falkenstein
Coleman Technologies Inc.
CLA, CPI, AIA-Vision
Labview 4.0- 2013, RT, Vision, FPGAThere is a vi for the Garmin GPS, here.
Here is an application in the Developper's Zone
You may want to check out this thread
Message Edited by JoeLabView on 06-13-2007 08:48 AM -
Calculating co-ordinate distances between specific atoms
Hi,
Below is some code to calculate distances between all pairs of atoms. However, i need to make it slightly more specific by only calculating the distance between certain pairs of atoms
input
ATOM 5 CA PHE 1 113.142 75.993 130.862
ATOM 119 CA LEU 7 113.101 72.808 140.110
ATOM 138 CA ASP 8 109.508 74.207 140.047
ATOM 150 CA LYS 9 108.132 70.857 141.312
ATOM 172 CA LEU 10 110.758 70.962 144.119
e.g distance between all pairs for atoms 5, 119, 150 and 172 (say), last three columns are x,y and z co-ordinates
code it self
import java.util.*;
import java.io.*;
public class Distance {
public static void main(String[] args) {
System.out.println("***Campbells PDB Distance Calculator***" + "\n");
new Distance();
System.out.println("\nResults printed to file DistanceCalculations" + "\n");
System.out.println("\nDue to nature of code, if rerun results will be appended to the end of previous run.");
public Distance() {
Vector atomArray = new Vector();
String line;
try{
System.out.println("Enter PDB file:" + "\n");
BufferedReader inputReader =new BufferedReader (new InputStreamReader(System.in));
String fileName = inputReader.readLine();
if ( fileName !=null) {
BufferedReader inputDistance = new BufferedReader (new FileReader (fileName));
while (( line = inputDistance.readLine()) !=null && !line.equals(""))
Atom atom = new Atom(line);
atomArray.addElement(atom);
for (int j=0; j<atomArray.size(); j++) {
for (int k=j+1; k<atomArray.size(); k++) {
Atom a = (Atom) atomArray.elementAt(j);
Atom b = (Atom) atomArray.elementAt(k);
Atom.printDistance (a,b);
} //if
} //try
catch (IOException e) {
System.out.println("Input file problem");
} catch (Exception ex) {
System.out.println (ex);
class Atom {
public double x, y, z;
public String name;
public Atom(String s) throws IllegalArgumentException {
try {
StringTokenizer t = new StringTokenizer (s, " ");
t.nextToken();
this.name = t.nextToken();
for (int j=0; j<3; j++) t.nextToken();
this.x = new Double(t.nextToken()).doubleValue();
this.y = new Double(t.nextToken()).doubleValue();
this.z = new Double(t.nextToken()).doubleValue();
catch (Exception ex) {
throw new IllegalArgumentException ("Problem!!!! :-(");
public String toString() {
return "atom : " + name + "(x=" + x + " y=" + y + " z=" + z + ")";
public double distanceFrom (Atom other) {
return calculateDistance (x, y, z, other.x, other.y, other.z);
public static double calculateDistance (double x1, double y1, double z1, double x2, double y2, double z2) {
return Math.sqrt(Math.sqrt(Math.pow(Math.abs(x1-x2),2)+Math.pow(Math.abs(y1-y2),2))+Math.pow(Math.abs(z1-z2),2));
public static void printDistance (Atom a, Atom b) {
try{
FileWriter fw = new FileWriter("DistanceCalculations", true);
PrintWriter pw = new PrintWriter (fw, true);
if
(a.distanceFrom(b) <9){
pw.println("Distance between " + a.toString() + " and " + b.toString() + " is " + a.distanceFrom(b));
pw.flush();
pw.close();
} // if??
} //try loop
catch(IOException e) {
System.out.println("System error");
}ok, essentially
want to calculate distance between to ranges. Say
range 1 is the first three, range 2 the rest. THen
calculate distance between all possible pairs between
these two rangesYes - and no doubt that any number of people here could write it for you. But that's not what the forum is about. So what, exactly, is preventing you from doing it?
Sylvia. -
Distance between two points with degrees and minutes
I would like to store several points in the database given degrees and minutes as position. In this example I have point 1 that is E 150, 0/S 30, 0 and points 2 that is E 150, 0/S 30.1. For example if I enter 2 km as distance from position of point 1 I would like the search to return all points witin 2 km.(should return points 2 that is very near)
If I run the query
SELECT c.name
FROM cola_markets_cs c
WHERE
SDO_WITHIN_DISTANCE(c.shape,
SDO_GEOMETRY(2001, 8307, SDO_POINT_TYPE(150.0, 30.1, NULL), NULL, NULL),
'distance=10000 unit=KM')
= 'TRUE';
I get result both position 1 and 2, but if I decrease to distance=1000 no rows is returned.
Can you see what I am doing wrong here?
Can I also combine SDO_WITHIN_DISTANCE with SDO_NN_DISTANCE so I can ask for all points 10 km in distance from the reference point and I can also see the actual distance for each point?
Thank you
I have tested with the following code. Do I save the position wrong..?
CREATE TABLE cola_markets_cs (
mkt_id NUMBER PRIMARY KEY,
name VARCHAR2(32),
shape MDSYS.SDO_GEOMETRY);
INSERT INTO cola_markets_cs VALUES (
1,
'Point 1',
MDSYS.SDO_GEOMETRY(
2001,
8307,
MDSYS.SDO_POINT_TYPE(150.0, 30.0, NULL),
NULL,
NULL
INSERT INTO cola_markets_cs VALUES (
2,
'Point 2',
MDSYS.SDO_GEOMETRY(
2001,
8307,
MDSYS.SDO_POINT_TYPE(150.0, 30.1, NULL),
NULL,
NULL
-- UPDATE METADATA VIEW --
-- Update the USER_SDO_GEOM_METADATA view. This is required
-- before the Spatial index can be created. Do this only once for each
-- layer (i.e., table-column combination; here: cola_markets_cs and shape).
INSERT INTO USER_SDO_GEOM_METADATA
VALUES (
'cola_markets_cs',
'shape',
MDSYS.SDO_DIM_ARRAY(
MDSYS.SDO_DIM_ELEMENT('Longitude', -180, 180, 10), -- 10 meters tolerance
MDSYS.SDO_DIM_ELEMENT('Latitude', -90, 90, 10) -- 10 meters tolerance
8307 -- SRID for 'Longitude / Latitude (WGS 84)' coordinate system
-- CREATE THE SPATIAL INDEX --
-- Must be R-tree; quadtree not supported for geodetic data.
CREATE INDEX cola_spatial_idx_cs
ON cola_markets_cs(shape)
INDEXTYPE IS MDSYS.SPATIAL_INDEX;
--This search only return if distance is 10 000 km...
SELECT c.name
FROM cola_markets_cs c
WHERE
SDO_WITHIN_DISTANCE(c.shape,
SDO_GEOMETRY(2001, 8307, SDO_POINT_TYPE(150.0, 30.1, NULL), NULL, NULL),
'distance=10000 unit=KM')
= 'TRUE';
--According to this search the distance to point 1 is 3331198,72256398,
--this should be zero..
SELECT
c.mkt_id, c.name, SDO_NN_DISTANCE(1) dist
FROM cola_markets_cs c
WHERE SDO_NN(c.shape,
sdo_geometry(2001, 8307,sdo_point_type(150.0, 30.1, NULL), NULL, NULL),
'sdo_num_res=2', 1) = 'TRUE' ORDER BY distHi,
What version of Oracle are you using? I got this using your example:
SELECT
c.mkt_id, c.name, SDO_NN_DISTANCE(1) dist
FROM cola_markets_cs c
WHERE SDO_NN(c.shape,
sdo_geometry(2001, 8307,sdo_point_type(150.0, 30.1, NULL), NULL, NULL), 'sdo_num_res=2', 1) = 'TRUE'
ORDER BY dist ;
MKT_ID NAME DIST
2 Point 2 0
1 Point 1 11085.3285
This is 10.1.0.4
Also:
Can I also combine SDO_WITHIN_DISTANCE with SDO_NN_DISTANCE so I can ask for all points 10 km in distance from the reference point and I can also see the actual distance for each point?
No, but you can add a distance calculation:
SELECT
c.mkt_id, c.name, SDO_GEOM.SDO_DISTANCE(c.shape,sdo_geometry(2001, 8307,sdo_point_type(150.0, 30.1, NULL), NULL, NULL),1) dist
FROM cola_markets_cs c
WHERE SDO_WITHIN_DISTANCE(c.shape,
sdo_geometry(2001, 8307,sdo_point_type(150.0, 30.1, NULL), NULL, NULL), 'distance=10 unit=km') = 'TRUE'
ORDER BY dist ;
Maybe you are looking for
-
Hi is there a way to do a host summary report that gives me a list of all of the hosts and their current status. I know I can run a detail report but this gives me pages and pages of information, and I can run a management report (host count) which i
-
IMovie '11 preview/play issues?
I just bought iMovie '11 for my MacBook (using OS X Lion (10.7.1)), and I am having this weird issue during playback. I have placed PNG images (transparent backgrounds) on top of the main background scenes using the 'cutaway' option. When I do a test
-
Unable to Open spreadsheets exported from SAP in Smartphones like Iphone
Hi, My program sends an email with excel attachment. I am able to open and view the attachments in the mail in Laptops/desktops. But unable to open the excel attachments in Smartphones like iphone etc. Can any one help me out with a solution? Satish
-
64bit version of firefox, i mean mine field has so many bugs
MineField beta 4 (FireFox x64) has many bugs, i don't know, maybe it's so common, because in every update none of them were fixed, for example my bookmark not only doesn't work, but also it clean up my previous one each time i close and open mine fie
-
How to repeat duplication with changing values?
Hello all! First of all - english is not my first language so I don't really know how to explain this in an easy way (and therefore I don't know what to search for either). Maybe a better topic title is needed as well. I made an illustration to show