Format.WKT.write method

3 messages Options
Embed this post
Permalink
Simon Cantem

Format.WKT.write method

Reply Threaded More More options
Print post
Permalink
Some javascript/style in this post has been disabled (why?)

I’ve been playing with the Format.WKT class recently and just have a query with the write method. I’m using it to convert the vector elements to WKT so that I can then post the form and easily save it into PostgreSQL (with PostGIS). I’ve noticed that unlike the other Format classes, it expects a either a geometry object or an array of geometry objects, the other Format classes (eg Format.GML and Format.WFS) expect a features array. The disadvantage of this is that you can’t just pass it the features property of the vector layer, and quickly convert it to WKT. I’ve made a change to my copy of /Format/WKT.js starting at line 67:

 

if(isCollection) {

if (i>0) {

pieces.push(',');

}

                geometry = collection[i].geometry;

} else {

geometry = collection[i];

}

 

The check for “isCollection” is so that the WKT example still works.

 

Is this a valid change or have I missed an easier way of doing this conversion?

 

Thanks,

Simon

 

------------------------------------------------------------------------------------------------

Simon Cantem

System Administrator / Analyst Programmer

CitySafe - www.citysafe.org


_______________________________________________
Users mailing list
[hidden email]
http://openlayers.org/mailman/listinfo/users
Tim Schaub-2

Re: Format.WKT.write method

Reply Threaded More More options
Print post
Permalink
Hey-

Simon Cantem wrote:
> ... I’ve noticed that unlike the other Format
> classes, it expects a either a geometry object or an array of geometry
> objects, the other Format classes (eg Format.GML and Format.WFS) expect
> a features array.

I agree.  This is weird.

Since WKT is about geometries (and doesn't have a place for feature
attributes), I made it read and write geometries (in the OpenLayers sense).

However, I agree that the serializer/deserializer should deal in
features - since people should seldom be dealing with geometries
(especially collections of geometry) in OpenLayers.

I've created a ticket and patch that changes the behavior of the WKT
format.  If approved, wkt.read() will return a feature or array of
features and wkt.write() will take a feature or array of features.

Let me know what you think,
Tim
_______________________________________________
Users mailing list
[hidden email]
http://openlayers.org/mailman/listinfo/users
Simon Cantem

Re: Format.WKT.write method

Reply Threaded More More options
Print post
Permalink
Hi Tim,

Yep that's exactly what I was thinking, and the patch works great.

Thanks,
Simon

-----Original Message-----
From: [hidden email] [mailto:[hidden email]]
On Behalf Of Tim Schaub
Sent: 17 May 2007 00:09
To: [hidden email]
Subject: Re: [OpenLayers-Users] Format.WKT.write method

Hey-

Simon Cantem wrote:
> ... I've noticed that unlike the other Format
> classes, it expects a either a geometry object or an array of geometry

> objects, the other Format classes (eg Format.GML and Format.WFS)
expect
> a features array.

I agree.  This is weird.

Since WKT is about geometries (and doesn't have a place for feature
attributes), I made it read and write geometries (in the OpenLayers
sense).

However, I agree that the serializer/deserializer should deal in
features - since people should seldom be dealing with geometries
(especially collections of geometry) in OpenLayers.

I've created a ticket and patch that changes the behavior of the WKT
format.  If approved, wkt.read() will return a feature or array of
features and wkt.write() will take a feature or array of features.

Let me know what you think,
Tim
_______________________________________________
Users mailing list
[hidden email]
http://openlayers.org/mailman/listinfo/users
_______________________________________________
Users mailing list
[hidden email]
http://openlayers.org/mailman/listinfo/users