Hello list,
I want to insert/update/delete polygons in my oracle 9i database. In order to get this working i've chosen to use geoserver 1.6.0-RC3 in combination with openlayers 2.5.
Currently i don't know what would be the good way to make this working, but i've started with the sample's wfs-t, http://www.nabble.com/WFS-T-delete-update-td14843989.html, and a lot of other snippets.
My question is the following:
- What is the way to make the functionality of insert/update/delete (to put it into viewer.php) or is there a sample which can help.
(currently insert appears to be working, update misses a image, and not sure how i should implement the delete, but i lack the feeling that i'm following the correct path)
client enviroment:
=================
Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.8.1.11) Gecko/20071127 Firefox/2.0.0.11
server enviroment:
=================
Microsoft Windows XP [versie 5.1.2600]
(C) Copyright 1985-2001 Microsoft Corp.
GeoServer 1.6.0-RC3 - <http://downloads.sourceforge.net/geoserver/geoserver-1.6.0-RC3.exe?modtime=1200549612&big_mirror=0>
GeoServer-1.6.0-RC3-oracle-plugin - <http://downloads.sourceforge.net/geoserver/geoserver-1.6.0-RC3-oracle-plugin.zip?modtime=1200550429&big_mirror=0>
Oracle91 Enterprise Edition Release 9.2.0.7.0 - Production
With the Partitioning, OLAP and Oracle Data Mining options
JServer Release 9.2.0.7.0
viewer.php
==========
<?php
header("Content-Type:text/html;charset=utf-8");
// get the extend
isset($_REQUEST['extent']) || die('parameter extent was not specified!');
list($min, $max) = split(' ', $_REQUEST['extent']);
isset($min) && isset($max) || die('parameter extent did not contain a min and max seperated by a space');
list($minx, $miny) = split(',', $min);
isset($minx) && isset($miny) || die('parameter extent did not contain two values in the min part, seperated by a comma');
list($maxx, $maxy) = split(',', $max);
isset($maxx) && isset($maxy) || die('parameter extent did not contain two values in the max part, seperated by a comma');
// convert dot float values
$minx = floatval($minx);
$miny = floatval($miny);
$maxx = floatval($maxx);
$maxy = floatval($maxy);
// retrieve the gml from the extend,..
?><html xmlns="http://www.w3.org/1999/xhtml">
<head>
        <title></title>
<link rel="stylesheet" href="style.css" type="text/css" />
<style type="text/css">
body {
margin: 1em;
}
#map {
width: 800px;
height: 475px;
border: 1px solid black;
}
</style>
        <script src="http://www.openlayers.org/api/OpenLayers.js"></script>
<scipt type="text/javascript">
                //<![CDATA[                 
                // WFS-T : http://www.nabble.com/WFS-T-delete-update-td14843989.html
                var map;
                OpenLayers.ProxyHost="proxy.php?url=";
                OpenLayers.IMAGE_RELOAD_ATTEMPTS = 3;
                if(OpenLayers.VERSION_NUMBER != '$Revision: 4899 $') {
                        alert('Build on version 2.5, running with unsupported version:' + OpenLayers.VERSION_NUMBER + '($Revision: 4899 $ required)');
                }                
function init()
                {                        
                // MAP
var bounds = new OpenLayers.Bounds(
<?php echo($minx) ?>, <?php echo($miny) ?>,
<?php echo($maxx) ?>, <?php echo($maxy) ?>
);
var options = {
controls: [
//new OpenLayers.Control.Navigation(),
//new OpenLayers.Control.PanZoomBar(),
//new OpenLayers.Control.Attribution(),
                                        new OpenLayers.Control.MousePosition(
                                                {
                                                        element: $('location')
                                                }
                                        ),
                 //new OpenLayers.Control.Scale($('scale')),
                                        //new OpenLayers.Control.LayerSwitcher(),
                                ],
maxExtent: bounds,
                                // maxResolution: 111.50037148187619,
maxExtent: new OpenLayers.Bounds(
                                        <?php echo($minx - 100) ?>, <?php echo($miny - 100) ?>,
                                        <?php echo($maxx + 100) ?>, <?php echo($maxy + 100) ?>
                                ),
projection: "EPSG:28992",
units: 'meter'
};
map = new OpenLayers.Map('map', options);                        
                //LAYER WAS WMS
                        var wms = new OpenLayers.Layer.WMS(
                                "Orgineel",
                                "http://192.168.198.73:8080/geoserver/wms",
                                {
                                        layers: 'aaenhunze:MY_TABLE'
                                }
                        );        
                        map.addLayer(wms);
                        
                // LAYER AS WFS
wfs = new OpenLayers.Layer.WFS(
                                "WFS",
                                "http://192.168.198.73:8080/geoserver/wfs",
                                {
                                        'typename':'aaenhunze:MY_TABLE'
                                },
                                {
                                        typename: 'MY_TABLE',
                                        featureNS: 'http://aaenhunze.nl/gml',
                                        extractAttributes: false
                                }
                        );
                        var modifyOptions = {
                                onModificationStart: function(feature) {
                                        OpenLayers.Console.log("start modifying", feature.id);
                                },
                                onModification: function(feature) {
                                        OpenLayers.Console.log("modified", feature.id);
                                },
                                onModificationEnd: function(feature) {
                                        OpenLayers.Console.log("end modifying", feature.id);
                                        feature.state = OpenLayers.State.UPDATE;
                                },
                                onDelete: function(feature) {
                                        OpenLayers.Console.log("delete", feature.id);
                                }
                        };
                        var modify = new OpenLayers.Control.ModifyFeature(wfs, modifyOptions);                        
                        wfs.style.strokeColor = "#00ffff";
                        map.addLayer(wfs);
                // INSERT POLYGON
                        var drawPolygon = new OpenLayers.Control.DrawFeature(
wfs,
                                OpenLayers.Handler.Polygon,
{
                                        displayClass: 'olControlDrawFeaturePolygon'
                                }
)                        
drawPolygon.featureAdded = function(feature) {
feature.layer.eraseFeatures([feature]);
feature.geometry = new OpenLayers.Geometry.MultiPolygon(
feature.geometry
);
feature.style.strokeColor = "#ff0000";
feature.state = OpenLayers.State.INSERT;
feature.layer.drawFeature(feature);
};
                // MODIFY POLYGON
                        // TODO: the modify icon is missing
                        var modifyPolygon = new OpenLayers.Control.ModifyFeature(
wfs,
                                OpenLayers.Handler.Polygon,
{
                                        displayClass: 'olControlModifyFeature'
                                }
)
                        //mode = OpenLayers.Control.ModifyFeature.RESHAPE
                        //mode = OpenLayers.Control.ModifyFeature.RESIZE
                        //mode = OpenLayers.Control.ModifyFeature.ROTATE
modifyPolygon.featureAdded = function(feature) {
feature.layer.eraseFeatures([feature]);
feature.geometry = new OpenLayers.Geometry.MultiPolygon(
feature.geometry
);
feature.style.strokeColor = "#ff0000";
feature.state = OpenLayers.State.UPDATE;
feature.layer.drawFeature(feature);
};
                // CONTROLS
                        var panel = new OpenLayers.Control.Panel(
{
                                        displayClass: 'olControlEditingToolbar'
                                }
);
                        panel.addControls(
[
                                        new OpenLayers.Control.Navigation(),
                                        modifyPolygon,
                                        drawPolygon,
                                ]
);
                        map.addControl(panel);                         
                // ZOOM
                        map.zoomToExtent(bounds);
                }
//]]>
</script>
</head>
<body onload="init()">
        <!--
                minx: <?php echo($minx); ?>
                miny: <?php echo($miny); ?>
                max: <?php echo($maxx); ?>
                maxy: <?php echo($maxy); ?>
        -->
<div id="map"></div>
        <p>When adding a polygon, use shift-click to stop.</p>
        <button onclick="map.layers[2].commit();return false">Save</button>
</body>
</html>
proxy.php:
==========
<?php
// what is our url?
isset($_REQUEST['url']) || die('parameter url was not specified!');
$url = $_REQUEST['url'];
$customAllowedHosts = array(
        // add here your own trusted sites
        '192.168.198.73:8080' => 'allowed'
);
// the defualt allowd hosts
$defaultAllowedHosts = array(
        'www.openlayers.org' => 'allowed',
        'openlayers.org' => 'allowed',
        'labs.metacarta.com' => 'allowed',
        'world.freemap.in' => 'allowed',
        'prototype.openmnnd.org' => 'allowed',
        'geo.openplans.org' => 'allowed',
        'www.openstreetmap.org' => 'allowed'
);
// now check the allowed hosts
$allowedHosts = array_merge($customAllowedHosts, $defaultAllowedHosts);
// now look what our hostname is:
$allowedStart = 'http://';
$urlStart = substr($url, 0, strlen($allowedStart));
if($urlStart != $allowedStart) {
        die("url has to start with '$allowedStart'(started with:'$urlStart')");
}
$urlHost = substr($url, strlen($urlStart));
$urlHost = substr($urlHost, 0, strpos($urlHost, '/'));
// look if the host is allowed
if(!array_key_exists($urlHost, $allowedHosts)){
        die("Host: $urlHost not allowed, the following hosts are allowed:" . print_r($allowedHosts, true));
}
// add here your proxy settings
$proxy_name = 'proxyserver';
$proxy_port = 8080;
$proxy_user = "proxy-username";
$proxy_pass = "proxy-password";
$proxy_cont = '';
$proxy_fp = fsockopen($proxy_name, $proxy_port);
$proxy_fp || die("could not open proxy server");
fputs($proxy_fp, "GET $url HTTP/1.0\r\nHost: $proxy_name\r\n");
fputs($proxy_fp, "Proxy-Authorization: Basic " . base64_encode ("$proxy_user:$proxy_pass") . "\r\n\r\n");
while(!feof($proxy_fp)) {
        $proxy_cont .= fread($proxy_fp, 4096);
}
fclose($proxy_fp);
$proxy_cont = substr($proxy_cont, strpos($proxy_cont,"\r\n\r\n") + 4);
echo($proxy_cont);
?>
geoserver featuresource (info.xml)
==================================
<featureType datastore = "oracle" >
<name>MY_TABLE</name>
<!--
native wich EPGS code for the FeatureTypeInfoDTO
-->
<SRS>28992</SRS>
<SRSHandling>2</SRSHandling>
<title>MY_TABLE_Type</title>
<abstract>Generated from oracle</abstract>
<wmspath>/</wmspath>
<numDecimals value = "8" />
<keywords>MY_TABLE, oracle</keywords>
<latLonBoundingBox dynamic = "false" maxx = "6.9392967077493575" maxy = "53.09548387383236" minx = "6.559948069483866" miny = "52.86960589905802" />
<nativeBBox dynamic = "false" maxx = "258935.87914926722" maxy = "568090.0287869847" minx = "233918.60022782636" miny = "543420.6528895505" />
<!--
the default style this FeatureTypeInfoDTO can be represented by.
at least must contain the "default" attribute
-->
<styles default = "table_style" />
<cacheinfo enabled = "false" maxage = "" />
</featureType>
geoserver catalog.xml
=====================
        ....
        ....
<datastore id = "oracle" enabled = "true" namespace = "aaenhunze" >
<connectionParams >
<parameter name = "schema" value = "my_schema" />
<parameter name = "port" value = "1521" />
<parameter name = "passwd" value = "password" />
<parameter name = "dbtype" value = "oracle" />
<parameter name = "host" value = "oracleserver" />
<parameter name = "validate connections" value = "true" />
<parameter name = "max connections" value = "10" />
<parameter name = "instance" value = "test" />
<parameter name = "user" value = "beheerder" />
<parameter name = "min connections" value = "4" />
<parameter name = "namespace" value = "aaenhunze" />
</connectionParams>
</datastore>
        ....
        ....
oracle.sql
==========
CREATE TABLE MY_TABLE (
GID CHAR(32) DEFAULT RAWTOHEX(sys_guid()) NOT NULL,
GEOM MDSYS.SDO_GEOMETRY,
CONSTRAINT MY_TABLE_PK PRIMARY KEY (GID)
);
INSERT INTO USER_SDO_GEOM_METADATA (
TABLE_NAME, COLUMN_NAME, DIMINFO, SRID
)
VALUES (
'MY_TABLE', 'GEOM',
MDSYS.SDO_DIM_ARRAY
(MDSYS.SDO_DIM_ELEMENT('X', -7000, 300000, 0.001),
MDSYS.SDO_DIM_ELEMENT('Y', 289000, 6290000, 0.001)
),
90112
);
/// load the data (import shp2sdo.exe ouput with sqlldr)
CREATE INDEX MY_TABLE_GI ON VB_PAND(GEOM)
INDEXTYPE IS MDSYS.SPATIAL_INDEX
PARAMETERS ('sdo_indx_dims=2 layer_gtype=MULTIPOLYGON') ;
************************************************************************************************
DISCLAIMER:
Aan de informatie in deze e-mail en ieder aangehecht databestand kunnen geen rechten
worden ontleend en de gemeente Aa en Hunze aanvaardt geen aansprakelijkheid voor
schade als gevolg van onjuistheden en/of gedateerde informatie.
Als u niet de bedoelde ontvanger bent wilt u dan dit bericht en ieder aangehecht
databestand verwijderen en de afzender hiervan via e-mail op de hoogte stellen.
************************************************************************************************
Deze mail is gescand met McAfee Webshield en bevat geen virussen.
Gemeente Aa en Hunze.