1

How can I validate the geometry in Openlayers?

I need to check "MULTILINESTRING()" (which is empty) is valid/not valid. In postGIS, for Geometry validation we are using "isValid()" function. Like this, is there any options in Openlayers?

3

In OpenLayers you can't but you can use the excellent JavaScript Topology Suite (a Javascript rewrite of the Java Topology Suite).

Example:

  var reader = new jsts.io.WKTReader();
  var geom = reader.read('POLYGON ((80 300, 280 300, 280 80, 80 80, 80 300), (260 280, 180 200, 100 280, 100 100, 260 100, 260 280))');        
  console.log(geom.isValid());
  • do you know how to handle errors thrown if it's not a valid Polygon? – Alex Mar 29 '18 at 10:19
0

If you are using geodata through some form of GeoJson I can recommend this link;

http://geojsonlint.com/

It has an API that you can use as well, both python and javascript are explained on the website. With the api you are able to post a geojson and it will reply with a request status.

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.