[OpenLayers-Users] setting WKT returned from postGIS in form fieldto openlayers feature

Burgholzer,Robert rwburgholzer at deq.virginia.gov
Fri Oct 31 16:45:51 EDT 2008


Well, thanks to some help from the folks on this list, I managed to get
this working.  I thought I would post a couple of observations that I
noted when implementing my display of active model elements in
Openlayers via WKT.  

 

My objects are stored as SRID 4326 in my database, but I am using
googlemaps as the base layer for my web interface, so I need to do some
transformations.  Fortunately, with the fantastic capabilities of
OpenLayers, it is really quite simple.  

 

When I want to display a newly activated element, I simply ship the wkt
to my script setScratchGoogleShape(WKTgeom), which exploits the feature
of Openlayers.Format to use an internal and external projection.  In
this case the internalProjection is spherical mercator, and the external
is SRID4326.  The function is as follows (and many thanks to the work of
the team at OL and list members):

 

        function setScratchGoogleShape(WKTgeom) {

           

          // assumes that vlayer is set in globals

          // set up projection info 

          // I think the following projections should be set up
automagically, but my installation does not seem to work without
explicitly defining them here

          Proj4js.defs["EPSG:4326"] = "+proj=longlat +ellps=WGS84
+datum=WGS84 +no_defs";

          Proj4js.defs["EPSG:900913"] = "+proj=merc +a=6378137
+b=6378137 +lat_ts=0.0 +lon_0=0.0 +x_0=0.0 +y_0=0 +k=1.0 +units=m
+nadgrids=@null +no_defs";

 

          var proj4326 = new OpenLayers.Projection("EPSG:4326");

          var projGoogle = new OpenLayers.Projection("EPSG:900913");

          

          

          var wktObj = new OpenLayers.Format.WKT;

          wktObj.internalProjection = projGoogle;

          wktObj.externalProjection = proj4326;

          

          var wktfeatures = wktObj.read(WKTgeom);

          vlayer.addFeatures(wktfeatures);

          

          //var backatya = wktObj.write(wktfeatures);

          //alert(backatya);

          

          vlayer.redraw();

 

        }

 

Robert W. Burgholzer

Surface Water Modeler

Office of Water Supply and Planning

Virginia Department of Environmental Quality

rwburgholzer at deq.virginia.gov

804-698-4405

Open Source Modeling Tools:

http://sourceforge.net/projects/npsource/

-----Original Message-----
From: arnd.wippermann at web.de [mailto:arnd.wippermann at web.de] 
Sent: Friday, October 31, 2008 1:56 PM
To: Burgholzer,Robert
Cc: users at openlayers.org
Subject: AW: [OpenLayers-Users] setting WKT returned from postGIS in
form fieldto openlayers feature

 

if I add a right parenthesis at the end of your wkt string, I can import
it to OpenLayers with OpenLayers.Format.WKT. It's some area in Richmond
at Staples Mill Road.

 

Arnd Wippermann

 

  _____  

Von: users-bounces at openlayers.org [mailto:users-bounces at openlayers.org]
Im Auftrag von Burgholzer,Robert
Gesendet: Freitag, 31. Oktober 2008 16:51
An: users at openlayers.org
Betreff: [OpenLayers-Users] setting WKT returned from postGIS in form
fieldto openlayers feature

My application returns a WKT representation of an element geometry in a
hidden form field.  I am trying to take that geometry and push it into
an openlayers feature layer, so that as the user goes views different
elements from the PG server, those features appear in the foreground on
the OL map.

 

I have tried to implement some code from the WKT example, but I am not
having any luck.  The feature fails to draw, although I know it is
there, because I have been using an alert() to show me the contents of
the WKT string.  Thus, I am guessing that somehow my format returned
from PostGIS is incorrect.  Here is the contents of my hidden form
field:

 

MULTIPOLYGON(((-8623549.09290489 4522549.65191948,-8623596.86604756
4522931.83706085,-8623635.0845617 4523629.32494386,-8624131.92524548
4523591.10642972,-8624619.21130074 4523619.77031532,-8625488.68249736
4523610.21568679,-8626224.3888945 4523552.88791558,-8626319.93517984
4523552.88791558,-8626597.01940734 4523849.08140015,-8626721.22957829
4524040.17397083,-8627256.28877621 4523973.2915711,-8627390.05357569
4523954.18231403,-8627409.16283276 4523715.31660067,-8627447.38134689
4523581.55180119,-8627265.84340474 4523266.24905955,-8627208.51563353
4523103.82037447,-8626979.20454871 4522884.06391818,-8626616.12866441
4522759.85374724,-8626052.40558088 4522654.75283335,-8625555.5648971
4522444.5510056,-8625240.26215547 4522243.90380638,-8625058.72421331
4522463.66026267,-8624724.31221461 4522501.87877681,-8624514.11038686
4522406.33249147,-8624237.02615936 4522234.34917785,-8623959.94193187
4522234.34917785,-8623644.63919024 4522282.12232052,-8623549.09290489
4522549.65191948))

 

 

Any help would be most appreciated,

r.b.

 

Robert W. Burgholzer

Surface Water Modeler

Office of Water Supply and Planning

Virginia Department of Environmental Quality

rwburgholzer at deq.virginia.gov

804-698-4405

Open Source Modeling Tools:

http://sourceforge.net/projects/npsource/

 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.osgeo.org/pipermail/openlayers-users/attachments/20081031/1852d8c9/attachment.html


More information about the Users mailing list