Post on 02-Jun-2018
8/9/2019 Tip Tricks Spatial Apex
1/18
Tips and Tricks PL/SQL, Locator& Application Express (Apex)
Simon Greener,The SpatialDB Advisor
&
Jamie Keene,Senior Spatial Analyst
Open Spatial Pty Ltd
8/9/2019 Tip Tricks Spatial Apex
2/18
Genesis ...
The bac!ro"nd to this #oint presentation $as$or done $hen both o% "s $ored at orestryTasmania Pty Ltd'
The $or bein! presented incl"des t$o elements A set o% PL(S)L paca!es that $ere $ritten *+i to a"!ment
Spatial(Locator %"nctionality- Tip on "sin! pipelined %"nctions
A series o% applications b"ilt "sin! .ebDB, /tmlDB and
AP01' Demonstration o% Ape2, PL(S)L and 3ap4ie$er
8/9/2019 Tip Tricks Spatial Apex
3/18
Genesis PL/SQL packages
Oracle5s e2cellent PL(S)L allo$ed "s to create additional%"nctionality %or deployment $ithin an Oracle database' 6sed %or spatial re%erential inte!rity checs- A"tomation o% sdo7!eometry constr"ction *e! tri!!er to
constr"ct point %rom bearin!(distance %rom no$n pointstored in northin!(eastin! col"mns-
6se o% spatial %"nctionality in Oracle5s r"n 8"e"e- A"!mentin! the standard Locator(Spatial PL(S)L paca!es'
These paca!es have been completely re9$ritten since SimonGreener le%t orestry' /e $ill present a %e$ slides on these paca!es hi!hli!htin!
one partic"lar per%ormance tip'
8/9/2019 Tip Tricks Spatial Apex
4/18
Genesis !e"#$
.e %irst started inte!ratin! Spatial and Oracle5s:o"t o% the database; $ith .ebDB'
B"ilt database reports on spatial database activities *e!prod"ction o% PD based maps, data access etc
6sed %or billin! and b"d!etry reasons Also b"ilt point :editin!; applications that allo$ed %oresters
to create, move and delete simple point based data via !?= all o"r .ebDBapplications $ere ported to /tmlDB *no$Application 02press 9 Ape2
02perience !ained $ith .ebDB, co"pled $ith !reatercapability and %le2ibility o% /tmlDB(Ape2, hasallo$ed %or an e2plosion in spatial inte!ration c%Goo!le 3aps via :mash"ps; etc'
Jamie Keene $ill present some slides oninte!ratin! Ape2 $ith 3ap4ie$er and Simon5sPL(S)L paca!es'
8/9/2019 Tip Tricks Spatial Apex
6/18
PL/SQL G Package
The paca!es that $ill be "sed today are the@OGO and G0O3 paca!es'
The G0O3 paca!e contains !eneral %"nctions
s"ch as a :point in poly!on; %"nction *!"aranteesthe point %alls inside its poly!on, and a:vectorisation; %"nction that is "sed in this
presentation' The @OGO paca!e $as %irst constr"cted %or "se
inside a critical application :inventory; database atorestry'
8/9/2019 Tip Tricks Spatial Apex
7/18
Extracting "earings and distances
Let5s start $ith somethin! simple /ere is a poly!on
8/9/2019 Tip Tricks Spatial Apex
8/18
*etes and $o+nds..
B"t $e have a b"siness re8"irement to annotate itby bearin!s and distances dynamically !enerated%rom the act"al vectors that mae "p the bo"ndary
o% the poly!on'
8/9/2019 Tip Tricks Spatial Apex
9/18
%o-
A little bit o% PL(S)L in some types & paca!es'''CREATE OR REPLACE PACKAGE COGOAS
FUNCTION PI RETURN NUMBER;
FUNCTION Bearing( dE1 in number dN1 in number dE! in number dN! in number" RETURN NUMBER #ETERMINISTIC;
FUNCTION #i$%an&e( dE1 in number dN1 in number
dE! in number dN! in number" RETURN NUMBER #ETERMINISTIC;
'''
EN# COGO;
CREATE OR REPLACE PACKAGE GEOMAS
FUNCTION Ge%e&%)r!# ( *+ge)me%r, in md$,$'$d)+ge)me%r," RETURN CO#ES-S'e&%)r!#Se%T,*e #ETERMINISTIC;
EN# GEOM;
CREATE OR REPLACE T-PE C))rd!#T,*e ASOB.ECT ( / NUMBER , NUMBER ";
CREATE OR REPLACE T-PE e&%)r!#T,*e AS
OB.ECT ( $%ar%C))rd C))rd!#T,*e endC))rd C))rd!#T,*e ";
CREATE OR REPLACE T-PE e&%)r!#Se%T,*e AS TABLE OF e&%)r!#T,*e;
8/9/2019 Tip Tricks Spatial Apex
10/18
A ie ...CREATE OR REPLACE VIEWapex_demo
ASSELECTrownumASgid, codesysCogo!!"!#S$ codesysCogo%earing$s&ar&x,s&ar&y,endx,endy'
($)*+codesysCogoPI' '
AS-earing, RO./!$codesysCogo!is&ance$s&ar&x,s&ar&y,endx,endy',"' ASdis&ance, #!S0Ssdo_geome&ry$"++",/.LL,/.LL, #!S0SS!O_ELE#_I/1O_ARRA0$),",)', #!S0SS!O_OR!I/ATE_ARRA0$s&ar&x,s&ar&0,end2,end0''
ASgeome&ry 1RO#$ SELECT!ISTI/CTcS&ar&Coord2ASs&ar&2,
cS&ar&Coord0ASs&ar&0,
cEndCoord2 ASend2,cEndCoord0 ASend0 1RO#$ SELECTgeom
1RO#Pro3Po4y"!W5EREgid 6 7 ' a,
TA%LE$CAST$codesys8eom8e&Vec&or"!$ageom'AScodesysVec&or"!Se&Type'' c
'9
8/9/2019 Tip Tricks Spatial Apex
11/18
Perorance Tip Pipelining
6se o% Pipelined %"nctions s"bstantially improvesper%ormance, red"ces memory "se and is morescalable'
< De%initions o% 4ector
8/9/2019 Tip Tricks Spatial Apex
12/18
#ierence0 rdinar1 on9Pipelined %"nctions re8"ire memory'''
1./CTIO/8e&Vec&or"! $ p_geome&ry I/mdsyssdo_geome&ry' RET.R/CO!ES0SVec&or"!Se&Type !ETER#I/ISTIC9 :ec&ors Vec&or"!Se&Type ;6 Vec&or"!Se&Type$'9%E8I/ I1:_:er&ex 6 ) T5E/ :ec&orsE2TE/!9 :_:ec&or ;6 :ec&orsLAST9 :ec&ors$:_:ec&or' ;6 Vec&or"!Type$Coord"!Type$
8/9/2019 Tip Tricks Spatial Apex
13/18
#ierence0 Pipelined
Pipelined "se internal Oracle inter9process ernelcomm"nications $hich are not dependent on "ser memory'''
1./CTIO/8e&Vec&or"! $ p_geome&ry I/mdsyssdo_geome&ry' RET.R/CO!ES0SVec&or"!Se&Type PIPELI/E!9 %E8I/ I1:_:er&ex 6 ) T5E/ :_:ec&ors&ar&Coordx ;6 :_coordx9 :_:ec&ors&ar&Coordy ;6 :_coordy9 ELSE :_:ec&orendCoordx ;6 :_coordx9 :_:ec&orendCoordy ;6 :_coordy9 PIPE ROW$ :_:ec&or '9
:_:ec&ors&ar&Coordx ;6 :_coordx9 :_:ec&ors&ar&Coordy ;6 :_coordy9 :_:ec&orendCoordx ;6
8/9/2019 Tip Tricks Spatial Apex
14/18
Perorance etrics...
Pipelinin! is ASTC B"t don5t tae my $ord %or it' Let5s vectorise some poly!on data "sin! the
Get4ector
8/9/2019 Tip Tricks Spatial Apex
15/18
Perorance etrics...CREATE TA%LE@non_pipe4ined_:ersion
ASSELECT rownumASgid, #!S0SS!O_8EO#ETR0$"++",/.LL,/.LL, #!S0SS!O_ELE#_I/1O_ARRA0$),",)', #!S0SS!O_OR!I/ATE_ARRA0$s&ar&x,s&ar&0,end2,end0''
ASgeome&ry 1RO#$ SELECT!ISTI/CT cS&ar&Coord2ASs&ar&2,
cS&ar&Coord0ASs&ar&0,
cEndCoord2 ASend2,cEndCoord0 ASend0
1RO#$ SELECTgeome&ry 1RO#SP_PARCEL ' a,
TA%LE$CAST$ codesys8eom8e&Vec&or"!@AsPipe4ined$ageome&ry'
AScodesysVec&or"!Se&Type'' c '9
8/9/2019 Tip Tricks Spatial Apex
16/18
2+"ers...
Function TimeInSeconds
ector!D"et#y$e %la$sed: &&:&!:'()'*
ector!D"et#y$eAsPi$elined %la$sed: &&:&&:+,)-&
Pi$elinin. im$roved $erformance by:
/ ' 0 / +( 0 '*( 1 2 '&& 3 !(,4
SELECTCO./T$(' 1RO#PIPELI/E!_VERSIO/9
CO./T$('
8/9/2019 Tip Tricks Spatial Apex
17/18
3se o +nctions in Apex
8/9/2019 Tip Tricks Spatial Apex
18/18
S+ar1
PL(S)L is part o% yo"r Oracle Spatial :S$issArmy Kni%e; Pipelinin! is %ast, scalable and memory %riendly'
Ape2 is %ree, %"lly inte!rated, %ast and po$er%"l Ape2 Spatial 3ap4ie$er is a po$er%"l
combination'
ThansE 3id @oast .ater and Bar$on .ater %or"se o% their data'