Oracle Spatial function to find nearest line string based on lat/long

Hi,
Here is my scenario. I have a table that contains geometries of type line strings (the roadway network). The line geomteries are of type Ohio state plane south (SRID 41104).
I have a requirement - given a lat/long, find the line string that snaps to that lat/long or the nearest set of line strings within a distance of 0.02 miles.
This is a typical example of trying to identify a crash location on our roadway network. The crashes being reported to us in lat/long thru the GPS system.
How can i acheive this through any spatial functions?
Thanks for the help in advance.
thanx,
L.

Hi L,
That is not the way I would do it. I would convert my road segments to LRS data, then you can do all queries on the same data.
Or, if you do not want to modify your original data, create a copy of your road segments with the same ID's and convert the copy into LRS data. If you keep the ID's identical, you can easily use geometry from one and LRS data from the other - as long as you are sure the ID is the same.
Which will make the workflow a bit easier:
1. Use SDO_NN to get the closest segments
2. Use SDO_LRS.PROJECT_PT to get the projected point
3. Use SDO_LRS.GET_MEASURE to get the measure
And most of these you can incorporate into one single query. Now I am writing this of the top of my head (It's been a while since I played with LRS). so this has not been tested, but something like this should work (but could probably be greatly improved - it's getting late for me :-) ):
SELECT
SDO_LRS.FIND_MEASURE  --//find_measure needs an LRS segment and a point
    SELECT            --//here we select the LRS segment
      r.geometry 
    FROM
      roadsegments r
    WHERE SDO_NN(r.geometry,    --//based on the given GPS point
                 sdo_geometry(2001, 41104, sdo_point_type(lat,lon,NULL), NULL, NULL), 
                 'sdo_num_res=2 distance=0.02 unit=mile') = 'TRUE'
  SDO_LRS.PROJECT_PT  --//We project the point on the LRS segment
      SELECT         --//here we select the LRS segment (again, which could probably be improved!!)
        r.geometry 
      FROM
        roadsegments r
      WHERE SDO_NN(r.geometry,
                   sdo_geometry(2001, 41104, sdo_point_type(lat,lon,NULL), NULL, NULL), 
                   'sdo_num_res=2 distance=0.02 unit=mile') = 'TRUE'
    sdo_geometry(2001, 41104, sdo_point_type(lat,lon,NULL), NULL, NULL) --//The GPS point again
AS milemarker from dual;So it is not as complicated as you think, it can easily be done with just one query (SQL can do a lot more than you think ;-) ).
Good luck,
Stefan

Similar Messages

  • Standard function to find alphabet in string?

    Is there a standard function to find alphabet in string?
    For example, a variable define as char (10),
    I need a function to find out if this variable contains alphabet.
    Any standard function there?

    hiii
    use following code
    data: wa_str(100) type c.
    data: wa_str1 type string.
    data: wa_str2 type string.
    data: wa_str3 type string.
    data: len type i.
    data: ofset type i.
    wa_str = 'ABCD435hjK'.
    len = strlen( wa_str ).
    TRANSLATE wa_str TO UPPER CASE.
    do.
      if ofset = len.
        exit.
      endif.
    if wa_str+ofset(1) co sy-abcde  .
          concatenate wa_str2 wa_str+ofset(1) into wa_str2.
    else.
        concatenate wa_str3 wa_str+ofset(1) into wa_str3.
      endif.
      ofset = ofset + 1.
    enddo.
    write:/ wa_str.
    write:/ 'alphabatic char', 20 wa_str2.
    here TRANSLATE wa_str TO UPPER CASE.
    statement have added .i hope this will solve your problem.
    regards
    twinkal

  • Oracle sql function to find VARCHAR2 data is numeric

    Hi Everyone,
    Is there oracle sql function to find whether the VARCHAR2 data is numeric?
    Thanks

    hi,
    see the below example .
    with t as
    (select '12'  as col from dual union all
    select '1 2'  as col from dual union all
    select '2 1 3'  as col from dual union all
    select 'abcde'  as col from dual union all
    select '12345'  as col from dual union all
    select '1a4A5'  as col from dual union all
    select '12a45'  as col from dual union all
    select '12aBC'  as col from dual union all
    select '12abc'  as col from dual union all
    select '12ab5'  as col from dual union all
    select '12aa5'  as col from dual union all
    select '12AB5'  as col from dual union all
    select 'ABCDE'  as col from dual union all
    select '123-5'  as col from dual union all
    select '12.45'  as col from dual union all
    select '1a4b5'  as col from dual union all
    select '1 3 5'  as col from dual union all
    select '1  45'  as col from dual union all
    select '1   5'  as col from dual union all
    select 'a  b  c  d'  as col from dual union all
    select 'a b  c   d    e'  as col from dual union all
    select 'a              e'  as col from dual union all
    select 'Steven'  as col from dual union all
    select 'Stephen'  as col from dual union all
    select '111.222.3333'  as col from dual union all
    select '222.333.4444'  as col from dual union all
    select '333.444.5555'  as col from dual union all
    select 'abcdefabcdefabcxyz'  as col from dual union all
    select 'aaa'  as col from dual union all
    select 'ddd'  as col from dual union all
    select 'ccc'  as col from dual union all
    select 'aaaaa'  as col from dual union all
    select 'aaaaaaaa'  as col from dual
    select * from t where regexp_like(col,'[1-9]')
    Result
    COL
    12
    1 2
    2 1 3
    12345
    1a4A5
    12a45
    12aBC
    12abc
    12ab5
    12aa5
    12AB5
    123-5
    12.45
    1a4b5
    1 3 5
    1  45
    1   5
    111.222.3333
    222.333.4444
    333.444.5555Thanks,
    P Prakash

  • Oracle Spatial functionality with WFS

    Hi all
    My first post here so be gentle on me ;-)
    This may be an obvious question but here goes ...
    When using a WFS client can you access the full SDO_... SQL functions within Oracle Spatial? I've had a read of the WFS spec and it is all a bit vague on how the queries get passed through to the data store.
    Also with the WFS locking, is this done at the web server level? If so how would that impact on any direct access to the database? A bit dangerous??
    Appreciate any advice on WFS implemtations with a 9i back end. I want to retain the full native Oracle functionality and still deploy via WFS ... a pipe dream??
    Thanks
    Richard

    Thanks for your response Andreas
    Sorry, perhaps I wasn't clear, I realise the WFS client will never directly access the data source, that it is the WFS server that makes the request to the data store, not the client, but can the call be passed through to Oracle as native SQL?
    I think I found the answer in the OGC Filter Encoding Imp Spec where it desribes in great detail the optional filter component of a WFS request. It desribes the CQL filter operators that include some spatial operators. These could, I understand, be translated from CGL and Feature based schema to SQL (in GML?) and relational based schema.
    While I don't think at first glance that the spatial operators in CQL match all the Oracle SDO_ functions they probably go far enough for most normal users.
    Am I on the right track?
    Does anyone know of any work that has been done in this filter translation to SQL and if it has been implemented successfully anywhere.
    I think the locks would still pose a problem, but that's for another day :-)
    Thanks
    Richard

  • Convert Oracle Spatial heterogenous collection (2004) to multiline string (2006)

    Hi,
    I have all the SDO geometries in 2004 (heterogeneous collection) gtype and I want to convert all the geometries to 2006 (multiline string) gtype since the consuming application can't render 2004 gtypes. I am running a update query to change the gtype from 2004 to 2006, keeping SDO_SRID, SDO_POINT, SDO_ELEM_INFO and SDO_ORDINATES as the same. I have tested the multiline string (2006) geometries in a viewer and the shape remains the same.
    Are there any caveat that I am missing, where there is a possibility that the shape may get changed? Please give me some pointers if there are any other solution of converting 2004 gtypes to 2006.
    Regards,
    Ananda

    Hi Ananda,
    What you are doing is really not a good idea.  As Luc points out it will only work if the collection is already only composed of linestrings and if your collection is homogenous then its not a collection.
    You might explain how are you ending up with collections when apparently you only want linestrings?  Either the "other stuff" is of value to you or its not.
    For example, if you are intersecting lines and getting back collections, then probably you are getting back lines and a few points where things happen to intersect at a single point.  What do you want to do with those points?
    The simplest solution is to just toss the points away.  You need to make sure your business rules support that.  A more complex solution is to pick through the results and branch to handle each accordingly.
    However for the simple solution here is some code to "scrub" away collections into pure lines or polygons.
    Cheers,
    Paul
       -----------------------------------------------------------------------------    -----------------------------------------------------------------------------    CREATE OR REPLACE FUNCTION scrub_lines(       p_input               IN MDSYS.SDO_GEOMETRY    ) RETURN MDSYS.SDO_GEOMETRY    AS       int_gtype   PLS_INTEGER;       sdo_temp    MDSYS.SDO_GEOMETRY;       output      MDSYS.SDO_GEOMETRY;          BEGIN       IF p_input IS NULL       THEN          RETURN NULL;                END IF;       int_gtype := p_input.get_gtype();       IF int_gtype IN (3,7)       THEN          RAISE_APPLICATION_ERROR(-20001,'found polygons in your lines');                ELSIF int_gtype IN (2,6)       THEN          RETURN p_input;                ELSIF int_gtype IN (1,5)       THEN          RETURN NULL;                ELSIF int_gtype = 4       THEN          FOR i IN 1 .. SDO_UTIL.GETNUMELEM(p_input)          LOOP             sdo_temp := SDO_UTIL.EXTRACT(p_input,i);             IF sdo_temp.get_gtype() = 2             THEN                IF output IS NULL                THEN                   output := sdo_temp;                                  ELSE                   output := SDO_UTIL.APPEND(output,sdo_temp);                                  END IF;                            ELSIF sdo_temp.get_gtype() = 3             THEN                RAISE_APPLICATION_ERROR(-20001,'found polygons in your lines');                            END IF;                      END LOOP;                   RETURN output;                END IF;    END scrub_lines;    -----------------------------------------------------------------------------    -----------------------------------------------------------------------------    CREATE OR REPLACE FUNCTION scrub_polygons(       p_input                  IN MDSYS.SDO_GEOMETRY    ) RETURN MDSYS.SDO_GEOMETRY    AS       int_gtype   PLS_INTEGER;       sdo_temp    MDSYS.SDO_GEOMETRY;       output      MDSYS.SDO_GEOMETRY;    BEGIN       IF p_input IS NULL       THEN          RETURN NULL;       END IF;       int_gtype := p_input.get_gtype();       IF int_gtype IN (3,7)       THEN          RETURN p_input;                ELSIF int_gtype IN (1,2,5,6)       THEN          RETURN NULL;                ELSIF int_gtype = 4       THEN          FOR i IN 1 .. SDO_UTIL.GETNUMELEM(p_input)          LOOP             sdo_temp := SDO_UTIL.EXTRACT(p_input,i);             IF sdo_temp.get_gtype() = 3             THEN                IF output IS NULL                THEN                   output := sdo_temp;                                  ELSE                   output := SDO_UTIL.APPEND(output,sdo_temp);                                  END IF;                            END IF;                      END LOOP;                   RETURN output;                END IF;    END scrub_polygons;

  • Create point geometry off Line string

    Hi,
    I am new in using the oracle spatial functions. I need some help in trying to generate point geomteries off a line string.
    E.g. I have a line string say is a mile long; I need to dynseg this line string at regular intervals say 1/100th of a mile (52 feet accuracy) and extract the point geometries.
    Basically for a mile long line string, I need 10 point geomteries at equal distances (.01 mile apart). How can I achieve this? Do we have any geomtery functions that does this dyn seg?
    Any help is appreciated.
    This is an e.g of a line string in my table.
    Route: SFRAIR00270**C
    Begin_log:     15.21
    End-log:     15.42
    SD_GEOM: 2002, 41104, NULL, MDSYS.SDO_ELEM_INFO_ARRAY(NUMBER(1, 2, 1)), MDSYS.SDO_ORDINATE_ARRAY(NUMBER(545906.05083, 229998.885452, 545888.2, 230082.23, 545838.54, 230335.43))
    Thanks,
    LS.
    Edited by: user12035460 on Nov 9, 2012 12:35 PM

    If you are licensed for Spatial then look at the SDO_LRS package. It has all the functionality you need.
    If you are not so licensed, have a look at the LINEAR package on my website.
    http://www.spatialdbadvisor.com/source_code/214/linear-package-sdo_lrs-replacement
    regards
    Simon

  • How oracle spatial deals with self-looping polylines?

    Hi,folks
    I have a general question on self-looping polylines.
    If one polyline is self-closing, can oracle spatial recognize it as a line or polygon?
    Anyone can give some hints on that?

    HI!
    Review this page:
    http://download-west.oracle.com/docs/cd/A91202_01/901_doc/appdev.901/a88805/sdo_intr.htm#877625
    They say that "Self-crossing polygons are not supported, although self-crossing line strings ARE supported. If a line string crosses itself, it does not become a polygon. A self-crossing line string does not have any implied interior."
    Also, line strings are defined with their own SDO_GTYPE, such as "DL06" for MULTILINE or MULTICURVE, where POLYGON is "DL03" and MULTIPOLYGON is "DL07", so they can't be confused one with another.(See http://download-west.oracle.com/docs/cd/A91202_01/901_doc/appdev.901/a88805/sdo_objr.htm#1005537)

  • Data Retrieval Speed in Oracle Spatial vs. ESRI ArcSDE

    I would appreciate any opinions regarding data retrieval
    performance between Oracle Spatial and ESRI ArcSDE. Would an end-
    user (using ESRI software) experience significant differences in
    data retrieval speed depending on how the data were stored in
    Oracle (MDSYS.SDO_GEOMETRY verses ESRI Binary/Blob formats).
    Knowing that the ESRI binary formats are tailored to their
    software front-end apps (ArcGIS, ArcMap, ArcCatalog, and
    ArcInfo), wouldn't this be a "non-issue" until the spatial
    dataset gets "large", and even then, wouldn't performance be
    (almost) equal if the spatial indexes were created properly?
    Thanks for your inputs,
    Bruce

    John,
    You can't do that type of query in sql from sql*plus using
    SDEBINARY. HOwever, you can perform spatial queries in ArcMap
    if you are using SDEBINARY.
    You can use the query builder to perform point-in-polygon type
    queries.
    Hope that helps.
    For my two cents, I think SDO_GEOMETRY gives you a more robust
    database to work with, because you have the added power of
    Oracle Spatial functions. If you are using SDEBINARY you are
    limited to only what you can do thru ArcGIS.
    If you are concerned more about performance than accessibility,
    especially with a large number of users, then SDEBINARY might
    be the better choice.
    I love Oracle Spatial and am hoping that the performance issue
    will not be a serious one when we start putting ArcIMS developed
    apps into production.
    Dave

  • ORACLE SPATIAL

    Please i need help on how to connect to oracle spatial in 10g.Please can i get a step by step instructions on where to start making my connections and how to view the spatial after making teh connection.Thanks

    Hi what connection types do you mean please.I am new to oracle 10g and oracle spatial.I can find my way round 10g but not spatial.in this case please what options would you suggest.Thanks

  • Keep Oracle spatial data in memory

    Can I keep Oracle Spatial data (including metadata and related functions and procedures) in memory using TimesTen?

    It depends what form the data takes. TimesTen does not support any spatial types, only regular relational data types. Also, TimesTen does not support any of the Oracle spatial functions.
    In general this is not possible.
    Chris

  • I need help on Oracle Spatial

    Hello;
    I4m about to develop an application using your Spatial cartridge, but i4m not sure if it4s the best way to do it. Well, this application must store images caracteristics, but in more than 3 dimensions, i haven4t found any information about this, in the documents I found in your web site. I4d be very pleased if you could give me some information about if this cartridge is the best way to develop my application and how could Ido it.
    Thanks very much for your time, Cmc
    null

    Hi what connection types do you mean please.I am new to oracle 10g and oracle spatial.I can find my way round 10g but not spatial.in this case please what options would you suggest.Thanks

  • How do I find duplicate lines in Oracle Spatial?

    Hi,
    I am looking at all of the Oracle locator/spatial functions and I am wondering how to I find if two lines, or two polygons are the same? That is a user has partially loaded more lines into the database and the data had previously been loaded. I do not want to rely on any attribute names preferring to only compare GEOM data.
    thanks,
    Susan

    hi
    i think u can use this procedure to compare all geometry
    DECLARE
    v_id number;
    CURSOR cur1 is select * from Layer;
    CURSOR cur2(v_id number,v_geom mdsys.sdo_geometry) is select * from layer a
    where SDO_GEOM.RELATE(a.geom,'EQUAL',v_geom,0.005) = 'EQUAL' and v_id <> GID;
    ------------------------------ define your LAYER (LINES) ----------------------------
    row1 LAYER%rowtype;
    row2 LAYER%rowtype;
    BEGIN
    open cur1;
    loop
    fetch cur1 into row1;
    exit when cur1%NOTFOUND;
    open cur2(row1.GID,row1.geom) ;
    loop
    fetch cur2 into row2;
    exit when cur2%notfound;
    select row2.id from dual;
    -- or insert into ......
    end loop;
    close cur2;
    end loop;
    close cur1;
    end;
    -------------------------------GOOD LUCK ---------------------------------------------
    --Author Geomaticien @09                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

  • How to find ANGLE B/W two edges in Oracle Spatial

    How to find ANGLE B/W two edges in Oracle Spatial. I have two edge connected on same node. I wanted to know the angle betwwn them. Can somebody help me out????

    Ok. My first example was an approximation. The farther you get north or south of equator, the more inacurate it gets.
    This one should do the trick with some degree of accuracy.
    declare
      PI constant number := 3.14159265358979;
      g1 sdo_geometry;
      g2 sdo_geometry;
      g3 sdo_geometry;
      angle1 number;
      angle2 number;
      FUNCTION POINT(P_LAT  IN number
                    ,P_LONG IN number)
        RETURN MDSYS.SDO_GEOMETRY IS
      BEGIN
        -- we load both the ordinate array and the point type because some spatial functions show inconsistent behavior
        -- it is not important for this example, just something to be aware of
        return(mdsys.sdo_geometry(2001,8307 -- WGS84
                                 ,mdsys.sdo_point_type(p_long,p_lat,null)
                                                      ,mdsys.sdo_elem_info_array(1,2,1)
                                                      ,mdsys.sdo_ordinate_array(p_long,p_lat)));
      END;
    begin
      -- For the example, project in WGS84
      -- g1,g2,g3 could also come straight out of the database as sdo_geometry
      g1 := point(50, 7);          -- Point A
      g2 := point(51, 7);          -- Point B
      g3 := point(50,10);          -- Point C
      angle1 := atan2(g2.sdo_point.x - g1.sdo_point.x,
                      g2.sdo_point.y - g1.sdo_point.y);
      angle2 := atan2(g3.sdo_point.x - g1.sdo_point.x,
                      g3.sdo_point.y - g1.sdo_point.y);
      -- depending on rotation and where we are on the planet, adjustments may be needed
      if angle1 < 0      then angle1 := angle1 + 2 * PI; end if;
      if angle2 < 0      then angle2 := angle2 + 2 * PI; end if;
      if angle2 < angle1 then angle2 := angle2 + 2 * PI; end if;
      dbms_output.put_line('Angle between the lines A-B and A-C: '||
                           round(sdo_util.convert_unit(angle2-angle1,'Radian','Degree'),1));
    end;
    Angle between the lines A-B and A-C: 90

  • How can i find start line of any functions or procedures stored in package body?

    hi
    how can i find start line of any functions or procedures stored in package body?
    is there any way to write a query from for example user_source?
    thanks

    how can i find start line of any functions or procedures stored in package body?
    Why? What will you do differently if a procedure starts on line 173 instead of line 254?
    Tell us what PROBLEM you are trying to solve so we can help you find the best way to solve it.
    If you use PL_SCOPE that info is available in the *_IDENTIFIERS views. See 'Using PL/Scope in the Advanced Dev Doc
    http://docs.oracle.com/cd/B28359_01/appdev.111/b28424/adfns_plscope.htm
    Try this simple sample code. The query is modified from that doc sample:
    -- tell the compiler to collect the info
    ALTER SESSION SET PLSCOPE_SETTINGS='IDENTIFIERS:ALL';
    -- recompile the package
    CREATE OR REPLACE package SCOTT.pack1 as
    PROCEDURE proc1;
    PROCEDURE proc2;
    END;
    CREATE OR REPLACE package BODY SCOTT.pack1 as
    PROCEDURE proc1 IS
    BEGIN
      NULL;
    END;
    PROCEDURE proc2 IS
    BEGIN
      proc1;
    END;
    PROCEDURE proc3 IS
    BEGIN
      proc1;
      proc2;
    END;
    END;
    -- query the info for the package spec
    WITH v AS (
      SELECT    Line,
                Col,
                INITCAP(NAME) Name,
                LOWER(TYPE)   Type,
                LOWER(USAGE)  Usage,
                USAGE_ID,
                USAGE_CONTEXT_ID
        FROM USER_IDENTIFIERS
          WHERE Object_Name = 'PACK1'
            AND Object_Type = 'PACKAGE'
    SELECT LINE, RPAD(LPAD(' ', 2*(Level-1)) ||
                     Name, 20, '.')||' '||
                     RPAD(Type, 20)||
                     RPAD(Usage, 20)
                     IDENTIFIER_USAGE_CONTEXTS
      FROM v
      START WITH USAGE_CONTEXT_ID = 0
      CONNECT BY PRIOR USAGE_ID = USAGE_CONTEXT_ID
      ORDER SIBLINGS BY Line, Col
    LINE,IDENTIFIER_USAGE_CONTEXTS
    1,Pack1............... package             declaration        
    2,  Proc1............. procedure           declaration        
    3,  Proc2............. procedure           declaration        
    -- query the info for the package body - change 'PACKAGE' to 'PACKAGE BODY' in the query above
    LINE,IDENTIFIER_USAGE_CONTEXTS
    1,Pack1............... package             definition         
    2,  Proc1............. procedure           definition         
    6,  Proc2............. procedure           definition         
    8,    Proc1........... procedure           call               
    10,  Proc3............. procedure           declaration        
    10,    Proc3........... procedure           definition         
    12,      Proc1......... procedure           call               
    13,      Proc2......... procedure           call               

  • Oracle map function  with spatial

    Hi Experts,
    I have a database10.2.0.4 in red hat 5.0. the java application at 32 bit winrow 2003 sp2 server with tocmat ISS server6.0.
    Last week, the IE or forefox broower could not display oracle map when window server updated into 2008.
    all of other oracle function works well. We do not get any error message for this event.
    Does any expert have experience for this issue?
    Thanks
    Jim

    Try looking at this as a first step http://www.oracle.com/webfolder/technetwork/tutorials/obe/db/10g/r2/prod/datamgmt/spatial/spatial_otn.htm?cid=4553&ssid=0 that will give you a primer on getting data in and out of Oracle Spatial.  You will find lots of tutorials on the web.  There is no substitute for reading the manuals - http://docs.oracle.com/cd/E16655_01/nav/portal_7.htm#oracle_spatial_and_location_information
    I can highly recommend a book called Pro Oracle Spatial The 12c version is due out in June but the 11g version will get you started,

Maybe you are looking for

  • Treo 755p, Leopard, missing sync, no event syncing

    i initially had entourage but decided it *****, so i'd simply use ical and apple mail. when i had entourage i installed the palm software, but used isync to sync and everything worked fine. once i stopped uing entourage, and deleted the conduits, isy

  • New ipod classic won't  sync with itunes on windows 8

    I transferred my itunes library (via an external hard drive) from laptop windows xp to new laptop windows 8. I am now unable to sync my new ipod classic 160gb. I have also tried my old ipod classic 80gb but it won't sync either. 

  • Why does Lightroom color not match when editing in Photoshop CS3

    I just started Using Lightroom 4, the only version of lightroom that I have used. Short version, saves me heaps of time. But I went to edit more in photoshop and noticed that the color is dramatically different. I have Photoshop CS3 (10.0.1)and the c

  • How to make a form be excutable (exe)

    Hi all, Is it possible to make a form be excutable (exe)? and if yes, HOW? Best Regards, hany

  • Internet Filtering for iPod Touch

    I have a 12 year old boy that just got an iPod touch for his birthday.  Is there anything anyone can reccomend to filter the internet ie. Net Nanny?  Thank you!