[OpenLayers-Users] Manipulating polygons with openlayers 2.5

Eduard Witteveen eywitteveen at gmail.com
Tue Feb 5 10:46:56 EST 2008


Hello list,

First of all, sorry of my posting in html, the email server somehow
converts the type.

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
               &nbspvar map;
               &nbspOpenLayers.ProxyHost="proxy.php?url=";
               &nbspOpenLayers.IMAGE_RELOAD_ATTEMPTS = 3;
               &nbspif(OpenLayers.VERSION_NUMBER != '$Revision: 4899 $') {
                       &nbspalert('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(),
                                       &nbspnew
OpenLayers.Control.MousePosition(
                                                {
                                                       &nbspelement:
$('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
                       &nbspvar wms = new OpenLayers.Layer.WMS(
                                "Orgineel",
                                "http://192.168.198.73:8080/geoserver/wms",
                                {
                                       &nbsplayers: 'aaenhunze:MY_TABLE'
                                }
                        );
                       &nbspmap.addLayer(wms);

                // LAYER AS WFS
            wfs = new OpenLayers.Layer.WFS(
                                "WFS",
                                "http://192.168.198.73:8080/geoserver/wfs",
                                {
                                        'typename':'aaenhunze:MY_TABLE'
                                },
                                {
                                       &nbsptypename: 'MY_TABLE',
                                       &nbspfeatureNS:
'http://aaenhunze.nl/gml',
                                       &nbspextractAttributes: false
                                }
                        );
                       &nbspvar modifyOptions = {
                               &nbsponModificationStart: function(feature) {

&nbspOpenLayers.Console.log("start modifying", feature.id);
                                },
                               &nbsponModification: function(feature) {

&nbspOpenLayers.Console.log("modified", feature.id);
                                },
                               &nbsponModificationEnd: function(feature) {

&nbspOpenLayers.Console.log("end modifying", feature.id);
                                       &nbspfeature.state =
OpenLayers.State.UPDATE;
                                },
                               &nbsponDelete: function(feature) {

&nbspOpenLayers.Console.log("delete", feature.id);
                                }
                        };
                       &nbspvar modify = new
OpenLayers.Control.ModifyFeature(wfs, modifyOptions);
                       &nbspwfs.style.strokeColor = "#00ffff";
                       &nbspmap.addLayer(wfs);
                // INSERT  POLYGON
                       &nbspvar drawPolygon = new
OpenLayers.Control.DrawFeature(
                wfs,
                               &nbspOpenLayers.Handler.Polygon,
                {
                                       &nbspdisplayClass:
'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
                       &nbspvar modifyPolygon = new
OpenLayers.Control.ModifyFeature(
                wfs,
                               &nbspOpenLayers.Handler.Polygon,
                {
                                       &nbspdisplayClass:
'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
                       &nbspvar panel = new OpenLayers.Control.Panel(
                {
                                       &nbspdisplayClass:
'olControlEditingToolbar'
                                }
            );
                       &nbsppanel.addControls(
                [
                                       &nbspnew OpenLayers.Control.Navigation(),
                                       &nbspmodifyPolygon,
                                       &nbspdrawPolygon,
                                ]
            );
                       &nbspmap.addControl(panel);
                // ZOOM
                       &nbspmap.zoomToExtent(bounds);
                }
    //]]>
    </script>
  </head>
<body onload="init()">
        <!--
               &nbspminx: <?php echo($minx); ?>
               &nbspminy: <?php echo($miny); ?>
               &nbspmax: <?php echo($maxx); ?>
               &nbspmaxy: <?php echo($maxy); ?>
       &nbsp-->
    <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) {
       &nbspdie("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)){
       &nbspdie("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
=====================
       &nbsp....
       &nbsp....
    <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>
       &nbsp....
       &nbsp....

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') ;



More information about the Users mailing list