Feeds:
Posts
Comments

Oracle for gis

We are going to use oracle as gis database server. We will use AutoCAD Map 3D for creating editing and updating gis data in the database. As database client we will use sqlplusw and sqldeveloper. We will also use GeoRaptor for viewing geometry data in sqldeveloper.

Creating a table with geometry field:

create table kavel(

id varchar2(30 BYTE) PRIMARY KEY,

description varchar2(30 BYTE),

type varchar2(30 BYTE),

geom MDSYS.SDO_GEOMETRY

)

A spatial table must have a primary key

All Oracle gis database stuff (tables, views, types,functions) are stored under MDSYS user account.  So to use SDO_GEOMETRY we need ot use MDSYS.SDO_GEOMETRY.

Add Meta data in to user_sdo_geom_metadata table:

Then we need to add an entry in the user_sdo_geom_metadata table. It has the following columns

TABLE_NAME : Name of the table.

COLUMN_NAME : Name of column.

DIMINFO : Dimention of the geometry objects.(???)

SRID : Special reference ID. For WGS84 we use SRID 4326. (??? Does oracle uses its own SRID ???)

DELETE FROM user_sdo_geom_metadata

WHERE table_name=’kavel”;

INSERT INTO user_sdo_geom_metadata VALUES

(‘KAVEL’,'GEOM’,

MDSYS.SDO_DIM_ARRAY(MDSYS.SDO_DIM_ELEMENT(‘LONGITUDE’, -180, 180,.5),

MDSYS.SDO_DIM_ELEMENT(‘LATITUDE’, -90, 90,.5)),

4326

);

- Note: You will only need to populate the metadata for the city_geometries table if it was exported from the source system prior to the table being spatially indexed. If a spatial table is exported while the spatial index exists then the import will populate the metadata and create the spatial index.

- USER_SDO_GEOM_METADATA is used by Oracle Spatial to define the valid values for a spatial tables coordinate system. You must have at least 2 dimensions defined for each spatial table. In this case, we are defining a geodetic coordinate system containing a longitude and latitude value. We also identify the coordinate system by specifying the SRID value of 4326 (WGS84). If the metadata table identifies a SRID for the spatial table then each record with a populated geometry must also specify the same SRID in the spatial object.

- You must have a metadata entry for all tables containing a spatial geometry column. If the metadata entry does not exist, then Oracle will generate errors whenever you try to index the spatial column or utilize any of the spatial operators.

- The SDO_DIM_ELEMENT specifies the dimensions name, lower boundary, upper boundary and tolerance. Tolerance is used to determine when two points are close enough to be considered the same point. For geodetic coordinate systems, like the one we define above, the tolerance is specified in meters. In this case, we are using a tolerance of 1/2 of a meter.

Add Index to geometry column:

Now we have to create a index on the geometry column (???)

CREATE INDEX kavel_geometry_idx ON kavel(geom)

INDEXTYPE IS MDSYS.SPATIAL_INDEX;

GIS file formats

A GIS file format is a standard of encoding geographical information into a file. They are created mainly by government mapping agencies (such as the USGS) or by GIS software developers.

Metadata often includes:

  • Elevation data, either in raster or vector form (e.g., contours)
  • Shape layers, usually expressed as line drawings, for streets, postal zone boundaries, etc.
  • Coordinate system descriptions.
  • One or more datums describing the precise shape of the Earth assumed by the coordinates.

Popular GIS file formats

Raster formats

Vector formats

Grid formats (for elevation)

Other formats

Virtual Earth provieds quite powerful API’s to control the viewer. It also has a online Interactive SDK (http://dev.live.com/virtualearth/sdk/) where we can see the use of different API calls.

I was interested to restrict the viewable area and the zoom scale of the viewer. The reason was one of our clients wishes to restrict the users of there site only to the area of interest.

Restrict Viewable Area

For this sample I will restrict the viewer on Bangladesh. To do that first we have to decide the center point of Bangladesh which is 24.0966, 90.4833. Lets consider that we will restrict the user within 400 km from the center point.

First we have to create the map as usual using 24.0966, 90.4833 as center point. And use a global variable for storing the distance.

map = new VEMap('myMap');
map.LoadMap(new VELatLong(24.0966, 90.4833), 10 ,'h' ,false);
var mapRestrictionDistance = 400;

Now we need a javascript function for calculating distance. There are different formulas for measuring distance between two co-ordinates. For this sample I used Haversine formula which is as follows

R = earth’s radius (mean radius = 6,371km)
Δlat = lat2− lat1
Δlong = long2− long1
a = sin²(Δlat/2) + cos(lat1).cos(lat2).sin²(Δlong/2)
c = 2.atan2(√a, √(1−a))
d = R.c

So the javascript function for calculating distance will be

function distHaversine(lat1, lon1, lat2, lon2) {
  var R = 6371; // earth's mean radius in km
  var dLat = (lat2-lat1).toRad();
  var dLon = (lon2-lon1).toRad();
  lat1 = lat1.toRad(), lat2 = lat2.toRad();

  var a = Math.sin(dLat/2) * Math.sin(dLat/2) +
          Math.cos(lat1) * Math.cos(lat2) *
          Math.sin(dLon/2) * Math.sin(dLon/2);
  var c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1-a));
  var d = R * c;
  return d;
}

Now we have to use the OnEndPan and OnStartPan events. To do this we have to attach the event handlers to these events

//Attach our onendpan event handler
map.AttachEvent(“onendpan”, map_onendpan);

//Attach our onstartpan event handler
map.AttachEvent(“onstartpan”, map_onstartpan);

Next,we need to add code to the event handler method stubs shown above that will actually restrict the maps viewable area.

In the map_onstartpan event handler we will record the maps center point in a global variable before the panning begins. To do this we have to add the following code:

// global variable to keep track of maps center point before panning began
var mapStartPanPoint = null;

function map_onstartpan(e)
{
//Get the current map center point before panning begins
mapStartPanPoint = map.GetCenter();
}

In the map_onendpan event handler we will place the actual code that imposes our restriction. The following code will check if the map has been panned past the desired limitation of 400 km from the original center point. If it has, it will reposition the map back to the last point the map was at before the invalid panning began. Here’s the code to implement this within the map_onendpan event handler:

function map_onendpan(e)
{
//Get total distance panned from map center
var distance =
distHaversine(mapOriginalCenterPoint.Latitude, mapOriginalCenterPoint.Longitude,
map.GetCenter().Latitude, map.GetCenter().Longitude);

//Check distance panned from original center point
if (distance > mapRestrictionDistance)
{
//Move map back to the last point that was
//within the desired restriction radius
map.SetCenter(mapStartPanPoint);
}
}

Restrict Maximum Zoom Level

To restrict the Maximum Zooom Level to 7 we need to implement a handler for the maps OnEndZoom event.

var mapRestrictionZoomLevel = 7;

//Attach our onendzoom event handler
map.AttachEvent(“onendzoom”, map_onendzoom);

Now in the event handler function we have to check the zoom level and if it exceds the desired maximum zoom level then we set the zoom level to maximum allowed level that is 7 for our example

function map_onendzoom(e)
{
//Check if the map is zoomed out further than
//the set restriction
if (e.zoomLevel < mapRestrictionZoomLevel)
{
//Zoom the map back in to the restricted area
map.SetZoomLevel(mapRestrictionZoomLevel);
}
}

Understanding features is fundamental to being able to use the MapGuide
Web API. Nearly every application will need to interact with feature data in
one form or another.
Features are map objects representing items like roads (polylines), lakes
(polygons), or locations (points).
A feature source is a resource that contains a set of related features, stored in a
file or database. Some common feature source types are SDF files, SHP files,
or data in a spatial database.
For example, you may have a feature source that contains data for roads.
Feature sources can be stored in the library repository or in a session repository.
A feature source identifier describes a complete path in the repository. For
example,
Library://Samples/Sheboygan/Data/RoadCenterLines.FeatureSource
Within a single feature source there may be one or more feature classes. A
feature class describes a subset of the features in the feature source. In many
cases, there is one feature class for each feature source. For example, there may
be a Roads feature class in the RoadCenterLines feature source.
A feature class contains one or more features. Each feature has a geometry
that defines the spatial representation of the feature. Features will also generally
have one or more properties that provide additional information. For example,
a feature class containing road data may have properties for the road name
and the number of lanes. Feature properties can be of different types, like
strings, integers, and floating point numbers. Possible types are defined in the
class MgPropertyType.
In some cases, a feature property will be another feature. For example, a Roads
feature might have a Sidewalk feature as one of its properties.
A map layer may contain the features from a feature class. The features are
rendered using the feature geometry.
The Web API Feature Service provides functions for querying and updating
feature data.