0

I'm using OpenLayers 2.13 and Postgresql 9.3 for my development activities. I want to load region data from database and load into openlayers.

Below result i'm getting from St_astext(geom) in postgresql 9.0 and above

"MULTIPOLYGON(((77.6620335903023 12.8381894855534,77.6620330917475 12.8384550503658,77.662583464913 12.8384554346975,77.6625831247336 12.8381894684868,77.66234257162 12.8381895285991,77.6622741102056 12.8381895459662,77.6620335903023 12.8381894855534)))"

But in postgresql 9.3 i'm getting the below result with height parameter while using St_astext(geom)

"MULTIPOLYGON ZM (((77.6620335903023 12.8381894855534 0 0,77.6620330917475 12.8384550503658 0 0,77.662583464913 12.8384554346975 0 0,77.6625831247336 12.8381894684868 0 0,77.66234257162 12.8381895285991 0 0,77.6622741102056 12.8381895459662 0 0,77.662033590 (...)"

Below is the OpenLayers code to featch the wkt format

var feature = new OpenLayers.Feature.Vector(new OpenLayers.Geometry.fromWKT("MULTIPOLYGON ZM (((77.6620330345526 12.8382017120463 0 0,77.6620403164933 12.8384556061155 0 0,77.6625840206627 12.8384543231982 0 0,77.6625747884884 12.8381889127371 0 0,77.6620330345526 12.8382017120463 0 0)))"), null,{

label : "TEST", irregular: true, cursor:'pointer', fontSize: "14px", fontFamily: "arial, monospace", fontWeight: "bolder", labelAlign: "cm", fillColor: "#9fdaef", fillOpacity: 0.3, strokeWidth:4, strokeColor: "#005596" });

I'm getting an error like below

TypeError: a.geometry.getBounds is not a function in OpenLayers.js (line 611, col 334)

By using Multipolygon without height parameter i can able to load region data in Openlayers

but, with the height parameter i can't.

Please guide me to load wkt value with height parameter in Openlayers.

1

You can use ST_Force2D

ST_AsText(ST_Force2D(your_geometry_column))
from your_table;

Just try this to see the effect:

SELECT g,
      ST_AsText(ST_Force2D(g::geometry)),
      ST_AsEWKT(ST_Force2D(g::geometry))
      FROM ( SELECT
'MULTIPOLYGON ZM (((77.6620335903023 12.8381894855534 0 0,77.6620330917475 12.8384550503658 0 0,77.662583464913 12.8384554346975 0 0,77.6625831247336 12.8381894684868 0 0,77.66234257162 12.8381895285991 0 0,77.6622741102056 12.8381895459662 0 0,77.6620335903023 12.8381894855534 0 0)))'
::text as g ) as foo;

If you use this WKT you should be fine:

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.