Shapefiles are a popular way to distribute spatial vector data but how do you get them into your Oracle Spatial Database?
shp2sdo is a command line utility that can be downloaded from Oracle and it converts shapefiles into sqlloader format so they can be easily loaded into the database. The download includes versions that can be used on Windows, Linux and Unix.
Extract the executable into the same location as your shapefiles then navigate to the same location in you command window or terminal..
In Windows enter the following command:
shp2sdo.exe a_road_polyline a_road_polyline -g geom -d -x (0,750000) -y (0,1350000) -s 81989 -t 0.5 -v
The first two parameters are the name of the shapefile and the name of the table you intend to load you data into – keep them the same.
-g is the name of the colum in the table that will contain you geometry.
-d is the bounds of your coordinate system – here the x and y values represent the bounds of the UK.
-s is the SRID (Spatial Reference ID) and this is where it gets confusing with Oracle. Spatial References normaly refer to those defined by the European Petroleum Survey Group – for the UK this would be EPSG 27700 representing British National Grid. Unfortunately this dosen’t map directly to the Oracle SRID but you can look up the equivalent. Use SDO_CS.MAP_EPSG_TO_ORACLE to determine your SRID.
-t is the tolerance. In this case the units are meters so out tolerance is 0.5 meter.
-v means we get verbose output.
If you are using this tool from a terminal window in Linux you will have to escape the round brackets so your line would look like this.
shp2sdo.exe a_road_polyline a_road_polyline -g geom -d -x \(0,750000\) -y \(0,1350000\) -s 81989 -t 0.5 -v
Below is the output from the Windows Command Line.
At the end of the output you can see that shp2sdo has created two files – a sql file to create the table and a control file that contains the data and can be loaded into the database using sqlloader.
You will have to look at the scripts to make sure they will work – in my example the table creation script trys to create colums called NUMBER and ACCESS Oracle dosen’t like this so I had to change them.
CREATE TABLE A_ROAD_POLYLINE (
If you make changes to the table creation file you will also have to make the same changes to the Control file.
Call sqlloader from the command line with your user credentials specifying your controlfile.