Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

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?

share|improve this question
    
How are you getting/building the Geometry? From User interaction? or From GeoJSON/WKT? or something else? –  Devdatta Tengshe Jan 28 at 7:39
    
From user interaction –  Mohammed shafeek Jan 28 at 8:46
    
Please provide more information on how you are getting the geometry from the user. Please see this post on how you could improve this question: meta.gis.stackexchange.com/questions/3349/… –  Devdatta Tengshe Jan 28 at 9:25

2 Answers 2

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());
share|improve this answer

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.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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