use apex to visualize spatial data˜yvind-isene...json support in 12c •generate json with sql...

87

Upload: others

Post on 30-Aug-2020

22 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Use APEX to Visualize Spatial Data˜yvind-Isene...JSON support in 12c •Generate JSON with SQL •Store JSON in your database •Enables schema-on-read (“store now — think later”)
Page 2: Use APEX to Visualize Spatial Data˜yvind-Isene...JSON support in 12c •Generate JSON with SQL •Store JSON in your database •Enables schema-on-read (“store now — think later”)

UseAPEXtoVisualizeSpatialData• Displaydataonmapswithminimalefforts

Page 3: Use APEX to Visualize Spatial Data˜yvind-Isene...JSON support in 12c •Generate JSON with SQL •Store JSON in your database •Enables schema-on-read (“store now — think later”)

Øyvind Isene @OyvindIsene

http://oisene.blogspot.com

http://sysco.no http://www.bicon.no

https://enesi.no/

Page 4: Use APEX to Visualize Spatial Data˜yvind-Isene...JSON support in 12c •Generate JSON with SQL •Store JSON in your database •Enables schema-on-read (“store now — think later”)

3MembershipTiers•  OracleACEDirector•  OracleACE•  OracleACEAssociate

bit.ly/OracleACEProgram

500+TechnicalExpertsHelpingPeersGlobally

Connect:

Nominateyourselforsomeoneyouknow:acenomina?on.oracle.com

@oracleace

Facebook.com/oracleaces

[email protected]

Page 5: Use APEX to Visualize Spatial Data˜yvind-Isene...JSON support in 12c •Generate JSON with SQL •Store JSON in your database •Enables schema-on-read (“store now — think later”)

Agenda

• QuickintrotoAPEX• Findsomecooldata-ImportthemtoOracle• UseApextobuildanicewebpage.

Page 6: Use APEX to Visualize Spatial Data˜yvind-Isene...JSON support in 12c •Generate JSON with SQL •Store JSON in your database •Enables schema-on-read (“store now — think later”)

I’maDBA-sowhyAPEX?

• Funtocreatesomethingonmyown• Itisfast!• DBAshouldrecommendAPEX• itgivesyoulesspain• Fewermovingpartsthan• Weknowthetechnologybehindit• WithAPEXIcanreporteasilytomanagement• Customersloveit

Page 7: Use APEX to Visualize Spatial Data˜yvind-Isene...JSON support in 12c •Generate JSON with SQL •Store JSON in your database •Enables schema-on-read (“store now — think later”)

OK,butwhyspatial?

• Peoplelovemaps• Peoplemovearoundandliketoseeitin2D• Boringdatacanbeenrichedandlookgreatonmaps

• Lotsofpeopledon’tknowhoweasyyoucanworkwithgeographicdatainOracle

Page 8: Use APEX to Visualize Spatial Data˜yvind-Isene...JSON support in 12c •Generate JSON with SQL •Store JSON in your database •Enables schema-on-read (“store now — think later”)

Licenses

• Notmyfavouritesubject• Locator—subsetofSpatialincludedwithyourdblicense

• Locatorincludeswhatyouneedforfun• YoucandoalotofadvancedstuffwithextraSpatialandGraphlicense

• TestinlabandcheckDBA_FEATURE_USAGE_STATISTICS

Page 9: Use APEX to Visualize Spatial Data˜yvind-Isene...JSON support in 12c •Generate JSON with SQL •Store JSON in your database •Enables schema-on-read (“store now — think later”)

Installation

• UseDockerorVirtualBoxwithVagrant• OrdownloadOracleDatabaseAppDevelopmentVMforVirtualBox

• Orapex.oracle.com• Oryourfriend’scloud?

Page 10: Use APEX to Visualize Spatial Data˜yvind-Isene...JSON support in 12c •Generate JSON with SQL •Store JSON in your database •Enables schema-on-read (“store now — think later”)

AnoteonDocker

• LearningDockerisagoodinvestment• Setupyourownlabwithlittlehassle• Focusonyourtask-notinstallation• ExcellentsupportfromOracle• https://github.com/oracle/docker-images• AlsocheckoutworkbyGeraldVenzl• Seeashortintroattheend.

Page 11: Use APEX to Visualize Spatial Data˜yvind-Isene...JSON support in 12c •Generate JSON with SQL •Store JSON in your database •Enables schema-on-read (“store now — think later”)

ALittleBitofHistory• Itusedtobecomplicated

Page 12: Use APEX to Visualize Spatial Data˜yvind-Isene...JSON support in 12c •Generate JSON with SQL •Store JSON in your database •Enables schema-on-read (“store now — think later”)

MapsbeforeGoogle

• ComplicatedandslowAPIs• Involvedheavyserver-sidetechnology• Requiredsomeinsighttocartography

Page 13: Use APEX to Visualize Spatial Data˜yvind-Isene...JSON support in 12c •Generate JSON with SQL •Store JSON in your database •Enables schema-on-read (“store now — think later”)

MapswithGoogle

• GoogleandOpenStreetMaps(OSM)madesimpleAPIs

• MapsanddatacouldbeaccessedwithoutadegreeinGIS

• Showmapsastileswith256x256px• Zoomingandpanningdonebyloadingtileswithoutcompleterefreshofpage

Page 14: Use APEX to Visualize Spatial Data˜yvind-Isene...JSON support in 12c •Generate JSON with SQL •Store JSON in your database •Enables schema-on-read (“store now — think later”)

Evensimplier

• Leafletwantedtosimplifyfurther• MapboxisastartupbuildonLeafletwithmorefeatures.

• YoucanchoseJavaScriptAPIfromoneplace• Andatileserverfromanother.

Page 15: Use APEX to Visualize Spatial Data˜yvind-Isene...JSON support in 12c •Generate JSON with SQL •Store JSON in your database •Enables schema-on-read (“store now — think later”)

Let’sgetstartedInAPEX

Page 16: Use APEX to Visualize Spatial Data˜yvind-Isene...JSON support in 12c •Generate JSON with SQL •Store JSON in your database •Enables schema-on-read (“store now — think later”)

CreateanewemptypageCreateastaticregionwiththefollowingsource:

<div id="mapRegion" style="width:100%;height:430px;"></div>

You’llneedthislater

Page 17: Use APEX to Visualize Spatial Data˜yvind-Isene...JSON support in 12c •Generate JSON with SQL •Store JSON in your database •Enables schema-on-read (“store now — think later”)
Page 18: Use APEX to Visualize Spatial Data˜yvind-Isene...JSON support in 12c •Generate JSON with SQL •Store JSON in your database •Enables schema-on-read (“store now — think later”)

JavaScriptandCSS

• Frominthisexample• Severalotheroptionsexist• JSAPIcontainsfunctionstoshowmapanddrawonit

• CSSmakesitlookgood• URLsforJSandCSSisaddedtothepageinAPEX

Page 19: Use APEX to Visualize Spatial Data˜yvind-Isene...JSON support in 12c •Generate JSON with SQL •Store JSON in your database •Enables schema-on-read (“store now — think later”)
Page 20: Use APEX to Visualize Spatial Data˜yvind-Isene...JSON support in 12c •Generate JSON with SQL •Store JSON in your database •Enables schema-on-read (“store now — think later”)
Page 21: Use APEX to Visualize Spatial Data˜yvind-Isene...JSON support in 12c •Generate JSON with SQL •Store JSON in your database •Enables schema-on-read (“store now — think later”)

CreateauseratMapboxSignupforfreetogetanaccesstoken

Actually, you ca

n do this later

and use the public

token shown here

Page 22: Use APEX to Visualize Spatial Data˜yvind-Isene...JSON support in 12c •Generate JSON with SQL •Store JSON in your database •Enables schema-on-read (“store now — think later”)

Somecode…L.mapbox.accessToken = 'pk.eyJ1Ijoib2lzZW5lIiwiYSI6ImNqN25tOXRmZjMyN3gzNHFwa2IzMHR1bGkifQ.WDyAyQ9PaBhf9DdA-dQLCw';

var map = L.mapbox.map('mapRegion', 'mapbox.streets')

.setView([59.910349, 10.725035], 9);

var marker = L.marker([59.910349, 10.725035]).addTo(map); Your id from <div …>

Page 23: Use APEX to Visualize Spatial Data˜yvind-Isene...JSON support in 12c •Generate JSON with SQL •Store JSON in your database •Enables schema-on-read (“store now — think later”)

Addithere

Page 24: Use APEX to Visualize Spatial Data˜yvind-Isene...JSON support in 12c •Generate JSON with SQL •Store JSON in your database •Enables schema-on-read (“store now — think later”)
Page 25: Use APEX to Visualize Spatial Data˜yvind-Isene...JSON support in 12c •Generate JSON with SQL •Store JSON in your database •Enables schema-on-read (“store now — think later”)

Itworks,letusmapsomedatafromthedatabase,ofcourse

Page 26: Use APEX to Visualize Spatial Data˜yvind-Isene...JSON support in 12c •Generate JSON with SQL •Store JSON in your database •Enables schema-on-read (“store now — think later”)

Finda(cool)dataset

• data.norge.no• UseGoogle• Orseemynextsession

Page 27: Use APEX to Visualize Spatial Data˜yvind-Isene...JSON support in 12c •Generate JSON with SQL •Store JSON in your database •Enables schema-on-read (“store now — think later”)

Examplewithpostoffices

• http://www.bedreinnsikt.no/innhold/datasett-postnummer

• Datadownloadedastextfile• ImportwithSQLDeveloper

Page 28: Use APEX to Visualize Spatial Data˜yvind-Isene...JSON support in 12c •Generate JSON with SQL •Store JSON in your database •Enables schema-on-read (“store now — think later”)
Page 29: Use APEX to Visualize Spatial Data˜yvind-Isene...JSON support in 12c •Generate JSON with SQL •Store JSON in your database •Enables schema-on-read (“store now — think later”)

AfewslidesonJavaScriptandJSON

Page 30: Use APEX to Visualize Spatial Data˜yvind-Isene...JSON support in 12c •Generate JSON with SQL •Store JSON in your database •Enables schema-on-read (“store now — think later”)

JavaScriptandJSON

• JSlibrarywantsdatainJSON• NottoodifficulttogeneratewithPL/SQL• 12ccomeswithrichJSONsupport• Agoodreasontoupgrade!

Page 31: Use APEX to Visualize Spatial Data˜yvind-Isene...JSON support in 12c •Generate JSON with SQL •Store JSON in your database •Enables schema-on-read (“store now — think later”)

JSONsupportin12c

• GenerateJSONwithSQL• StoreJSONinyourdatabase• Enablesschema-on-read(“storenow—thinklater”)

• Checkout“JSONDevelopersGuide”• evenifyou’reaDBA

Every new database

release

is an opportuni

ty to simplify co

de

Page 32: Use APEX to Visualize Spatial Data˜yvind-Isene...JSON support in 12c •Generate JSON with SQL •Store JSON in your database •Enables schema-on-read (“store now — think later”)

Usefulfunctions

• JSON_OBJECT• createsaJSON-objectfromcolumn(s)• JSON_ARRAYAGG• aggregatefunction• JSON-arrayofobjectsorcolumn(s)

Page 33: Use APEX to Visualize Spatial Data˜yvind-Isene...JSON support in 12c •Generate JSON with SQL •Store JSON in your database •Enables schema-on-read (“store now — think later”)

Returnalistofpoints

select json_object('postnummer' value json_arrayagg(json_longlat )) json_arr from ( select json_object('postnummer' value postnummer, 'poststed' value apex_escape.html(poststed), 'lat' value latitude, 'lng' value longitude) json_longlat from postnummer where rownum < 10 );

APEX is full of u

seful packages

that makes life easier

Page 34: Use APEX to Visualize Spatial Data˜yvind-Isene...JSON support in 12c •Generate JSON with SQL •Store JSON in your database •Enables schema-on-read (“store now — think later”)

Oneannoyingbug

• FunctionscanreturnVARCHAR2(max4000bytes)orCLOB

• Butduetobug25186856,CLOBdoesn’twork:(• SeeDatabaseReadme• Arewritenottoocomplicated

Page 35: Use APEX to Visualize Spatial Data˜yvind-Isene...JSON support in 12c •Generate JSON with SQL •Store JSON in your database •Enables schema-on-read (“store now — think later”)

Considerextendeddatatypes

• Increaselimitfrom4000to32767bytesforVARCHAR2(for12c)

• Thisisdonebydefaultinthecloud• Foron-premdatabaseyou’llneedtodoit.• SeeTimHallspost:https://oracle-base.com/articles/12c/extended-data-types-12cR1

Page 36: Use APEX to Visualize Spatial Data˜yvind-Isene...JSON support in 12c •Generate JSON with SQL •Store JSON in your database •Enables schema-on-read (“store now — think later”)

create or replace function get_json return varchar2 is l_json varchar2(32767); i pls_integer; begin i:=0; for piece in ( select json_object('id' value id, 'postnummer' value postnummer, 'poststed' value apex_escape.html(poststed), 'kategori' value postnummerkategori,'lat' value latitude, 'lng' value longitude null on null) longlat from postnummer where rownum < 20) loop if i>1 then l_json := l_json || ',' || piece.longlat; else l_json := piece.longlat; end if; i := i + 1; end loop; return '{"postnummer": [' || l_json || ']}'; end; /

PL/SQL to be called from APEX

Page 37: Use APEX to Visualize Spatial Data˜yvind-Isene...JSON support in 12c •Generate JSON with SQL •Store JSON in your database •Enables schema-on-read (“store now — think later”)

BacktoAPEXexample

• AddahiddenitemtostoretheJSON-array• AddaprocesstobeexecutedBeforeHeader

begin :P3_JSON := get_json(); end;

Page 38: Use APEX to Visualize Spatial Data˜yvind-Isene...JSON support in 12c •Generate JSON with SQL •Store JSON in your database •Enables schema-on-read (“store now — think later”)

Add to previous “Execute when Page loads”

L.mapbox.accessToken='pk.eyJ1Ijoib2lzZW5lIiwiYSI6ImNqN25tOXRmZjMyN3gzNHFwa2IzMHR1bGkifQ.WDyAyQ9PaBhf9DdA-dQLCw';varmap=L.mapbox.map('mapRegion','mapbox.streets').setView([59.910349,10.725035],9);varmarker=L.marker([59.910349,10.725035]).addTo(map);

varpopupOptions={offset:newL.Point(3,-25)};

varjson=JSON.parse($v('P3_JSON'));varpn=json.postnummer;varmarker,nummer,text,id,lat,lng,sted,kategori;varMarkers=[];

for(vari=0;i<pn.length;i++){id=[i].id;lat=Number(pn[i].lat);lng=Number(pn[i].lng);nummer=pn[i].postnummer;sted=pn[i].poststed;

Page 39: Use APEX to Visualize Spatial Data˜yvind-Isene...JSON support in 12c •Generate JSON with SQL •Store JSON in your database •Enables schema-on-read (“store now — think later”)

Still pretty easy

, right?

Page 40: Use APEX to Visualize Spatial Data˜yvind-Isene...JSON support in 12c •Generate JSON with SQL •Store JSON in your database •Enables schema-on-read (“store now — think later”)

AddmoreStuff

• Addcircles,polygons,etc• CheckoutAPIdocumentationfrom• https://www.mapbox.com/mapbox.js/api/v3.1.1/

Page 41: Use APEX to Visualize Spatial Data˜yvind-Isene...JSON support in 12c •Generate JSON with SQL •Store JSON in your database •Enables schema-on-read (“store now — think later”)

WhataboutSpatial?Whenyouneedtoanalyseyourstuff

Page 42: Use APEX to Visualize Spatial Data˜yvind-Isene...JSON support in 12c •Generate JSON with SQL •Store JSON in your database •Enables schema-on-read (“store now — think later”)

• Datatypetostorespatialobjectsindatabase• Fromapointtocomplexobjects• Neededforspatialanalysis• Spatialapplicationsusethisdatatype• TheirdatacanbedisplayedinAPEX.

SDO_GEOMETRY

Page 43: Use APEX to Visualize Spatial Data˜yvind-Isene...JSON support in 12c •Generate JSON with SQL •Store JSON in your database •Enables schema-on-read (“store now — think later”)

Somecleanupfirst

update postnummer set longitude = null,latitude = null where latitude ='(blank)' or longitude='(blank)';

Page 44: Use APEX to Visualize Spatial Data˜yvind-Isene...JSON support in 12c •Generate JSON with SQL •Store JSON in your database •Enables schema-on-read (“store now — think later”)

alter table postnummer add geom_location sdo_geometry; -- 8307 for WGS 84 with order lon,lat update postnummer set geom_location=sdo_geometry(2001, 8307, sdo_point_type(longitude,latitude,null),null,null) where longitude is not null and latitude is not null;

2001forpoints

Typeofmapforthesedata,8307iscommon

Columnsintable(longitude,latitude)fromdatasetSlightlyconfusingnames.Lookatdatatoseewhatiswhat

ConvertyourdatatoSDO_GEOMETRY

Page 45: Use APEX to Visualize Spatial Data˜yvind-Isene...JSON support in 12c •Generate JSON with SQL •Store JSON in your database •Enables schema-on-read (“store now — think later”)

• YoucanusefunctionsinSpatial

WithSDO_GEOMETRY

Page 46: Use APEX to Visualize Spatial Data˜yvind-Isene...JSON support in 12c •Generate JSON with SQL •Store JSON in your database •Enables schema-on-read (“store now — think later”)

“Whatistheminimumdistancetonextplace,foreachplace?”

select postnummer,round(min(distance)) distance from ( select a.postnummer, SDO_GEOM.sdo_distance( a.geom_location, SDO_DIM_ARRAY( SDO_DIM_ELEMENT('long', -180,180,1), SDO_DIM_ELEMENT('lat',-90,90,1)), b.geom_location, SDO_DIM_ARRAY( SDO_DIM_ELEMENT('long', -180,180,1), SDO_DIM_ELEMENT('lat',-90,90,1))) distance from postnummer a, postnummer b where a.FYLKE='FINNMARK' and a.postnummerkategori ='Postbokser' and b.postnummerkategori ='Postbokser' and a.latitude != b.latitude ) group by postnummer order by 2 ;

Page 47: Use APEX to Visualize Spatial Data˜yvind-Isene...JSON support in 12c •Generate JSON with SQL •Store JSON in your database •Enables schema-on-read (“store now — think later”)

POSTNUMMERDISTANCE9505 16829504 16829502 16829501 16829506 16829503 16829916 24259914 24259508 34099507 34099915 47709846 141819820 141819811 164729810 164729616 211619621 211619615 211619991 322399981 32239

Default unit is

meter for geodetic data

Page 48: Use APEX to Visualize Spatial Data˜yvind-Isene...JSON support in 12c •Generate JSON with SQL •Store JSON in your database •Enables schema-on-read (“store now — think later”)

SpatialIndex

• Specialindextospeedupsearch• Oracleneedssomedataaboutthedata—metadatabeforeanindexcanbecreated

• InsertonerowinUSER_SDO_GEOM_METADATAforeachcolumn(akalayer)

• Notallfunctionsrequiresaspatialindex(previousexample)

• AllSpatialOperatorsdo!

Page 49: Use APEX to Visualize Spatial Data˜yvind-Isene...JSON support in 12c •Generate JSON with SQL •Store JSON in your database •Enables schema-on-read (“store now — think later”)

insert into user_sdo_geom_metadata (TABLE_NAME,COLUMN_NAME,DIMINFO,SRID) values ('POSTNUMMER','GEOM_LOCATION',SDO_DIM_ARRAY( SDO_DIM_ELEMENT('long', -180,180,1), SDO_DIM_ELEMENT('lat',-90,90,1)), 8307 ); commit;

Lowerboundary

Higherboundary

Tolerance

Nameyougivethedimension

Page 50: Use APEX to Visualize Spatial Data˜yvind-Isene...JSON support in 12c •Generate JSON with SQL •Store JSON in your database •Enables schema-on-read (“store now — think later”)

Tip:Shift-F4inSQLDeveloperPut cursor on object_type Hit Shift-F4

Page 51: Use APEX to Visualize Spatial Data˜yvind-Isene...JSON support in 12c •Generate JSON with SQL •Store JSON in your database •Enables schema-on-read (“store now — think later”)

OrusemenusinSQLDeveloper

Page 52: Use APEX to Visualize Spatial Data˜yvind-Isene...JSON support in 12c •Generate JSON with SQL •Store JSON in your database •Enables schema-on-read (“store now — think later”)

Create the Indexcreate index postnummer_geom_location_si on POSTNUMMER(geom_location) indextype is MDSYS.SPATIAL_INDEX;

PackageAPEX_SPATIALcanalsohelpwiththis.

Page 53: Use APEX to Visualize Spatial Data˜yvind-Isene...JSON support in 12c •Generate JSON with SQL •Store JSON in your database •Enables schema-on-read (“store now — think later”)

SpatialOperators

• UsedasnormaloperatorsinWHEREclause• Filterrowsasearlybeforefurtherprocessing• RequireSpatialIndex

Page 54: Use APEX to Visualize Spatial Data˜yvind-Isene...JSON support in 12c •Generate JSON with SQL •Store JSON in your database •Enables schema-on-read (“store now — think later”)

Findthethreeclosestplacestous

select postnummer,round(sdo_nn_distance(1)) distance_meters, geom_location from postnummer where sdo_nn(geom_location, sdo_geometry(2001, 8307, sdo_point_type(10.725035,59.910349,null),null,null), 'sdo_num_res=3',1) = 'TRUE' order by 2;

Ourposition

Page 55: Use APEX to Visualize Spatial Data˜yvind-Isene...JSON support in 12c •Generate JSON with SQL •Store JSON in your database •Enables schema-on-read (“store now — think later”)

POSTNUMMER DISTANCE_METERS GEOM_LOCATION0250 47 [MDSYS.SDO_GEOMETRY]

0021 80 [MDSYS.SDO_GEOMETRY]

0252 241 [MDSYS.SDO_GEOMETRY]

Page 56: Use APEX to Visualize Spatial Data˜yvind-Isene...JSON support in 12c •Generate JSON with SQL •Store JSON in your database •Enables schema-on-read (“store now — think later”)

TO_GEOJSON

• ConvertSDO_GEOMETRYtoGEO_JSON• GEO_JSONsupportedinJSAPI• SDO_UTIL.TO_GEOJSON• Examplewithpreviousquery• Warning:GeoJSONinvertstheorder(lon,lat)

Page 57: Use APEX to Visualize Spatial Data˜yvind-Isene...JSON support in 12c •Generate JSON with SQL •Store JSON in your database •Enables schema-on-read (“store now — think later”)

select postnummer,round(sdo_nn_distance(1)) distance_m, sdo_util.to_geojson(geom_location)location_json from postnummer where sdo_nn(geom_location, sdo_geometry(2001, 8307, sdo_point_type(10.725035,59.910349,null),null,null), 'sdo_num_res=3',1) = 'TRUE' order by 2;

POSTNUMMER DISTANCE_M LOCATION_JSON250 47 {"type":"Point","coordinates":[10.72507,59.90993]}21 80 {"type":"Point","coordinates":[10.725392,59.909658]}252 241 {"type":"Point","coordinates":[10.72301,59.90844]}

Again, 12c makes th

is so much eas

ier

Page 58: Use APEX to Visualize Spatial Data˜yvind-Isene...JSON support in 12c •Generate JSON with SQL •Store JSON in your database •Enables schema-on-read (“store now — think later”)

Codebeforeheader

begin select '[' || listagg(geo_json,',') within group ( order by id) || ']' into :P4_JSON from ( select id, sdo_util.to_geojson(geom_location) geo_json from postnummer where sdo_nn(geom_location, sdo_geometry(2001, 8307, sdo_point_type(10.725035,59.910349,null),null,null), 'sdo_num_res=3',1) = 'TRUE' ); end;

Page 59: Use APEX to Visualize Spatial Data˜yvind-Isene...JSON support in 12c •Generate JSON with SQL •Store JSON in your database •Enables schema-on-read (“store now — think later”)

JSonload

L.mapbox.accessToken = 'pk.eyJ1Ijoib2lzZW5lIiwiYSI6ImNqN25tOXRmZjMyN3gzNHFwa2IzMHR1bGkifQ.WDyAyQ9PaBhf9DdA-dQLCw'; var map = L.mapbox.map('map2Region', 'mapbox.streets') .setView([59.910349, 10.725035], 9);

var geo_json = JSON.parse($v('P4_JSON')); var layer = L.geoJson(geo_json).addTo(map);

Heretheorderislat,lon

GeoJSONuseslon,lat

Page 60: Use APEX to Visualize Spatial Data˜yvind-Isene...JSON support in 12c •Generate JSON with SQL •Store JSON in your database •Enables schema-on-read (“store now — think later”)

AddtoGeoJSON

• to_geojsonreturnsthegeometries-partofGeoJSON

• AddothercolumnsforbetterUX

Page 61: Use APEX to Visualize Spatial Data˜yvind-Isene...JSON support in 12c •Generate JSON with SQL •Store JSON in your database •Enables schema-on-read (“store now — think later”)

{ "type": "FeatureCollection", "features": [ { "type": "Feature", "geometry": {"type": "Point", "coordinates": [102.0, 0.5]}, "properties": {"prop0": "value0"} }, { "type": "Feature", "geometry": { "type": "LineString", "coordinates": [ [102.0, 0.0], [103.0, 1.0], [104.0, 0.0], [105.0, 1.0] ] }, "properties": { "prop0": "value0", "prop1": 0.0 } }, { "type": "Feature", "geometry": { "type": "Polygon", "coordinates": [ [ [100.0, 0.0], [101.0, 0.0], [101.0, 1.0], [100.0, 1.0], [100.0, 0.0] ] ] }, "properties": { "prop0": "value0", "prop1": {"this": "that"} } } ] }

GeoJSON example

Page 62: Use APEX to Visualize Spatial Data˜yvind-Isene...JSON support in 12c •Generate JSON with SQL •Store JSON in your database •Enables schema-on-read (“store now — think later”)

Trydifferentmapstyles

• ParametertoL.mapbox.map

• Trymapbox.pirates,mapbox.pencil,mapbox.comic,etc

Page 63: Use APEX to Visualize Spatial Data˜yvind-Isene...JSON support in 12c •Generate JSON with SQL •Store JSON in your database •Enables schema-on-read (“store now — think later”)

BeerDatafromUntappdMydrinkingonamap

Page 64: Use APEX to Visualize Spatial Data˜yvind-Isene...JSON support in 12c •Generate JSON with SQL •Store JSON in your database •Enables schema-on-read (“store now — think later”)

• Supportinguserscandownloadtheirdata

• Positionforeachvenueandotherinformation.

• Asearlier,easytoimportwithSQLDeveloper

Page 65: Use APEX to Visualize Spatial Data˜yvind-Isene...JSON support in 12c •Generate JSON with SQL •Store JSON in your database •Enables schema-on-read (“store now — think later”)

Addspatialcolumn

alter table untappd add location sdo_geometry;

update untappd set location= sdo_geometry(2001, 8307, sdo_point_type(venue_lng,VENUE_LAT,null),null,null) where venue_lng is not null and venue_lat is not null; commit;

Page 66: Use APEX to Visualize Spatial Data˜yvind-Isene...JSON support in 12c •Generate JSON with SQL •Store JSON in your database •Enables schema-on-read (“store now — think later”)

Code fetching dataselect json_object('type' value 'FeatureCollection', 'features' value json_arrayagg(feature format json returning varchar2(32000)) returning varchar2(32000)) into :P7_JSON from ( select json_object('type' value 'Feature', 'properties' value json_object('description' value beer_name , 'title' value venue_name) , 'geometry' value cast (sdo_util.to_geojson(location) as varchar2(32000)) format json) feature from untappd where venue_city='Oslo');

Extended data types has been enabled

Page 67: Use APEX to Visualize Spatial Data˜yvind-Isene...JSON support in 12c •Generate JSON with SQL •Store JSON in your database •Enables schema-on-read (“store now — think later”)

JavaScript code

L.mapbox.accessToken = 'pk.eyJ1Ijoib2lzZW5lIiwiYSI6ImNqN25tOXRmZjMyN3gzNHFwa2IzMHR1bGkifQ.WDyAyQ9PaBhf9DdA-dQLCw';

var map = L.mapbox.map('mapRegion', 'mapbox.streets') .setView([59.910349, 10.725035], 13);

var geo_json = JSON.parse($v('P7_JSON')); L.mapbox.featureLayer(geo_json).addTo(map);

Page 68: Use APEX to Visualize Spatial Data˜yvind-Isene...JSON support in 12c •Generate JSON with SQL •Store JSON in your database •Enables schema-on-read (“store now — think later”)
Page 69: Use APEX to Visualize Spatial Data˜yvind-Isene...JSON support in 12c •Generate JSON with SQL •Store JSON in your database •Enables schema-on-read (“store now — think later”)

OtherSuppliers

Page 70: Use APEX to Visualize Spatial Data˜yvind-Isene...JSON support in 12c •Generate JSON with SQL •Store JSON in your database •Enables schema-on-read (“store now — think later”)

TilesServers

• JavaScriptlibraryusesatileservertofetchmaptiles• Someavailable:• Google• OpenStreetMap• MapQuest• Nokia• Microsoft• Mapbox• StatensKartverk

Page 71: Use APEX to Visualize Spatial Data˜yvind-Isene...JSON support in 12c •Generate JSON with SQL •Store JSON in your database •Enables schema-on-read (“store now — think later”)

$$$

• Somerequireregistration(APIkey)• Freeuseuptoalimit(requestprtimeperiod)• Extrafeaturesorenterpriseusecostsmoney.• Youcanhostyourown(opensource).

Page 72: Use APEX to Visualize Spatial Data˜yvind-Isene...JSON support in 12c •Generate JSON with SQL •Store JSON in your database •Enables schema-on-read (“store now — think later”)

PreviousExamplewithStatensKartverk

Page 73: Use APEX to Visualize Spatial Data˜yvind-Isene...JSON support in 12c •Generate JSON with SQL •Store JSON in your database •Enables schema-on-read (“store now — think later”)
Page 74: Use APEX to Visualize Spatial Data˜yvind-Isene...JSON support in 12c •Generate JSON with SQL •Store JSON in your database •Enables schema-on-read (“store now — think later”)

Moremappingoptions

• Seehttps://www.kartverket.no/data/lage-kart-pa-nett/fordetails

• Trydifferentkindofmaps(atleast6available)

Page 75: Use APEX to Visualize Spatial Data˜yvind-Isene...JSON support in 12c •Generate JSON with SQL •Store JSON in your database •Enables schema-on-read (“store now — think later”)

• DifferentAPI• NottoodifficultwhenyouknowLeaflet• NeedtosignupforanAPIkey• IfoundLeaflet/Mapboxeasiertoworkwith

GoogleMaps?

Page 76: Use APEX to Visualize Spatial Data˜yvind-Isene...JSON support in 12c •Generate JSON with SQL •Store JSON in your database •Enables schema-on-read (“store now — think later”)
Page 77: Use APEX to Visualize Spatial Data˜yvind-Isene...JSON support in 12c •Generate JSON with SQL •Store JSON in your database •Enables schema-on-read (“store now — think later”)

Summary-Youneed

• OneJavaScriptlibrary/APIneeded• UseLeafletorMapbox• Atileserverthatservesyoumaptiles• OpenStreetMap,Mapbox,Mapquest• AutomaticinMapbox• AprocesstoloaddataintoJSON• JavaScriptcodethatrendersitonthemap

Page 78: Use APEX to Visualize Spatial Data˜yvind-Isene...JSON support in 12c •Generate JSON with SQL •Store JSON in your database •Enables schema-on-read (“store now — think later”)

Tipsattheendfortroubleshootingandfun

Page 79: Use APEX to Visualize Spatial Data˜yvind-Isene...JSON support in 12c •Generate JSON with SQL •Store JSON in your database •Enables schema-on-read (“store now — think later”)

Whenyourpageisblank

• DeveloperToolinChrome• “F12”inIE• Checkconsoleforerrormessages• Prettyeasytospottypos

Page 80: Use APEX to Visualize Spatial Data˜yvind-Isene...JSON support in 12c •Generate JSON with SQL •Store JSON in your database •Enables schema-on-read (“store now — think later”)

• console.log()• Verifydataandlogic• Ifdataarenotshownitmaybewrongorder• RFC5870

Logtoconsole

Page 81: Use APEX to Visualize Spatial Data˜yvind-Isene...JSON support in 12c •Generate JSON with SQL •Store JSON in your database •Enables schema-on-read (“store now — think later”)

Conclusion

Page 82: Use APEX to Visualize Spatial Data˜yvind-Isene...JSON support in 12c •Generate JSON with SQL •Store JSON in your database •Enables schema-on-read (“store now — think later”)

• Apexiseasyandfun• GoodsupportforJSONin12c• Displayeasilyspatialand“normal”data• Showyourdataandgetattention!

Page 83: Use APEX to Visualize Spatial Data˜yvind-Isene...JSON support in 12c •Generate JSON with SQL •Store JSON in your database •Enables schema-on-read (“store now — think later”)

CrashintroductiontoDockerSpendtimeonlearning,notinstallation

Page 84: Use APEX to Visualize Spatial Data˜yvind-Isene...JSON support in 12c •Generate JSON with SQL •Store JSON in your database •Enables schema-on-read (“store now — think later”)

OracleonDockerinfewsteps

1.DownloadDocker:• www.docker.com/docker-mac• www.docker.com/docker-windows• www.docker.com/docker-oracle-linux2.DownloadOracledatabasesoftware• otn.oracle.com3.CloneDockerfilesbyOraclefromGithub• git clonegithub.com/oracle/docker-images

Page 85: Use APEX to Visualize Spatial Data˜yvind-Isene...JSON support in 12c •Generate JSON with SQL •Store JSON in your database •Enables schema-on-read (“store now — think later”)

Buildandstartwith

4../buildDockerImage.sh -v 12.2.0.1 -e

5. docker run -p 1521:1521 \ -p 8080:8080 \ —name oracle-ee \ oracle/database:12.2.0.1-ee

Page 86: Use APEX to Visualize Spatial Data˜yvind-Isene...JSON support in 12c •Generate JSON with SQL •Store JSON in your database •Enables schema-on-read (“store now — think later”)

Upandrunning

• SYSandSYSTEMpasswordisgeneratedeachtimeacontaineriscreated

• Passwordprintedouttoscreen• Databaseiscreatedduringfirstrun.• UseSQLDeveloperCommandLineforeasytesting

Page 87: Use APEX to Visualize Spatial Data˜yvind-Isene...JSON support in 12c •Generate JSON with SQL •Store JSON in your database •Enables schema-on-read (“store now — think later”)

OrperhapsVagrant?

• IfyouknowVirtualBox,Vagrantmaybeeveneasier.

• Findreadytousestuffhere:https://github.com/gvenzl/vagrant-boxes