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
Similar Messages
-
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 -
This is an information request from a complete coordinate systems newbie:
1. Does Oracle Spatial in 9.0.1 have an entry in MDSYS.CS_SRS that
corresponds to the coordinate system commonly known as "Earth Centered, Earth
Fixed" - where would I look (besides the table itself - I already tried that
with the 8.1.7 EE to no avail - it may be because I don't know enough about how
coordinate systems are referenced (the common nomenclature used) and just
didn't recognize it when I saw it.)
2. Are there any existing pl/sql snippets of code that can handle coordinate
conversions between ECEF-Lat/Long, geodetic degrees-decimal degrees? (If yes,
where should I go to look for them? By the way, please, please say yes, there
are many such packages just like there are for unit conversions (like binary to
hex).)
3. Where should I look to get information on a product called Map Viewer which
was mentioned in the latest edition of Oracle Magazine (May/June 2002, p.25 -
it was said to be a part of the 9iAS suite of products - I looked all over the
documentation but didn't find any mention of it.)
Thank you very much for your time and attention!
JulienThis is an information request from a complete coordinate systems newbie:
1. Does Oracle Spatial in 9.0.1 have an entry in MDSYS.CS_SRS that
corresponds to the coordinate system commonly known as "Earth Centered, Earth
Fixed" - where would I look (besides the table itself - I already tried that
with the 8.1.7 EE to no avail - it may be because I don't know enough about how
coordinate systems are referenced (the common nomenclature used) and just
didn't recognize it when I saw it.)
2. Are there any existing pl/sql snippets of code that can handle coordinate
conversions between ECEF-Lat/Long, geodetic degrees-decimal degrees? (If yes,
where should I go to look for them? By the way, please, please say yes, there
are many such packages just like there are for unit conversions (like binary to
hex).)You can get the proper params from the EPSG <http://www.epsg.org>,
I recall seeing some coord conversion samples in the tutorials/sample code - look in the OTN library
MArk -
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 -
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,
ChrisI 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.
-
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 -
How can i make network between two databases ?
Good Morning to all ;
Going to configure oracle 10g - ( I trying to exchange data between two different databases.
Each database is configured in different operating systems.
For ex : one database from windows XP(seperate virtual machinne)
one database from linux rhel (seperate virtual machinne)
I am waiting for some suggestions ..
Thanks ..
Edited by: 969352 on Mar 19, 2013 10:04 AM969352 wrote:
What virtualization product are you using?*#* vmware-toolbox-cmd -v
8.1.3.9911 (build-203739)
VMWARE Product Information :
Version : 7.0.0 build - 203739
OK. You will need to make sure the ip addresses you assign to your vms are in the same subnet as the adapter create by the installation of vmware. Once you get the fundamental network setup fixed, you can treat these vms just like any machine in your data center. Forget the vm console and access them exactly like you would any remote server -- putty for the linux machine and Windows Remote Desktop for the Windows machine.
At a command prompt on the host, issue this:
c:> ipconfig -allYou will get back info on several net adapters, two of which are identified as being with vmware -- vmNet1 and vmNet8. Note the IP addresses of both. We'll need it later.
You will also need to know how you configured the network adapters on your vm's -- NAT, bridged, hostonly, ???
Note that these issues are out of scope for this forum. I don't mind helping, but I no longer have a vmware installation to reference details.
What have you actually tried to do? ( Data Transfer )I tried to exchange data from windows database to linux DB
That's pretty vague. Exactly how did you try to "exchange data"? A sql statement using a db_link? export/import? Carrier Pigeon?
>
Where are you stuck?
I don't know , how to configure ip and necessary information for windows database.
Configuring an IP address is purely an OS admin issue and is out of scope for this database forum.
Google is your friend, but only if you use it: [url http://lmgtfy.com/?q=configure+windows+ip+address]http://lmgtfy.com/?q=configure+windows+ip+address
>
That's it Edstevens .. thanks .. -
Sync Mail between two computers
After Leopard upgrade, I switched from Entourage to Mail.app, so I'm new to it.
I use two Macs and POP accounts. How can I sync Mail.app between two computers in Leopard? The Sync Service of Smart Folders is not enough for me.
May I use a sync app like Folders Synchrnonizer?
Thanks
StefanoBoth my wife and I have multiple macs and work at home and on the road - we've tried all sorts, and there are 3 approaches that work:
1) IMAP
I know you think this isn't the ideal solution for you, but it is unbelievably simple and rock solid once you get it working.
Set your POP mail addresses to forward all mail to your IMAP address (I use .mac which is brilliant, I don't know about Gmail).
Your mail is server based, so your laptop, desktop, iPhone, webmail from a PC etc. are all always in sync.
You will still get your mail from your old accounts.
You can set rules on any of your machines to filter your mail into folders according to which address they were originally sent to.
HOWEVER the mail you SEND will be FROM your IMAP address, so your clients / friends may get confused if you don't want them to use your IMAP address as your main address.
2)
Leave POP mail on the server.
In Mail preferences, highlight your POP account and click on the "Advanced" tab.
Select "Remove mail from server" to a 1 day if you come home each night.
If you are away for longer, make it 1 week or Never.
This way, if you download mail on your Laptop, when you get home that evening, your desktop will download the same mail again, as it has been left on the server.
It's sort of fake IMAP.
The downside is you can end up with a full mailbox at the server very quickly as you are now leaving messages on it, and you may have to empty the server yourself sometimes (in the same menu you just adjusted).
Also, if you are away from your laptop too long, you may download and later delete-from-the-server messages on your desktop, leaving your laptop out of date.
Use Mac Sync to keep your rules, mailboxes and preferences synced up.
This is the way it's designed to work, so it should work fine.
3)
Drag the Mail folder.
Assuming you're only using one Mac at any one time, you simply move the main mail folder to whichever machine is current.
Quit Mail on both machines.
On your target mac, go to youruserfolder/Library and rename the "Mail" folder to something else like "Mail Old". This is just so you have a backup.
On your source mac, go to youruserfolder/Library and copy that entire folder (not just the mailboxes) either to a drive to transfer to your target mac, or straight to it if you have it networked.
When you start up mail you will find the messages, folders, mailboxes etc. are the same as they were on your source mac.
Now you use your target mac (say your laptop) for a while.
When you are going back to your original source mac (e.g. your desktop), you now repeat the process in the other direction, replacing your desktop's mail folder with your newer laptop's version.
It's really important you use one mac at a time and swap the folder each time you switch.
If you rename the previous version before you overwrite it, you know you have a backup if things get out of sync.
It works really well if you only take the laptop out occassionally, or if you use it exclusively for days at a time (i.e you go away) and you only need to do the transfer every so often.
Also, it helps if you don't have thousands of emails - if your Mail folder is under half a gig, you can do this quickly using a USB keyring or similar. Any bigger and the transfer can get a bit slow.
I use option 1, and felt it was worth changing my email address for.
My wife uses option 2 when she is using her laptop in the day and she can run her desktop each evening the download the mail left on the server.
But she sometimes gets trouble with her popmail server filling up (she gets lots of video and audio attachments) so if she's going away or not planning to use her desktop in the evenings, she reverts to option 3 and removes messages from the server "right away", updating her desktop's mail folder at the end of the week and just using her laptop until then.
Good luck! -
Difference between two dates: a complete solution
There have been many posts asking how to get the number of days between two dates. There is no method in java like the VB method dateDiff(), and there is only the method date.getTime() which gives you the number of milliseconds since Jan 1 1970, the Epoch. I have not seen a solution that makes use of the fact that there are 86400000 milliseconds per day, only when trying to get the number of days , i.e. multiples of 24 hours between two millisecond points in time.
So what if date1 was Oct 26th 11.30pm and date2 was Oct 27th 12.30am? If you get the millisecond difference, and divide by 86400000, you do not notice that these two times are on separate days, but only one hour apart.
My solution takes account of the modulo (%) function. If you use the date.getTime() method, and use % 86400000 on this number of milliseconds, it will tell you how far (milliseconds) this date is into this day, after 12am. If you subtract this amount from the total number of milliseconds, then divide by 86400000, this will give you the number of days after the Epoch, so you are able to know which day the millisecond time is in. If you want to know the days between two millisecond times, this will tell you, whereas just dividing by 86400000, will not, and may be misleading.
I think this could be incorporated into the Date class easily. There are some problems though, as not every day has 86400000 milliseconds, if you are talking about days when Daylight Saying Time begins or ends. Doing calculations like that will create errors, unless you know whether each date is in Daylight Saving Time or not. Leap years are OK, unless want to work out the number of years from the number of days by dividing by 365, as calculating numbers of days is only done by looking at a 24 hour time period. However where 'leap seconds' have been added, like once every ten years, there may be small errors. This was not included in anyone elses calculations.
So the calculation would go like this:
public class BetterDate extends Date
public int dayDifference(Date d)
long time = this.getTime() ; // gets milliseconds
long timed = d.getTime() ; // gets milliseconds of other date
int days = (time - (time % 86400000))/86400000 ; // number of days
int daysd = (timed - (timed % 86400000))/86400000 ; // number of days of other date
int difference = daysd - days ; // difference in days between two dates
return difference ;
If you want you can use the value (time % 86400000), and modulo this amount with the number of milliseconds in one hour, then subtract the result from the (time % 86400000) and divide by the millliseconds in one hour to give you the number of hours, but there are JDK functions that you can use to get the hour if needed.
This method is not perfect, but for most cases will get you the difference in days between two dates.
JamesHi James,
I tried out your solution, but it seems to fail on dates without times. I tries the difference between 31/03/2002 and 01/04/2002 and the result is 0. I guess it is because the times are assumed to be 00:00 as no times are mentioned and 31st March I believe is the date when DST change will take place this year. If I set the two times as well to a time much later than midnight for example 0600 then I seem to get the right answer.
Joag
There have been many posts asking how to get the
number of days between two dates. There is no method
in java like the VB method dateDiff(), and there is
only the method date.getTime() which gives you the
number of milliseconds since Jan 1 1970, the Epoch. I
have not seen a solution that makes use of the fact
that there are 86400000 milliseconds per day, only
when trying to get the number of days , i.e. multiples
of 24 hours between two millisecond points in time.
So what if date1 was Oct 26th 11.30pm and date2 was
Oct 27th 12.30am? If you get the millisecond
difference, and divide by 86400000, you do not notice
that these two times are on separate days, but only
one hour apart.
My solution takes account of the modulo (%) function.
If you use the date.getTime() method, and use %
86400000 on this number of milliseconds, it will tell
you how far (milliseconds) this date is into this day,
after 12am. If you subtract this amount from the total
number of milliseconds, then divide by 86400000, this
will give you the number of days after the Epoch, so
you are able to know which day the millisecond time is
in. If you want to know the days between two
millisecond times, this will tell you, whereas just
dividing by 86400000, will not, and may be
misleading.
I think this could be incorporated into the Date class
easily. There are some problems though, as not every
day has 86400000 milliseconds, if you are talking
about days when Daylight Saying Time begins or ends.
Doing calculations like that will create errors,
unless you know whether each date is in Daylight
Saving Time or not. Leap years are OK, unless want to
work out the number of years from the number of days
by dividing by 365, as calculating numbers of days is
only done by looking at a 24 hour time period. However
where 'leap seconds' have been added, like once every
ten years, there may be small errors. This was not
included in anyone elses calculations.
So the calculation would go like this:
public class BetterDate extends Date
public int dayDifference(Date d)
long time = this.getTime() ; // gets milliseconds
long timed = d.getTime() ; // gets milliseconds of
other date
int days = (time - (time % 86400000))/86400000 ; //
number of days
int daysd = (timed - (timed % 86400000))/86400000 ; //
number of days of other date
int difference = daysd - days ; // difference in days
between two dates
return difference ;
If you want you can use the value (time % 86400000),
and modulo this amount with the number of milliseconds
in one hour, then subtract the result from the (time %
86400000) and divide by the millliseconds in one hour
to give you the number of hours, but there are JDK
functions that you can use to get the hour if needed.
This method is not perfect, but for most cases will
get you the difference in days between two dates.
James -
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 -
Unable to find line break between two lines in attachment file.
Dear all I will be very great full if someone help me out,
I am trying to send mail through SMTP server with an attachment of oracle report, but I am unable to find line break between two lines, when I down load the attachment from mail and open attach.txt file by double click on it. Next line starts right after previous line ends, it should starts with new line.
In order to send an attachment file, I am reading source file line by line and put MIME protocol’s attachment instance, contain of source file is being properly written into target file if I open that attachment on cmd prompt.
Following code may help you to understand the case.
Thanks in advance.
My code is as follows:-
create or replace procedure bec_file_test
v_subject varchar2, -- Subject of the email
v_body varchar2, -- Body of the email
v_from VARCHAR2 default 'XYZ.com', -- sender mail id
v_to varchar2 default 'XYZ.com', -- Field To of the email
v_cc varchar2 default 'XYZ.com' -- cc address
) is
-- variable to hold the smtp server connection
v_smtp_connection utl_smtp.connection;
-- variable to hold the smtp host name
v_smtp_host varchar2(100) default 'mail.bec-group.com';
-- variable to hold the smtp port
v_smtp_port number default 25;
-- composite of {CR}{LF} caridge return and line feed.
CRLF varchar2(2):=CHR(13)||CHR(10);
cursor pr_rec is
select requisition_no,line_no,release_no,a.contract,
a.project_id,substr(a.activity_seq,1,11)ACT_SEQ,
substr(a.part_no,1,12)PART_NO,
substr(a.description,1,32)DESCRIPTION,
substr(a.Bal_qty,1,8) BAL_QTY,
substr(a.unit_meas,1,5)UOM,
a.wanted_receipt_date WAN_REC_DT,
a.latest_order_date LAT_ORD_DT
from bec_pr_line_rep a
where a.Bal_qty>0 and a.header_state not in 'Closed'
and upper(a.state1) like 'RELEASED' and a.contract not in ('U1ENG','ULENG','U1FND','U2FND')
and a.buyer_code='70306'
order by a.part_no;
begin
declare
fHandle UTL_FILE.FILE_TYPE;
v_msg_line varchar2(2000);
-- v_buffer varchar2(20000);
--ALTER SYSTEM SET utl_file_dir = 'D:\Database\temp'
--COMMENT='Temporary change on Dec 14'
--SCOPE=SPFILE;
SELECT name, value
FROM gv$parameter
WHERE name = 'utl_file_dir';
--drop directory my_directory
--CREATE or replace DIRECTORY my_directory AS 'D:\database\temp';
--GRANT read,write ON DIRECTORY my_directory TO PUBLIC;
begin ---writing data into a file.
fHandle := UTL_FILE.FOPEN('MY_DIRECTORY', 'pending_pr_summry.txt', 'w');
UTL_FILE.put_line(fHandle, ' Pending PR to process (detail report)');
UTL_FILE.put_line(fHandle,TO_CHAR(SYSDATE,'MM-DD-YY HH:MI:SS AM'));
UTL_FILE.put_line(fHandle, '--------------------------------------------------------------------------------------------------------------------------------------------------');
UTL_FILE.put_line(fHandle, 'Req.no. li Re Site Prj Id Act seq Part no Description Qty UOM want rec dt lat ord dt' );
UTL_FILE.put_line(fHandle, '--------------------------------------------------------------------------------------------------------------------------------------------------');
for pr_temp in pr_rec loop
begin
v_msg_line:=to_char(rpad(pr_temp.requisition_no,12,' ')||'|'||
lpad(pr_temp.line_no,3,' ')||'|'||
lpad(pr_temp.release_no,3,' ')||'|'||
rpad(pr_temp.contract,7,' ')||'|'||
lpad(nvl(pr_temp.project_id,' '),7,' ')||'|'||
lpad(nvl(pr_temp.act_seq,' '),12,' ')||'|'||
lpad(pr_temp.part_no,12,' ')||'|'||
rpad(pr_temp.description,35,' ')||'|'||
lpad(pr_temp.bal_qty,10,' ')||'|'||
rpad(pr_temp.uom,6,' ')||'|'||
lpad(pr_temp.wan_rec_dt,14,' ')||'|'||
lpad(pr_temp.lat_ord_dt,14,' '));
UTL_FILE.put_line(fHandle,v_msg_line);
end;
end loop;
UTL_FILE.put_line(fHandle, '--------------------------------------------------------------------------------------------------------------------------------------------------');
UTL_FILE.put_line(fHandle, ' Regards : IFSAPP ( Application owner ) ');
UTL_FILE.FCLOSE(fHandle); ------------writing into file is successfuly done here!
--Reading of file starts here containt will be added in attchment file
fHandle :=UTL_FILE.FOPEN('MY_DIRECTORY','pending_pr_summry.txt','R' );
-- establish the connection to the smtp server
v_smtp_connection := utl_smtp.open_connection(v_smtp_host, v_smtp_port); /** OPEN CONNECTION ON THE SERVER **/
-- perform a handshake with the smtp server
utl_smtp.helo(v_smtp_connection, v_smtp_host); /** DO THE INITIAL HAND SHAKE **/
-- set the 'from' address of the message
utl_smtp.mail(v_smtp_connection, v_from);
-- add the recipient to the message
utl_smtp.rcpt(v_smtp_connection, v_to);
-- send the email
utl_smtp.open_data(v_smtp_connection);
v_msg_line:='Date: ' || TO_CHAR( SYSDATE, 'dd Mon yy hh24:mi:ss' ) || CRLF ||
'From: ' || v_from || CRLF ||
'Subject: ' || v_subject || CRLF ||
'To: ' || v_to || CRLF ||
'Cc: ' || v_cc || CRLF ||
'MIME-Version: 1.0'|| CRLF || -- Use MIME mail standard
'Content-Type: multipart/mixed;'||CRLF ||
' boundary="-----SECBOUND"'||CRLF||
CRLF ||'-------SECBOUND'|| CRLF ||
'Content-Type: text/plain;'|| CRLF ||
'Content-Transfer_Encoding: 7bit'|| CRLF ||
CRLF ||v_body|| CRLF; -- Message body
utl_smtp.write_data(v_smtp_connection,v_msg_line);
v_msg_line:='-------SECBOUND'|| CRLF ||
'Content-Type: application/octet-stream;'|| CRLF ||
'Content-Type: text/plain;'|| CRLF ||
'name="pending_pr_summry.txt"'|| CRLF ||
'Content-Transfer_Encoding: 8bit'|| CRLF ||
'Content-Disposition: attachment;'|| CRLF ||
' filename="pending_pr_summry.txt"'|| CRLF || CRLF; -- Content of attachment
utl_smtp.write_data(v_smtp_connection,v_msg_line);
-- check file is opened
IF utl_file.is_open(fHandle) THEN
-- loop lines in the file
LOOP
BEGIN -- Content of attachment
utl_file.get_line(fHandle,v_msg_line);
v_msg_line:=concat(v_msg_line,CRLF);
utl_smtp.write_data(v_smtp_connection,v_msg_line);
EXCEPTION
WHEN NO_DATA_FOUND THEN
EXIT;
END;
END LOOP;
END IF;
--end of attachment containt
utl_smtp.write_data(v_smtp_connection,v_msg_line);
UTL_FILE.FCLOSE(fHandle);
utl_smtp.close_data(v_smtp_connection);
utl_smtp.quit(v_smtp_connection);
exception
when utl_smtp.invalid_operation then
dbms_output.put_line(' Invalid Operation in Mail attempt using UTL_SMTP.');
when utl_smtp.transient_error then
dbms_output.put_line(' Temporary e-mail issue - try again');
when utl_smtp.permanent_error then
dbms_output.put_line(' Permanent Error Encountered.');
when others then
dbms_output.put_line('Exception: SQLCODE=' || SQLCODE || ' SQLERRM=' || SQLERRM);
RAISE;
end;
end bec_file_test;Pending PR to process (detail report)01-17-13 12:43:19 PM--------------------------------------------------------------------------------------------------------------------------------------------------Req.no. li Re Site Prj Id Act seq Part no Description Qty UOM want rec dt lat ord dt--------------------------------------------------------------------------------------------------------------------------------------------------MAT/250370 | 2| 1|ISCSP | 4977| 100004207| 0104000016|Angle 50 X 50 X 6 IS:2062 Grade |500|kg |30-NOV-2012| 20-nov-2012MAT/250370 | 3| 1|ISCSP | 4977| 100004207| 0105000002|Channel 100 X 50 IS:2062 Grade A | 1000|kg | 30-NOV-2012| 20-nov-2012MAT/250579 | 2| 1|NMDCJ | 6001| 100005580| 0109020002|TMT Bar 10 mm Fe 415 IS:1786 | 2991|kg | 13-DEC-2012| 03-dec-2012MAT/250606 | 2| |NMDCJ | 6002| 100005860| 0109020002|TMT Bar 10 mm Fe 415 IS:1786 | 4500|kg | 29-DEC-2012| 19-dec-2012MAT/250607 | |1|NMDCJ|6001|100005580| 0109020002|TMT Bar 10 mm Fe 415 IS:1786 | 1500|kg | 29-DEC-2012| 19-dec-2012MAT/250194 | 3| 1|NMDCJ | 6002| 100005818| 0109020002|TMT Bar 10 mm Fe 415 IS:1786 | 3939|kg | 29-DEC-2012| 19-dec-2012MAT/250606 | 4| 1|NMDCJ | 6002| 100005860| 0109020004|TMT Bar 16 mm Fe 415 IS:1786 | 39000|kg | 29-DEC-2012| 19-dec-2012MAT/250607 | 4| 1|NMDCJ | 6001| 100005580| 0109020004|TMT Bar 16 mm Fe 415 IS:1786 | 17500|kg | 29-DEC-2012| 19-dec-2012MAT/250194 | 2| 1|NMDCJ | 6002| 100005818| 0109020004|TMT Bar 16 mm Fe 415 IS:1786 | 12183|kg | 29-DEC-2012| 19-dec-2012MAT/250606 | 6| 1|NMDCJ | 6002| 100005860| 0109020006|TMT Bar 25 mm Fe 415 IS:1786 | 9500|kg | 29-DEC-2012| 19-dec-2012MAT/250607 | 6| 1|NMDCJ | 6001| 100005580| 0109020006|TMT Bar 25 mm Fe 415 IS:1786 | 4500|kg | 29-DEC-2012| 19-dec-2012MAT/250194 | 6| 1|NMDCJ | 6002| 100005818| 0109020006|TMT Bar 25 mm Fe 415 IS:1786 | 17500|kg | 29-DEC-2012| 19-dec-2012MAT/250607 | 7| 1|NMDCJ | 6001| 100005580| 0109020008|TMT Bar 32 mm Fe 415 IS:1786 | 22000|kg | 29-DEC-2012| 19-dec-2012MAT/250194 | 7| 1|NMDCJ | 6002| 100005818| 0109020008|TMT Bar 32 mm Fe 415 IS:1786 | 27060|kg | 29-DEC-2012| 19-dec-2012MAT/251138 | 1| 1|NMDCJ | 6002| 100005825| 3501000001|Cement 50 kg | 1|pkt | 25-DEC-2013| 14-dec-2013--------------------------------------------------------------------------------------------------------------------------------------------------
where as source file is like that:-
Pending PR to process (detail report)
01-17-13 12:43:19 PM
Req.no. li Re Site Prj Id Act seq Part no Description Qty UOM want rec dt lat ord dt
MAT/250370 | 2| 1|ISCSP | 4977| 100004207| 0104000016|Angle 50 X 50 X 6 IS:2062 Grade | 5500|kg | 30-NOV-2012| 20-nov-2012
MAT/250370 | 3| 1|ISCSP | 4977| 100004207| 0105000002|Channel 100 X 50 IS:2062 Grade A | 1000|kg | 30-NOV-2012| 20-nov-2012
MAT/250579 | 2| 1|NMDCJ | 6001| 100005580| 0109020002|TMT Bar 10 mm Fe 415 IS:1786 | 2991|kg | 13-DEC-2012| 03-dec-2012
MAT/250606 | 2| 1|NMDCJ | 6002| 100005860| 0109020002|TMT Bar 10 mm Fe 415 IS:1786 | 4500|kg | 29-DEC-2012| 19-dec-2012
MAT/250607 | 2| 1|NMDCJ | 6001| 100005580| 0109020002|TMT Bar 10 mm Fe 415 IS:1786 | 1500|kg | 29-DEC-2012| 19-dec-2012
MAT/250194 | 3| 1|NMDCJ | 6002| 100005818| 0109020002|TMT Bar 10 mm Fe 415 IS:1786 | 3939|kg | 29-DEC-2012| 19-dec-2012
MAT/250606 | 4| 1|NMDCJ | 6002| 100005860| 0109020004|TMT Bar 16 mm Fe 415 IS:1786 | 39000|kg | 29-DEC-2012| 19-dec-2012
MAT/250607 | 4| 1|NMDCJ | 6001| 100005580| 0109020004|TMT Bar 16 mm Fe 415 IS:1786 | 17500|kg | 29-DEC-2012| 19-dec-2012
MAT/250194 | 2| 1|NMDCJ | 6002| 100005818| 0109020004|TMT Bar 16 mm Fe 415 IS:1786 | 12183|kg | 29-DEC-2012| 19-dec-2012
MAT/250606 | 6| 1|NMDCJ | 6002| 100005860| 0109020006|TMT Bar 25 mm Fe 415 IS:1786 | 9500|kg | 29-DEC-2012| 19-dec-2012
MAT/250607 | 6| 1|NMDCJ | 6001| 100005580| 0109020006|TMT Bar 25 mm Fe 415 IS:1786 | 4500|kg | 29-DEC-2012| 19-dec-2012
MAT/250194 | 6| 1|NMDCJ | 6002| 100005818| 0109020006|TMT Bar 25 mm Fe 415 IS:1786 | 17500|kg | 29-DEC-2012| 19-dec-2012
MAT/250607 | 7| 1|NMDCJ | 6001| 100005580| 0109020008|TMT Bar 32 mm Fe 415 IS:1786 | 22000|kg | 29-DEC-2012| 19-dec-2012
MAT/250194 | 7| 1|NMDCJ | 6002| 100005818| 0109020008|TMT Bar 32 mm Fe 415 IS:1786 | 27060|kg | 29-DEC-2012| 19-dec-2012
MAT/251138 | 1| 1|NMDCJ | 6002| 100005825| 3501000001|Cement 50 kg | 1 |pkt | 25-DEC-2013| 14-dec-2013
Ignore alignment. It is well formatted in source file. -
iTunes no longer works properly (aka at all) while using one of the user accounts set up on my iMac. It does, however, work when logging in under another user account on the same iMac. (if any of you can help me solve this issue that would be perfect). If there is no solution can anyone help with my request to share an iTunes library between two different accounts on one Mac. How do I do this?
jc_hering wrote:
that works for anything he purchases after he creates the new account. What about his current music that currently resides in my itunes library? How can I get his current music out of my library into his new account/library?? Thanks..
Copy it to his computer into his iTunes library and authorize his computer with the iTunes account used to purchase them..
You cannot tranfser items from one iTunes account to another. Purchased items remain part of the iTunes account is was purchased with.
iTunes account - used to purchase items
iTunes library - where purchases (and CD RIPs) go on the computer -
Sharing One iPhoto Database Between Two Accounts
Below is a reply to a question I have regarding sharing photos with my wife on the same Mac. I would like for us both to able to upload, edit, and use photos from the same iPhoto database. Do all of the buggaboos listed in the reply below still apply?
Thanks,
Jim
Re: Sharing Photo's on the same iMac between two user accounts
Posted: Jun 2, 2009 8:27 AM in response to: Thomas Harrigan Solved
Tom
For iPhoto 09 (version 8.0.2) and later:
What you mean by 'share'.
If you want the other user to be able to see the pics, but not add to, change or alter your library, then enable Sharing in your iPhoto (Preferences -> Sharing), leave iPhoto running and use Fast User Switching to open the other account. In that account, enable 'Look For Shared Libraries'. Your Library will appear in the other source pane.
Any user can drag a pic from the Shared Library to their own in the iPhoto Window.
Remember iPhoto must be running in both accounts for this to work.
If you want the other user to have the same access to the library as you: to be able to add, edit, organise, keyword etc.
Quit iPhoto in both accounts. Move the Library to the Users / Shared Folder
(You can also use an external HD set to ignore permissions, a Disk Image or even partition your Hard Disk.)
In each account in turn: Double click on the Library to open it. (You may be asked to repair the Library Permissions.) From that point on, this will be the default library location. Both accounts will have full access to the library, in fact, both accounts will 'own' it.
However, there is a catch with this system and it is a significant one. iPhoto is not a multi-user app., it does not have the code to negotiate two users simultaneously writing to the database, and trying will cause db corruption. So only one user at a time, and back up, back up back up.
Regards
TDNo. All the folks who post here are just Users, like you.
Regards
TD -
How to insert a local member in a column between two different nested row dimensions
Hi Experts,
We have a report which has two dimensions in rows with nesting. The dimensions are PROGRAMS and ACCOUNT.
I have attached the layout of the report.
We need to have a column for local member in between Col A and Col B, wherein we have to pull the long description of the program.
We have long description of programs maintained in a property of PROGRAM dimension
So if we can insert a column between Col A and Col B, we can have a local member in it with formula "EPMMemberProperty" refering to Col A
Currently we are are not able to insert a local member in between Col A and Col B in EPM 10 SP 14 version because its not a data range
I remember we used to do it in BPC 7.5 using expansion ranges to insert a blank column. So I believe similiar thing can be done in EPM 10
I have tried the option of VBA macro to insert a column before Col A and populate the long description and then hide Col A. It works. But I dont want to complicate it with Macro, and want to use EPM functionality to achieve the same.
Please advise if this is possible with BPC 10 to have a column for local member in between Col A and Col B.
Thanks a lot in advance.
Regards,
ShivaHi Sathish,
Thanks a lot for replying. Since I had to insert the local member in between two dimensions, I couldnt use the position option in the local members. Because positions were staring from the data range.
How ever I have tried the suggestion given by Varaprasad and Bishwajith above and it worked.
Thanks,
Shiva -
How do I share files between two Macs on my wireless network?
I have an iMac G4 and an ibook G3 on a wireless network. I have "file sharing" activated on both computers. (Also Appletalk, which may or may not be a misguided move, but I got the idea from OSX "Help.")
When I try to get from either computer onto the other, my computer is recognized by name (another alternative is to log on as a "guest"). I'm prompted for a password. None of the passwords I use works. I've tried the administrative passwords for both computers.
How do I get beyond this hurdle to share files? I've posted elsewhere to no avail. This must be an easy one. How do you share files between two macs on one network?Do your accounts on the machines have the same short name? It's an issue I've seen a few names.. one machine with bsmith, the other with bobsmith, but the long names for both being "Bob Smith". The login windows would confuse users because it showed their names, but because the short names didn't match, it wouldn't work.
The password you should use is the administrative one, so I don't know why you're not having luck.
Maybe you are looking for
-
Mail & Yahoo Mail Sending problems
Hello all, I have finally admitted defeat. I have been using Apple Mail to pick up my Yahoo Mail for a long time without any issues. Suddenly it has decided to not send emails...and I have no idea why. I got the settings off of Yahoo's site. The pop.
-
Error in SMTP server configuration 11gR2
Hi Expertes, I have done the below steps for configurting the notification. 1. Created an IT resource of type mail server. 2. Provided the SMTP server name in the IT Resource. 3. Modified the system configuration and set the XL.MailServer as the newl
-
Problem adding columns and rows in JTable
hi, hope somebody can help me i have some problems when i add columns and later i try to set number of rows in JTable, ocurr some exceptions my code is something like thisJTable tabla = new JTable(); TableColumn tc = new TableColumn(); tc.setHeaderVa
-
IPhone 3gs V3.1.2 shuts down sometimes
Hello, just want to double check if other users have the same problem. My Phone sometimes like once a week will shut down ( like if i manuell shut down the phone ) its happen by for example by open a hyperlink in the mail application or listen to mus
-
39L4333DG CloudTV: I don't understand! Guide needed
Hello, I just set up my new TV, I think it's great (apart from being too slow), but I don't understand how to use the CloudTV. My TV came with NO manuals: it only included a quick setup guide and a brief Cloud TV description. I've been able to downlo