-1

I have a web mapping application (using OpenLayers) that user can draw polygons in map interface and then the output WKT format create. Here is an example:

Shows the use of WKT (Well known text) to draw features in OpenLayers

How can I save this WKT polygons in PostGIS database?

host = localhost

enter image description here

closed as too broad by John Powell, user30184, Dan C, Mapperz Nov 4 '16 at 13:34

Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer. Avoid asking multiple distinct questions at once. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

  • Welcome to gis.stackexchange! Please note that a good question on this site is expected to show some degree of research on your part, i.e. what you have tried and - if applicable - code so far. For more info, you can check our faq. – underdark Nov 3 '16 at 20:24
  • 1
    With OpenLayers, you might want to check out this tutorial: boundlessgeo.com/2014/06/openlayers-editing-wfs-t seems like something you would be looking to implement... – DPSSpatial Nov 3 '16 at 20:25
2

Assuming that you already have a list of coordinates that describe your polygons, and also assuming you are using WGS84 projection then a simple query using ST_GeomFromEWKT should work:

INSERT INTO my_polygons (the_geom, ...) VALUES (ST_GeomFromEWKT('SRID=4326;POLYGON((75.15 29.53 1,77 29 1,77.6 29.5 1,75.15 29.53 1))'), ...);
  • Those are quite big assumptions. I think the OP is asking how to get the GeoJSON from the drawn polygon, how to transfer it to a server, rather that the syntax of an insert statement -- correct though that may be. – John Powell Nov 4 '16 at 11:01

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