[OpenLayers-Users] writing to my own wfs server

Burgholzer,Robert rwburgholzer at deq.virginia.gov
Tue Jul 31 09:00:17 EDT 2007


Arnd,
I managed to locate the following object "OpenLayers.Format.WKT" in the very comprehensive library.  (I become more impressed with the openlayers core libraries every day - kudos to whoever deserves them).  I followed your lead on this alternative format, and now it is working quite nicely.

So, in my modified WFS.js, I have created a method that takes all created shapes and places them in a POST array, which is then read by a php script which has access to the PostGIS constructirs for setting the SRID(epsg), code follows:

Javascript: -->
        var wktObj = new OpenLayers.Format.WKT;

        for(var i=0; i<this.features.length; ++i) {
           var wktdata = wktObj.write(this.features[i]);
           pParams += "&WKTDATA[";
           pParams += i;
           pParams += "]=";
           pParams += wktdata;
	    }

end Javascript: -->
 
BEGIN php: 

$wkt = $_POST['WKTDATA'];
#print_r($wkt);
$i = 2;
foreach ($wkt as $thiswkt) {
   $listobject->querystring = " insert into proj_features (gid, name, the_geom) ";
   $listobject->querystring .= " select $i, 'test shape', GeomFromText('$thiswkt', 4326) ";
   print("$listobject->querystring ");
   $listobject->performQuery();
   $i++;
}

END php


-----Original Message-----
From: arnd.wippermann at web.de [mailto:arnd.wippermann at web.de] 
Sent: Monday, July 30, 2007 4:34 PM
To: Burgholzer,Robert
Subject: AW: [OpenLayers-Users] writing to my own wfs server

Hello Robert,

I have a look at the wfs-t.html and have seen, that the feature.geometry is
a WKTString. Perhaps you can use this instead of the XMLserialization. After
adding the EPSG-Code to the WKTString you can insert the string into the
geometry column of your db. I myself didnt use GML, but perhaps there is
something in Openlayers to convert GML to WKT (GML to feature ->
feature.geometry = WKTString ?).

The code snippets show how I use the drawing and saving of features.

Mit freundlichen Grüssen

Arnd Wippermann
http://gis.ibbeck.de/ginfo/



This is the way I use the editing tool, but I think I must have a closer
look at wfs-t.html

First  : draw a point, line or polygon
Second : select the feature
Third  : call Insertfunction (inserts the feature into db, deletes feature
from vector-layer and refreshes the WMS-layer with the new feature


2.
Part of the script to get the selected feature

    map.events.register('click', map, function (e) {
    ...
        if(QueryMode == false)
        {
            if(map.layers[3].selectedFeatures.length>0)
            {   WKTString = map.layers[3].selectedFeatures[0].geometry;
                var derTyp =
WKTString.CLASS_NAME.replace(/OpenLayers.Geometry./i,"");
            ...
        }
        else
        {
            //Query WMS DataLayer, GetFeatureRequest, Returnvalue :
ID_GEOOBJEKT
            //Selection for deleting
        ...
        }
    ...    

3.
Part of the script to insert or delete a feature
    ...
    if(flag==1)
    {
        var derTyp =
WKTString.CLASS_NAME.replace(/OpenLayers.Geometry./i,"").toUpperCase();
        if(derTyp=="POINT")
            var db = "GEOPOINTS";
        else if(derTyp=="LINESTRING")
            var db = "GEOLINES";
        else if(derTyp=="POLYGON")
            var db = "GEOPOLYGONS";
        else
            var db = "";

        if(db=="")
        {   alert("Der Typ " + derTyp + " wird nicht unterstützt!");
            return false;
        }

        var GEOOBJEKT = document.getElementById("iGEOOBJEKT").value;
        if(GEOOBJEKT=="")
        {   alert("GEOOBJEKT benennen!");
            return false;
        }

        var POSITION   = WKTString.toString();

        //wird nicht gebraucht, sondern serverseitig erstellt
        var SQLString = "INSERT INTO [" + db + "]
(GEOOBJEKT,POSITION,KATEGORIE) VALUES ('" + GEOOBJEKT + "'," + POSITION + ",
31466','" + KATEGORIE + "');";
        alert(SQLString);

        var theUrl = aspfile;
        var theParams   = "MODE=INSERT";
            theParams  += "&DB=" + db;
            theParams  += "&GEOOBJEKT="  + GEOOBJEKT;
            theParams  += "&POSITION="   + POSITION;
            theParams  += "&KATEGORIE="  + KATEGORIE;
    }
    else if(flag==-1)
    {

        var theUrl = aspfile;
        var theParams   = "MODE=DELETE";
            theParams  += "&DB=" + parDB;
            theParams  += "&ID_GEOOBJEKT=" + parID;
    }

    var myAjax = new OpenLayers.Ajax.Request(
    	theUrl,
    	{
    		method: 'get',
    		parameters: theParams,
    		onComplete: showResponseGEO,
    		onFailure: showResponseFailureGEO
    	});
    ...

#################

part of wfs-t.html

            df = new OpenLayers.Control.DrawFeature(rlayer,
OpenLayers.Handler.Path, {handlerOptions: {'freehand': false},
'displayClass': 'olControlDrawFeaturePath'});
            df.featureAdded = function(feature) {
              feature.state = OpenLayers.State.INSERT;
              feature.style['strokeColor'] = "#0000ff";
              feature.layer.drawFeature(feature);

              //###################################################
              //#### Openlayers use a WKTString for the feature
              //#### (but without the EPSG-Code for the projection)
              //###################################################
              WKTString = feature.geometry;
              alert(WKTString.CLASS_NAME + "\r\n" + WKTString);
              //###################################################

            }

################# 

-----Ursprüngliche Nachricht-----
Von: users-bounces at openlayers.org [mailto:users-bounces at openlayers.org] Im
Auftrag von Burgholzer,Robert
Gesendet: Montag, 30. Juli 2007 19:15
An: users at openlayers.org
Betreff: Re: [OpenLayers-Users] writing to my own wfs server

Arnd,
Thanks much for your response.  I am endeavoring to do what you suggest,
although using PHP's native PostgreSQL connectors instead of ODBC.  

Currently, I am using the wfs-t.html scripts as my basis, and passing in the
result of "OpenLayers.Ajax.serializeXMLToString(data);" to get the edited
features into a form I can work with.  Having done that, I realize I now
have to contend with parsing this GML, and am wading through that.
I would be interested in any code that you have put together that can handle
the conversion from GML to WKT (if that is in fact what you are doing).  

Regards,
r.b.

-----Original Message-----
From: arnd.wippermann at web.de [mailto:arnd.wippermann at web.de]
Sent: Monday, July 30, 2007 12:37 PM
To: Burgholzer,Robert
Cc: users at openlayers.org
Subject: AW: [OpenLayers-Users] writing to my own wfs server

Hello Robert,

I would think, you can talk to your postgis-db via odbc. 

I use the editing functions of openlayers to draw a feature, select that
feature and use a serverside asp-script to insert the selected feature as
WKT string via odbc into an access-db. With mapserver and ogr I can request
the geometry and attributes from the access-db and show it in the map.

It is also possible with a WMS GetFeatureRequest to select features from the
db and delete the features in the db with odbc.

When the great editing tools from openlayers get the possibility to update
features (changing the geometry after drawing it), one can use an internet
explorer and openlayers for drawing, updating and deleting geometry data.

Mit freundlichen Grüssen

Arnd Wippermann
http://gis.ibbeck.de/ginfo/








-----Ursprüngliche Nachricht-----
Von: users-bounces at openlayers.org [mailto:users-bounces at openlayers.org] Im
Auftrag von Burgholzer,Robert
Gesendet: Freitag, 27. Juli 2007 21:44
An: Users at openlayers.org
Betreff: Re: [OpenLayers-Users] writing to my own wfs server

I am thinking perhaps to post the data from the openlayers, and intercept it
with some php, that can then enter it into postgis via WKT (assuming that
the openlayers wfs-t object produces point cords for the shapes, which I
haven't verified, but assume that it must).

I will look at the packages to see further.

r.b.

-----Original Message-----
From: Christopher Schmidt [mailto:crschmidt at metacarta.com]
Sent: Friday, July 27, 2007 3:41 PM
To: Burgholzer,Robert
Cc: Users at openlayers.org
Subject: Re: [OpenLayers-Users] writing to my own wfs server

On Fri, Jul 27, 2007 at 02:46:50PM -0400, Burgholzer,Robert wrote:
> Ahh yes, double-drat!
> 
> Don't suppose anyone has put together any PostGIS functions in 
> openlayers that will permit writing a WKT feature directly to a
PostGIS
> server? I am really dreading the prospect of another map-serving
entity
> on my machine.

If you mean something that allows you to talk to PostGIS directly from a web
browser... I can't imagine how that would work. You're going to need some
kind of layer inbetween that speaks a non-binary language. 

FeatureServer is a Python CGI that is designed to speak a variety of
languages on the input side and output side, and is designed to be as little
work as possible to install. However, it requires some level of
configuration, and it is likely, or even possible, that you would be better
off with GeoServer.

Regards,
--
Christopher Schmidt
MetaCarta
_______________________________________________
Users mailing list
Users at openlayers.org
http://openlayers.org/mailman/listinfo/users
_______________________________________________
Users mailing list
Users at openlayers.org
http://openlayers.org/mailman/listinfo/users



More information about the Users mailing list