Skip to content

Expose method for converting features to WKT and GeoJSON #172

@paul121

Description

@paul121

Similar to #171. Right now there is no way to return the geometry of feature(s) in a usable WKT or GeoJSON format unless using the edit behavior. You can get a simple array of coordinates for a feature using layer.getSource().getFeatureById(id).getGeometry().getCoordinates(); which is fine for Point geometries but less convenient for Polygon and other more complex geometries.

Because the edit control already has functions for this perhaps this could be easier to expose than my request in #171. I think the only consideration is if & how we export these functions and what impact it will have on the bundle size(s). I believe this would require including the openalyers WKT and GeoJSON classes which could be quite large.

WKT:

/**
* Getter that returns the geometry of all features in the drawing layer in
* Well Known Text (WKT) format.
* @api
*/
getWKT() {
return new WKT().writeFeatures(this.getFeatures(), projection);
}

GeoJson:
/**
* Getter that returns the geometry of all features in the drawing layer in
* GeoJSON format.
* @api
*/
getGeoJSON() {
const features = this.layer.getSource().getFeatures();
return new GeoJSON().writeFeatures(features, projection);
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions