contrib:shp2ndm
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
contrib:shp2ndm [2007/07/20 17:25] – sleleiva | contrib:shp2ndm [2008/01/28 10:11] (current) – deleted -- obsolete information sleleiva | ||
---|---|---|---|
Line 1: | Line 1: | ||
- | * Import a Shapefile into Oracle Spatial as a normal vector map; | ||
- | * Replace all occurrences of SHP_TABLE (case sensitive, can be part of a word) in the script below with the table name of the imported map from Shapefile (copy all script from below to a text editor and perform that replace); | ||
- | * Copy/Paste (in Linux: select text and then use middle mouse button or Shift+Insert to paste it in a console) the script line-by-line, | ||
- | |||
- | <code oracle8> | ||
- | -- delete any tables existing | ||
- | EXECUTE SDO_NET.DROP_NETWORK(' | ||
- | DROP TABLE SHP_TABLE_PLINK$; | ||
- | DROP TABLE SHP_TABLE_EDGE$; | ||
- | DROP TABLE SHP_TABLE_NODE$; | ||
- | DROP TABLE SHP_TABLE_LINK$; | ||
- | DROP TABLE SHP_TABLE_FACE$; | ||
- | |||
- | -- delete any existing geometry layer | ||
- | EXECUTE SDO_TOPO.DELETE_TOPO_GEOMETRY_LAYER(' | ||
- | DROP TABLE SHP_TABLE_TOPO; | ||
- | |||
- | -- then drop existing topology | ||
- | EXECUTE SDO_TOPO.DROP_TOPOLOGY(' | ||
- | -- create new topology | ||
- | EXECUTE SDO_TOPO.CREATE_TOPOLOGY(' | ||
- | -- insert the universal face for an empty topology | ||
- | INSERT INTO SHP_TABLE_FACE$(face_id, | ||
- | VALUES(-1, NULL, SDO_LIST_TYPE(), | ||
- | -- create an Oracle table with a feature layer | ||
- | DROP TABLE SHP_TABLE_TOPO; | ||
- | -- note, do not create unique id (PRIMARY KEY) as the data in teleatlas.dbf is inconsistent | ||
- | CREATE TABLE SHP_TABLE_TOPO(id number, feature SDO_TOPO_GEOMETRY); | ||
- | --CREATE TABLE SHP_TABLE_TOPO(id number, type varchar2(1), | ||
- | |||
- | -- register feature layer with topology | ||
- | EXECUTE SDO_TOPO.ADD_TOPO_GEOMETRY_LAYER(' | ||
- | -- create updatable TOPO_MAP object and load the whole topology in cache | ||
- | -- since we just created the topology, the cache will be empty | ||
- | EXECUTE SDO_TOPO_MAP.DROP_TOPO_MAP(' | ||
- | EXECUTE SDO_TOPO_MAP.CREATE_TOPO_MAP(' | ||
- | EXECUTE SDO_TOPO_MAP.LOAD_TOPO_MAP(' | ||
- | |||
- | -- copy/paste everything in one go between BEGIN and COMMIT; (including): | ||
- | -- this one will demand a considerable amount of time | ||
- | BEGIN | ||
- | FOR r IN (SELECT id, geometry FROM SHP_TABLE) LOOP | ||
- | -- associate topological primitives with features | ||
- | INSERT INTO SHP_TABLE_TOPO(id, | ||
- | VALUES(r.id, | ||
- | SDO_TOPO_MAP.CREATE_FEATURE(' | ||
- | ' | ||
- | ' | ||
- | r.geometry) | ||
- | ); | ||
- | END LOOP; | ||
- | END; | ||
- | COMMIT; | ||
- | |||
- | -- commit topology changes | ||
- | EXECUTE SDO_TOPO_MAP.COMMIT_TOPO_MAP; | ||
- | EXECUTE SDO_TOPO_MAP.DROP_TOPO_MAP(' | ||
- | |||
- | -- check how many primitives were converted (should be the same number as primitives in the DB) | ||
- | SELECT COUNT(*) FROM SHP_TABLE_TOPO; | ||
- | |||
- | -- after an initial bulk load into an empty topology, initialize_metadata | ||
- | EXECUTE SDO_TOPO.INITIALIZE_METADATA(' | ||
- | |||
- | -- check here what tables have been created: | ||
- | SELECT table_name FROM user_tables WHERE table_name LIKE ' | ||
- | |||
- | CREATE TABLE SHP_TABLE_LINK$ | ||
- | AS SELECT | ||
- | start_node_id, | ||
- | end_node_id, | ||
- | geometry | ||
- | FROM SHP_TABLE_EDGE$; | ||
- | |||
- | -- FULL NETWORK: | ||
- | --CREATE TABLE SHP_TABLE_PATH$(PATH_ID NUMBER, | ||
- | -- PATH_NAME | ||
- | -- PATH_TYPE | ||
- | -- START_NODE_ID | ||
- | -- END_NODE_ID | ||
- | -- COST NUMBER, | ||
- | -- SIMPLE | ||
- | -- PATH_GEOMETRY | ||
- | --CREATE TABLE roads_incompl_plink$(path_id number not null, link_id number not null, seq_no number not null); | ||
- | --INSERT INTO USER_SDO_NETWORK_METADATA( | ||
- | -- network, network_category, | ||
- | -- node_table_name, | ||
- | -- link_table_name, | ||
- | -- path_table_name, | ||
- | -- path_link_table_name) | ||
- | -- VALUES( | ||
- | -- ' | ||
- | -- ' | ||
- | -- ' | ||
- | -- ' | ||
- | -- ' | ||
- | |||
- | -- MINIMAL NETWORK: | ||
- | INSERT INTO USER_SDO_NETWORK_METADATA( | ||
- | network, network_category, | ||
- | node_table_name, | ||
- | link_table_name, | ||
- | VALUES( | ||
- | ' | ||
- | ' | ||
- | ' | ||
- | |||
- | SELECT SDO_NET.VALIDATE_NETWORK(' | ||
- | |||
- | COMMIT; | ||
- | </ | ||
- | |||
- | If anything, contact me (the creator of this page) {at} unibz {dot} it. | ||
/data/www/wiki.inf.unibz.it/data/attic/contrib/shp2ndm.1184945142.txt.gz · Last modified: 2019/01/16 10:03 (external edit)