Using polygon coordinates passed as a string
117897Apr 24 2008 — edited Jun 10 2008I'm building an Application Express application that allows the user to redline a polygon on a map and then sends the coordinates to an Application Express page for use in a report query. So I have a string of coordinate points, but I'm unable to successfully bind those points to a variable to use in a query. So the following query works:
select "BK_LOAD"."ID" as "ID",
"BK_LOAD"."LOC_NAME" as "LOC_NAME",
"BK_LOAD"."STATUS" as "STATUS",
"BK_LOAD"."BK_SCORE" as "BK_SCORE",
"BK_LOAD"."SIDE" as "SIDE",
"BK_LOAD"."STAN_ADDR" as "STAN_ADDR",
"BK_LOAD"."REF_ID" as "REF_ID",
"BK_LOAD"."MATCH_ADDR" as "MATCH_ADDR",
"BK_LOAD"."CERT" as "CERT",
"BK_LOAD"."NAMEFULL" as "NAMEFULL",
"BK_LOAD"."REGAGNT" as "REGAGNT",
"BK_LOAD"."BKCLASS" as "BKCLASS",
"BK_LOAD"."STALP" as "STALP",
"BK_LOAD"."STNAME" as "STNAME",
"BK_LOAD"."CNTYNAME" as "CNTYNAME",
"BK_LOAD"."CNTYNUM" as "CNTYNUM",
"BK_LOAD"."STCNTY" as "STCNTY"
from "BK_LOAD" "BK_LOAD"
where sdo_anyinteract(location,SDO_GEOMETRY(
2003,
8307,
NULL,
SDO_ELEM_INFO_ARRAY(1,1003,1),SDO_ORDINATE_ARRAY(-94.8488855786868,39.15377902759394, -94.65897150865807,39.3620718785932, -94.33427971151216, 39.29059884148561, -94.27505919505158, 38.896476094006616, -94.54461464928592, 38.714730371075895, -94.87951688030433, 38.910770701428134, -94.8488855786868,39.15377902759394))) = 'TRUE'
=======================
But a bind variable in place of the coordinate list does not. So I created a stored function to return a SDO_GEOMETRY object:
create or replace
FUNCTION GET_SDO_GEOMETRY
( p_coord_string IN VARCHAR2
) RETURN MDSYS.SDO_GEOMETRY AS
geom MDSYS.SDO_GEOMETRY;
sql_stmt varchar2(4000);
BEGIN
sql_stmt := 'select SDO_GEOMETRY(
2003,
8307,
NULL,
SDO_ELEM_INFO_ARRAY(1,1003,1),SDO_ORDINATE_ARRAY('||p_coord_string||')) into :geom from dual';
execute immediate sql_stmt;
RETURN geom;
END GET_SDO_GEOMETRY;
=========================
But the following query using the function returns no data? Any ideas on how to get this to work?
select "BK_LOAD"."ID" as "ID",
"BK_LOAD"."LOC_NAME" as "LOC_NAME",
"BK_LOAD"."STATUS" as "STATUS",
"BK_LOAD"."BK_SCORE" as "BK_SCORE",
"BK_LOAD"."SIDE" as "SIDE",
"BK_LOAD"."STAN_ADDR" as "STAN_ADDR",
"BK_LOAD"."REF_ID" as "REF_ID",
"BK_LOAD"."MATCH_ADDR" as "MATCH_ADDR",
"BK_LOAD"."CERT" as "CERT",
"BK_LOAD"."NAMEFULL" as "NAMEFULL",
"BK_LOAD"."REGAGNT" as "REGAGNT",
"BK_LOAD"."BKCLASS" as "BKCLASS",
"BK_LOAD"."STALP" as "STALP",
"BK_LOAD"."STNAME" as "STNAME",
"BK_LOAD"."CNTYNAME" as "CNTYNAME",
"BK_LOAD"."CNTYNUM" as "CNTYNUM",
"BK_LOAD"."STCNTY" as "STCNTY"
from "BK_LOAD" "BK_LOAD"
where sdo_anyinteract(location,(GET_SDO_GEOMETRY('-94.8488855786868,39.15377902759394, -94.65897150865807,39.3620718785932, -94.33427971151216, 39.29059884148561, -94.27505919505158, 38.896476094006616, -94.54461464928592, 38.714730371075895, -94.87951688030433, 38.910770701428134, -94.8488855786868,39.15377902759394'))) = 'TRUE'