当前位置:网站首页>Oracle livelabs experiment: introduction to Oracle Spatial
Oracle livelabs experiment: introduction to Oracle Spatial
2022-06-12 21:38:00 【dingdingfish】
This experiment introduces the application of Oracle Spatial function .
The application address for this experiment is here , Time is 60 minute .
For the help of this experiment, see here .
Oracle Spatial Previously, the database option was charged separately , It has been included in the Database Enterprise Edition .
Introduction
About Oracle Spatial
Oracle Our mission is to help people view data in new ways 、 Discover insight and unleash infinite possibilities . Spatial analysis is about understanding complex interactions based on geographic relationships —— According to the personnel 、 The location of assets and resources to answer questions . Spatial insight enables you to provide better customer service 、 Optimize the workforce 、 Positioning retail and distribution centers 、 Evaluate sales and marketing activities, etc . With the help of Oracle Space products for , Developer 、 Database professionals and analysts can use a complete set of spatial data management 、 Analysis and visualization tools , Integrate spatial analysis and mapping into an enterprise data management infrastructure (Oracle Database and Oracle Exadata) In the application on .
As shown in the figure below ,Oracle The spatial characteristics of database provide scalable high-performance storage for basic and advanced spatial data types 、 Processing and analysis . A series of deployable Java EE Component to support common middle tier services .
For more information , Please visit https://oracle.com/goto/spatial
Workshop Overview
In this workshop , You will create and configure spatial data and perform some basic spatial queries . The scheme involves WAREHOUSES, BRANCHES, and COASTAL_ZONE. WAREHOUSES and BRANCHES Yes. ,COASTAL_ZONE It's a polygon . You will create and configure these spatial tables , Then perform a spatial query to identify adjacent and contained items .
precondition
- This workshop requires a visit to Oracle Database and SQL client ( namely SQL Developer、SQL Developer Web、SQL*Plus), To create sample data .
- It does not need to have been used before Oracle Spatial Experience .
thank
The author of this experiment is David Lapp, Database product manager , as well as Marion Smith.
experiment 1: Configure the autonomous database
stay OCI Created in ,ATP or ADW Fine . Soon , Just a few minutes .
In fact, this experiment has a Oracle Common databases are also OK
experiment 2: Connect to ADB And run your first query
Introduce
In this experiment , You will use SQL The worksheet explores the sample datasets that come with the database instance . about 5 minute .
This experiment uses SQL Worksheet , It is Oracle The database operation of autonomous database is based on Web One of the functions of the interface .
This experiment will demonstrate that ADW Out of the box queries for the sample datasets provided . ADW Provide Oracle Sales history sample pattern and star pattern benchmark (SSB) Data sets . These datasets are located in SH and SSB In the pattern . But in fact, neither of these two models will be used in the experiment .
You will be right SSB Data sets run basic queries , The dataset is a 1 TB Data set of , One of them contains about 60 100 million rows of fact tables and multiple dimension tables .
The goal is
- Learn how to use SQL Worksheet Connect to the new autonomous database
- understand Star Schema Benchmark (SSB) and Sales History (SH) Sample data set
- Yes ADW Sample datasets run queries
Mission 1: Connect SQL Worksheet
Actually SQL Worksheet You can use the local version of SQL Developer, You can also use the cloud Database Action Medium SQL Developer Web edition (Database Action>Development>SQL). Use the latter , You can avoid configuring the interface .
Mission 2: stay SQL Worksheet Run script in
Run the following SQL
select /* low */ c_city,c_region,count(*)
from ssb.customer c_low
group by c_region, c_city
order by count(*);
UNITED KI1 EUROPE 119082
UNITED ST4 AMERICA 119245
MOZAMBIQU2 AFRICA 119283
INDIA 2 ASIA 119380
ETHIOPIA 5 AFRICA 119393
...
If possible ,ADW It also caches query results for you . If you run the same query multiple times , You will notice that the response time after caching the results is much shorter .
experiment 3: Create sample spatial data
This experiment will guide you through Oracle Steps to create sample spatial data in the database . about 10 minute .
Oracle Database native data types SDO_GEOMETRY Storage space data ( spot 、 Line 、 polygon ). Oracle Databases also provide native spatial indexes for high-performance spatial operations . This spatial index depends on the spatial metadata entered for each table and geometric column that stores the spatial data . Once spatial data is published and indexed , Powerful API Can be used to perform spatial analysis 、 Calculation and processing .
SDO_GEOMETRY The type has the following format :
SDO_GEOMETRY(
[geometry type], --ID for point/line/polygon
[coordinate system], --ID of coordinate system
[point coordinate], --for points only
[line/polygon info], --for lines/polygons only
[line/polygon coordinates] --for lines/polygons only
)
The most common type of geometry is two-dimensional :
| ID | type |
|---|---|
| 2001 | Point |
| 2002 | Line |
| 2003 | Polygon |
The most common coordinate system is :
| ID | Coordinate system |
|---|---|
| 4326 | Latitude/Longitude ( Longitude and latitude ) |
| 3857 | World Mercator( World Mercator ) |
Use latitude / Longitude time , Please note that the latitude is Y coordinate , Longitude is X coordinate . Because the coordinates are listed as X,Y Yes , So these values are actually in longitude 、 The order of latitudes .
The following is the latitude used / Example geometric point shapes for longitude coordinates :
SDO_GEOMETRY(
2001, --2D point
4326, --latitude/longitude
SDO_POINT_TYPE(
-100.123, 20.456 --coordinate
),
NULL, --for lines/polygons only
NULL --for lines/polygons only
)
The following is the latitude used / Example geometric polygon for longitude coordinates :
SDO_GEOMETRY(
2003, --2D polygon
4326, --latitude/longitude
NULL, --for points only
SDO_ELEM_INFO_ARRAY(
1, 1003, 1 --indicates simple exterior polygon
),
SDO_ORDINATE_ARRAY(
-98.789065,39.90973, -- coordinates
-101.2522,39.639537,
-99.84374,37.160316,
-96.67987,35.460699,
-94.21875,39.639537,
-98.789025,39.90973
)
)
);
SDO_ELEM_INFO_ARRAY The value in (1, 1003, 1) It's a fixed mix , Represents a polygon ( Outer polygon ring ).
In this experiment , You will :
- Create a table with geometric Columns
- Fill Geometry
- Create spatial metadata and indexes
Mission 1: Create a table with coordinates
Let's first create a with latitude 、 A table of longitude coordinates . This is a common starting task for creating spatial data , For example, from GPS Coordinates of , Or from a geocoded street address or IP The coordinates of the address .
Run the following script :
CREATE TABLE WAREHOUSES (WAREHOUSE_NAME VARCHAR2(30), LAT NUMBER, LON NUMBER);
CREATE TABLE BRANCHES (BRANCH_NAME VARCHAR2(30),ZIPCODE VARCHAR2(5), LAT NUMBER, LON NUMBER, BRANCH_TYPE VARCHAR2(30));
INSERT INTO WAREHOUSES VALUES ('Amarillo Warehouse',35.532226,-101.557617);
INSERT INTO WAREHOUSES VALUES ('Odessa Warehouse',31.334871,-102.062988);
INSERT INTO WAREHOUSES VALUES ('San Antonio Warehouse',29.496987,-98.833007);
INSERT INTO WAREHOUSES VALUES ('Dallas Warehouse',33.027087,-97.316894);
INSERT INTO WAREHOUSES VALUES ('Houston Warehouse',30.069093,-95.317382);
INSERT INTO WAREHOUSES VALUES ('Abelene Warehouse',32.583849,-99.667968);
INSERT INTO WAREHOUSES VALUES ('Waco Warehouse',31.27855,-97.097167);
INSERT INTO BRANCHES VALUES('Marshall Branch','75672',32.50555,-94.35579,'WHOLESALE');
INSERT INTO BRANCHES VALUES('Austin Branch-2','78745',30.20538,-97.75902,'RETAIL');
INSERT INTO BRANCHES VALUES('Grand Prairie Branch','75050',32.76199,-96.99732,'RETAIL');
INSERT INTO BRANCHES VALUES('Pasadena Branch','77505',29.64587,-95.15763,'WHOLESALE');
INSERT INTO BRANCHES VALUES('Sulphur Springs Branch','75482',33.12357,-95.5972,'RETAIL');
INSERT INTO BRANCHES VALUES('San Angelo Branch-1','76901',31.44721,-100.49426,'RETAIL');
INSERT INTO BRANCHES VALUES('Houston Branch-6','77025',29.67853,-95.43044,'WHOLESALE');
INSERT INTO BRANCHES VALUES('Mount Pleasant Branch','75455',33.17527,-94.98048,'WHOLESALE');
INSERT INTO BRANCHES VALUES('Palestine Branch','75802',31.77344,-95.63011,'RETAIL');
INSERT INTO BRANCHES VALUES('Amarillo Branch-3','79119',35.11141,-101.91082,'WHOLESALE');
INSERT INTO BRANCHES VALUES('Weatherford Branch','76086',32.75696,-97.70715,'RETAIL');
INSERT INTO BRANCHES VALUES('Port Lavaca Branch','77979',28.66005,-96.422,'RETAIL');
INSERT INTO BRANCHES VALUES('Tomball Branch','77375',30.015,-95.5912,'RETAIL');
INSERT INTO BRANCHES VALUES('Hebbronville Branch','78361',27.30652,-98.67612,'WHOLESALE');
INSERT INTO BRANCHES VALUES('Beaumont Branch-1','77706',30.11087,-94.13984,'RETAIL');
INSERT INTO BRANCHES VALUES('Mabank Branch','75147',32.36565,-96.10197,'RETAIL');
INSERT INTO BRANCHES VALUES('Quitman Branch','75783',32.79578,-95.44701,'RETAIL');
INSERT INTO BRANCHES VALUES('Kerrvile Branch','78028',30.04845,-99.13948,'RETAIL');
INSERT INTO BRANCHES VALUES('Goldthwaite Branch','76844',31.44557,-98.5275,'RETAIL');
INSERT INTO BRANCHES VALUES('Katy Branch','77450',29.7848,-95.7326,'WHOLESALE');
INSERT INTO BRANCHES VALUES('Bowie Branch-1','76230',33.53709,-97.87829,'RETAIL');
INSERT INTO BRANCHES VALUES('Weslaco Branch','78596',26.17235,-97.98209,'RETAIL');
INSERT INTO BRANCHES VALUES('Eagle Pass Branch','78852',28.6865,-100.47394,'RETAIL');
INSERT INTO BRANCHES VALUES('Tyler Branch','75711',32.32208,-95.30069,'WHOLESALE');
INSERT INTO BRANCHES VALUES('Uvalde Branch','78801',29.23102,-99.75492,'RETAIL');
INSERT INTO BRANCHES VALUES('Odessa Branch','79760',31.8467,-102.36689,'RETAIL');
INSERT INTO BRANCHES VALUES('Houston Branch-1','77025',29.67853,-95.43044,'WHOLESALE');
INSERT INTO BRANCHES VALUES('Decatur Branch','76234',33.24962,-97.54674,'RETAIL');
INSERT INTO BRANCHES VALUES('Lewisville Branch','75067',33.05725,-97.01165,'RETAIL');
INSERT INTO BRANCHES VALUES('Brenham Branch','77833',30.15595,-96.41905,'RETAIL');
INSERT INTO BRANCHES VALUES('Austin Branch-1','78751',30.32012,-97.71481,'RETAIL');
INSERT INTO BRANCHES VALUES('Rockdale Branch','76567',30.6503,-97.01023,'RETAIL');
INSERT INTO BRANCHES VALUES('San Antonio Branch-3','78216',29.55217,-98.48661,'RETAIL');
INSERT INTO BRANCHES VALUES('Abilene Branch-2','79605',32.4517,-99.77579,'RETAIL');
INSERT INTO BRANCHES VALUES('Cleburne Branch','76033',32.42166,-97.38356,'WHOLESALE');
INSERT INTO BRANCHES VALUES('College Station Branch','77845',30.6355,-96.30516,'WHOLESALE');
INSERT INTO BRANCHES VALUES('Denton Branch','76210',33.14925,-97.09016,'RETAIL');
INSERT INTO BRANCHES VALUES('Alvin Branch-1','77512',29.41878,-95.24026,'RETAIL');
INSERT INTO BRANCHES VALUES('Amarillo Branch-1','79120',35.18857,-101.81719,'RETAIL');
INSERT INTO BRANCHES VALUES('Henderson Branch','75654',32.10862,-94.82693,'WHOLESALE');
INSERT INTO BRANCHES VALUES('Paris Branch','75460',33.66771,-95.5678,'RETAIL');
INSERT INTO BRANCHES VALUES('Waxahachie Branch','75167',32.42936,-96.86103,'RETAIL');
INSERT INTO BRANCHES VALUES('Slaton Branch','79364',33.45031,-101.6518,'RETAIL');
INSERT INTO BRANCHES VALUES('Brady Branch','76825',31.13424,-99.3349,'RETAIL');
INSERT INTO BRANCHES VALUES('Fordt Worth Branch','76119',32.66555,-97.2406,'WHOLESALE');
INSERT INTO BRANCHES VALUES('Carrollton Branch','75006',32.94441,-96.90386,'RETAIL');
INSERT INTO BRANCHES VALUES('Itasca Branch','76055',32.15944,-97.15097,'RETAIL');
INSERT INTO BRANCHES VALUES('Winnie Branch','77665',29.81749,-94.37706,'RETAIL');
INSERT INTO BRANCHES VALUES('Burkburnett Branch','73654',34.08013,-98.55913,'RETAIL');
INSERT INTO BRANCHES VALUES('Boerne Branch','78006',29.80671,-98.70248,'RETAIL');
INSERT INTO BRANCHES VALUES('Mesquite Branch','75150',32.80576,-96.62761,'WHOLESALE');
INSERT INTO BRANCHES VALUES('Baytown Branch','77521',29.80219,-94.9955,'WHOLESALE');
INSERT INTO BRANCHES VALUES('Orange Branch','77630',30.09311,-93.74627,'RETAIL');
INSERT INTO BRANCHES VALUES('Kaufman Branch','75142',32.58899,-96.30101,'RETAIL');
INSERT INTO BRANCHES VALUES('Frisco Branch','75034',33.08329,-96.8487,'RETAIL');
INSERT INTO BRANCHES VALUES('Portland Branch','78374',27.8892,-97.31627,'RETAIL');
INSERT INTO BRANCHES VALUES('Fort Stockton Branch','79735',30.86708,-102.84237,'RETAIL');
INSERT INTO BRANCHES VALUES('San Antonio Branch-1','78220',29.41375,-98.4102,'WHOLESALE');
INSERT INTO BRANCHES VALUES('San Angelo Branch-3','76901',31.44748,-100.494,'RETAIL');
INSERT INTO BRANCHES VALUES('Crosby Branch','77532',29.88909,-95.06142,'RETAIL');
INSERT INTO BRANCHES VALUES('Jacksonville Branch','75766',31.96639,-95.2485,'RETAIL');
INSERT INTO BRANCHES VALUES('La Grange Branch','78945',29.92131,-96.88931,'WHOLESALE');
INSERT INTO BRANCHES VALUES('Corpus Christi Branch-2','78410',27.84873,-97.63101,'RETAIL');
INSERT INTO BRANCHES VALUES('Graham Branch','76450',33.10964,-98.56536,'RETAIL');
INSERT INTO BRANCHES VALUES('Corsicana Branch','75110',32.0986,-96.44383,'WHOLESALE');
INSERT INTO BRANCHES VALUES('San Antonio Branch-2','78238',29.40633,-98.51827,'RETAIL');
INSERT INTO BRANCHES VALUES('Kenedy Branch-1','78119',28.79531,-97.85081,'RETAIL');
INSERT INTO BRANCHES VALUES('Comanche Branch','76442',31.90838,-98.59057,'RETAIL');
INSERT INTO BRANCHES VALUES('Hutto Branch','78634',30.53991,-97.56444,'RETAIL');
INSERT INTO BRANCHES VALUES('Plainview Branch','79072',34.19627,-101.72565,'WHOLESALE');
INSERT INTO BRANCHES VALUES('El Paso Branch-1','79925',31.78992,-106.39392,'RETAIL');
INSERT INTO BRANCHES VALUES('Temple Branch','76503',31.10109,-97.33947,'WHOLESALE');
INSERT INTO BRANCHES VALUES('Edna Branch-1','77957',28.96753,-96.6678,'RETAIL');
INSERT INTO BRANCHES VALUES('Dallas Branch-2','75228',32.79436,-96.69455,'RETAIL');
INSERT INTO BRANCHES VALUES('El Paso Branch-3','79925',31.78385,-106.41769,'RETAIL');
INSERT INTO BRANCHES VALUES('Whitesboro Branch','76273',33.67134,-96.90732,'RETAIL');
INSERT INTO BRANCHES VALUES('Galvston Branch','77554',29.28626,-94.85884,'WHOLESALE');
INSERT INTO BRANCHES VALUES('New Boston Branch','75570',33.45857,-94.42665,'WHOLESALE');
INSERT INTO BRANCHES VALUES('Wharton Branch','77488',29.31394,-96.10216,'RETAIL');
INSERT INTO BRANCHES VALUES('Tulia Branch','79088',34.54383,-101.77545,'RETAIL');
INSERT INTO BRANCHES VALUES('Alvin Branch-2','77512',29.45094,-95.23649,'RETAIL');
INSERT INTO BRANCHES VALUES('Marble Falls Branch','78654',30.50005,-98.26728,'RETAIL');
INSERT INTO BRANCHES VALUES('Houston Branch-7','77074',29.71841,-95.49676,'RETAIL');
INSERT INTO BRANCHES VALUES('Arlington Branch-2','76004',32.73479,-97.10408,'RETAIL');
INSERT INTO BRANCHES VALUES('Wichita Falls Branch','76310',33.87128,-98.57951,'RETAIL');
INSERT INTO BRANCHES VALUES('Floresville Branch','78114',29.16354,-98.19341,'RETAIL');
INSERT INTO BRANCHES VALUES('El Paso Branch-2','79936',31.73947,-106.32398,'RETAIL');
INSERT INTO BRANCHES VALUES('Terrell Branch','75616',32.73366,-96.25685,'RETAIL');
INSERT INTO BRANCHES VALUES('Texas City Branch','77590',29.39525,-94.9323,'WHOLESALE');
INSERT INTO BRANCHES VALUES('Humble Branch','77338',29.99421,-95.27188,'RETAIL');
INSERT INTO BRANCHES VALUES('Richwood Branch','77531',29.03962,-95.40011,'RETAIL');
INSERT INTO BRANCHES VALUES('Coleman Branch','76834',31.85603,-99.44611,'RETAIL');
INSERT INTO BRANCHES VALUES('Seguin Branch','78155',29.56276,-97.96538,'RETAIL');
INSERT INTO BRANCHES VALUES('Georgetown Branch','78627',30.62275,-97.68708,'RETAIL');
INSERT INTO BRANCHES VALUES('Mckinney Branch','75070',33.1688,-96.68446,'RETAIL');
INSERT INTO BRANCHES VALUES('Houston Branch-5','77034',29.62228,-95.2223,'RETAIL');
INSERT INTO BRANCHES VALUES('Muenster Branch','76252',33.66937,-97.37965,'WHOLESALE');
INSERT INTO BRANCHES VALUES('Abilene Branch-1','79605',32.45175,-99.77668,'WHOLESALE');
INSERT INTO BRANCHES VALUES('Big Spring Branch-1','79720',32.24941,-101.48127,'WHOLESALE');
INSERT INTO BRANCHES VALUES('Corpus Christi Branch-3','78412',27.70189,-97.35781,'RETAIL');
INSERT INTO BRANCHES VALUES('Hondo Branch','78861',29.3483,-99.12811,'RETAIL');
INSERT INTO BRANCHES VALUES(' Corpus Christi Branch-1','78412',27.70189,-97.35781,'RETAIL');
INSERT INTO BRANCHES VALUES('Lufkin Branch-1','75901',31.34264,-94.69127,'RETAIL');
INSERT INTO BRANCHES VALUES('Port Arthur Branch','77642',29.93701,-93.9351,'RETAIL');
INSERT INTO BRANCHES VALUES('Arlington Branch-1','76017',32.67551,-97.1301,'RETAIL');
INSERT INTO BRANCHES VALUES('Copperas Cove Branch','76522',31.10028,-97.89377,'RETAIL');
INSERT INTO BRANCHES VALUES('Burleson Branch','76028',32.55993,-97.31844,'RETAIL');
INSERT INTO BRANCHES VALUES('Silsbee Branch','77625',30.38197,-94.34406,'RETAIL');
INSERT INTO BRANCHES VALUES('Kenedy Branch-2','78119',28.79531,-97.85081,'WHOLESALE');
INSERT INTO BRANCHES VALUES('Raymondville Branch','78580',26.48079,-97.77893,'RETAIL');
INSERT INTO BRANCHES VALUES('Livingston Branch','77351',30.70821,-94.91611,'RETAIL');
INSERT INTO BRANCHES VALUES('Beeville Branch','78102',28.40093,-97.74818,'RETAIL');
INSERT INTO BRANCHES VALUES('Liberty Branch','77575',30.05823,-94.77322,'RETAIL');
INSERT INTO BRANCHES VALUES('Victoria Branch-1','77904',28.83684,-97.00175,'WHOLESALE');
INSERT INTO BRANCHES VALUES('Kingsville Branch-1','78364',27.51574,-97.85543,'RETAIL');
INSERT INTO BRANCHES VALUES('Carthage Branch','75633',32.14415,-94.33211,'WHOLESALE');
INSERT INTO BRANCHES VALUES('Dalhart Branch-2','79022',36.10865,-102.55245,'RETAIL');
INSERT INTO BRANCHES VALUES('Bay City Branch','77414',28.99702,-95.9164,'WHOLESALE');
INSERT INTO BRANCHES VALUES('Mexia Branch','76667',31.68292,-96.48395,'RETAIL');
INSERT INTO BRANCHES VALUES('San Antonio Branch-5','78233',29.29499,-98.63473,'WHOLESALE');
INSERT INTO BRANCHES VALUES('Amarillo Branch-2','79120',35.18857,-101.81719,'RETAIL');
INSERT INTO BRANCHES VALUES('Beaumont Branch-2','77706',30.11087,-94.13984,'RETAIL');
INSERT INTO BRANCHES VALUES('Houston Branch-2','77054',29.67793,-95.42368,'RETAIL');
INSERT INTO BRANCHES VALUES('Houston Branch-3','77040',29.88204,-95.57178,'RETAIL');
INSERT INTO BRANCHES VALUES('Sour Lake Branch','77659',30.14708,-94.38847,'RETAIL');
INSERT INTO BRANCHES VALUES('Nixon Branch','78140',29.29947,-97.76736,'RETAIL');
INSERT INTO BRANCHES VALUES('Alice Branch','78332',27.75495,-98.05881,'RETAIL');
INSERT INTO BRANCHES VALUES('Anson Branch','79601',32.74837,-99.89681,'WHOLESALE');
INSERT INTO BRANCHES VALUES('Manvel Branch','77578',29.54028,-95.38673,'RETAIL');
INSERT INTO BRANCHES VALUES('Marlin Branch','76661',31.30914,-96.87926,'RETAIL');
INSERT INTO BRANCHES VALUES('Levelland Branch','79336',33.58844,-102.38274,'RETAIL');
INSERT INTO BRANCHES VALUES('Buda Branch','78610',30.08571,-97.82003,'RETAIL');
INSERT INTO BRANCHES VALUES('Stafford Branch','77477',29.64631,-95.57441,'RETAIL');
INSERT INTO BRANCHES VALUES('Madisonville Branch','77864',30.96249,-95.87933,'RETAIL');
INSERT INTO BRANCHES VALUES('Schulenburg Branch','78956',29.69367,-96.90506,'RETAIL');
INSERT INTO BRANCHES VALUES('Lufkin Branch-2','75901',31.34264,-94.69127,'RETAIL');
INSERT INTO BRANCHES VALUES('Edna Branch-2','77957',28.96753,-96.6678,'WHOLESALE');
INSERT INTO BRANCHES VALUES('Gordon Branch','76453',32.54932,-98.37008,'RETAIL');
INSERT INTO BRANCHES VALUES('Houston Branch-4','77024',29.78386,-95.55237,'WHOLESALE');
INSERT INTO BRANCHES VALUES('Nacogdoches Branch','75964',31.61312,-94.65307,'RETAIL');
INSERT INTO BRANCHES VALUES('San Antonio Branch-4','78224',29.34856,-98.53987,'RETAIL');
INSERT INTO BRANCHES VALUES('North Richland Hills Branch','76180',32.84109,-97.22351,'WHOLESALE');
INSERT INTO BRANCHES VALUES('Plano Branch-2','75093',33.01631,-96.77654,'RETAIL');
INSERT INTO BRANCHES VALUES('Bowie Branch-2','76230',33.53709,-97.87829,'RETAIL');
INSERT INTO BRANCHES VALUES('Perryton Branch','79070',36.39554,-100.80268,'RETAIL');
INSERT INTO BRANCHES VALUES('Gilmer Branch','75644',32.75561,-94.98716,'RETAIL');
INSERT INTO BRANCHES VALUES('Kingsville Branch-2','78364',27.51574,-97.85543,'RETAIL');
INSERT INTO BRANCHES VALUES('Jasper Branch','75951',30.94009,-93.99693,'RETAIL');
INSERT INTO BRANCHES VALUES('Dallas Branch-1','75247',32.80804,-96.88519,'RETAIL');
INSERT INTO BRANCHES VALUES('Plano Branch-1','75093',33.01631,-96.77654,'RETAIL');
INSERT INTO BRANCHES VALUES('Angleton Branch','77515',29.16828,-95.4472,'RETAIL');
INSERT INTO BRANCHES VALUES('Gruver Branch','79040',36.30556,-101.49286,'RETAIL');
INSERT INTO BRANCHES VALUES('Pleasanton Branch','78064',28.95839,-98.48412,'RETAIL');
INSERT INTO BRANCHES VALUES('El Campo Branch','77437',29.21313,-96.28317,'RETAIL');
INSERT INTO BRANCHES VALUES('Frankston Branch','75763',32.05138,-95.50602,'WHOLESALE');
INSERT INTO BRANCHES VALUES('Ennis Branch','75120',32.32955,-96.6237,'WHOLESALE');
INSERT INTO BRANCHES VALUES('Clifton Branch','76634',31.82186,-97.50742,'RETAIL');
INSERT INTO BRANCHES VALUES('Edinburg Branch','78539',26.30616,-98.19573,'RETAIL');
INSERT INTO BRANCHES VALUES('Austin Branch-3','78759',30.41233,-97.74605,'RETAIL');
INSERT INTO BRANCHES VALUES('Devine Branch','78016',29.14836,-98.87534,'WHOLESALE');
INSERT INTO BRANCHES VALUES('Andrews Branch','79714',32.3428,-102.5541,'RETAIL');
INSERT INTO BRANCHES VALUES('Hillsboro Branch','76645',31.97179,-97.12218,'RETAIL');
INSERT INTO BRANCHES VALUES('Galveston Branch','77554',29.28684,-94.85711,'RETAIL');
INSERT INTO BRANCHES VALUES('Manor Branch','78653',30.22456,-97.95029,'RETAIL');
INSERT INTO BRANCHES VALUES('Sherman Branch-2','75091',33.66046,-96.60687,'RETAIL');
INSERT INTO BRANCHES VALUES('Dalhart Branch-1','79022',36.10865,-102.55245,'WHOLESALE');
INSERT INTO BRANCHES VALUES('Farmersville Branch','75442',33.1661,-96.35521,'RETAIL');
INSERT INTO BRANCHES VALUES('Caldwell Branch','77836',30.52876,-96.67828,'RETAIL');
INSERT INTO BRANCHES VALUES('Big Spring Branch-2','79720',32.24941,-101.48127,'RETAIL');
INSERT INTO BRANCHES VALUES('Stephenville Branch','76401',32.20144,-98.24628,'RETAIL');
INSERT INTO BRANCHES VALUES('San Angelo Branch-2','76902',31.46196,-100.44465,'RETAIL');
INSERT INTO BRANCHES VALUES('Dickinson Branch','77539',29.46108,-95.05394,'RETAIL');
INSERT INTO BRANCHES VALUES('Midland Branch','79704',31.97118,-102.12296,'RETAIL');
INSERT INTO BRANCHES VALUES('Sherman Branch-1','75090',33.62946,-96.58004,'WHOLESALE');
INSERT INTO BRANCHES VALUES('Victoria Branch-2','77904',28.83684,-97.00175,'RETAIL');
INSERT INTO BRANCHES VALUES('Gonzales Branch','78629',29.50051,-97.46726,'WHOLESALE');
INSERT INTO BRANCHES VALUES('Kilgore Branch','75662',32.39171,-94.87641,'WHOLESALE');
INSERT INTO BRANCHES VALUES('West Branch','76691',31.79749,-97.10157,'RETAIL');
INSERT INTO BRANCHES VALUES('Del Rio Branch','78840',29.37022,-100.86395,'RETAIL');
Mission 2: Create geometry from coordinates
have access to SQL Fill Geometry , for example , This example specifies the coordinates of the point geometry based on the latitude and longitude columns .
Add geometry Columns :
ALTER TABLE WAREHOUSES ADD (
GEOMETRY SDO_GEOMETRY
);
ALTER TABLE BRANCHES ADD (
GEOMETRY SDO_GEOMETRY
);
Publish geometry Columns :
UPDATE WAREHOUSES
SET
GEOMETRY = SDO_GEOMETRY(
2001, 4326, SDO_POINT_TYPE(
LON, LAT, NULL
), NULL, NULL
);
UPDATE BRANCHES
SET
GEOMETRY = SDO_GEOMETRY(
2001, 4326, SDO_POINT_TYPE(
LON, LAT, NULL
), NULL, NULL
);
Mission 3: Create a table with polygons
You can create lines and polygons in the same way . Although point geometry requires a coordinate , But lines and polygons need to define all the coordinates of the geometry . under these circumstances , We create a table to store a polygon .
CREATE TABLE COASTAL_ZONE (
ZONE_ID NUMBER,
GEOMETRY SDO_GEOMETRY
);
INSERT INTO COASTAL_ZONE VALUES (
1,
SDO_GEOMETRY(
2003, 4326, NULL, SDO_ELEM_INFO_ARRAY(
1, 1003, 1
), SDO_ORDINATE_ARRAY(
-93.719934, 30.210638,
-95.422592, 29.773714,
-95.059698, 29.322204,
-96.013892, 28.787021,
-96.660964, 28.925638,
-97.528688, 28.042050,
-97.858501, 27.447461,
-97.497364, 25.880056,
-96.977826, 25.969716,
-97.211445, 27.054605,
-96.870226, 27.816077,
-93.794290, 29.535729,
-93.719934, 30.210638
)
)
);
Mission 4: Add spatial metadata and indexes
Oracle Databases provide native spatial indexes for high-performance spatial operations . Our sample data is very small , You may not actually need a spatial index . however , We still perform the following steps , Because they are important for a typical volume of production data . A spatial index requires a row of metadata for the geometry being indexed . We create this metadata , Then create a spatial index .
-- Add metadata
INSERT INTO USER_SDO_GEOM_METADATA VALUES (
'WAREHOUSES',
'GEOMETRY',
SDO_DIM_ARRAY(
SDO_DIM_ELEMENT(
'x', -180, 180, 0.05
), SDO_DIM_ELEMENT(
'y', -90, 90, 0.05
)
),
4326
);
INSERT INTO USER_SDO_GEOM_METADATA VALUES (
'BRANCHES',
'GEOMETRY',
SDO_DIM_ARRAY(
SDO_DIM_ELEMENT(
'x', -180, 180, 0.05
), SDO_DIM_ELEMENT(
'y', -90, 90, 0.05
)
),
4326
);
INSERT INTO USER_SDO_GEOM_METADATA VALUES (
'COASTAL_ZONE',
'GEOMETRY',
SDO_DIM_ARRAY(
SDO_DIM_ELEMENT(
'x', -180, 180, 0.05
), SDO_DIM_ELEMENT(
'y', -90, 90, 0.05
)
),
4326
);
-- Create index
CREATE INDEX WAREHOUSES_SIDX ON
WAREHOUSES (
GEOMETRY
)
INDEXTYPE IS MDSYS.SPATIAL_INDEX;
CREATE INDEX BRANCHES_SIDX ON
BRANCHES (
GEOMETRY
)
INDEXTYPE IS MDSYS.SPATIAL_INDEX;
CREATE INDEX COASTAL_ZONE_SIDX ON
COASTAL_ZONE (
GEOMETRY
)
INDEXTYPE IS MDSYS.SPATIAL_INDEX;
After index creation , Refresh table list . You will see 3 Names with MDRT_ Table at the beginning . These are the products of spatial indexes , from Oracle Automatic database management . Do not manually manipulate these tables .
Our sample data is now ready , You can start spatial queries .
If you need to restore this lab and delete the created project , Please run the following command :
DROP TABLE BRANCHES;
DROP TABLE WAREHOUSES;
DROP TABLE COASTAL_ZONE;
DELETE FROM USER_SDO_GEOM_METADATA;
COMMIT;
Learn more
experiment 4: Run a spatial query
This lab will guide you through Oracle Basic spatial queries in databases . You will use the sample data created in the last lab to identify projects based on proximity and inclusion . about 15 minute .
Oracle The database includes a powerful library of functions and operators for spatial analysis . This includes spatial relationships 、 measurement 、 polymerization 、 Conversion and so on . These operations This machine can be used SQL、PL/SQL、Java API As well as Oracle Any other language for database communication Visit .
In this experiment , You will :
- Identification and WAREHOUSE Having adjacency BRANCHES
- Identification and COASTAL_ZONE Having inclusion and adjacency BRANCHES
Spatial query
Oracle Spatial queries in the database are the same as any other traditional query you are used to . The only difference is that a set of spatial functions and operators may be new to you .
Identify the nearest... To the Dallas warehouse 5 A branch :
SELECT
BRANCH_NAME,
BRANCH_TYPE
FROM
BRANCHES B,
WAREHOUSES W
WHERE
W.WAREHOUSE_NAME = 'Dallas Warehouse'
AND SDO_NN(
B.GEOMETRY, W.GEOMETRY, 'sdo_num_res=5'
) = 'TRUE';
BRANCH_NAME BRANCH_TYPE
--------------------------- -----------
Decatur Branch RETAIL
Lewisville Branch RETAIL
Denton Branch RETAIL
Arlington Branch-2 RETAIL
North Richland Hills Branch WHOLESALE
explain :
- SDO_NN Use spatial index to identify the nearest neighbor of geometry (NN Express Nearest Neighbour), The first parameter ( In the previous example B.GEOMETRY) Is the column to search , Search results . The second parameter ( In the previous example W.GEOMETRY) Is where you want to find the nearest neighbor , That is, the center position . The third parameter represents the behavior ,
sdo_num_res=5Indicates the number of returned results (number of results) by 5. The order in which the results are returned should not be assumed . for example , There is no guarantee that the first row returned is the closest . If two or more branches are equidistant from the warehouse , Either one may be called later SDO_NN When to return to . - Use SDO_NUM_RES When parameters are ,WHERE No other conditions are used in the clause . SDO_NUM_RES Consider only proximity . for example , If you ask WHERE Clause adds a condition , Because you want the five closest branches to have specific postal codes , And four of the five closest branches have different postal codes , Then the above query will return a row . This behavior is specific to SDO_NUM_RES Parameters . In the following query , You will use alternative parameters for scenarios with additional query criteria .
Identify the nearest... To the Dallas warehouse 5 A branch , And display the distance :
SELECT
BRANCH_NAME,
BRANCH_TYPE,
ROUND(
SDO_NN_DISTANCE(
1
), 2
) DISTANCE_KM
FROM
BRANCHES B,
WAREHOUSES W
WHERE
W.WAREHOUSE_NAME = 'Dallas Warehouse'
AND SDO_NN(
B.GEOMETRY, W.GEOMETRY, 'sdo_num_res=5 unit=km', 1
) = 'TRUE'
ORDER BY
DISTANCE_KM;
BRANCH_NAME BRANCH_TYPE DISTANCE_KM
--------------------------- ----------- -----------
North Richland Hills Branch WHOLESALE 22.4
Denton Branch RETAIL 25.13
Lewisville Branch RETAIL 28.71
Decatur Branch RETAIL 32.7
Arlington Branch-2 RETAIL 38.05
explain :
- SDO_NN_DISTANCE Operator is SDO_NN Auxiliary operator of operator ; It can only be found in SDO_NN Operator . The argument to this operator is an and specified as SDO_NN The last parameter of the number matches the number ; In this case it is 1. This parameter has no hidden meaning , It's just a label . If you specify SDO_NN_DISTANCE(), You can sort the results by distance , And ensure that the first line returned is the most recent . If the data you want to query is stored as longitude and latitude , be SDO_NN_DISTANCE The default unit of is meters .
- SDO_NN The operator has another UNIT Parameters , Used to determine the SDO_NN_DISTANCE The unit of measurement returned .
- ORDER BY DISTANCE Clause to ensure that the distances are returned sequentially , The shortest distance is in front .
Identify the nearest... To the Dallas warehouse 5 A wholesale branch :
SELECT
BRANCH_NAME,
BRANCH_TYPE,
ROUND(
SDO_NN_DISTANCE(
1
), 2
) DISTANCE_KM
FROM
BRANCHES B,
WAREHOUSES W
WHERE
W.WAREHOUSE_NAME = 'Dallas Warehouse'
AND B.BRANCH_TYPE = 'WHOLESALE'
AND SDO_NN(
B.GEOMETRY, W.GEOMETRY, 'sdo_batch_size=5 unit=km', 1
) = 'TRUE'
AND ROWNUM <= 5
ORDER BY
DISTANCE_KM;
BRANCH_NAME BRANCH_TYPE DISTANCE_KM
--------------------------- ----------- -----------
North Richland Hills Branch WHOLESALE 22.4
Fordt Worth Branch WHOLESALE 40.73
Cleburne Branch WHOLESALE 67.43
Mesquite Branch WHOLESALE 68.99
Muenster Branch WHOLESALE 71.48
explain :
- SDO_BATCH_SIZE It's an adjustable parameter , It may affect query performance . SDO_NN Calculate the distance internally at one time . The rows of the returned initial batch may not meet WHERE Constraints in clause , So it keeps coming back SDO_BATCH_SIZE Number of rows specified , Until you meet WHERE All constraints in clause . You should choose one SDO_BATCH_SIZE, Its initial return may satisfy WHERE The number of rows of constraints in the clause .
- B.BRANCH_TYPE = ‘WHOLESALE’ AND ROWNUM <= 5 yes WHERE Additional constraints in clause . rownum Clause to limit the number of returned results to 5 be necessary .
Identify Houston warehouse 50 Branches within km
SELECT
B.BRANCH_NAME,
B.BRANCH_TYPE
FROM
BRANCHES B,
WAREHOUSES W
WHERE
W.WAREHOUSE_NAME = 'Houston Warehouse'
AND SDO_WITHIN_DISTANCE(
B.GEOMETRY, W.GEOMETRY, 'distance=50 unit=km'
) = 'TRUE';
BRANCH_NAME BRANCH_TYPE
---------------- -----------
Houston Branch-2 RETAIL
Houston Branch-1 WHOLESALE
Houston Branch-6 WHOLESALE
Houston Branch-7 RETAIL
Houston Branch-4 WHOLESALE
Baytown Branch WHOLESALE
Houston Branch-3 RETAIL
Crosby Branch RETAIL
Humble Branch RETAIL
Tomball Branch RETAIL
Pasadena Branch WHOLESALE
11 rows selected.
explain :
- SDO_WITHIN_DISTANCE The first parameter to is the column to search . The second parameter is where you want to determine the distance . The order in which the results are returned should not be assumed . for example , The first line returned is not guaranteed to be from the warehouse 3 Recent customers .
- SDO_WITHIN_DISTANCE Operator DISTANCE Parameter specifies the distance value ; In this case 50.
- SDO_WITHIN_DISTANCE Operator UNIT Parameter assignment DISTANCE The unit of measurement of the parameter . The default unit is the unit of measure associated with the data . For latitude and longitude data , The default is meters ; In this case , It's miles .
Identify the distance from Houston warehouse 50 Branches within km , And display the distance
SELECT
B.BRANCH_NAME,
B.BRANCH_TYPE,
ROUND(
SDO_GEOM.SDO_DISTANCE(
B.GEOMETRY, W.GEOMETRY, 0.05, 'unit=km'
), 2
) AS DISTANCE_KM
FROM
BRANCHES B,
WAREHOUSES W
WHERE
W.WAREHOUSE_NAME = 'Houston Warehouse'
AND SDO_WITHIN_DISTANCE(
B.GEOMETRY, W.GEOMETRY, 'distance=50 unit=km'
) = 'TRUE'
ORDER BY
DISTANCE_KM;
BRANCH_NAME BRANCH_TYPE DISTANCE_KM
---------------- ----------- -----------
Humble Branch RETAIL 9.39
Tomball Branch RETAIL 27.08
Crosby Branch RETAIL 31.75
Houston Branch-3 RETAIL 32.14
Houston Branch-4 WHOLESALE 38.92
Houston Branch-7 RETAIL 42.56
Baytown Branch WHOLESALE 42.91
Houston Branch-2 RETAIL 44.56
Houston Branch-6 WHOLESALE 44.65
Houston Branch-1 WHOLESALE 44.65
Pasadena Branch WHOLESALE 49.39
11 rows selected.
explain :
- SDO_GEOM.SDO_DISTANCE Function to calculate the distance between the branch location and the Houston warehouse .
- SDO_GEOM.SDO_DISTANCE Before 2 Parameters are used to calculate the distance BRANCH and WAREHOUSE Location .
- SDO_GEOM.SDO_DISTANCE The third parameter of is the tolerance value . Tolerance is Oracle Spatial Rounding error value used . The tolerance of longitude and latitude data is in meters . In this case , The tolerance is 50 mm (0.05 rice ).
- SDO_GEOM.SDO_DISTANCE Parameter UNIT The parameter is specified by SDO_GEOM.SDO_DISTANCE The unit of measure of the distance calculated by the function . The default unit is the unit of measure associated with the data . For longitude and latitude data , The default value is meters . In this example , It's miles .
- ORDER BY DISTANCE_IN_MILES Clause to ensure that the distances are returned sequentially , The shortest distance is in front , Distance is in miles .
Identify branches in coastal areas
SELECT
B.BRANCH_NAME,
B.BRANCH_TYPE
FROM
BRANCHES B,
COASTAL_ZONE C
WHERE
SDO_ANYINTERACT(
B.GEOMETRY, C.GEOMETRY
) = 'TRUE';
BRANCH_NAME BRANCH_TYPE
------------------------ -----------
Baytown Branch WHOLESALE
Winnie Branch RETAIL
Port Arthur Branch RETAIL
Orange Branch RETAIL
Corpus Christi Branch-1 RETAIL
Corpus Christi Branch-3 RETAIL
Corpus Christi Branch-2 RETAIL
Portland Branch RETAIL
Port Lavaca Branch RETAIL
Richwood Branch RETAIL
Galvston Branch WHOLESALE
Galveston Branch RETAIL
Texas City Branch WHOLESALE
Dickinson Branch RETAIL
Houston Branch-5 RETAIL
Pasadena Branch WHOLESALE
16 rows selected.
explain :
- SDO_ANYINTERACT Operator accepts 2 Parameters ,geometry1 and geometry2. about geometry1 stay geometry2 A line on an inner or boundary , Operator return TRUE.
- In this example ,geometry1 yes B.GEOMETRY, That is, the geometry of the branch ,geometry2 yes C.GEOMETRY, That is, the geometry of the coastal zone . COASTAL_ZONE Table only 1 That's ok , Therefore, no other conditions are required .
Identify areas outside the coastal area 10 Branches within km
( SELECT
B.BRANCH_NAME,
B.BRANCH_TYPE
FROM
BRANCHES B,
COASTAL_ZONE C
WHERE
SDO_WITHIN_DISTANCE(
B.GEOMETRY, C.GEOMETRY, 'distance=10 unit=km'
) = 'TRUE'
)
MINUS
( SELECT
B.BRANCH_NAME,
B.BRANCH_TYPE
FROM
BRANCHES B,
COASTAL_ZONE C
WHERE
SDO_ANYINTERACT(
B.GEOMETRY, C.GEOMETRY
) = 'TRUE'
);
BRANCH_NAME BRANCH_TYPE
------------------- -----------
Alvin Branch-1 RETAIL
Alvin Branch-2 RETAIL
Angleton Branch RETAIL
Beaumont Branch-1 RETAIL
Beaumont Branch-2 RETAIL
Crosby Branch RETAIL
Edna Branch-1 RETAIL
Edna Branch-2 WHOLESALE
Houston Branch-1 WHOLESALE
Houston Branch-2 RETAIL
Houston Branch-6 WHOLESALE
Houston Branch-7 RETAIL
Kingsville Branch-1 RETAIL
Kingsville Branch-2 RETAIL
14 rows selected.
explain :
- In the first part of this query ,SDO_WITHIN_DISTANCE Operator recognition COASTAL_ZONE 10 Branches within km . This includes COASTAL_ZONE Branch offices within .
- This query uses MINUS Delete COASTAL_ZONE Branch offices within , Leave only 10 Within km and COASTAL_ZONE External branch .
Learn more
边栏推荐
- MySql主从复制
- ICML2022 | GALAXY:极化图主动学习
- Select sort
- ASCII code comparison table
- Solution of good number pairs
- Main stages of garbage collection in ZGC
- Gzip compression decompression
- Distributed cloud service developer'allegro Xile technology 'received an angel round financing of US $3million
- Oracle 19C installation documentation
- Oracle数据库中查询执行计划的权限
猜你喜欢

Icml2022 | Galaxy: apprentissage actif des cartes de polarisation

Design and practice of Hudi bucket index in byte skipping

多线程模型下的生产者消费者模式

#113 Path Sum II

The salted fish has been transmitted for 5W times, and the latest spring recruit face-to-face test questions of bytes have been leaked

CVPR 2022 | 应对噪声标签,西安大略大学、字节跳动等提出对比正则化方法

【目标检测】|Dive Deeper Into Box for Object Detection 基于FCOS新训练方法

SQL调优指南笔记18:Analyzing Statistics Using Optimizer Statistics Advisor

SQL调优指南笔记15:Controlling the Use of Optimizer Statistics

ICML2022 | GALAXY:极化图主动学习
随机推荐
ICML2022 | GALAXY:極化圖主動學習
[qnx hypervisor 2.2 manuel de l'utilisateur] 4.2 environnement de construction pris en charge
测试基础之:单元测试
VagrantBox重新安装vboxsf驱动
Zip compression decompression
#113 Path Sum II
Digital intelligence data depth | Bi goes down the altar? It's not that the market has declined, it's that the story has changed
Oracle 19C installation documentation
【QNX Hypervisor 2.2 用戶手册】4.2 支持的構建環境
阅读笔记 Deep Hough Voting for 3D Object Detection in Point Clouds
SQL调优指南笔记14:Managing Extended Statistics
建立高可用的数据库
好数对的求解
SQL调优指南笔记12:Configuring Options for Optimizer Statistics Gathering
SQL调优指南笔记15:Controlling the Use of Optimizer Statistics
Principales étapes de la collecte des ordures à Zgc
Kdd2022 | graphmae: self supervised mask map self encoder
[QNX hypervisor 2.2 user manual] 4.4 build host
Distributed cloud service developer'allegro Xile technology 'received an angel round financing of US $3million
Common error in script execution: build sh: caller: not found